rpuch commented on code in PR #5134:
URL: https://github.com/apache/ignite-3/pull/5134#discussion_r1936812788
##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionRaftListener.java:
##########
@@ -51,47 +70,121 @@ public void onRead(Iterator<CommandClosure<ReadCommand>>
iterator) {
@Override
public void onWrite(Iterator<CommandClosure<WriteCommand>> iterator) {
- iterator.forEachRemaining((CommandClosure<? extends WriteCommand> clo)
-> {
- Command command = clo.command();
-
- Serializable result = null;
-
+ iterator.forEachRemaining(clo -> {
try {
- if (command instanceof FinishTxCommand) {
- FinishTxCommand cmd = (FinishTxCommand) command;
-
- result = new TransactionResult(cmd.commit() ? COMMITTED :
ABORTED, cmd.commitTimestamp());
- } else {
- LOG.debug("Message type " + command.getClass() + " is not
supported by the zone partition RAFT listener yet");
- }
+ processWriteCommand(clo);
} catch (Throwable t) {
LOG.error(
"Unknown error while processing command
[commandIndex={}, commandTerm={}, command={}]",
t,
- clo.index(), clo.index(), command
+ clo.index(), clo.index(), clo.command()
);
clo.result(t);
throw t;
}
-
- clo.result(result);
});
}
+ private void processWriteCommand(CommandClosure<WriteCommand> clo) {
+ Command command = clo.command();
+
+ if (command instanceof FinishTxCommand) {
+ FinishTxCommand cmd = (FinishTxCommand) command;
+
+ clo.result(new TransactionResult(cmd.commit() ? COMMITTED :
ABORTED, cmd.commitTimestamp()));
+ } else if (command instanceof PrimaryReplicaChangeCommand) {
+ // This is a hack for tests, this command is not issued in
production because no zone-wide placement driver exists yet.
+ CommandClosure<WriteCommand> idempotentCommandClosure =
idempotentCommandClosure(clo);
+
+ tablePartitionRaftListeners.values().forEach(listener ->
listener.onWrite(singletonIterator(idempotentCommandClosure)));
+
+ clo.result(null);
+ } else if (command instanceof UpdateCommand) {
+ TablePartitionId tablePartitionId = ((UpdateCommand)
command).tablePartitionId().asTablePartitionId();
+
+ processTableSpecificCommand(tablePartitionId, clo);
+ } else if (command instanceof UpdateAllCommand) {
+ TablePartitionId tablePartitionId = ((UpdateAllCommand)
command).tablePartitionId().asTablePartitionId();
+
+ processTableSpecificCommand(tablePartitionId, clo);
+ } else {
+ LOG.info("Message type " + command.getClass() + " is not supported
by the zone partition RAFT listener yet");
Review Comment:
Should this be a WARN?
##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionRaftListener.java:
##########
@@ -51,47 +70,121 @@ public void onRead(Iterator<CommandClosure<ReadCommand>>
iterator) {
@Override
public void onWrite(Iterator<CommandClosure<WriteCommand>> iterator) {
- iterator.forEachRemaining((CommandClosure<? extends WriteCommand> clo)
-> {
- Command command = clo.command();
-
- Serializable result = null;
-
+ iterator.forEachRemaining(clo -> {
try {
- if (command instanceof FinishTxCommand) {
- FinishTxCommand cmd = (FinishTxCommand) command;
-
- result = new TransactionResult(cmd.commit() ? COMMITTED :
ABORTED, cmd.commitTimestamp());
- } else {
- LOG.debug("Message type " + command.getClass() + " is not
supported by the zone partition RAFT listener yet");
- }
+ processWriteCommand(clo);
} catch (Throwable t) {
LOG.error(
"Unknown error while processing command
[commandIndex={}, commandTerm={}, command={}]",
t,
- clo.index(), clo.index(), command
+ clo.index(), clo.index(), clo.command()
);
clo.result(t);
throw t;
}
-
- clo.result(result);
});
}
+ private void processWriteCommand(CommandClosure<WriteCommand> clo) {
+ Command command = clo.command();
+
+ if (command instanceof FinishTxCommand) {
+ FinishTxCommand cmd = (FinishTxCommand) command;
+
+ clo.result(new TransactionResult(cmd.commit() ? COMMITTED :
ABORTED, cmd.commitTimestamp()));
+ } else if (command instanceof PrimaryReplicaChangeCommand) {
+ // This is a hack for tests, this command is not issued in
production because no zone-wide placement driver exists yet.
+ CommandClosure<WriteCommand> idempotentCommandClosure =
idempotentCommandClosure(clo);
+
+ tablePartitionRaftListeners.values().forEach(listener ->
listener.onWrite(singletonIterator(idempotentCommandClosure)));
+
+ clo.result(null);
+ } else if (command instanceof UpdateCommand) {
+ TablePartitionId tablePartitionId = ((UpdateCommand)
command).tablePartitionId().asTablePartitionId();
+
+ processTableSpecificCommand(tablePartitionId, clo);
+ } else if (command instanceof UpdateAllCommand) {
+ TablePartitionId tablePartitionId = ((UpdateAllCommand)
command).tablePartitionId().asTablePartitionId();
+
+ processTableSpecificCommand(tablePartitionId, clo);
+ } else {
+ LOG.info("Message type " + command.getClass() + " is not supported
by the zone partition RAFT listener yet");
+
+ clo.result(null);
+ }
+ }
+
+ private void processTableSpecificCommand(TablePartitionId
tablePartitionId, CommandClosure<WriteCommand> clo) {
+
tablePartitionRaftListeners.get(tablePartitionId).onWrite(singletonIterator(clo));
+ }
+
+ private static <T> Iterator<T> singletonIterator(T value) {
+ return Collections.singleton(value).iterator();
+ }
+
+ private static CommandClosure<WriteCommand>
idempotentCommandClosure(CommandClosure<WriteCommand> clo) {
Review Comment:
It seems that this is a 'no-result-propagating' closure. Why is it called
idempotent?
##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionRaftListener.java:
##########
@@ -51,47 +70,121 @@ public void onRead(Iterator<CommandClosure<ReadCommand>>
iterator) {
@Override
public void onWrite(Iterator<CommandClosure<WriteCommand>> iterator) {
- iterator.forEachRemaining((CommandClosure<? extends WriteCommand> clo)
-> {
- Command command = clo.command();
-
- Serializable result = null;
-
+ iterator.forEachRemaining(clo -> {
try {
- if (command instanceof FinishTxCommand) {
- FinishTxCommand cmd = (FinishTxCommand) command;
-
- result = new TransactionResult(cmd.commit() ? COMMITTED :
ABORTED, cmd.commitTimestamp());
- } else {
- LOG.debug("Message type " + command.getClass() + " is not
supported by the zone partition RAFT listener yet");
- }
+ processWriteCommand(clo);
} catch (Throwable t) {
LOG.error(
"Unknown error while processing command
[commandIndex={}, commandTerm={}, command={}]",
t,
- clo.index(), clo.index(), command
+ clo.index(), clo.index(), clo.command()
);
clo.result(t);
throw t;
}
-
- clo.result(result);
});
}
+ private void processWriteCommand(CommandClosure<WriteCommand> clo) {
+ Command command = clo.command();
+
+ if (command instanceof FinishTxCommand) {
+ FinishTxCommand cmd = (FinishTxCommand) command;
+
+ clo.result(new TransactionResult(cmd.commit() ? COMMITTED :
ABORTED, cmd.commitTimestamp()));
+ } else if (command instanceof PrimaryReplicaChangeCommand) {
+ // This is a hack for tests, this command is not issued in
production because no zone-wide placement driver exists yet.
Review Comment:
Don't we need a TODO here to remove the hack later?
--
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]