zstan commented on code in PR #4762:
URL: https://github.com/apache/ignite-3/pull/4762#discussion_r1855926622


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItLocksSystemViewTest.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.sql.engine;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.await;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.emptyString;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.sql.BaseSqlIntegrationTest;
+import org.apache.ignite.internal.sql.engine.util.MetadataMatcher;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.internal.tx.Lock;
+import org.apache.ignite.internal.tx.LockMode;
+import org.apache.ignite.sql.ColumnType;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+/**
+ * End-to-end tests to verify {@code LOCKS} system view.
+ */
+public class ItLocksSystemViewTest extends BaseSqlIntegrationTest {
+    private Set<String> nodeNames;
+
+    private Set<String> lockModes;
+
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @BeforeAll
+    void beforeAll() {
+        await(systemViewManager().completeRegistration());
+
+        nodeNames = CLUSTER.runningNodes()
+                .map(Ignite::name)
+                .collect(Collectors.toSet());
+
+        lockModes = Arrays.stream(LockMode.values())
+                .map(Enum::name)
+                .collect(Collectors.toSet());
+    }
+
+    @Test
+    public void testMetadata() {
+        assertQuery("SELECT * FROM SYSTEM.LOCKS")
+                .columnMetadata(
+                        new 
MetadataMatcher().name("OWNING_NODE_ID").type(ColumnType.STRING).nullable(false),
+                        new 
MetadataMatcher().name("TX_ID").type(ColumnType.STRING).nullable(true),
+                        new 
MetadataMatcher().name("OBJECT_ID").type(ColumnType.STRING).nullable(true),
+                        new 
MetadataMatcher().name("MODE").type(ColumnType.STRING).nullable(true)
+                )
+                // RO tx doesn't take locks.
+                .returnNothing()
+                .check();
+    }
+
+    @Test
+    public void testData() {
+        Ignite node = CLUSTER.aliveNode();
+
+        sql("CREATE TABLE test (id INT PRIMARY KEY, val INT)");
+        sql("INSERT INTO test VALUES (0, 0), (2, 2)");
+
+        InternalTransaction tx1 = (InternalTransaction) 
node.transactions().begin();
+        InternalTransaction tx2 = (InternalTransaction) 
node.transactions().begin();
+        InternalTransaction tx3 = (InternalTransaction) 
node.transactions().begin();
+
+        try {
+            sql(tx1, "INSERT INTO test VALUES (1, 1)");
+            sql(tx2, "UPDATE test SET val = 1 WHERE id = 0");
+            sql(tx3, "DELETE FROM test WHERE id = 2");
+
+            List<List<Object>> rows = sql("SELECT * FROM SYSTEM.LOCKS");
+
+            List<Lock> locks = new ArrayList<>();
+
+            locks.addAll(activeLocks(tx1));
+            locks.addAll(activeLocks(tx2));
+            locks.addAll(activeLocks(tx3));
+
+            assertThat(rows.size(), is(locks.size()));
+
+            Set<String> expectedTxIds = Set.of(
+                    tx1.id().toString(),
+                    tx2.id().toString(),
+                    tx3.id().toString()
+            );
+
+            for (List<Object> row : rows) {
+                verifyLockInfo(row, expectedTxIds);
+            }
+        } finally {
+            tx1.rollback();
+            tx2.rollback();
+            tx3.rollback();
+        }
+    }
+
+    private void verifyLockInfo(List<Object> row, Set<String> expectedTxIds) {
+        int idx = 0;
+
+        String owningNode = (String) row.get(idx++);
+        String txId = (String) row.get(idx++);
+        String objectId = (String) row.get(idx++);
+        String mode = (String) row.get(idx);
+
+        assertThat(nodeNames, hasItem(owningNode));
+        assertThat(expectedTxIds, hasItem(txId));
+        assertThat(objectId, not(emptyString()));
+        assertThat(lockModes, hasItem(mode));
+    }
+
+    private List<Lock> activeLocks(InternalTransaction tx) {
+        List<Lock> res = new ArrayList<>();
+
+        CLUSTER.runningNodes().forEach(node -> unwrapIgniteImpl(node)
+                .txManager()
+                .lockManager()

Review Comment:
   deprecated API, use LockManager directly, honestly - i don\`t know how to 
make it properly, probably we need @TestOnly annotation here, need to discuss 
with tx team



##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -945,7 +944,7 @@ public class IgniteImpl implements Ignite {
 
         var transactionInflights = new 
TransactionInflights(placementDriverMgr.placementDriver(), clockService);
 
-        LockManager lockMgr = new HeapLockManager();
+        HeapLockManager lockMgr = new HeapLockManager();

Review Comment:
   revert it plz



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/HeapLockManager.java:
##########
@@ -251,22 +251,18 @@ public void releaseAll(UUID txId) {
         }
     }
 
+    @Override
+    public Iterator<Lock> locks() {

Review Comment:
   why do we need additional method if we can gather all txId and further call 
locks(UUID txId) for each ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to