You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "SammyVimes (via GitHub)" <gi...@apache.org> on 2023/04/10 13:45:22 UTC

[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #1892: IGNITE-19185 Fix index destruction after index creation started

SammyVimes commented on code in PR #1892:
URL: https://github.com/apache/ignite-3/pull/1892#discussion_r1161716057


##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuilder.java:
##########
@@ -133,71 +176,77 @@ private BuildIndexTask(
 
         @Override
         public void run() {
-            if (!busyLock.enterBusy()) {
-                return;
-            }
+            completedFuture(null)

Review Comment:
   The first action in the `thenCompose` callback creates a future, do we really need `completedFuture(null)` here? 😰



##########
modules/index/src/main/java/org/apache/ignite/internal/index/BuildIndexTaskId.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.index;
+
+import java.util.UUID;
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * ID of the index build task.
+ */
+class BuildIndexTaskId {
+    private final UUID tableId;
+
+    private final UUID indexId;
+
+    private final int partitionId;
+
+    BuildIndexTaskId(UUID tableId, UUID indexId, int partitionId) {
+        this.tableId = tableId;
+        this.indexId = indexId;
+        this.partitionId = partitionId;
+    }
+
+    UUID getTableId() {

Review Comment:
   I though we don't use `get` in getter names



##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuilder.java:
##########
@@ -133,71 +176,77 @@ private BuildIndexTask(
 
         @Override
         public void run() {

Review Comment:
   This future is really hard to read, maybe it can be somehow split into separate methods? I am afraid of it turning out like the TableManager



##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuilder.java:
##########
@@ -133,71 +176,77 @@ private BuildIndexTask(
 
         @Override
         public void run() {
-            if (!busyLock.enterBusy()) {
-                return;
-            }
+            completedFuture(null)
+                    .thenCompose(unused -> inBusyLock(() -> {
+                        // At the time of creating the index, we should have already waited for the table to be created and its raft of
+                        // clients (services) to start for all partitions, so there should be no errors.
+                        RaftGroupService raftGroupService = table.internalTable().partitionRaftGroupService(partitionId);
+
+                        return raftGroupService
+                                // We do not check the presence of nodes in the topology on purpose, so as not to get into races on
+                                // rebalancing, it will be more convenient and reliable for us to wait for a stable topology with a
+                                // chosen leader.

Review Comment:
   I don't get it, maybe you can paraphrase it somehow?



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java:
##########
@@ -468,4 +475,45 @@ public static void waitForIndex(String indexName) throws InterruptedException {
                 10_000)
         );
     }
+
+    /**
+     * Waits for the index to be built on all nodes.
+     *
+     * @param tableName Table name.
+     * @param indexName Index name.
+     * @throws Exception If failed.
+     */
+    public static void waitForIndexBuild(String tableName, String indexName) throws Exception {
+        // TODO: IGNITE-18733 We are waiting for the synchronization of schemes
+        for (Ignite clusterNode : CLUSTER_NODES) {
+            CompletableFuture<Table> tableFuture = clusterNode.tables().tableAsync(tableName);
+
+            assertThat(tableFuture, willCompleteSuccessfully());
+
+            TableImpl tableImpl = (TableImpl) tableFuture.join();
+
+            InternalTable internalTable = tableImpl.internalTable();
+
+            assertTrue(
+                    waitForCondition(() -> getIndexConfiguration(clusterNode, indexName) != null, 10, 10_000),
+                    String.format("node=%s, tableName=%s, indexName=%s", clusterNode.name(), tableName, indexName)
+            );
+
+            UUID indexId = getIndexConfiguration(clusterNode, indexName).id().value();
+
+            for (int partitionId = 0; partitionId < internalTable.partitions(); partitionId++) {
+                RaftGroupService raftGroupService = internalTable.partitionRaftGroupService(partitionId);
+
+                Stream<Peer> allPeers = Stream.concat(Stream.of(raftGroupService.leader()), raftGroupService.peers().stream());
+
+                if (allPeers.map(Peer::consistentId).noneMatch(clusterNode.name()::equals)) {

Review Comment:
   A comment would help here



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java:
##########
@@ -468,4 +475,45 @@ public static void waitForIndex(String indexName) throws InterruptedException {
                 10_000)
         );
     }
+
+    /**
+     * Waits for the index to be built on all nodes.
+     *
+     * @param tableName Table name.
+     * @param indexName Index name.
+     * @throws Exception If failed.
+     */
+    public static void waitForIndexBuild(String tableName, String indexName) throws Exception {
+        // TODO: IGNITE-18733 We are waiting for the synchronization of schemes
+        for (Ignite clusterNode : CLUSTER_NODES) {
+            CompletableFuture<Table> tableFuture = clusterNode.tables().tableAsync(tableName);
+
+            assertThat(tableFuture, willCompleteSuccessfully());
+
+            TableImpl tableImpl = (TableImpl) tableFuture.join();
+
+            InternalTable internalTable = tableImpl.internalTable();
+
+            assertTrue(
+                    waitForCondition(() -> getIndexConfiguration(clusterNode, indexName) != null, 10, 10_000),
+                    String.format("node=%s, tableName=%s, indexName=%s", clusterNode.name(), tableName, indexName)
+            );
+
+            UUID indexId = getIndexConfiguration(clusterNode, indexName).id().value();
+
+            for (int partitionId = 0; partitionId < internalTable.partitions(); partitionId++) {
+                RaftGroupService raftGroupService = internalTable.partitionRaftGroupService(partitionId);
+
+                Stream<Peer> allPeers = Stream.concat(Stream.of(raftGroupService.leader()), raftGroupService.peers().stream());
+
+                if (allPeers.map(Peer::consistentId).noneMatch(clusterNode.name()::equals)) {
+                    continue;
+                }
+
+                IndexStorage index = internalTable.storage().getOrCreateIndex(partitionId, indexId);
+
+                assertTrue(waitForCondition(() -> index.getNextRowIdToBuild() == null, 10, 10_000));

Review Comment:
   ```suggestion
                   assertTrue(waitForCondition(() -> index.getNextRowIdToBuild() == null, 10, TimeUnit.SECONDS.toMillis(10)));
   ```



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java:
##########
@@ -468,4 +475,45 @@ public static void waitForIndex(String indexName) throws InterruptedException {
                 10_000)
         );
     }
+
+    /**
+     * Waits for the index to be built on all nodes.
+     *
+     * @param tableName Table name.
+     * @param indexName Index name.
+     * @throws Exception If failed.
+     */
+    public static void waitForIndexBuild(String tableName, String indexName) throws Exception {
+        // TODO: IGNITE-18733 We are waiting for the synchronization of schemes
+        for (Ignite clusterNode : CLUSTER_NODES) {
+            CompletableFuture<Table> tableFuture = clusterNode.tables().tableAsync(tableName);
+
+            assertThat(tableFuture, willCompleteSuccessfully());
+
+            TableImpl tableImpl = (TableImpl) tableFuture.join();
+
+            InternalTable internalTable = tableImpl.internalTable();
+
+            assertTrue(
+                    waitForCondition(() -> getIndexConfiguration(clusterNode, indexName) != null, 10, 10_000),

Review Comment:
   ```suggestion
                       waitForCondition(() -> getIndexConfiguration(clusterNode, indexName) != null, 10, TimeUnit.SECONDS.toMillis(10)),
   ```



##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuilder.java:
##########
@@ -272,5 +325,50 @@ private List<RowId> collectRowIdBatch(RowId nextRowIdToBuild) {
 
             return createBatchRowIds(nextRowIdToBuild, BUILD_INDEX_ROW_ID_BATCH_SIZE);
         }
+
+        private boolean enterBusy() {
+            if (!taskBusyLock.enterBusy()) {

Review Comment:
   Can't we use one `busyLock` for tasks?



##########
modules/index/src/main/java/org/apache/ignite/internal/index/IndexBuilder.java:
##########
@@ -133,71 +176,77 @@ private BuildIndexTask(
 
         @Override
         public void run() {
-            if (!busyLock.enterBusy()) {
-                return;
-            }
+            completedFuture(null)
+                    .thenCompose(unused -> inBusyLock(() -> {
+                        // At the time of creating the index, we should have already waited for the table to be created and its raft of
+                        // clients (services) to start for all partitions, so there should be no errors.

Review Comment:
   probably something like
   ```suggestion
                           // At the time of index creation, table and raft services of all partitions 
                           // should be already started, so there should be no errors.
   ```



-- 
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-unsubscribe@ignite.apache.org

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