This is an automated email from the ASF dual-hosted git repository.
vpyatkov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 52af924913 IGNITE-21634 Fixed NPE in HeapLockManager (#3375)
52af924913 is described below
commit 52af92491327c9596d705b224fb99b18f20d2f2d
Author: Denis Chudov <[email protected]>
AuthorDate: Fri Mar 15 15:52:51 2024 +0300
IGNITE-21634 Fixed NPE in HeapLockManager (#3375)
---
.../ignite/internal/tx/ItMultipleLocksTest.java | 54 ++++++++++++++++++++++
.../ignite/internal/tx/impl/HeapLockManager.java | 4 +-
2 files changed, 56 insertions(+), 2 deletions(-)
diff --git
a/modules/transactions/src/integrationTest/java/org/apache/ignite/internal/tx/ItMultipleLocksTest.java
b/modules/transactions/src/integrationTest/java/org/apache/ignite/internal/tx/ItMultipleLocksTest.java
new file mode 100644
index 0000000000..043409064e
--- /dev/null
+++
b/modules/transactions/src/integrationTest/java/org/apache/ignite/internal/tx/ItMultipleLocksTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.tx;
+
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.sql.Session;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test producing massive number of locks which can cause race conditions on
lock manager.
+ */
+public class ItMultipleLocksTest extends ClusterPerTestIntegrationTest {
+ @Override
+ protected int initialNodes() {
+ return 1;
+ }
+
+ @Test
+ void test() {
+ var node0 = runningNodes().findAny().orElseThrow();
+
+ try (Session session = node0.sql().createSession()) {
+ session.execute(null, "CREATE TABLE test("
+ + "c1 INT PRIMARY KEY, c2 INT, c3 INT, c4 INT, c5 INT,"
+ + "c6 INT, c7 INT, c8 INT, c9 INT, c10 INT)");
+
+ for (int i = 2; i <= 10; i++) {
+ session.execute(null, format("CREATE INDEX c{}_idx ON test
(c{})", i, i));
+ }
+
+ session.execute(null, "INSERT INTO test"
+ + " SELECT x as c1, x as c2, x as c3, x as c4, x as c5, "
+ + " x as c6, x as c7, x as c8, x as c9, x as c10"
+ + " FROM TABLE (system_range(1, 20000))");
+ }
+ }
+}
diff --git
a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/HeapLockManager.java
b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/HeapLockManager.java
index 298ef7df44..8c4cce4c10 100644
---
a/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/HeapLockManager.java
+++
b/modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/HeapLockManager.java
@@ -290,10 +290,10 @@ public class HeapLockManager extends
AbstractEventProducer<LockEvent, LockEventP
locks.compute(key, (k, v) -> {
if (v == null) {
- if (empty.isEmpty()) {
+ v = empty.poll();
+ if (v == null) {
res[0] = slots[index];
} else {
- v = empty.poll();
v.markedForRemove = false;
v.key = k;
res[0] = v;