Skip to content

Commit

Permalink
IGNITE-22962 Move conflict resolver metrics to cache metrics (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksaska authored Aug 12, 2024
1 parent 2e49deb commit fe451d5
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 97 deletions.
13 changes: 0 additions & 13 deletions docs/_docs/cdc/change-data-capture-extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,6 @@ Conflict resolution field should contain user provided monotonically increasing
. If `conflictResolveField` if provided then field values comparison used to determine order.
. Conflict resolution failed. Update will be ignored.

=== Conflict Resolver Metrics

The Ignite's built-in `CacheVersionConflictResolverPluginProvider` provides the following metrics:

[cols="35%,65%",opts="header"]
|===
|Name |Description
| `AcceptedCount` | Count of accepted entries.
| `RejectedCount` | Count of rejected entries.
|===

These metrics are registered under `conflict-resolver` registry for each node configured with this plugin.

=== Configuration example
Configuration is done via Ignite node plugin:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.ignite.internal.processors.cache.CacheConflictResolutionManager;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver;
import org.apache.ignite.internal.processors.metric.MetricRegistryImpl;
import org.apache.ignite.lang.IgniteFuture;

/**
Expand All @@ -31,9 +30,6 @@
* @see CacheVersionConflictResolver
*/
public class CacheConflictResolutionManagerImpl<K, V> implements CacheConflictResolutionManager<K, V> {
/** Conflict resolver metrics registry name. */
public static final String CONFLICT_RESOLVER_METRICS_REGISTRY_NAME = "conflict-resolver";

/** Logger. */
private IgniteLogger log;

Expand Down Expand Up @@ -76,16 +72,13 @@ public CacheConflictResolutionManagerImpl(
@Override public CacheVersionConflictResolver conflictResolver() {
CacheVersionConflictResolver rslvr;

MetricRegistryImpl mreg = cctx.grid().context().metric().registry(CONFLICT_RESOLVER_METRICS_REGISTRY_NAME);

if (resolver != null)
rslvr = resolver;
else {
rslvr = new CacheVersionConflictResolverImpl(
clusterId,
conflictResolveField,
conflictResolverLog,
mreg
conflictResolverLog
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersionConflictContext;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersionedEntryEx;
import org.apache.ignite.internal.processors.metric.MetricRegistryImpl;
import org.apache.ignite.internal.processors.metric.impl.LongAdderMetric;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
Expand All @@ -44,18 +42,6 @@
* </ul>
*/
public class CacheVersionConflictResolverImpl implements CacheVersionConflictResolver {
/** Accepted entries count name. */
public static final String ACCEPTED_EVENTS_CNT = "AcceptedCount";

/** Accepted entries count description. */
public static final String ACCEPTED_EVENTS_CNT_DESC = "Count of accepted entries";

/** Rejected entries count name. */
public static final String REJECTED_EVENTS_CNT = "RejectedCount";

/** Rejected entries count description. */
public static final String REJECTED_EVENTS_CNT_DESC = "Count of rejected entries";

/**
* Cluster id.
*/
Expand All @@ -80,32 +66,21 @@ public class CacheVersionConflictResolverImpl implements CacheVersionConflictRes
@GridToStringInclude
protected final boolean conflictResolveFieldEnabled;

/** Accepted entries count. */
private final LongAdderMetric acceptedCnt;

/** Rejected entries count. */
private final LongAdderMetric rejectedCnt;

/**
* @param clusterId Data center id.
* @param conflictResolveField Field to resolve conflicts.
* @param log Logger.
* @param mreg Metric registry.
*/
public CacheVersionConflictResolverImpl(
byte clusterId,
String conflictResolveField,
IgniteLogger log,
MetricRegistryImpl mreg
IgniteLogger log
) {
this.clusterId = clusterId;
this.conflictResolveField = conflictResolveField;
this.log = log;

conflictResolveFieldEnabled = conflictResolveField != null;

acceptedCnt = mreg.longAdderMetric(ACCEPTED_EVENTS_CNT, ACCEPTED_EVENTS_CNT_DESC);
rejectedCnt = mreg.longAdderMetric(REJECTED_EVENTS_CNT, REJECTED_EVENTS_CNT_DESC);
}

/** {@inheritDoc} */
Expand All @@ -122,14 +97,10 @@ public CacheVersionConflictResolverImpl(
if (log.isDebugEnabled())
debugResolve(ctx, useNew, oldEntry, newEntry);

if (useNew) {
if (useNew)
res.useNew();
acceptedCnt.increment();
}
else {
else
res.useOld();
rejectedCnt.increment();
}

return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
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.internal.processors.metric.MetricRegistryImpl;
import org.apache.ignite.internal.processors.metric.impl.LongAdderMetric;
import org.apache.ignite.testframework.ListeningTestLogger;
import org.apache.ignite.testframework.LogListener;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
Expand All @@ -56,9 +54,6 @@
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.cdc.conflictresolve.CacheConflictResolutionManagerImpl.CONFLICT_RESOLVER_METRICS_REGISTRY_NAME;
import static org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl.ACCEPTED_EVENTS_CNT;
import static org.apache.ignite.cdc.conflictresolve.CacheVersionConflictResolverImpl.REJECTED_EVENTS_CNT;

/**
* Cache conflict operations test.
Expand Down Expand Up @@ -264,22 +259,6 @@ public void testUpdatesConflict() throws Exception {
putConflict(key, 5, conflictResolveField() != null);
}

/** */
@Test
public void testMetrics() throws Exception {
String key = key("UpdateClusterUpdateReorder", otherClusterId);

checkMetrics(0, 0);

putConflict(key, 1, true);

checkMetrics(1, 0);

putConflict(key, 1, false);

checkMetrics(1, 1);
}

/** Test switching debug log level for ConflictResolver during runtime */
@Test
public void testResolveDebug() throws Exception {
Expand Down Expand Up @@ -392,15 +371,4 @@ private String key(String key, byte otherClusterId) {
protected String conflictResolveField() {
return null;
}

/** Checks metrics for conflict resolver. */
protected void checkMetrics(int acceptedCnt, int rejectedCnt) {
MetricRegistryImpl mreg = ign.context().metric().registry(CONFLICT_RESOLVER_METRICS_REGISTRY_NAME);

assertNotNull(mreg.findMetric(ACCEPTED_EVENTS_CNT));
assertNotNull(mreg.findMetric(REJECTED_EVENTS_CNT));

assertEquals(acceptedCnt, ((LongAdderMetric)mreg.findMetric(ACCEPTED_EVENTS_CNT)).value());
assertEquals(rejectedCnt, ((LongAdderMetric)mreg.findMetric(REJECTED_EVENTS_CNT)).value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ public class CacheConflictOperationsWithCustomResolverTest extends CacheConflict
GridTestUtils.assertThrows(log, super::testUpdatesConflict, AssertionError.class, "");
}

/** {@inheritDoc} */
@Test
@Override public void testMetrics() throws Exception {
// LWW strategy resolves conflicts in unexpected way at versioned resolve test.
GridTestUtils.assertThrows(log, super::testMetrics, AssertionError.class, "");
}

/** {@inheritDoc} */
@Test
@Override public void testResolveDebug() throws Exception {
Expand All @@ -82,9 +75,4 @@ private static final class LwwConflictResolver implements CacheVersionConflictRe
return res;
}
}

/** {@inheritDoc} */
@Override protected void checkMetrics(int acceptedCnt, int rejectedCnt) {
// No op.
}
}

0 comments on commit fe451d5

Please sign in to comment.