tkalkirill commented on code in PR #2030:
URL: https://github.com/apache/ignite-3/pull/2030#discussion_r1197610004


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/index/IndexBuildTask.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.table.distributed.index;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static java.util.concurrent.CompletableFuture.supplyAsync;
+import static java.util.stream.Collectors.toList;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Function;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.raft.service.RaftGroupService;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.RowId;
+import org.apache.ignite.internal.storage.index.IndexStorage;
+import org.apache.ignite.internal.table.distributed.TableMessagesFactory;
+import org.apache.ignite.internal.table.distributed.command.BuildIndexCommand;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.lang.IgniteStringFormatter;
+
+/**
+ * Task of building a table index.
+ */
+class IndexBuildTask {
+    private static final IgniteLogger LOG = 
Loggers.forClass(IndexBuildTask.class);
+
+    private static final TableMessagesFactory TABLE_MESSAGES_FACTORY = new 
TableMessagesFactory();
+
+    private final IndexBuildTaskId taskId;
+
+    private final IndexStorage indexStorage;
+
+    private final MvPartitionStorage partitionStorage;
+
+    private final RaftGroupService raftClient;
+
+    private final ExecutorService executor;
+
+    private final IgniteSpinBusyLock busyLock;
+
+    private final int batchSize;
+
+    private final IgniteSpinBusyLock taskBusyLock = new IgniteSpinBusyLock();
+
+    private final AtomicBoolean taskStopGuard = new AtomicBoolean();
+
+    private final CompletableFuture<Void> taskFuture = new 
CompletableFuture<>();
+
+    IndexBuildTask(
+            IndexBuildTaskId taskId,
+            IndexStorage indexStorage,
+            MvPartitionStorage partitionStorage,
+            RaftGroupService raftClient,
+            ExecutorService executor,
+            IgniteSpinBusyLock busyLock,
+            int batchSize
+    ) {
+        this.taskId = taskId;
+        this.indexStorage = indexStorage;
+        this.partitionStorage = partitionStorage;
+        this.raftClient = raftClient;
+        this.executor = executor;
+        this.busyLock = busyLock;
+        this.batchSize = batchSize;
+    }
+
+    /**
+     * Starts building the index.
+     */
+    void start() {
+        if (!enterBusy()) {
+            taskFuture.complete(null);
+
+            return;
+        }
+
+        LOG.info("Start building the index: [{}]", getCommonIndexInfo());
+
+        try {
+            supplyAsync(this::handleNextBatch, executor)

Review Comment:
   I would not like to load a thread that will start building the index, so I 
think it's right to do it in a separate pool.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to