sk0x50 commented on code in PR #5276:
URL: https://github.com/apache/ignite-3/pull/5276#discussion_r1975236130


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/handlers/BuildIndexCommandHandler.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.raft.handlers;
+
+import static java.util.Objects.requireNonNull;
+import static 
org.apache.ignite.internal.table.distributed.index.MetaIndexStatus.BUILDING;
+import static 
org.apache.ignite.internal.table.distributed.index.MetaIndexStatus.REGISTERED;
+import static org.apache.ignite.internal.util.CollectionUtils.last;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Stream;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.lang.IgniteBiTuple;
+import org.apache.ignite.internal.lang.IgniteInternalException;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import 
org.apache.ignite.internal.partition.replicator.network.command.BuildIndexCommand;
+import 
org.apache.ignite.internal.partition.replicator.raft.handlers.AbstractCommandHandler;
+import 
org.apache.ignite.internal.partition.replicator.raft.snapshot.PartitionDataStorage;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.schema.BinaryRowUpgrader;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.schema.SchemaRegistry;
+import org.apache.ignite.internal.storage.BinaryRowAndRowId;
+import org.apache.ignite.internal.storage.MvPartitionStorage.Locker;
+import org.apache.ignite.internal.storage.RowId;
+import org.apache.ignite.internal.table.distributed.StorageUpdateHandler;
+import org.apache.ignite.internal.table.distributed.index.IndexMeta;
+import org.apache.ignite.internal.table.distributed.index.IndexMetaStorage;
+import 
org.apache.ignite.internal.table.distributed.index.MetaIndexStatusChange;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Raft command handler that process {@link BuildIndexCommand}.
+ */
+public class BuildIndexCommandHandler extends 
AbstractCommandHandler<BuildIndexCommand> {
+    private static final IgniteLogger LOG = 
Loggers.forClass(BuildIndexCommandHandler.class);
+
+    /** Data storage to which the command will be applied. */
+    private final PartitionDataStorage storage;
+
+    private final IndexMetaStorage indexMetaStorage;
+
+    /** Handler that processes storage updates. */
+    private final StorageUpdateHandler storageUpdateHandler;
+
+    private final SchemaRegistry schemaRegistry;
+
+    /**
+     * Creates a new instance of the command handler.
+     *
+     * @param storage Partition data storage.
+     * @param indexMetaStorage Index meta storage.
+     * @param storageUpdateHandler Storage update handler.
+     * @param schemaRegistry Schema registry.
+     */
+    public BuildIndexCommandHandler(
+            PartitionDataStorage storage,
+            IndexMetaStorage indexMetaStorage,
+            StorageUpdateHandler storageUpdateHandler,
+            SchemaRegistry schemaRegistry
+    ) {
+        this.storage = storage;
+        this.indexMetaStorage = indexMetaStorage;
+        this.storageUpdateHandler = storageUpdateHandler;
+        this.schemaRegistry = schemaRegistry;
+    }
+
+    @Override
+    protected IgniteBiTuple<Serializable, Boolean> handleInternally(
+            BuildIndexCommand command,
+            long commandIndex,
+            long commandTerm,
+            @Nullable HybridTimestamp safeTimestamp
+    ) throws IgniteInternalException {
+        // Skips the write command because the storage has already executed it.
+        if (commandIndex <= storage.lastAppliedIndex()) {
+            return new IgniteBiTuple<>(null, false);
+        }

Review Comment:
   Yes, I thought about it, but it doesn't seem to improve the readability of 
the code very much. I think we can come back to this a little later, when we 
implement all the handlers, for example.



-- 
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