timoninmaxim commented on a change in pull request #9661:
URL: https://github.com/apache/ignite/pull/9661#discussion_r782103156



##########
File path: 
modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerConsistencyTest.java
##########
@@ -62,6 +66,23 @@
     /** Partitions. */
     private static final int PARTITIONS = 32;
 
+    /** */
+    @Parameterized.Parameters(name = "strategy={0}")
+    public static Iterable<Object[]> data() {
+        List<Object[]> res = new ArrayList<>();
+
+        for (ReadRepairStrategy strategy : ReadRepairStrategy.values())
+            res.add(new Object[] {strategy});
+
+        return res;

Review comment:
       Method can be replaced with 
   
   ```
       public static Object[] data() {
           return ReadRepairStrategy.values();
       }
   ```

##########
File path: docs/_docs/tools/control-script.adoc
##########
@@ -1037,21 +1038,22 @@ The command allows to perform cache consistency check 
and repair (when possible)
 tab:Unix[]
 [source,shell]
 ----
-control.sh --enable-experimental --consistency repair cache-name partition
+control.sh --enable-experimental --consistency repair cache-name partition 
strategy
 ----
 tab:Window[]
 [source,shell]
 ----
-control.bat --enable-experimental --consistency repair cache-name partition
+control.bat --enable-experimental --consistency repair cache-name partition 
strategy
 ----
 --
 Parameters:
 
 [cols="1,3",opts="header"]
 |===
 | Parameter | Description
-| `cache-name`| Cache to be checked/repaired..
+| `cache-name`| Cache to be checked/repaired.
 | `partition`| Cache's partition to be checked/repaired.
+| `strategy`| Repair strategy [LWW - default, PRIMARY, MAJORITY, REMOVE, 
CHECK_ONLY], optional.

Review comment:
       Remove mention of `optional` here.

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
##########
@@ -232,7 +233,10 @@ public void 
setCacheManager(org.apache.ignite.cache.CacheManager cacheMgr) {
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteCache<K, V> withReadRepair() {
+    @Override public IgniteCache<K, V> withReadRepair(ReadRepairStrategy 
strategy) {
+        if (strategy == null)

Review comment:
       Use `A.notNull()` instead.

##########
File path: 
modules/core/src/main/java/org/apache/ignite/events/CacheConsistencyViolationEvent.java
##########
@@ -109,6 +130,15 @@ public String getCacheName() {
         return cacheName;
     }
 
+    /**
+     * Resurns strategy.

Review comment:
       s/Resurns/Returns/

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridCompoundReadRepairFuture.java
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.processors.cache.distributed.near.consistency;
+
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.lang.IgniteInClosure;
+
+/**
+ * Compound future that represents the result of the external fixes for some 
keys.
+ */
+public class GridCompoundReadRepairFuture extends GridFutureAdapter<Void> 
implements IgniteInClosure<IgniteInternalFuture<Void>> {
+    /** Listener calls updater. */
+    private static final 
AtomicIntegerFieldUpdater<GridCompoundReadRepairFuture> LSNR_CALLS_UPD =
+        
AtomicIntegerFieldUpdater.newUpdater(GridCompoundReadRepairFuture.class, 
"lsnrCalls");
+
+    /** Initialized. */
+    private volatile boolean inited;
+
+    /** Listener calls. */
+    private volatile int lsnrCalls;
+
+    /** Count of compounds in the future. */
+    private volatile int size;
+
+    /** Irreparable Keys. */
+    private volatile Collection<Object> irreparableKeys;

Review comment:
       Let's make it KeyCacheObject too?

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -254,51 +275,114 @@ else if (!canRemap)
      */
     protected abstract void reduce();
 
+    /**
+     *
+     */
+    protected Map<KeyCacheObject, EntryGetResult> check() throws 
IgniteCheckedException {
+        Map<KeyCacheObject, EntryGetResult> resMap = new 
HashMap<>(keys.size());
+        Set<KeyCacheObject> inconsistentKeys = new HashSet<>();
+
+        for (GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut : 
futs.values()) {
+            for (KeyCacheObject key : fut.keys()) {
+                EntryGetResult curRes = fut.result().get(key);
+
+                if (!resMap.containsKey(key)) {
+                    resMap.put(key, curRes);
+
+                    continue;
+                }
+
+                EntryGetResult prevRes = resMap.get(key);
+
+                if (curRes != null) {
+                    if (prevRes == null || 
prevRes.version().compareTo(curRes.version()) != 0)
+                        inconsistentKeys.add(key);
+                    else {
+                        CacheObjectAdapter curVal = curRes.value();
+                        CacheObjectAdapter prevVal = prevRes.value();
+
+                        byte[] curBytes = 
curVal.valueBytes(ctx.cacheObjectContext());
+                        byte[] prevBytes = 
prevVal.valueBytes(ctx.cacheObjectContext());
+
+                        if (!Arrays.equals(curBytes, prevBytes))
+                            inconsistentKeys.add(key);
+
+                    }
+                }
+                else if (prevRes != null)
+                    inconsistentKeys.add(key);
+            }
+        }
+
+        if (!inconsistentKeys.isEmpty())
+            throw new IgniteConsistencyViolationException(inconsistentKeys);
+
+        return resMap;
+    }
+
     /**
      * @param fixedEntries Fixed map.
      */
     protected void recordConsistencyViolation(
-        Set<KeyCacheObject> inconsistentKeys,
-        Map<KeyCacheObject, EntryGetResult> fixedEntries
+        Collection<KeyCacheObject> inconsistentKeys,
+        Map<KeyCacheObject, EntryGetResult> fixedEntries,
+        ReadRepairStrategy strategy
     ) {
         GridEventStorageManager evtMgr = ctx.gridEvents();
 
         if (!evtMgr.isRecordable(EVT_CONSISTENCY_VIOLATION))
             return;
 
-        Map<Object, Map<ClusterNode, 
CacheConsistencyViolationEvent.EntryInfo>> originalMap = new HashMap<>();
+        Map<Object, Map<ClusterNode, 
CacheConsistencyViolationEvent.EntryInfo>> entries = new HashMap<>();
 
         for (Map.Entry<ClusterNode, GridPartitionedGetFuture<KeyCacheObject, 
EntryGetResult>> pair : futs.entrySet()) {
             ClusterNode node = pair.getKey();
 
             GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut = 
pair.getValue();
 
-            for (Map.Entry<KeyCacheObject, EntryGetResult> entry : 
fut.result().entrySet()) {
-                KeyCacheObject key = entry.getKey();
-
+            for (KeyCacheObject key : fut.keys()) {
                 if (inconsistentKeys.contains(key)) {
-                    EntryGetResult res = entry.getValue();
-                    CacheEntryVersion ver = res.version();
+                    Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo> 
map =
+                        entries.computeIfAbsent(
+                            ctx.unwrapBinaryIfNeeded(key, !deserializeBinary, 
false, null), k -> new HashMap<>());
 
-                    Object val = ctx.unwrapBinaryIfNeeded(res.value(), 
!deserializeBinary, false, null);
+                    EntryGetResult res = fut.result().get(key);
+                    CacheEntryVersion ver = res != null ? res.version() : null;
 
-                    Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo> 
map =
-                        originalMap.computeIfAbsent(
-                            ctx.unwrapBinaryIfNeeded(key, false, false, null), 
k -> new HashMap<>());
+                    Object val = res != null ? 
ctx.unwrapBinaryIfNeeded(res.value(), !deserializeBinary, false, null) : null;
 
                     boolean primary = primaries.get(key).equals(fut.affNode());
-                    boolean correct = fixedEntries != null && 
fixedEntries.get(key).equals(res);
+                    boolean correct = fixedEntries != null &&
+                        ((fixedEntries.get(key) != null && 
fixedEntries.get(key).equals(res)) ||
+                            (fixedEntries.get(key) == null && res == null));
 
                     map.put(node, new EventEntryInfo(val, ver, primary, 
correct));
                 }
             }
         }
 
+        Map<Object, Object> fixed;
+
+        if (fixedEntries == null)
+            fixed = Collections.emptyMap();
+        else {
+            fixed = new HashMap<>();
+
+            for (Map.Entry<KeyCacheObject, EntryGetResult> entry : 
fixedEntries.entrySet()) {
+                Object key = ctx.unwrapBinaryIfNeeded(entry.getKey(), 
!deserializeBinary, false, null);
+                Object val = entry.getValue() != null ?
+                    ctx.unwrapBinaryIfNeeded(entry.getValue().value(), 
!deserializeBinary, false, null) : null;
+
+                fixed.put(key, val);
+            }
+        }
+
         evtMgr.record(new CacheConsistencyViolationEvent(
             ctx.name(),
             ctx.discovery().localNode(),
             "Consistency violation fixed.",

Review comment:
       It fixed, but `fixed` can be empty? Should we change message here?

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -128,17 +138,26 @@ protected GridNearReadRepairAbstractFuture(
         this.expiryPlc = expiryPlc;
         this.tx = tx;
 
+        assert strategy != null;
+
+        this.strategy = strategy;
+
         canRemap = topVer == null;
 
-        map(canRemap ? ctx.affinity().affinityTopologyVersion() : topVer);
+        this.topVer = canRemap ? ctx.affinity().affinityTopologyVersion() : 
topVer;
     }
 
     /**
-     * @param topVer Affinity topology version.
+     *
      */
-    protected synchronized void map(AffinityTopologyVersion topVer) {
-        this.topVer = topVer;
+    protected void init() {
+        map();
+    }
 
+    /**
+     *
+     */
+    protected synchronized void map() {

Review comment:
       What do actually those methods synchronize? 

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
##########
@@ -5115,7 +5118,7 @@ protected V get(
                 ctx.operationContextPerCall(opCtx);
 
                 try (Transaction tx = 
ctx.grid().transactions().txStart(PESSIMISTIC, SERIALIZABLE)) {
-                    get(key); // Repair.
+                    get((K)key); // Repair.

Review comment:
       Should we invoke directly `repairableGet` here? Looks like `get` make 
some additional actions we actually don't need here - writing statistics, 
invokes interceptors, unwrap to KeyCacheObject again. WDYT?

##########
File path: 
modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerConsistencyTest.java
##########
@@ -122,13 +143,17 @@ private void testAtomicAndTx(boolean incVal) throws 
Exception {
         assertContains(log, testOut.toString(),
             "conflict partitions has been found: [counterConflicts=0, 
hashConflicts=" + brokenParts.get());
 
-        readRepairTx(brokenParts, txCacheName);
+        Integer fixesPerEntry = fixesPerEntry();
 
-        assertEquals(PARTITIONS, brokenParts.get()); // Half fixed.
+        readRepair(brokenParts, txCacheName, fixesPerEntry);

Review comment:
       Let's separate test for atomic and for transactional caches. It's 
actually hard to read the test, I firstly though that `brokenParts  == 64` 
because of `backups == 2` and not because there are 2 caches. Then I can't 
understand why it fixes only half of conflicts for tx cache. There is no need 
to test both caches in single test, let's add a test param instead.

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -254,51 +275,114 @@ else if (!canRemap)
      */
     protected abstract void reduce();
 
+    /**
+     *
+     */
+    protected Map<KeyCacheObject, EntryGetResult> check() throws 
IgniteCheckedException {

Review comment:
       Please, mark all protected methods with `final`, also please add some 
javadocs here, at least description of returning value. This method is 
important and it should be marked as important somehow, because CHECK_ONLY 
strategy relies on this method only. 

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
##########
@@ -699,12 +701,12 @@ public void onKernalStop() {
             /*skip values*/true,
             false);
 
-        boolean readRepair = opCtx != null && opCtx.readRepair();
+        ReadRepairStrategy readRepairStrategy = opCtx != null ? 
opCtx.readRepairStrategy() : null;
 
-        if (readRepair)
+        if (readRepairStrategy != null)
             return getWithRepairAsync(
                 fut,
-                () -> repairAsync(key, opCtx, true),
+                (ks) -> repairAsync(ks, opCtx, true),

Review comment:
       Actually we already knows the key to repair to. Because the original 
method accepts single key. Can we leverage on that here? 

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -128,17 +138,26 @@ protected GridNearReadRepairAbstractFuture(
         this.expiryPlc = expiryPlc;
         this.tx = tx;
 
+        assert strategy != null;
+
+        this.strategy = strategy;
+
         canRemap = topVer == null;
 
-        map(canRemap ? ctx.affinity().affinityTopologyVersion() : topVer);
+        this.topVer = canRemap ? ctx.affinity().affinityTopologyVersion() : 
topVer;
     }
 
     /**
-     * @param topVer Affinity topology version.
+     *
      */
-    protected synchronized void map(AffinityTopologyVersion topVer) {
-        this.topVer = topVer;
+    protected void init() {
+        map();
+    }
 
+    /**
+     *
+     */
+    protected synchronized void map() {

Review comment:
       Should be `private`, also as the `onResult` method.

##########
File path: docs/_docs/tools/control-script.adoc
##########
@@ -1037,21 +1038,22 @@ The command allows to perform cache consistency check 
and repair (when possible)
 tab:Unix[]
 [source,shell]
 ----
-control.sh --enable-experimental --consistency repair cache-name partition
+control.sh --enable-experimental --consistency repair cache-name partition 
strategy
 ----
 tab:Window[]
 [source,shell]
 ----
-control.bat --enable-experimental --consistency repair cache-name partition
+control.bat --enable-experimental --consistency repair cache-name partition 
strategy
 ----
 --
 Parameters:
 
 [cols="1,3",opts="header"]
 |===
 | Parameter | Description
-| `cache-name`| Cache to be checked/repaired..
+| `cache-name`| Cache to be checked/repaired.
 | `partition`| Cache's partition to be checked/repaired.
+| `strategy`| Repair strategy [LWW - default, PRIMARY, MAJORITY, REMOVE, 
CHECK_ONLY], optional.

Review comment:
       RELATIVE_MAJOIRTY?

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/consistency/GridNearReadRepairAbstractFuture.java
##########
@@ -254,51 +275,114 @@ else if (!canRemap)
      */
     protected abstract void reduce();
 
+    /**
+     *
+     */
+    protected Map<KeyCacheObject, EntryGetResult> check() throws 
IgniteCheckedException {
+        Map<KeyCacheObject, EntryGetResult> resMap = new 
HashMap<>(keys.size());
+        Set<KeyCacheObject> inconsistentKeys = new HashSet<>();
+
+        for (GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut : 
futs.values()) {
+            for (KeyCacheObject key : fut.keys()) {
+                EntryGetResult curRes = fut.result().get(key);
+
+                if (!resMap.containsKey(key)) {
+                    resMap.put(key, curRes);
+
+                    continue;
+                }
+
+                EntryGetResult prevRes = resMap.get(key);
+
+                if (curRes != null) {
+                    if (prevRes == null || 
prevRes.version().compareTo(curRes.version()) != 0)
+                        inconsistentKeys.add(key);
+                    else {
+                        CacheObjectAdapter curVal = curRes.value();
+                        CacheObjectAdapter prevVal = prevRes.value();
+
+                        byte[] curBytes = 
curVal.valueBytes(ctx.cacheObjectContext());
+                        byte[] prevBytes = 
prevVal.valueBytes(ctx.cacheObjectContext());
+
+                        if (!Arrays.equals(curBytes, prevBytes))
+                            inconsistentKeys.add(key);
+
+                    }
+                }
+                else if (prevRes != null)
+                    inconsistentKeys.add(key);
+            }
+        }
+
+        if (!inconsistentKeys.isEmpty())
+            throw new IgniteConsistencyViolationException(inconsistentKeys);
+
+        return resMap;
+    }
+
     /**
      * @param fixedEntries Fixed map.
      */
     protected void recordConsistencyViolation(
-        Set<KeyCacheObject> inconsistentKeys,
-        Map<KeyCacheObject, EntryGetResult> fixedEntries
+        Collection<KeyCacheObject> inconsistentKeys,
+        Map<KeyCacheObject, EntryGetResult> fixedEntries,
+        ReadRepairStrategy strategy
     ) {
         GridEventStorageManager evtMgr = ctx.gridEvents();
 
         if (!evtMgr.isRecordable(EVT_CONSISTENCY_VIOLATION))
             return;
 
-        Map<Object, Map<ClusterNode, 
CacheConsistencyViolationEvent.EntryInfo>> originalMap = new HashMap<>();
+        Map<Object, Map<ClusterNode, 
CacheConsistencyViolationEvent.EntryInfo>> entries = new HashMap<>();
 
         for (Map.Entry<ClusterNode, GridPartitionedGetFuture<KeyCacheObject, 
EntryGetResult>> pair : futs.entrySet()) {
             ClusterNode node = pair.getKey();
 
             GridPartitionedGetFuture<KeyCacheObject, EntryGetResult> fut = 
pair.getValue();
 
-            for (Map.Entry<KeyCacheObject, EntryGetResult> entry : 
fut.result().entrySet()) {
-                KeyCacheObject key = entry.getKey();
-
+            for (KeyCacheObject key : fut.keys()) {
                 if (inconsistentKeys.contains(key)) {
-                    EntryGetResult res = entry.getValue();
-                    CacheEntryVersion ver = res.version();
+                    Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo> 
map =
+                        entries.computeIfAbsent(
+                            ctx.unwrapBinaryIfNeeded(key, !deserializeBinary, 
false, null), k -> new HashMap<>());
 
-                    Object val = ctx.unwrapBinaryIfNeeded(res.value(), 
!deserializeBinary, false, null);
+                    EntryGetResult res = fut.result().get(key);
+                    CacheEntryVersion ver = res != null ? res.version() : null;
 
-                    Map<ClusterNode, CacheConsistencyViolationEvent.EntryInfo> 
map =
-                        originalMap.computeIfAbsent(
-                            ctx.unwrapBinaryIfNeeded(key, false, false, null), 
k -> new HashMap<>());
+                    Object val = res != null ? 
ctx.unwrapBinaryIfNeeded(res.value(), !deserializeBinary, false, null) : null;
 
                     boolean primary = primaries.get(key).equals(fut.affNode());
-                    boolean correct = fixedEntries != null && 
fixedEntries.get(key).equals(res);
+                    boolean correct = fixedEntries != null &&
+                        ((fixedEntries.get(key) != null && 
fixedEntries.get(key).equals(res)) ||
+                            (fixedEntries.get(key) == null && res == null));
 
                     map.put(node, new EventEntryInfo(val, ver, primary, 
correct));
                 }
             }
         }
 
+        Map<Object, Object> fixed;
+
+        if (fixedEntries == null)
+            fixed = Collections.emptyMap();
+        else {
+            fixed = new HashMap<>();
+
+            for (Map.Entry<KeyCacheObject, EntryGetResult> entry : 
fixedEntries.entrySet()) {
+                Object key = ctx.unwrapBinaryIfNeeded(entry.getKey(), 
!deserializeBinary, false, null);
+                Object val = entry.getValue() != null ?
+                    ctx.unwrapBinaryIfNeeded(entry.getValue().value(), 
!deserializeBinary, false, null) : null;
+
+                fixed.put(key, val);
+            }
+        }
+
         evtMgr.record(new CacheConsistencyViolationEvent(
             ctx.name(),
             ctx.discovery().localNode(),
             "Consistency violation fixed.",
-            originalMap));
+            entries,
+            fixed, strategy));

Review comment:
       Move strategy on new line.

##########
File path: docs/_docs/tools/control-script.adoc
##########
@@ -1037,21 +1038,22 @@ The command allows to perform cache consistency check 
and repair (when possible)
 tab:Unix[]
 [source,shell]
 ----
-control.sh --enable-experimental --consistency repair cache-name partition
+control.sh --enable-experimental --consistency repair cache-name partition 
strategy
 ----
 tab:Window[]
 [source,shell]
 ----
-control.bat --enable-experimental --consistency repair cache-name partition
+control.bat --enable-experimental --consistency repair cache-name partition 
strategy
 ----
 --
 Parameters:
 
 [cols="1,3",opts="header"]
 |===
 | Parameter | Description
-| `cache-name`| Cache to be checked/repaired..
+| `cache-name`| Cache to be checked/repaired.
 | `partition`| Cache's partition to be checked/repaired.
+| `strategy`| Repair strategy [LWW - default, PRIMARY, MAJORITY, REMOVE, 
CHECK_ONLY], optional.

Review comment:
       Remove `default` too.




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