Cyrill commented on code in PR #2877:
URL: https://github.com/apache/ignite-3/pull/2877#discussion_r1419150135


##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PlacementDriverHelper.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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 java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ignite.internal.util.ExceptionUtils.withCause;
+import static 
org.apache.ignite.lang.ErrorGroups.Replicator.REPLICA_UNAVAILABLE_ERR;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.hlc.HybridClock;
+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.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.tx.TransactionException;
+
+/**
+ * A helper class to retrieve primary replicas with exception handling.
+ */
+public class PlacementDriverHelper {
+    /** The logger. */
+    private static final IgniteLogger LOG = 
Loggers.forClass(PlacementDriverHelper.class);
+
+    private static final int AWAIT_PRIMARY_REPLICA_TIMEOUT = 10;
+
+    /** Placement driver. */
+    private final PlacementDriver placementDriver;
+
+    /** A hybrid logical clock. */
+    private final HybridClock clock;
+
+    /**
+     * Constructor.
+     *
+     * @param placementDriver Placement driver.
+     * @param clock A hybrid logical clock.
+     */
+    public PlacementDriverHelper(PlacementDriver placementDriver, HybridClock 
clock) {
+        this.placementDriver = placementDriver;
+        this.clock = clock;
+    }
+
+    /**
+     * Wait for primary replica to appear for the provided partition.
+     *
+     * @param partitionId Partition id.
+     * @return Future that completes with node id that is a primary for the 
provided partition, or completes with exception if no primary
+     *         appeared during the await timeout.
+     */
+    public CompletableFuture<ReplicaMeta> awaitPrimaryReplica(TablePartitionId 
partitionId) {
+        HybridTimestamp timestamp = clock.now();
+
+        return placementDriver.awaitPrimaryReplica(partitionId, timestamp, 
AWAIT_PRIMARY_REPLICA_TIMEOUT, SECONDS)
+                .handle((primaryReplica, e) -> {
+                    if (e != null) {
+                        LOG.error("Failed to retrieve primary replica for 
partition {}", partitionId, e);

Review Comment:
   What about log.debug?



-- 
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]

Reply via email to