sanpwc commented on code in PR #2877: URL: https://github.com/apache/ignite-3/pull/2877#discussion_r1419073033
########## modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxUnlockRequestSender.java: ########## @@ -0,0 +1,171 @@ +/* + * 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.impl; + +import static java.util.concurrent.CompletableFuture.allOf; +import static org.apache.ignite.internal.hlc.HybridTimestamp.hybridTimestampToLong; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.hlc.HybridClock; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.replicator.ReplicationGroupId; +import org.apache.ignite.internal.replicator.TablePartitionId; +import org.apache.ignite.internal.tx.impl.TxManagerImpl.TransactionFailureHandler; +import org.apache.ignite.internal.tx.message.LockReleaseMessage; +import org.apache.ignite.internal.tx.message.TxMessagesFactory; +import org.apache.ignite.internal.util.CompletableFutures; +import org.apache.ignite.network.ClusterService; +import org.jetbrains.annotations.Nullable; + +/** + * Sends TX Unlock request. + */ +public class TxUnlockRequestSender { + + /** Network timeout. */ + private static final long RPC_TIMEOUT = 3000; + + /** Tx messages factory. */ + private static final TxMessagesFactory FACTORY = new TxMessagesFactory(); + + /** Cluster service. */ + private final ClusterService clusterService; + + /** Placement driver helper. */ + private final PlacementDriverHelper placementDriverHelper; + + /** Hybrid clock. */ + private final HybridClock hybridClock; + + /** Cleanup processor. */ + private final TxCleanupProcessor txCleanupProcessor; + + /** + * The constructor. + * + * @param clusterService Cluster service. + * @param placementDriverHelper Placement driver helper. + * @param clock A hybrid logical clock. + * @param txCleanupProcessor A cleanup processor. + */ + public TxUnlockRequestSender( + ClusterService clusterService, + PlacementDriverHelper placementDriverHelper, + HybridClock clock, + TxCleanupProcessor txCleanupProcessor) { + this.clusterService = clusterService; + this.placementDriverHelper = placementDriverHelper; + this.hybridClock = clock; + this.txCleanupProcessor = txCleanupProcessor; + } + + /** + * Sends unlock request to the primary nodes of each one of {@code partitions}. + * + * @param partitions Enlisted partition groups. + * @param commit {@code true} if a commit requested. + * @param commitTimestamp Commit timestamp ({@code null} if it's an abort). + * @param txId Transaction id. + * @return Completable future of Void. + */ + public CompletableFuture<Void> unlock( + Collection<TablePartitionId> partitions, + boolean commit, + @Nullable HybridTimestamp commitTimestamp, + UUID txId + ) { + return placementDriverHelper.findPrimaryReplicas(partitions, hybridClock.now()) + .thenCompose(partitionData -> { + durableCleanupPartitionsWithNoPrimary(commit, commitTimestamp, txId, partitionData.partitionsWithoutPrimary); + + return unlockPartitions(partitionData.partitionsByNode, commit, commitTimestamp, txId); + }); + } + + private void durableCleanupPartitionsWithNoPrimary( + boolean commit, + @Nullable HybridTimestamp commitTimestamp, + UUID txId, + Set<TablePartitionId> noPrimaryFound + ) { + if (!noPrimaryFound.isEmpty()) { Review Comment: > no concerns regarding excess memory usage. Curios whether it really matters. Is it a best pattern by default or there was a benchmark? ########## modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxUnlockRequestSender.java: ########## @@ -0,0 +1,171 @@ +/* + * 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.impl; + +import static java.util.concurrent.CompletableFuture.allOf; +import static org.apache.ignite.internal.hlc.HybridTimestamp.hybridTimestampToLong; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import org.apache.ignite.internal.hlc.HybridClock; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.replicator.ReplicationGroupId; +import org.apache.ignite.internal.replicator.TablePartitionId; +import org.apache.ignite.internal.tx.impl.TxManagerImpl.TransactionFailureHandler; +import org.apache.ignite.internal.tx.message.LockReleaseMessage; +import org.apache.ignite.internal.tx.message.TxMessagesFactory; +import org.apache.ignite.internal.util.CompletableFutures; +import org.apache.ignite.network.ClusterService; +import org.jetbrains.annotations.Nullable; + +/** + * Sends TX Unlock request. + */ +public class TxUnlockRequestSender { + + /** Network timeout. */ + private static final long RPC_TIMEOUT = 3000; + + /** Tx messages factory. */ + private static final TxMessagesFactory FACTORY = new TxMessagesFactory(); + + /** Cluster service. */ + private final ClusterService clusterService; + + /** Placement driver helper. */ + private final PlacementDriverHelper placementDriverHelper; + + /** Hybrid clock. */ + private final HybridClock hybridClock; + + /** Cleanup processor. */ + private final TxCleanupProcessor txCleanupProcessor; + + /** + * The constructor. + * + * @param clusterService Cluster service. + * @param placementDriverHelper Placement driver helper. + * @param clock A hybrid logical clock. + * @param txCleanupProcessor A cleanup processor. + */ + public TxUnlockRequestSender( + ClusterService clusterService, + PlacementDriverHelper placementDriverHelper, + HybridClock clock, + TxCleanupProcessor txCleanupProcessor) { + this.clusterService = clusterService; + this.placementDriverHelper = placementDriverHelper; + this.hybridClock = clock; + this.txCleanupProcessor = txCleanupProcessor; + } + + /** + * Sends unlock request to the primary nodes of each one of {@code partitions}. + * + * @param partitions Enlisted partition groups. + * @param commit {@code true} if a commit requested. + * @param commitTimestamp Commit timestamp ({@code null} if it's an abort). + * @param txId Transaction id. + * @return Completable future of Void. + */ + public CompletableFuture<Void> unlock( + Collection<TablePartitionId> partitions, + boolean commit, + @Nullable HybridTimestamp commitTimestamp, + UUID txId + ) { + return placementDriverHelper.findPrimaryReplicas(partitions, hybridClock.now()) + .thenCompose(partitionData -> { + durableCleanupPartitionsWithNoPrimary(commit, commitTimestamp, txId, partitionData.partitionsWithoutPrimary); + + return unlockPartitions(partitionData.partitionsByNode, commit, commitTimestamp, txId); + }); + } + + private void durableCleanupPartitionsWithNoPrimary( + boolean commit, + @Nullable HybridTimestamp commitTimestamp, + UUID txId, + Set<TablePartitionId> noPrimaryFound + ) { + if (!noPrimaryFound.isEmpty()) { Review Comment: > no concerns regarding excess memory usage. Curios whether it really matters. Is it a best pattern by default or there was a benchmark? -- 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]
