This is an automated email from the ASF dual-hosted git repository.
wernerdv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-extensions.git
The following commit(s) were added to refs/heads/master by this push:
new 87758021 IGNITE-29216 Add metric for CacheVersionConflictResolver
resolution failures (#366)
87758021 is described below
commit 87758021cd0b61ec76f72693709ee3deab8d6c87
Author: Dmitry Werner <[email protected]>
AuthorDate: Tue Nov 3 01:32:59 2026 +0800
IGNITE-29216 Add metric for CacheVersionConflictResolver resolution
failures (#366)
---
docs/_docs/cdc/change-data-capture-extensions.adoc | 6 ++-
.../CacheVersionConflictResolverImpl.java | 18 +++++--
.../ignite/cdc/CacheConflictOperationsTest.java | 63 +++++++++++++++++++++-
3 files changed, 82 insertions(+), 5 deletions(-)
diff --git a/docs/_docs/cdc/change-data-capture-extensions.adoc
b/docs/_docs/cdc/change-data-capture-extensions.adoc
index 91cf8095..7ce7169e 100644
--- a/docs/_docs/cdc/change-data-capture-extensions.adoc
+++ b/docs/_docs/cdc/change-data-capture-extensions.adoc
@@ -189,9 +189,13 @@ Default conflict resolve algorithm based on entry version
and `conflictResolveFi
Conflict resolution field should contain user provided monotonically
increasing value such as query id or timestamp.
. Changes from the "local" cluster always win.
+. If the entry is freshly created (there is no previous version of it) then
the new entry is used.
. If both old and new entry from the same cluster version comparison used to
determine order.
. If `conflictResolveField` if provided then field values comparison used to
determine order.
-. Conflict resolution failed. Update will be ignored.
+. If the field values are equal and both entries hold the same value then the
update is ignored and is not considered a failure.
+. Conflict resolution failed. Update will be ignored. Failure will be logged.
+
+To monitor conflict resolution, use the `ConflictResolverAcceptedCount`,
`ConflictResolverRejectedCount`, `ConflictResolverMergedCount` and
`ConflictResolverFailedCount` metrics from the `cache.\{cache_name}`
link:https://ignite.apache.org/docs/latest/monitoring-metrics/new-metrics#caches[metric
registry].
=== Configuration example
Configuration is done via Ignite node plugin:
diff --git
a/modules/cdc-ext/src/main/java/org/apache/ignite/cdc/conflictresolve/CacheVersionConflictResolverImpl.java
b/modules/cdc-ext/src/main/java/org/apache/ignite/cdc/conflictresolve/CacheVersionConflictResolverImpl.java
index ed10b336..0013e83b 100644
---
a/modules/cdc-ext/src/main/java/org/apache/ignite/cdc/conflictresolve/CacheVersionConflictResolverImpl.java
+++
b/modules/cdc-ext/src/main/java/org/apache/ignite/cdc/conflictresolve/CacheVersionConflictResolverImpl.java
@@ -40,6 +40,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
* then entry with the greater {@link GridCacheVersionedEntryEx#order()}
used.</li>
* <li>If {@link #conflictResolveField} provided and field of new entry
greater then new version used.</li>
* <li>If {@link #conflictResolveField} provided and field of old entry
greater then old version used.</li>
+ * <li>If {@link #conflictResolveField} provided and values of both
entries are equal then old version used.</li>
* <li>Conflict can't be resolved. Update ignored. Old version used.</li>
* </ul>
*/
@@ -94,7 +95,7 @@ public class CacheVersionConflictResolverImpl implements
CacheVersionConflictRes
) {
GridCacheVersionConflictContext<K, V> res = new
GridCacheVersionConflictContext<>(ctx, oldEntry, newEntry);
- boolean useNew = isUseNew(ctx, oldEntry, newEntry);
+ boolean useNew = isUseNew(ctx, oldEntry, newEntry, res);
if (log.isDebugEnabled())
debugResolve(ctx, useNew, oldEntry, newEntry);
@@ -111,6 +112,7 @@ public class CacheVersionConflictResolverImpl implements
CacheVersionConflictRes
* @param ctx Context.
* @param oldEntry Old entry.
* @param newEntry New entry.
+ * @param res Conflict resolution context, marked as failed if the
conflict can't be resolved.
* @param <K> Key type.
* @param <V> Key type.
* @return {@code True} is should use new entry.
@@ -118,7 +120,8 @@ public class CacheVersionConflictResolverImpl implements
CacheVersionConflictRes
protected <K, V> boolean isUseNew(
CacheObjectValueContext ctx,
GridCacheVersionedEntryEx<K, V> oldEntry,
- GridCacheVersionedEntryEx<K, V> newEntry
+ GridCacheVersionedEntryEx<K, V> newEntry,
+ GridCacheVersionConflictContext<K, V> res
) {
if (newEntry.dataCenterId() == clusterId) // Update made on the local
cluster always win.
return true;
@@ -145,7 +148,14 @@ public class CacheVersionConflictResolverImpl implements
CacheVersionConflictRes
if (oldVal != null && newVal != null) {
try {
- return value(oldVal).compareTo(value(newVal)) < 0;
+ int cmp = value(oldVal).compareTo(value(newVal));
+
+ if (cmp != 0)
+ return cmp < 0;
+
+ // The same value came back, e.g. the resend command
strips otherClusterVersion. There is nothing to resolve.
+ if (oldVal.equals(newVal))
+ return false;
}
catch (Exception e) {
log.error("Error during field-based conflicts resolving " +
@@ -170,6 +180,8 @@ public class CacheVersionConflictResolverImpl implements
CacheVersionConflictRes
", fromCluster=" + newEntry.dataCenterId() +
", toCluster=" + oldEntry.dataCenterId() + ']');
+ res.markResolveFailed();
+
// Ignoring update.
return false;
}
diff --git
a/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsTest.java
b/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsTest.java
index b37af4f2..1f93d663 100644
---
a/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsTest.java
+++
b/modules/cdc-ext/src/test/java/org/apache/ignite/cdc/CacheConflictOperationsTest.java
@@ -44,6 +44,7 @@ import
org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.spi.metric.LongMetric;
import org.apache.ignite.testframework.ListeningTestLogger;
import org.apache.ignite.testframework.LogListener;
import org.apache.ignite.testframework.junits.WithSystemProperty;
@@ -58,6 +59,7 @@ import org.junit.runners.Parameterized;
import static java.util.Collections.singletonMap;
import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static
org.apache.ignite.internal.processors.metric.impl.MetricUtils.cacheMetricsRegistryName;
/**
* Cache conflict operations test.
@@ -227,6 +229,9 @@ public class CacheConflictOperationsTest extends
GridCommonAbstractTest {
// Remove with the higher nodeOrder should succeed.
putConflict(key, new GridCacheVersion(topVer, order, 3,
otherClusterId), true);
+
+ // Ignored reordered updates are regular rejections, not resolve
failures.
+ checkResolverFailed(0);
}
/** Tests cache operations for entry replicated from another cluster. */
@@ -263,6 +268,47 @@ public class CacheConflictOperationsTest extends
GridCommonAbstractTest {
// Conflict replicated update succeed only if resolved by field.
putConflict(key, 5, conflictResolveField() != null);
+
+ checkResolverFailed(conflictResolveField() != null ? 2 : 3);
+ }
+
+ /** Tests which outcomes of the field-based resolving are counted as a
resolve failure. */
+ @Test
+ public void testUpdateConflictResolveByField() throws Exception {
+ Assume.assumeTrue("Should run with enabled field",
conflictResolveField() != null);
+
+ cachex = cachex.keepBinary();
+
+ String key = key("UpdateThisDCConflictByField", otherClusterId);
+ GridCacheVersion ver = new GridCacheVersion(1, 1, 1, otherClusterId);
+
+ LogListener errLsnr = LogListener.matches("Conflict can't be
resolved").build();
+
+ listeningLog.registerListener(errLsnr);
+
+ put(key);
+
+ long reqId = ConflictResolvableTestData.REQUEST_ID.get();
+
+ // Old field is greater: regular rejection.
+ putConflict(key, ver, new ConflictResolvableTestData(new byte[] {1},
reqId - 1), false);
+
+ // The same value came back, e.g. after the CDC resend command:
nothing to resolve.
+ putConflict(key, ver, cache.get(key), false);
+
+ assertFalse(errLsnr.check());
+ checkResolverFailed(0);
+
+ // Equal fields, different values: the conflict can't be resolved.
+ putConflict(key, ver, new ConflictResolvableTestData(new byte[] {1},
reqId), false);
+
+ assertTrue(errLsnr.check());
+ checkResolverFailed(1);
+
+ // The field can't be read: the conflict can't be resolved.
+ putConflict(key, ver, "no-field-value", false);
+
+ checkResolverFailed(2);
}
/** Test switching debug log level for ConflictResolver during runtime. */
@@ -398,8 +444,17 @@ public class CacheConflictOperationsTest extends
GridCommonAbstractTest {
/** Puts entry via {@link IgniteInternalCache#putAllConflict(Map)}. */
private void putConflict(String k, GridCacheVersion newVer, boolean
success) throws IgniteCheckedException {
+ putConflict(k, newVer, ConflictResolvableTestData.create(), success);
+ }
+
+ /** Puts entry via {@link IgniteInternalCache#putAllConflict(Map)}. */
+ private void putConflict(
+ String k,
+ GridCacheVersion newVer,
+ Object newVal,
+ boolean success
+ ) throws IgniteCheckedException {
CacheEntry<String, ConflictResolvableTestData> oldEntry =
cache.getEntry(k);
- ConflictResolvableTestData newVal =
ConflictResolvableTestData.create();
KeyCacheObject key = new KeyCacheObjectImpl(k, null,
cachex.context().affinity().partition(k));
CacheObject val = new
CacheObjectImpl(client.binary().toBinary(newVal), null);
@@ -457,4 +512,10 @@ public class CacheConflictOperationsTest extends
GridCommonAbstractTest {
protected String conflictResolveField() {
return null;
}
+
+ /** */
+ private void checkResolverFailed(long expVal) {
+ assertEquals(expVal,
ign.context().metric().registry(cacheMetricsRegistryName(DEFAULT_CACHE_NAME,
false))
+ .<LongMetric>findMetric("ConflictResolverFailedCount").value());
+ }
}