sanpwc commented on code in PR #5197: URL: https://github.com/apache/ignite-3/pull/5197#discussion_r1948872367
########## modules/catalog-compaction/src/main/java/org/apache/ignite/internal/catalog/compaction/CatalogCompactionRunner.java: ########## @@ -403,10 +412,11 @@ CompletableFuture<Void> propagateTimeToLocalReplicas(long txBeginTime) { return schemaSyncService.waitForMetadataCompleteness(nowTs) .thenComposeAsync(ignore -> { - Int2IntMap tablesWithPartitions = - catalogManagerFacade.collectTablesWithPartitionsBetween(txBeginTime, nowTs.longValue()); + Int2IntMap idsWithPartitions = enabledColocationFeature + ? catalogManagerFacade.collectZonesWithPartitionsBetween(txBeginTime, nowTs.longValue()) + : catalogManagerFacade.collectTablesWithPartitionsBetween(txBeginTime, nowTs.longValue()); - ObjectIterator<Entry> itr = tablesWithPartitions.int2IntEntrySet().iterator(); + ObjectIterator<Entry> itr = idsWithPartitions.int2IntEntrySet().iterator(); Review Comment: It's ids because currently it's both table's and zone's ids depending on the feature flag, right? ########## modules/catalog-compaction/src/main/java/org/apache/ignite/internal/catalog/compaction/CatalogManagerCompactionFacade.java: ########## @@ -38,6 +38,7 @@ class CatalogManagerCompactionFacade { this.catalogManager = catalogManager; } + // TODO https://issues.apache.org/jira/browse/IGNITE-22115 Remove this method. Review Comment: I'd rather add https://issues.apache.org/jira/browse/IGNITE-22522 instead of epic. ########## modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZonePartitionReplicaListener.java: ########## @@ -17,95 +17,209 @@ package org.apache.ignite.internal.partition.replicator; +import static java.util.concurrent.CompletableFuture.completedFuture; import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeoutException; import java.util.function.Function; +import org.apache.ignite.internal.hlc.ClockService; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.lang.IgniteBiTuple; import org.apache.ignite.internal.logger.IgniteLogger; import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.partition.replicator.handlers.MinimumActiveTxTimeReplicaRequestHandler; +import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessagesFactory; +import org.apache.ignite.internal.partition.replicator.network.replication.ReadOnlyReplicaRequest; +import org.apache.ignite.internal.partition.replicator.network.replication.ReadWriteReplicaRequest; +import org.apache.ignite.internal.partition.replicator.network.replication.UpdateMinimumActiveTxBeginTimeReplicaRequest; +import org.apache.ignite.internal.raft.Command; import org.apache.ignite.internal.raft.service.RaftCommandRunner; import org.apache.ignite.internal.replicator.ReplicaResult; import org.apache.ignite.internal.replicator.ReplicationGroupId; import org.apache.ignite.internal.replicator.TablePartitionId; import org.apache.ignite.internal.replicator.ZonePartitionId; +import org.apache.ignite.internal.replicator.exception.ReplicationException; +import org.apache.ignite.internal.replicator.exception.ReplicationTimeoutException; import org.apache.ignite.internal.replicator.listener.ReplicaListener; +import org.apache.ignite.internal.replicator.message.ReadOnlyDirectReplicaRequest; import org.apache.ignite.internal.replicator.message.ReplicaRequest; +import org.apache.ignite.internal.replicator.message.SchemaVersionAwareReplicaRequest; import org.apache.ignite.internal.replicator.message.TableAware; +import org.apache.ignite.internal.tx.TransactionIds; import org.apache.ignite.internal.tx.message.TxFinishReplicaRequest; import org.apache.ignite.internal.tx.message.TxMessagesFactory; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.VisibleForTesting; /** * Zone partition replica listener. */ public class ZonePartitionReplicaListener implements ReplicaListener { + private static final IgniteLogger LOG = Loggers.forClass(ZonePartitionReplicaListener.class); + private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory(); - private static final IgniteLogger LOG = Loggers.forClass(ZonePartitionReplicaListener.class); + /** Factory to create RAFT command messages. */ + private static final PartitionReplicationMessagesFactory PARTITION_REPLICATION_MESSAGES_FACTORY = + new PartitionReplicationMessagesFactory(); // TODO: https://issues.apache.org/jira/browse/IGNITE-22624 await for the table replica listener if needed. private final Map<TablePartitionId, ReplicaListener> replicas = new ConcurrentHashMap<>(); + /** Raft client. */ private final RaftCommandRunner raftClient; + /** Clock service. */ + private final ClockService clockService; + + // TODO Probably the list of handlers should be moved to a map or something appropriate. + // Handler for minimum active tx time request. + private final MinimumActiveTxTimeReplicaRequestHandler minimumActiveTxTimeReplicaRequestHandler; + + /** Zone replication group id. */ + ZonePartitionId replicationGroupId; + /** * The constructor. * + * @param replicationGroupId Zone replication group identifier. + * @param clockService Clock service. * @param raftClient Raft client. */ - public ZonePartitionReplicaListener(RaftCommandRunner raftClient) { + public ZonePartitionReplicaListener( + ZonePartitionId replicationGroupId, + ClockService clockService, + RaftCommandRunner raftClient) { + this.replicationGroupId = replicationGroupId; + this.clockService = clockService; this.raftClient = raftClient; + + // Request handlers initialization. + minimumActiveTxTimeReplicaRequestHandler = new MinimumActiveTxTimeReplicaRequestHandler( + PARTITION_REPLICATION_MESSAGES_FACTORY, + clockService, + this::applyCmdWithExceptionHandling + ); } @Override public CompletableFuture<ReplicaResult> invoke(ReplicaRequest request, UUID senderId) { Review Comment: I've expected that you will copy ``` return ensureReplicaIsPrimary(request) .thenCompose(res -> processRequest(request, res.get1(), senderId, res.get2())) .thenApply(res -> { if (res instanceof ReplicaResult) { return (ReplicaResult) res; } else { return new ReplicaResult(res, null); } }); ``` With empty ensureReplicaIsPrimary. Anyway let's wait for https://github.com/apache/ignite-3/pull/5187. There are too many clashes for now. ########## modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/handlers/MinimumActiveTxTimeReplicaRequestHandler.java: ########## @@ -0,0 +1,73 @@ +/* + * 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.handlers; + +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; +import org.apache.ignite.internal.hlc.ClockService; +import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessagesFactory; +import org.apache.ignite.internal.partition.replicator.network.replication.UpdateMinimumActiveTxBeginTimeReplicaRequest; +import org.apache.ignite.internal.raft.Command; + +/** + * Handler for {@link org.apache.ignite.internal.partition.replicator.network.replication.UpdateMinimumActiveTxBeginTimeReplicaRequest}. + */ +public class MinimumActiveTxTimeReplicaRequestHandler { + /** Factory to create RAFT command messages. */ + private final PartitionReplicationMessagesFactory partitionReplicationMessageFactory; + + /** Closure that applies RAFT command message that is created by this handler. */ + private final Function<Command, CompletableFuture<?>> commandProcessor; + + /** Clock service. */ + private final ClockService clockService; + + /** + * Creates a new instance of MinimumActiveTxTimeReplicaRequestHandler. + * + * @param messageFactory Factory to create RAFT command messages. + * @param clockService Clock service. + * @param commandProcessor Closure that applies RAFT command message. + */ + public MinimumActiveTxTimeReplicaRequestHandler( + PartitionReplicationMessagesFactory messageFactory, + ClockService clockService, + Function<Command, CompletableFuture<?>> commandProcessor + ) { + this.partitionReplicationMessageFactory = messageFactory; + this.clockService = clockService; + this.commandProcessor = commandProcessor; + } + + /** + * Handles {@link org.apache.ignite.internal.partition.replicator.network.replication.UpdateMinimumActiveTxBeginTimeReplicaRequest}. + * + * @param request Request to handle. + * @return Future that will be completed when the request is handled. + */ + public CompletableFuture<?> handle(UpdateMinimumActiveTxBeginTimeReplicaRequest request) { + Command cmd = partitionReplicationMessageFactory.updateMinimumActiveTxBeginTimeCommand() + .timestamp(request.timestamp()) + .initiatorTime(clockService.now()) + .build(); + + // The timestamp must increase monotonically, otherwise it will have to be + // stored on disk so that reordering does not occur after the node is restarted. + return commandProcessor.apply(cmd); Review Comment: I guess you will need to use ReplicationRaftCommandApplicator from https://github.com/apache/ignite-3/pull/5187/files#diff-6397becb8896f2a259931efbaf51b1d352f12923b707319b6cee2e61d2443805 -- 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