sanpwc commented on code in PR #5187: URL: https://github.com/apache/ignite-3/pull/5187#discussion_r1948994643
########## modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/TxFinishReplicaRequestHandler.java: ########## @@ -0,0 +1,337 @@ +/* + * 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.partition.replicator; + +import static java.util.concurrent.CompletableFuture.completedFuture; +import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; +import static org.apache.ignite.internal.replicator.message.ReplicaMessageUtils.toTablePartitionIdMessage; +import static org.apache.ignite.internal.tx.TxState.ABORTED; +import static org.apache.ignite.internal.tx.TxState.COMMITTED; +import static org.apache.ignite.internal.tx.TxState.isFinalState; +import static org.apache.ignite.lang.ErrorGroups.Transactions.TX_COMMIT_ERR; +import static org.apache.ignite.lang.ErrorGroups.Transactions.TX_ROLLBACK_ERR; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.catalog.CatalogService; +import org.apache.ignite.internal.hlc.ClockService; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessagesFactory; +import org.apache.ignite.internal.partition.replicator.network.command.FinishTxCommandBuilder; +import org.apache.ignite.internal.partition.replicator.raft.UnexpectedTransactionStateException; +import org.apache.ignite.internal.partition.replicator.schema.ValidationSchemasSource; +import org.apache.ignite.internal.partition.replicator.schemacompat.CompatValidationResult; +import org.apache.ignite.internal.partition.replicator.schemacompat.SchemaCompatibilityValidator; +import org.apache.ignite.internal.raft.service.RaftCommandRunner; +import org.apache.ignite.internal.replicator.ReplicationGroupId; +import org.apache.ignite.internal.replicator.TablePartitionId; +import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory; +import org.apache.ignite.internal.replicator.message.TablePartitionIdMessage; +import org.apache.ignite.internal.schema.SchemaSyncService; +import org.apache.ignite.internal.tx.IncompatibleSchemaAbortException; +import org.apache.ignite.internal.tx.MismatchingTransactionOutcomeInternalException; +import org.apache.ignite.internal.tx.TransactionResult; +import org.apache.ignite.internal.tx.TxManager; +import org.apache.ignite.internal.tx.TxMeta; +import org.apache.ignite.internal.tx.message.TxFinishReplicaRequest; +import org.apache.ignite.internal.tx.storage.state.TxStatePartitionStorage; +import org.apache.ignite.tx.TransactionException; +import org.jetbrains.annotations.Nullable; + +/** + * Handles {@link TxFinishReplicaRequest}. + */ +public class TxFinishReplicaRequestHandler { + private static final IgniteLogger LOG = Loggers.forClass(TxFinishReplicaRequestHandler.class); + + /** Factory to create RAFT command messages. */ + private static final PartitionReplicationMessagesFactory PARTITION_REPLICATION_MESSAGES_FACTORY = + new PartitionReplicationMessagesFactory(); + + /** Factory for creating replica command messages. */ + private static final ReplicaMessagesFactory REPLICA_MESSAGES_FACTORY = new ReplicaMessagesFactory(); + + private final TxStatePartitionStorage txStatePartitionStorage; + private final ClockService clockService; + private final TxManager txManager; + private final ReplicationGroupId replicationGroupId; + + private final SchemaCompatibilityValidator schemaCompatValidator; + private final ReliableCatalogVersions reliableCatalogVersions; + private final ReplicationRaftCommandApplicator raftCommandApplicator; + private final ReplicaTxFinisher replicaTxFinisher; + + + /** Constructor. */ + public TxFinishReplicaRequestHandler( + TxStatePartitionStorage txStatePartitionStorage, + ClockService clockService, + TxManager txManager, + ValidationSchemasSource validationSchemasSource, + SchemaSyncService schemaSyncService, + CatalogService catalogService, + RaftCommandRunner raftCommandRunner, + ReplicationGroupId replicationGroupId + ) { + this.txStatePartitionStorage = txStatePartitionStorage; + this.clockService = clockService; + this.txManager = txManager; + this.replicationGroupId = replicationGroupId; + + schemaCompatValidator = new SchemaCompatibilityValidator(validationSchemasSource, catalogService, schemaSyncService); + reliableCatalogVersions = new ReliableCatalogVersions(schemaSyncService, catalogService); + raftCommandApplicator = new ReplicationRaftCommandApplicator(raftCommandRunner, replicationGroupId); + replicaTxFinisher = new ReplicaTxFinisher(txManager); + } + + /** + * Processes transaction finish request. + * <ol> + * <li>Get commit timestamp from finish replica request.</li> + * <li>If attempting a commit, validate commit (and, if not valid, switch to abort)</li> + * <li>Run specific raft {@code FinishTxCommand} command, that will apply txn state to corresponding txStateStorage.</li> + * <li>Send cleanup requests to all enlisted primary replicas.</li> + * </ol> + * + * @param request Transaction finish request. + * @return future result of the operation. + */ + public CompletableFuture<TransactionResult> processTxFinishAction(TxFinishReplicaRequest request) { Review Comment: handle? -- 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