rpuch commented on code in PR #7590:
URL: https://github.com/apache/ignite-3/pull/7590#discussion_r2804585182


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/handlers/BuildIndexCommandHandler.java:
##########
@@ -107,13 +108,31 @@ protected CommandResult handleInternally(
 
         if (indexMeta == null || indexMeta.isDropped()) {
             // Index has been dropped.
-
-            storage.runConsistently(locker -> {
+            return storage.runConsistently(locker -> {
                 storage.lastApplied(commandIndex, commandTerm);
-                return null;
+
+                return EMPTY_APPLIED_RESULT;
             });
+        }
+
+        IndexUpdateHandler indexUpdateHandler = 
storageUpdateHandler.getIndexUpdateHandler();
 
-            return EMPTY_APPLIED_RESULT;
+        RowId previousNextRowIdToBuild = 
indexUpdateHandler.getNextRowIdToBuildIndex(command.indexId());
+        if (previousNextRowIdToBuild == null) {
+            // Index is already built. This command either repeats the final 
batch, or it is one of the previous commands that's been
+            // processed out of order for some reason.
+            if (command.finish()) {
+                logCommandDuplication(command);
+            } else {
+                // TODO: https://issues.apache.org/jira/browse/IGNITE-27844
+                logCommandReordering(command);
+            }
+
+            return storage.runConsistently(locker -> {

Review Comment:
   What if we don't skip such duplicated/reordered commands completely, but 
instead execute them in a safe idempotent way (put data to index, but don't 
update nextRowToBuild)?



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/handlers/BuildIndexCommandHandler.java:
##########
@@ -107,13 +108,31 @@ protected CommandResult handleInternally(
 
         if (indexMeta == null || indexMeta.isDropped()) {
             // Index has been dropped.
-
-            storage.runConsistently(locker -> {
+            return storage.runConsistently(locker -> {
                 storage.lastApplied(commandIndex, commandTerm);
-                return null;
+
+                return EMPTY_APPLIED_RESULT;
             });
+        }
+
+        IndexUpdateHandler indexUpdateHandler = 
storageUpdateHandler.getIndexUpdateHandler();
 
-            return EMPTY_APPLIED_RESULT;
+        RowId previousNextRowIdToBuild = 
indexUpdateHandler.getNextRowIdToBuildIndex(command.indexId());
+        if (previousNextRowIdToBuild == null) {
+            // Index is already built. This command either repeats the final 
batch, or it is one of the previous commands that's been
+            // processed out of order for some reason.
+            if (command.finish()) {
+                logCommandDuplication(command);
+            } else {
+                // TODO: https://issues.apache.org/jira/browse/IGNITE-27844
+                logCommandReordering(command);

Review Comment:
   If I understand correctly, this can only happen due to retries, so we will 
not get an incomplete index because we skip application of this command. Could 
you please add a comment about this?



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