sanpwc commented on code in PR #3467:
URL: https://github.com/apache/ignite-3/pull/3467#discussion_r1547824502
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -2632,8 +2635,8 @@ private CompletableFuture<CompletableFuture<?>>
applyUpdateCommand(
CompletableFuture<UUID> fut =
applyCmdWithExceptionHandling(cmd, new CompletableFuture<>())
.thenApply(res -> {
- // This check guaranties the result will never be
lost. Currently always null.
- assert res == null : "Replication result is lost";
+ // This check guaranties the result will never be
lost.
+ assert res != null : "Replication result is lost";
Review Comment:
Is there any sense in such asserts?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,19 +2233,13 @@ private ReplicaRequest upsertAllInternal(
* @param e Exception to check.
* @return True if retrying is possible, false otherwise.
*/
- private boolean isRestartTransactionPossible(Throwable e) {
- if (e instanceof LockException) {
- return true;
- } else if (e instanceof TransactionException && e.getCause()
instanceof LockException) {
- return true;
- } else if (e instanceof CompletionException && e.getCause() instanceof
LockException) {
- return true;
- } else if (e instanceof CompletionException
- && e.getCause() instanceof TransactionException
- && e.getCause().getCause() instanceof LockException) {
- return true;
+ private static boolean isRestartTransactionPossible(Throwable e) {
Review Comment:
Method is confusing. It's not possible to restart the transaction just
because there was a lock exception or PrimaryReplicaMiss. It's just on of
prerequisites.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -2646,8 +2649,14 @@ private CompletableFuture<CompletableFuture<?>>
applyUpdateCommand(
applyCmdWithExceptionHandling(cmd, resultFuture);
return resultFuture.thenApply(res -> {
- // This check guaranties the result will never be lost.
Currently always null.
- assert res == null : "Replication result is lost";
+ // This check guaranties the result will never be lost.
+ assert res != null : "Replication result is lost";
+
+ UpdateCommandResult updateCommandResult =
(UpdateCommandResult) res;
+
+ if (full &&
!updateCommandResult.isPrimaryReplicaSuccess()) {
Review Comment:
Why not to throw the exception if it's not full?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -258,10 +262,18 @@ public void
onWrite(Iterator<CommandClosure<WriteCommand>> iterator) {
* @param commandIndex Index of the RAFT command.
* @param commandTerm Term of the RAFT command.
*/
- private void handleUpdateCommand(UpdateCommand cmd, long commandIndex,
long commandTerm) {
+ private UpdateCommandResult handleUpdateCommand(UpdateCommand cmd, long
commandIndex, long commandTerm) {
// Skips the write command because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
- return;
+ return new UpdateCommandResult(true);
+ }
+
+ if (cmd.leaseStartTime() != null) {
+ long leaseStartTime = requireNonNull(cmd.leaseStartTime(),
"Inconsistent lease information in command [cmd=" + cmd + "].");
+
+ if (leaseStartTime != txStateStorage.leaseStartTime()) {
Review Comment:
Are we going to read from the storage on every command with !=null
leaseStartTime? Meaning retrieve page from the disk etc? I'd expect sort of
caching as a PartitionListener field and actual retrieval from storage only on
start. However, it's perfectly fine if such cashing is implemented on the
storage side.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -3447,6 +3462,12 @@ private CompletableFuture<Boolean>
ensureReplicaIsPrimary(ReplicaRequest request
);
}
+ synchronized (this) {
+ if (leaseStartTime <
primaryReplicaMeta.getStartTime().longValue()) {
Review Comment:
How do you guarantee that command will be filled with matched leaseStartTime
that was assosiated with the command on enusreReplicaIsPrimary? Meanging.
1. request1 -> ensureReplicaIsPrimary -> leaseStartTime = t0 -> lock -> hang
2. request2 -> ensureReplicaIsPrimary -> leaseStartTime = t100 -> ...
3. reqest1 -> wakes up -> command(t100)
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/UpdateCommandResult.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.tx;
+
+import java.io.Serializable;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Result for both update and update all commands.
+ */
+public class UpdateCommandResult implements Serializable {
+ private static final long serialVersionUID = 2213057546590681613L;
+
+ private final boolean primaryReplicaSuccess;
Review Comment:
Please rename, it's more like primaryReplica**Match**. And please explain
with javadoc, what does it really means.
--
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]