Cyrill commented on code in PR #2832: URL: https://github.com/apache/ignite-3/pull/2832#discussion_r1392523375
########## modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/OrphanDetector.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.completedFuture; +import static java.util.concurrent.CompletableFuture.failedFuture; +import static java.util.concurrent.TimeUnit.SECONDS; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.ignite.internal.hlc.HybridClock; +import org.apache.ignite.internal.lang.NodeStoppingException; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.placementdriver.PlacementDriver; +import org.apache.ignite.internal.tx.TxStateMeta; +import org.apache.ignite.internal.tx.message.TxMessagesFactory; +import org.apache.ignite.internal.tx.message.TxRecoveryMessage; +import org.apache.ignite.internal.util.IgniteSpinBusyLock; +import org.apache.ignite.network.ClusterNode; +import org.apache.ignite.network.ClusterService; + +/** + * The class detects transactions that are left without a coordinator but still hold locks. For that orphan transaction, the recovery + * message is sent to the commit partition replication group. + */ +public class OrphanDetector { + /** The logger. */ + private static final IgniteLogger LOG = Loggers.forClass(OrphanDetector.class); + + /** Tx messages factory. */ + private static final TxMessagesFactory FACTORY = new TxMessagesFactory(); + + private static final long AWAIT_PRIMARY_REPLICA_TIMEOUT_SEC = 10; + + /** Busy lock to stop synchronously. */ + private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock(); + + /** Cluster service. */ + private final ClusterService clusterService; + + private final PlacementDriver placementDriver; + + private final HybridClock clock; + + /** The local map for tx states. */ + private ConcurrentHashMap<UUID, TxStateMeta> txStateMap; + + /** + * The constructor. + * + * @param clusterService Cluster service. + * @param placementDriver Placement driver. + * @param clock Clock. + */ + public OrphanDetector(ClusterService clusterService, PlacementDriver placementDriver, HybridClock clock) { + this.clusterService = clusterService; + this.placementDriver = placementDriver; + this.clock = clock; + } + + + /** + * Starts the detector. + * + * @param txStateMap Transaction state map. + */ + public void start(ConcurrentHashMap<UUID, TxStateMeta> txStateMap) { + this.txStateMap = txStateMap; + // Subscribe to lock conflicts here. + } Review Comment: The internal map leaks into this method and `TxRecoveryProcessor.start` from TxManagerImpl. A better solution would be to use something like a Function<UUID, TxStateMeta> or a specific interface to keep the state encapsulated. -- 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]
