This is an automated email from the ASF dual-hosted git repository.
zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new ca400bb025e IGNITE-27818 PerfStat: Add cache store operations (#12954)
ca400bb025e is described below
commit ca400bb025ea48509a9f1c236bc9479c971189c6
Author: Aleksandr Chesnokov <[email protected]>
AuthorDate: Tue Mar 31 09:51:37 2026 +0300
IGNITE-27818 PerfStat: Add cache store operations (#12954)
---
.../cache/store/GridCacheStoreManagerAdapter.java | 64 ++++++++++++++++
.../performancestatistics/OperationType.java | 24 +++++-
.../PerformanceStatisticsSelfTest.java | 87 ++++++++++++++++++++++
3 files changed, 174 insertions(+), 1 deletion(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
index adb13f44816..6221f9682dc 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
@@ -48,6 +48,7 @@ import
org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter;
import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import
org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import
org.apache.ignite.internal.processors.performancestatistics.OperationType;
import org.apache.ignite.internal.util.GridEmptyIterator;
import org.apache.ignite.internal.util.GridLeanMap;
import org.apache.ignite.internal.util.GridSetWrapper;
@@ -323,6 +324,10 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
Object val = null;
+ boolean perfStatEnabled =
cctx.kernalContext().performanceStatistics().enabled();
+
+ long start = perfStatEnabled ? System.nanoTime() : 0;
+
try {
val = singleThreadGate.load(storeKey);
@@ -338,6 +343,9 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
throw new IgniteCheckedException(new CacheLoaderException(e));
}
finally {
+ if (perfStatEnabled)
+ writeStatistics(OperationType.CACHE_LOAD, start);
+
IgniteInternalTx tx0 = tx;
if (tx0 != null && (tx0.dht() && tx0.local()))
@@ -454,6 +462,10 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
boolean threwEx = true;
+ boolean perfStatEnabled =
cctx.kernalContext().performanceStatistics().enabled();
+
+ long start = perfStatEnabled ? System.nanoTime() : 0;
+
try {
IgniteBiInClosure<Object, Object> c = new CI2<Object,
Object>() {
@Override public void apply(Object k, Object val) {
@@ -494,6 +506,9 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
throw new IgniteCheckedException(new CacheLoaderException(e));
}
finally {
+ if (perfStatEnabled)
+ writeStatistics(OperationType.CACHE_LOAD_ALL, start);
+
sessionEnd0(tx, threwEx);
}
@@ -512,6 +527,10 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
boolean threwEx = true;
+ boolean perfStatEnabled =
cctx.kernalContext().performanceStatistics().enabled();
+
+ long start = perfStatEnabled ? System.nanoTime() : 0;
+
try {
store.loadCache(new IgniteBiInClosure<Object, Object>() {
@Override public void apply(Object k, Object o) {
@@ -542,6 +561,9 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
throw new IgniteCheckedException(new CacheLoaderException(e));
}
finally {
+ if (perfStatEnabled)
+ writeStatistics(OperationType.CACHE_LOAD_CACHE, start);
+
sessionEnd0(null, threwEx);
}
@@ -578,6 +600,10 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
boolean threwEx = true;
+ boolean perfStatEnabled =
cctx.kernalContext().performanceStatistics().enabled();
+
+ long start = perfStatEnabled ? System.nanoTime() : 0;
+
try {
store.write(new CacheEntryImpl<>(key0, locStore ? F.t(val0,
ver) : val0));
@@ -593,6 +619,9 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
throw new IgniteCheckedException(new CacheWriterException(e));
}
finally {
+ if (perfStatEnabled)
+ writeStatistics(OperationType.CACHE_WRITE, start);
+
sessionEnd0(tx, threwEx);
}
@@ -633,6 +662,10 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
boolean threwEx = true;
+ boolean perfStatEnabled =
cctx.kernalContext().performanceStatistics().enabled();
+
+ long start = perfStatEnabled ? System.nanoTime() : 0;
+
try {
store.writeAll(entries);
@@ -657,6 +690,9 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
throw new IgniteCheckedException(e);
}
finally {
+ if (perfStatEnabled)
+ writeStatistics(OperationType.CACHE_WRITE_ALL, start);
+
sessionEnd0(tx, threwEx);
}
@@ -686,6 +722,10 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
boolean threwEx = true;
+ boolean perfStatEnabled =
cctx.kernalContext().performanceStatistics().enabled();
+
+ long start = perfStatEnabled ? System.nanoTime() : 0;
+
try {
store.delete(key0);
@@ -701,6 +741,9 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
throw new IgniteCheckedException(new CacheWriterException(e));
}
finally {
+ if (perfStatEnabled)
+ writeStatistics(OperationType.CACHE_DELETE, start);
+
sessionEnd0(tx, threwEx);
}
@@ -738,6 +781,10 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
boolean threwEx = true;
+ boolean perfStatEnabled =
cctx.kernalContext().performanceStatistics().enabled();
+
+ long start = perfStatEnabled ? System.nanoTime() : 0;
+
try {
store.deleteAll(keys0);
@@ -756,6 +803,9 @@ public abstract class GridCacheStoreManagerAdapter extends
GridCacheManagerAdapt
throw new IgniteCheckedException(e);
}
finally {
+ if (perfStatEnabled)
+ writeStatistics(OperationType.CACHE_DELETE_ALL, start);
+
sessionEnd0(tx, threwEx);
}
@@ -954,6 +1004,20 @@ public abstract class GridCacheStoreManagerAdapter
extends GridCacheManagerAdapt
*/
protected abstract CacheConfiguration cacheConfiguration();
+ /**
+ * Writes cache store operation performance statistics.
+ *
+ * @param op Operation type.
+ * @param start Start time in nanoseconds.
+ */
+ protected void writeStatistics(OperationType op, long start) {
+ cctx.kernalContext().performanceStatistics().cacheOperation(
+ op,
+ cctx.cacheId(),
+ U.currentTimeMillis(),
+ System.nanoTime() - start);
+ }
+
/**
*
*/
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java
index 371a1acda1f..2f1f76d7661 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/OperationType.java
@@ -105,13 +105,35 @@ public enum OperationType {
/** System view row. */
SYSTEM_VIEW_ROW(25),
+ /** Cache load from cache store. */
+ CACHE_LOAD(26),
+
+ /** Cache load all from cache store. */
+ CACHE_LOAD_ALL(27),
+
+ /** Cache preload from cache store. */
+ CACHE_LOAD_CACHE(28),
+
+ /** Cache write to cache store. */
+ CACHE_WRITE(29),
+
+ /** Cache write all to cache store. */
+ CACHE_WRITE_ALL(30),
+
+ /** Cache delete from cache store. */
+ CACHE_DELETE(31),
+
+ /** Cache delete all from cache store. */
+ CACHE_DELETE_ALL(32),
+
/** Version. */
VERSION(255);
/** Cache operations. */
public static final EnumSet<OperationType> CACHE_OPS =
EnumSet.of(CACHE_GET, CACHE_PUT, CACHE_REMOVE,
CACHE_GET_AND_PUT, CACHE_GET_AND_REMOVE, CACHE_INVOKE, CACHE_LOCK,
CACHE_GET_ALL, CACHE_PUT_ALL,
- CACHE_REMOVE_ALL, CACHE_INVOKE_ALL, CACHE_PUT_ALL_CONFLICT,
CACHE_REMOVE_ALL_CONFLICT);
+ CACHE_REMOVE_ALL, CACHE_INVOKE_ALL, CACHE_PUT_ALL_CONFLICT,
CACHE_REMOVE_ALL_CONFLICT, CACHE_LOAD,
+ CACHE_LOAD_ALL, CACHE_LOAD_CACHE, CACHE_WRITE, CACHE_WRITE_ALL,
CACHE_DELETE, CACHE_DELETE_ALL);
/** Transaction operations. */
public static final EnumSet<OperationType> TX_OPS = EnumSet.of(TX_COMMIT,
TX_ROLLBACK);
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSelfTest.java
index 26f0a23472c..3a9373a42b1 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSelfTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSelfTest.java
@@ -20,18 +20,25 @@ package
org.apache.ignite.internal.processors.performancestatistics;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.function.Consumer;
+import javax.cache.configuration.FactoryBuilder;
import javax.cache.processor.EntryProcessor;
import javax.cache.processor.EntryProcessorException;
import javax.cache.processor.MutableEntry;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.MapCacheStoreStrategy;
import org.apache.ignite.internal.util.GridIntList;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -44,17 +51,24 @@ import org.junit.runners.Parameterized;
import static
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.CLIENT;
import static
org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.ClientType.SERVER;
+import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_DELETE;
+import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_DELETE_ALL;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET_ALL;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET_AND_PUT;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_GET_AND_REMOVE;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_INVOKE;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_INVOKE_ALL;
+import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_LOAD;
+import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_LOAD_ALL;
+import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_LOAD_CACHE;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_LOCK;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_PUT;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_PUT_ALL;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_REMOVE;
import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_REMOVE_ALL;
+import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_WRITE;
+import static
org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_WRITE_ALL;
/**
* Tests performance statistics.
@@ -62,6 +76,9 @@ import static
org.apache.ignite.internal.processors.performancestatistics.Operat
@RunWith(Parameterized.class)
@SuppressWarnings({"LockAcquiredButNotSafelyReleased"})
public class PerformanceStatisticsSelfTest extends
AbstractPerformanceStatisticsTest {
+ /** Store cache name. */
+ private static final String STORE_CACHE_NAME = "store-cache";
+
/** Nodes count. */
private static final int NODES_CNT = 2;
@@ -105,12 +122,34 @@ public class PerformanceStatisticsSelfTest extends
AbstractPerformanceStatistics
/** Test cache. */
private static IgniteCache<Object, Object> cache;
+ /** Store-backed test cache. */
+ private static IgniteCache<Object, Object> storeCache;
+
+ /** Cache store operation types. */
+ private static final Set<OperationType> CACHE_STORE_OPS = EnumSet.of(
+ CACHE_LOAD,
+ CACHE_LOAD_ALL,
+ CACHE_LOAD_CACHE,
+ CACHE_WRITE,
+ CACHE_WRITE_ALL,
+ CACHE_DELETE,
+ CACHE_DELETE_ALL
+ );
+
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setCacheConfiguration(defaultCacheConfiguration());
+ CacheConfiguration<Object, Object> storeCacheCfg =
defaultCacheConfiguration()
+ .setName(STORE_CACHE_NAME)
+ .setReadThrough(true)
+ .setWriteThrough(true)
+
.setCacheStoreFactory(FactoryBuilder.factoryOf(MapCacheStoreStrategy.MapCacheStore.class));
+
+ cfg.setCacheConfiguration(defaultCacheConfiguration(), storeCacheCfg);
+
return cfg;
}
@@ -123,6 +162,7 @@ public class PerformanceStatisticsSelfTest extends
AbstractPerformanceStatistics
node = clientType == SERVER ? srv : client;
cache = node.cache(DEFAULT_CACHE_NAME);
+ storeCache = node.cache(STORE_CACHE_NAME);
for (int i = 0; i < ENTRY_COUNT; i++)
cache.put(i, i);
@@ -246,6 +286,26 @@ public class PerformanceStatisticsSelfTest extends
AbstractPerformanceStatistics
cache -> cache.invokeAllAsync(Collections.singleton(10),
CACHE_ENTRY_PROC).get());
}
+ /** @throws Exception If failed. */
+ @Test
+ public void testCacheStoreOperation() throws Exception {
+ checkCacheStoreOperation(Map.of(CACHE_LOAD, 1), cache -> cache.get(0));
+ checkCacheStoreOperation(Map.of(CACHE_LOAD_ALL, 1), cache ->
cache.getAll(Set.of(0, 1)));
+ checkCacheStoreOperation(Map.of(CACHE_LOAD_CACHE, 1), cache ->
cache.loadCache(null));
+
+ checkCacheStoreOperation(Map.of(CACHE_WRITE, 1, CACHE_DELETE, 1),
cache -> {
+ cache.put(0, 0);
+ cache.remove(0);
+ });
+
+ checkCacheStoreOperation(Map.of(CACHE_WRITE_ALL, 1, CACHE_DELETE_ALL,
1), cache -> {
+ Map<Object, Object> vals = Map.of(0, 0, 1, 1);
+
+ cache.putAll(vals);
+ cache.removeAll(vals.keySet());
+ });
+ }
+
/** Checks cache operation. */
private void checkCacheOperation(OperationType op,
Consumer<IgniteCache<Object, Object>> clo) throws Exception {
long startTime = U.currentTimeMillis();
@@ -274,6 +334,33 @@ public class PerformanceStatisticsSelfTest extends
AbstractPerformanceStatistics
assertEquals(1, ops.get());
}
+ /** Checks cache store operations. */
+ private void checkCacheStoreOperation(Map<OperationType, Integer> expOps,
Consumer<IgniteCache<Object, Object>> clo) throws Exception {
+ long startTime = U.currentTimeMillis();
+
+ cleanPerformanceStatisticsDir();
+
+ startCollectStatistics();
+
+ clo.accept(storeCache);
+
+ Map<OperationType, Integer> actOps = new
EnumMap<>(OperationType.class);
+
+ stopCollectStatisticsAndRead(new TestHandler() {
+ @Override public void cacheOperation(UUID nodeId, OperationType
type, int cacheId, long opStartTime, long duration) {
+ if (cacheId != CU.cacheId(STORE_CACHE_NAME) ||
!CACHE_STORE_OPS.contains(type))
+ return;
+
+ actOps.merge(type, 1, Integer::sum);
+
+ assertTrue(opStartTime >= startTime);
+ assertTrue(duration >= 0);
+ }
+ });
+
+ assertEquals(expOps, actOps);
+ }
+
/** @throws Exception If failed. */
@Test
public void testTransaction() throws Exception {