From a31c4316f0c139b0618a988e350aceee07b0be17 Mon Sep 17 00:00:00 2001 From: korlov42 Date: Mon, 30 Nov 2020 15:55:12 +0300 Subject: [PATCH 1/2] IGNITE-13776 BPlus tree lock retries limit reached with sqlOnHeapCacheEnabled --- .../persistence/GridCacheOffheapManager.java | 19 ++++++++- .../cache/index/H2RowCacheSelfTest.java | 39 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java index ad062a83d6a8e..0d7719a570173 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java @@ -1837,6 +1837,15 @@ public static class GridCacheDataStore implements CacheDataStore { */ private volatile long nextStoreCleanTimeNanos; + /** */ + private GridQueryRowCacheCleaner rowCacheCleaner; + + /** + * Mutex used to synchronise publication of initialized delegate link and actions that should change + * the delegate's state, so the delegate will not be in obsolete state. + */ + private final Object delegatePublicationMux = new Object(); + /** */ private PartitionMetaStorage partStorage; @@ -2130,7 +2139,11 @@ private CacheDataStore init0(boolean checkExists) throws IgniteCheckedException pageMem.releasePage(grpId, partMetaId, partMetaPage); } - delegate = delegate0; + synchronized (delegatePublicationMux) { + delegate0.setRowCacheCleaner(rowCacheCleaner); + + delegate = delegate0; + } } catch (Throwable ex) { U.error(log, "Unhandled exception during page store initialization. All further operations will " + @@ -2532,6 +2545,10 @@ private Metas getOrAllocatePartitionMetas() throws IgniteCheckedException { /** {@inheritDoc} */ @Override public void setRowCacheCleaner(GridQueryRowCacheCleaner rowCacheCleaner) { try { + synchronized (delegatePublicationMux) { + this.rowCacheCleaner = rowCacheCleaner; + } + CacheDataStore delegate0 = init0(true); if (delegate0 != null) diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2RowCacheSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2RowCacheSelfTest.java index ff985e9505ff2..99fc89a5ba879 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2RowCacheSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2RowCacheSelfTest.java @@ -17,6 +17,8 @@ package org.apache.ignite.internal.processors.cache.index; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -24,6 +26,7 @@ import java.util.Random; import java.util.Set; import javax.cache.Cache; +import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteDataStreamer; @@ -31,7 +34,11 @@ import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.cache.query.SqlQuery; import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.cluster.ClusterState; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.query.h2.H2RowCache; @@ -39,10 +46,13 @@ import org.apache.ignite.testframework.GridTestUtils; import org.jsr166.ConcurrentLinkedHashMap; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; /** * Tests H2RowCacheRegistry. */ +@RunWith(Parameterized.class) @SuppressWarnings({"unchecked", "ConstantConditions"}) public class H2RowCacheSelfTest extends AbstractIndexingCommonTest { /** Keys count. */ @@ -51,18 +61,45 @@ public class H2RowCacheSelfTest extends AbstractIndexingCommonTest { /** Random generator. */ private static final Random RND = new Random(System.currentTimeMillis()); + /** */ + @Parameterized.Parameters(name = "persistenceEnabled={0}") + public static Collection testParams() { + return Arrays.asList(new Object[]{true}, new Object[]{false}); + } + + /** */ + @Parameterized.Parameter + public boolean persistenceEnabled; + /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - startGrid(); + cleanPersistenceDir(); + + Ignite ignite = startGrid(); + + if (persistenceEnabled) + ignite.cluster().state(ClusterState.ACTIVE); } /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { stopAllGrids(); + cleanPersistenceDir(); + super.afterTest(); } + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setDataStorageConfiguration( + new DataStorageConfiguration().setDefaultDataRegionConfiguration( + new DataRegionConfiguration().setPersistenceEnabled(persistenceEnabled) + ) + ); + } + /** * @param name Cache name. * @param enableOnheapCache Enable on-heal SQL rows cache. From e2672d6cc6ff4041cb35df3ec695317451c889e1 Mon Sep 17 00:00:00 2001 From: korlov42 Date: Thu, 3 Dec 2020 13:23:37 +0300 Subject: [PATCH 2/2] add missed volatile --- .../ignite/internal/processors/cache/persistence/RowStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RowStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RowStore.java index d1386e7bf67e7..ebe5065ebd1aa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RowStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/RowStore.java @@ -50,7 +50,7 @@ public class RowStore { private final boolean persistenceEnabled; /** Row cache cleaner. */ - private GridQueryRowCacheCleaner rowCacheCleaner; + private volatile GridQueryRowCacheCleaner rowCacheCleaner; /** */ protected final CacheGroupContext grp;