You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/02/08 15:54:47 UTC

[GitHub] [ignite] anton-vinogradov opened a new pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

anton-vinogradov opened a new pull request #9807:
URL: https://github.com/apache/ignite/pull/9807


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r812850088



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -58,15 +57,12 @@
     /** Maximum number of attempts to remap key to the same primary node. */
     protected static final int MAX_REMAP_CNT = getInteger(IGNITE_NEAR_GET_MAX_REMAPS, DFLT_MAX_REMAP_CNT);
 
-    /** Remap count updater. */
-    protected static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> REMAP_CNT_UPD =
-        AtomicIntegerFieldUpdater.newUpdater(GridNearReadRepairAbstractFuture.class, "remapCnt");
-
-    /** Remap count. */
-    protected volatile int remapCnt;
+    /** Lsnr calls upd. */
+    private static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> LSNR_CALLS_UPD =

Review comment:
       Each get/getAll is a new request.
   Consistency check will check the whole partition, millions of keys batched by 1024.
   Am I missing something?




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r811709168



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -145,101 +150,94 @@ protected GridNearReadRepairAbstractFuture(
         canRemap = topVer == null;
 
         this.topVer = canRemap ? ctx.affinity().affinityTopologyVersion() : topVer;
-    }
 
-    /**
-     *
-     */
-    protected final void init() {
-        map();
+        Map<ClusterNode, Collection<KeyCacheObject>> mappings = new HashMap<>();
+
+        for (KeyCacheObject key : keys) {
+            List<ClusterNode> nodes = ctx.affinity().nodesByKey(key, this.topVer);
+
+            primaries.put(key, nodes.get(0));
+
+            for (ClusterNode node : nodes)
+                mappings.computeIfAbsent(node, k -> new HashSet<>()).add(key);
+        }
+
+        if (mappings.isEmpty())
+            onDone(new ClusterTopologyServerNotFoundException("Failed to map keys for cache " +
+                "(all partition nodes left the grid) [topVer=" + this.topVer + ", cache=" + ctx.name() + ']'));
+
+        for (Map.Entry<ClusterNode, Collection<KeyCacheObject>> mapping : mappings.entrySet()) {
+            ClusterNode node = mapping.getKey();
+
+            GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut =
+                new GridPartitionedGetFuture<>(
+                    ctx,
+                    mapping.getValue(), // Keys.
+                    readThrough,
+                    false, // Local get required.
+                    taskName,
+                    deserializeBinary,
+                    recovery,
+                    expiryPlc,
+                    false,
+                    true,
+                    true,
+                    tx != null ? tx.label() : null,
+                    tx != null ? tx.mvccSnapshot() : null,
+                    node);
+
+            futs.put(mapping.getKey(), fut);
+
+            fut.listen(this::onResult);
+        }
     }
 
     /**
      *
      */
-    private synchronized void map() {
-        assert futs.isEmpty() : "Remapping started without the clean-up.";
-
-        Map<KeyCacheObject, ClusterNode> primaryNodes = new HashMap<>();
+    protected final void init() {
+        assert !futs.isEmpty();
 
         IgniteInternalTx prevTx = ctx.tm().tx(tx); // Within the original tx.
 
         try {
-            Map<ClusterNode, Collection<KeyCacheObject>> mappings = new HashMap<>();
-
-            for (KeyCacheObject key : keys) {
-                List<ClusterNode> nodes = ctx.affinity().nodesByKey(key, topVer);
-
-                primaryNodes.put(key, nodes.get(0));
-
-                for (ClusterNode node : nodes)
-                    mappings.computeIfAbsent(node, k -> new HashSet<>()).add(key);
-            }
-
-            primaries = primaryNodes;
-
-            for (Map.Entry<ClusterNode, Collection<KeyCacheObject>> mapping : mappings.entrySet()) {
-                ClusterNode node = mapping.getKey();
-
-                GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut =
-                    new GridPartitionedGetFuture<>(
-                        ctx,
-                        mapping.getValue(), // Keys.
-                        readThrough,
-                        false, // Local get required.
-                        taskName,
-                        deserializeBinary,
-                        recovery,
-                        expiryPlc,
-                        false,
-                        true,
-                        true,
-                        tx != null ? tx.label() : null,
-                        tx != null ? tx.mvccSnapshot() : null,
-                        node);
-
-                fut.listen(this::onResult);
-
-                futs.put(mapping.getKey(), fut);
-            }
-
             for (GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut : futs.values())
                 fut.init(topVer);
-
-            if (futs.isEmpty())
-                onDone(new ClusterTopologyServerNotFoundException("Failed to map keys for cache " +
-                    "(all partition nodes left the grid) [topVer=" + topVer + ", cache=" + ctx.name() + ']'));
         }
         finally {
             ctx.tm().tx(prevTx);
         }
     }
 
     /**
-     * @param topVer Topology version.
+     * @param fut Future to be notified.
      */
-    protected final void remap(AffinityTopologyVersion topVer) {
-        futs.clear();
+    protected final void initOnRemap(GridNearReadRepairAbstractFuture fut) {
+        remapCnt = fut.remapCnt + 1;
+
+        listen(f -> {
+            assert !fut.isDone();
 
-        this.topVer = topVer;
+            fut.onDone(f.result(), f.error());
+        });
 
-        map();
+        init();
     }
 
+    /**
+     * @param topVer Topology version.
+     */
+    protected abstract void remap(AffinityTopologyVersion topVer);
+
     /**
      * Collects results of each 'get' future and prepares an overall result of the operation.
      *
      * @param finished Future represents a result of GET operation.
      */
-    protected final synchronized void onResult(IgniteInternalFuture<Map<KeyCacheObject, EntryGetResult>> finished) {
-        if (isDone() // All subfutures (including currently processing) were successfully finished at previous future processing.
-            || (topVer == null) // Remapping, ignoring any updates until remapped.
-            || !futs.containsValue((GridPartitionedGetFuture<KeyCacheObject, EntryGetResult>)finished)) // Remapped.
-            return;
-
+    protected final void onResult(IgniteInternalFuture<Map<KeyCacheObject, EntryGetResult>> finished) {

Review comment:
       Seems, currently possible to remap the future on each failure.
   Future should be remapped only once.




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r813995119



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -58,15 +57,16 @@
     /** Maximum number of attempts to remap key to the same primary node. */
     protected static final int MAX_REMAP_CNT = getInteger(IGNITE_NEAR_GET_MAX_REMAPS, DFLT_MAX_REMAP_CNT);

Review comment:
       Let's set it to 0, or fail on remap (unstable topology isn't in the scope of the ticket).

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairFuture.java
##########
@@ -79,11 +117,25 @@ public GridNearReadRepairFuture(
             deserializeBinary,
             recovery,
             expiryPlc,
-            tx);
+            tx,
+            remappedFut);
 
         assert ctx.transactional() : "Atomic cache should not be recovered using this future";
+    }
 
-        init();
+    /** {@inheritDoc} */
+    @Override protected GridNearReadRepairAbstractFuture remapFuture(AffinityTopologyVersion topVer) {
+        return new GridNearReadRepairFuture(
+            topVer,
+            ctx,
+            keys,
+            strategy,
+            readThrough,
+            taskName,
+            deserializeBinary,
+            recovery,
+            expiryPlc,
+            tx);

Review comment:
       There should be a `this` for remapping

##########
File path: modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTestSelfTest.java
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.testframework.junits.common;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class GridCommonAbstractTestSelfTest extends GridCommonAbstractTest {
+    /**
+     *
+     */
+    @Test
+    public void testOrderedCollectionsEqualityChecks() {
+        assertEqualsCollections(
+            Arrays.asList(1, 2, 3),
+            Arrays.asList(1, 2, 3));
+
+        asserFailed(() -> assertEqualsCollections(
+            Arrays.asList(1, 2, 3),
+            Arrays.asList(2, 3, 1)));
+
+        asserFailed(() -> assertEqualsCollections(
+            Arrays.asList(1, 2, 3, null),
+            Arrays.asList(2, 3, 1)));
+
+        asserFailed(() -> assertEqualsCollections(
+            Arrays.asList(1, 2, 3),
+            Arrays.asList(2, 3, 1, null)));
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testCollectionsEqualityChecks() {
+        assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 3),
+            Arrays.asList(1, 2, 3));
+
+        assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 3),
+            Arrays.asList(2, 3, 1));
+
+        assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 2, 3),
+            Arrays.asList(2, 3, 2, 1));
+
+        asserFailed(() -> assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 3),
+            Arrays.asList(2, 3, 1, 2)));
+
+        asserFailed(() -> assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 3),
+            Arrays.asList(1, 2, 2, 3)));
+
+        asserFailed(() -> assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 2, 3),
+            Arrays.asList(1, 1, 2, 3)));
+
+        asserFailed(() -> assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 2),
+            Arrays.asList(1, 2, 2, 4)));
+
+        asserFailed(() -> assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 2),
+            Arrays.asList(1, 2, 2, null)));
+
+        asserFailed(() -> assertEqualsCollectionsIgnoringOrder(
+            Arrays.asList(1, 2, 2, null),
+            Arrays.asList(1, 2, 2)));
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testMapsEqualityChecks() {
+        assertEqualsMaps(
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+            }},
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(3, 3);
+                put(2, 2);
+            }});
+
+        asserFailed(() -> assertEqualsMaps(
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+            }},
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+                put(4, 4);
+            }}));
+
+        asserFailed(() -> assertEqualsMaps(
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+                put(null, null);
+            }},
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+                put(4, 4);
+            }}));
+
+        asserFailed(() -> assertEqualsMaps(
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+                put(null, null);
+            }},
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+            }}));
+
+        asserFailed(() -> assertEqualsMaps(
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+            }},
+            new HashMap<Integer, Integer>() {{
+                put(1, 1);
+                put(2, 2);
+                put(3, 3);
+                put(null, null);
+            }}));
+    }
+
+    /**
+     * @param r Runnable.
+     */
+    private void asserFailed(Runnable r) {

Review comment:
       asser --> assert

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/consistency/AbstractFullSetReadRepairTest.java
##########
@@ -270,20 +270,20 @@
      * @param data Data.
      */
     protected void check(ReadRepairData data, IgniteIrreparableConsistencyViolationException e, boolean evtRecorded) {
-        Collection<?> irreparableKeys = e != null ? e.irreparableKeys() : null;
+        Collection<Object> irreparableKeys = e != null ? e.irreparableKeys() : null;
 
         if (e != null) {
-            Collection<?> repairableKeys = e.repairableKeys();
+            Collection<Object> repairableKeys = e.repairableKeys();
 
             if (repairableKeys != null)
                 assertTrue(Collections.disjoint(repairableKeys, irreparableKeys));
 
-            Collection<?> expectedToBeIrreparableKeys = data.data.entrySet().stream()
+            Collection<Object> expectedToBeIrreparableKeys = data.data.entrySet().stream()
                 .filter(entry -> !entry.getValue().repairable)
                 .map(Map.Entry::getKey)
                 .collect(Collectors.toSet());
 
-            assertEquals(expectedToBeIrreparableKeys, irreparableKeys);
+            assertEqualsCollectionsIgnoringOrder(expectedToBeIrreparableKeys, irreparableKeys);

Review comment:
       Why don't use `assertTrue(expectedToBeIrreparableKeys.equals(irreparableKeys))`?




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r818623202



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -58,15 +57,16 @@
     /** Maximum number of attempts to remap key to the same primary node. */
     protected static final int MAX_REMAP_CNT = getInteger(IGNITE_NEAR_GET_MAX_REMAPS, DFLT_MAX_REMAP_CNT);

Review comment:
       Retry on the same topology still needed to recheck unlocked entries.
   But I finally :) removed whole remap code! 




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov merged pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov merged pull request #9807:
URL: https://github.com/apache/ignite/pull/9807


   


-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r811142668



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -58,15 +57,12 @@
     /** Maximum number of attempts to remap key to the same primary node. */
     protected static final int MAX_REMAP_CNT = getInteger(IGNITE_NEAR_GET_MAX_REMAPS, DFLT_MAX_REMAP_CNT);
 
-    /** Remap count updater. */
-    protected static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> REMAP_CNT_UPD =
-        AtomicIntegerFieldUpdater.newUpdater(GridNearReadRepairAbstractFuture.class, "remapCnt");
-
-    /** Remap count. */
-    protected volatile int remapCnt;
+    /** Lsnr calls upd. */
+    private static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> LSNR_CALLS_UPD =

Review comment:
       Yes, but 
   
   > no many of instances of the future exist 
   
   Literally, it's only one per request. Are we going to have many request here?




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r811028205



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -58,15 +57,12 @@
     /** Maximum number of attempts to remap key to the same primary node. */
     protected static final int MAX_REMAP_CNT = getInteger(IGNITE_NEAR_GET_MAX_REMAPS, DFLT_MAX_REMAP_CNT);
 
-    /** Remap count updater. */
-    protected static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> REMAP_CNT_UPD =
-        AtomicIntegerFieldUpdater.newUpdater(GridNearReadRepairAbstractFuture.class, "remapCnt");
-
-    /** Remap count. */
-    protected volatile int remapCnt;
+    /** Lsnr calls upd. */
+    private static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> LSNR_CALLS_UPD =

Review comment:
       Looks like we can use AtomicInteger here without price. This future is created for whole batch of keys, then no many of instances of the future exist (actually only single one), doesn't it?

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
##########
@@ -2455,6 +2455,11 @@ private boolean enlistWriteEntry(GridCacheContext cacheCtx,
                         }
 
                         if (readRepairStrategy != null) { // Checking and repairing each locked entry (if necessary).
+                            AffinityTopologyVersion topVer = topologyVersionSnapshot();
+
+                            if (topVer == null)
+                                topVer = entryTopVer;

Review comment:
       There is no docs for `entryTopVer` in the method signature. Why do you check it after `topologyVersionSnapshot()`? What is a full priority queue of topology versions?

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -261,10 +257,19 @@ else if (!canRemap)
 
             return;
         }
+        else
+            LSNR_CALLS_UPD.incrementAndGet(this);

Review comment:
       It's possible to use returned value here in next lines.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -261,10 +257,19 @@ else if (!canRemap)
 
             return;
         }
+        else
+            LSNR_CALLS_UPD.incrementAndGet(this);
 
-        for (GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut : futs.values()) {
-            if (!fut.isDone() || fut.error() != null)
+        assert lsnrCalls <= futs.size();
+
+        if (isDone() || lsnrCalls != futs.size())
+            return;
+
+        synchronized (this) {

Review comment:
       I think it's possible to use `lsnrCalls` value immediately after incrementing it. This value is guarded from concurrency because incremented atomically, so we can leverage on this and remove any sync here. Am I missing smth here?

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairCheckOnlyFuture.java
##########
@@ -125,6 +146,8 @@ public GridNearReadRepairCheckOnlyFuture(
      * @return Future represents 1 entry's value.
      */
     public <K, V> IgniteInternalFuture<V> single() {
+        init();

Review comment:
       What if we add a parameter with an initialization flag for the constructor `GridNearReadRepairAbstractFuture`? Now it looks strange and a little bit dangerous (it's possible to forget to `init()` future somewhere)

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -93,16 +89,25 @@
     protected final IgniteInternalTx tx;
 
     /** Primaries per key. */
-    protected volatile Map<KeyCacheObject, ClusterNode> primaries;
+    protected final Map<KeyCacheObject, ClusterNode> primaries = new HashMap<>();
 
     /** Strategy. */
     protected final ReadRepairStrategy strategy;
 
+    /** Remap count. */
+    protected volatile int remapCnt;

Review comment:
       Looks like this definition wasn't changed but just moved lower (from line 66). Let's keep it on previous place

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -93,16 +89,25 @@
     protected final IgniteInternalTx tx;
 
     /** Primaries per key. */
-    protected volatile Map<KeyCacheObject, ClusterNode> primaries;
+    protected final Map<KeyCacheObject, ClusterNode> primaries = new HashMap<>();

Review comment:
       Let's define it in constructor as `Collections.unmodifiableMap()` of local HashMap.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -58,15 +57,12 @@
     /** Maximum number of attempts to remap key to the same primary node. */
     protected static final int MAX_REMAP_CNT = getInteger(IGNITE_NEAR_GET_MAX_REMAPS, DFLT_MAX_REMAP_CNT);
 
-    /** Remap count updater. */
-    protected static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> REMAP_CNT_UPD =
-        AtomicIntegerFieldUpdater.newUpdater(GridNearReadRepairAbstractFuture.class, "remapCnt");
-
-    /** Remap count. */
-    protected volatile int remapCnt;
+    /** Lsnr calls upd. */
+    private static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> LSNR_CALLS_UPD =
+        AtomicIntegerFieldUpdater.newUpdater(GridNearReadRepairAbstractFuture.class, "lsnrCalls");
 
     /** Affinity node's get futures. */
-    protected final Map<ClusterNode, GridPartitionedGetFuture<KeyCacheObject, EntryGetResult>> futs = new ConcurrentHashMap<>();
+    protected final Map<ClusterNode, GridPartitionedGetFuture<KeyCacheObject, EntryGetResult>> futs = new HashMap<>();

Review comment:
       Let's define it in constructor as `Collections.unmodifiableMap()` of local HashMap.
   




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r818623634



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairFuture.java
##########
@@ -79,11 +117,25 @@ public GridNearReadRepairFuture(
             deserializeBinary,
             recovery,
             expiryPlc,
-            tx);
+            tx,
+            remappedFut);
 
         assert ctx.transactional() : "Atomic cache should not be recovered using this future";
+    }
 
-        init();
+    /** {@inheritDoc} */
+    @Override protected GridNearReadRepairAbstractFuture remapFuture(AffinityTopologyVersion topVer) {
+        return new GridNearReadRepairFuture(
+            topVer,
+            ctx,
+            keys,
+            strategy,
+            readThrough,
+            taskName,
+            deserializeBinary,
+            recovery,
+            expiryPlc,
+            tx);

Review comment:
       Fixed by UnsupportedOperationException




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r811149162



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -93,16 +89,25 @@
     protected final IgniteInternalTx tx;
 
     /** Primaries per key. */
-    protected volatile Map<KeyCacheObject, ClusterNode> primaries;
+    protected final Map<KeyCacheObject, ClusterNode> primaries = new HashMap<>();
 
     /** Strategy. */
     protected final ReadRepairStrategy strategy;
 
+    /** Remap count. */
+    protected volatile int remapCnt;

Review comment:
       Now it doesn't matter for me, it was a note during I was reading the code.




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r812892263



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
##########
@@ -2455,6 +2455,11 @@ private boolean enlistWriteEntry(GridCacheContext cacheCtx,
                         }
 
                         if (readRepairStrategy != null) { // Checking and repairing each locked entry (if necessary).
+                            AffinityTopologyVersion topVer = topologyVersionSnapshot();
+
+                            if (topVer == null)
+                                topVer = entryTopVer;

Review comment:
       Rolled back this change since it cannot be finished/proved during this fix.




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r811134488



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -58,15 +57,12 @@
     /** Maximum number of attempts to remap key to the same primary node. */
     protected static final int MAX_REMAP_CNT = getInteger(IGNITE_NEAR_GET_MAX_REMAPS, DFLT_MAX_REMAP_CNT);
 
-    /** Remap count updater. */
-    protected static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> REMAP_CNT_UPD =
-        AtomicIntegerFieldUpdater.newUpdater(GridNearReadRepairAbstractFuture.class, "remapCnt");
-
-    /** Remap count. */
-    protected volatile int remapCnt;
+    /** Lsnr calls upd. */
+    private static final AtomicIntegerFieldUpdater<GridNearReadRepairAbstractFuture> LSNR_CALLS_UPD =

Review comment:
       AtomicInteger means we'll create an object for each future, while AtomicIntegerFieldUpdater works as a static singleton.




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r817705088



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/consistency/AbstractFullSetReadRepairTest.java
##########
@@ -270,20 +270,20 @@
      * @param data Data.
      */
     protected void check(ReadRepairData data, IgniteIrreparableConsistencyViolationException e, boolean evtRecorded) {
-        Collection<?> irreparableKeys = e != null ? e.irreparableKeys() : null;
+        Collection<Object> irreparableKeys = e != null ? e.irreparableKeys() : null;
 
         if (e != null) {
-            Collection<?> repairableKeys = e.repairableKeys();
+            Collection<Object> repairableKeys = e.repairableKeys();
 
             if (repairableKeys != null)
                 assertTrue(Collections.disjoint(repairableKeys, irreparableKeys));
 
-            Collection<?> expectedToBeIrreparableKeys = data.data.entrySet().stream()
+            Collection<Object> expectedToBeIrreparableKeys = data.data.entrySet().stream()
                 .filter(entry -> !entry.getValue().repairable)
                 .map(Map.Entry::getKey)
                 .collect(Collectors.toSet());
 
-            assertEquals(expectedToBeIrreparableKeys, irreparableKeys);
+            assertEqualsCollectionsIgnoringOrder(expectedToBeIrreparableKeys, irreparableKeys);

Review comment:
       Because equals fails on different collection types.
   Possible solution is to call Collections.unmodifiableMap(..) over expectedToBeIrreparableKeys, but this will look odd ...




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] anton-vinogradov commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
anton-vinogradov commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r811130700



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -93,16 +89,25 @@
     protected final IgniteInternalTx tx;
 
     /** Primaries per key. */
-    protected volatile Map<KeyCacheObject, ClusterNode> primaries;
+    protected final Map<KeyCacheObject, ClusterNode> primaries = new HashMap<>();
 
     /** Strategy. */
     protected final ReadRepairStrategy strategy;
 
+    /** Remap count. */
+    protected volatile int remapCnt;

Review comment:
       Just moved closer to canRemap.
   Can we keep it so?




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] timoninmaxim commented on a change in pull request #9807: IGNITE-16071 Read Repair futures should be rewritten to use wait-free sync instead of synchronized

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on a change in pull request #9807:
URL: https://github.com/apache/ignite/pull/9807#discussion_r822624226



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/consistency/AbstractFullSetReadRepairTest.java
##########
@@ -270,20 +270,20 @@
      * @param data Data.
      */
     protected void check(ReadRepairData data, IgniteIrreparableConsistencyViolationException e, boolean evtRecorded) {
-        Collection<?> irreparableKeys = e != null ? e.irreparableKeys() : null;
+        Collection<Object> irreparableKeys = e != null ? e.irreparableKeys() : null;
 
         if (e != null) {
-            Collection<?> repairableKeys = e.repairableKeys();
+            Collection<Object> repairableKeys = e.repairableKeys();
 
             if (repairableKeys != null)
                 assertTrue(Collections.disjoint(repairableKeys, irreparableKeys));
 
-            Collection<?> expectedToBeIrreparableKeys = data.data.entrySet().stream()
+            Collection<Object> expectedToBeIrreparableKeys = data.data.entrySet().stream()
                 .filter(entry -> !entry.getValue().repairable)
                 .map(Map.Entry::getKey)
                 .collect(Collectors.toSet());
 
-            assertEquals(expectedToBeIrreparableKeys, irreparableKeys);
+            assertEqualsCollectionsIgnoringOrder(expectedToBeIrreparableKeys, irreparableKeys);

Review comment:
       Just don't wrap irreparable keys to unmodifiable collection?




-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org