Repository: ignite Updated Branches: refs/heads/master 9ee7646ed -> cd0fc8344
IGNITE-10017 Infinite loop with 3rd party persistency and no value for the key in the data store - Fixes #5085. Signed-off-by: Pavel Kovalenko <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/cd0fc834 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/cd0fc834 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/cd0fc834 Branch: refs/heads/master Commit: cd0fc8344d9a7a4db46bf234efac78566baf3823 Parents: 9ee7646 Author: shroman <[email protected]> Authored: Fri Nov 30 20:25:15 2018 +0300 Committer: Pavel Kovalenko <[email protected]> Committed: Fri Nov 30 20:28:15 2018 +0300 ---------------------------------------------------------------------- .../cache/GridCacheConcurrentMapImpl.java | 4 +- ...IgniteGetNonPlainKeyReadThroughSelfTest.java | 155 +++++++++++++++++++ .../ignite/testsuites/IgniteCacheTestSuite.java | 3 + 3 files changed, 161 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/cd0fc834/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java index a463500..938fd72 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapImpl.java @@ -55,6 +55,8 @@ public abstract class GridCacheConcurrentMapImpl implements GridCacheConcurrentM @Nullable @Override public GridCacheMapEntry getEntry(GridCacheContext ctx, KeyCacheObject key) { CacheMapHolder hld = entriesMapIfExists(ctx.cacheIdBoxed()); + key = (KeyCacheObject)ctx.kernalContext().cacheObjects().prepareForCache(key, ctx); + return hld != null ? hld.map.get(key) : null; } @@ -89,7 +91,7 @@ public abstract class GridCacheConcurrentMapImpl implements GridCacheConcurrentM try { while (!done) { - GridCacheMapEntry entry = hld != null ? hld.map.get(key) : null; + GridCacheMapEntry entry = hld != null ? hld.map.get(ctx.kernalContext().cacheObjects().prepareForCache(key, ctx)) : null; created = null; doomed = null; http://git-wip-us.apache.org/repos/asf/ignite/blob/cd0fc834/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteGetNonPlainKeyReadThroughSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteGetNonPlainKeyReadThroughSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteGetNonPlainKeyReadThroughSelfTest.java new file mode 100644 index 0000000..21b09fc --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteGetNonPlainKeyReadThroughSelfTest.java @@ -0,0 +1,155 @@ +/* + * 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; + +import java.io.Serializable; +import javax.cache.Cache; +import javax.cache.configuration.Factory; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.store.CacheStore; +import org.apache.ignite.cache.store.CacheStoreAdapter; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.binary.BinaryUtils; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Tests read through for non-{@link BinaryUtils#BINARY_CLS} keys. + */ +public class IgniteGetNonPlainKeyReadThroughSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + private StoreFactory storeFactory; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); + + ccfg.setCacheMode(CacheMode.PARTITIONED); + + ccfg.setReadThrough(true); + + ccfg.setCacheStoreFactory(storeFactory); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + private static class StoreFactory implements Factory<CacheStore<Object, Object>> { + private boolean nullVal; + + public StoreFactory(boolean nullVal) { + this.nullVal = nullVal; + } + + /** {@inheritDoc} */ + @Override public CacheStore<Object, Object> create() { + if (nullVal) + return new IgniteGetNonPlainKeyReadThroughSelfTest.Store(true); + else + return new IgniteGetNonPlainKeyReadThroughSelfTest.Store(false); + } + } + + /** + * + */ + private static class Store extends CacheStoreAdapter<Object, Object> implements Serializable { + private boolean nullVal; + + public Store(boolean nullVal) { + this.nullVal = nullVal; + } + + /** {@inheritDoc} */ + @Override public Object load(Object key) throws CacheLoaderException { + if (nullVal) + return null; + else + return key; + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry e) + throws CacheWriterException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + // No-op. + } + } + + /** + * @throws Exception If failed. + */ + public void testGetNullRead() throws Exception { + storeFactory = new StoreFactory(true); + + testGet(true); + } + + /** + * @throws Exception If failed. + */ + public void testGetValueRead() throws Exception { + storeFactory = new StoreFactory(false); + + testGet(false); + } + + /** + * @throws Exception If failed. + */ + private void testGet(boolean nullRead) throws Exception { + try { + final Ignite ignite = startGrid(); + + final GridCacheAdapter cache = ((IgniteKernal)grid()).internalCache(DEFAULT_CACHE_NAME); + + IgniteBiTuple<String, String> key = new IgniteBiTuple<>(); + + if (nullRead) { + assertEquals(null, cache.get("key")); + assertEquals(null, cache.get(key)); + } + else { + assertEquals("key", cache.get("key")); + assertEquals(key, cache.get(key)); + } + } + finally { + stopAllGrids(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/cd0fc834/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java index dd03ef3..9781b85 100755 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java @@ -107,6 +107,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheTxInvokeTest; import org.apache.ignite.internal.processors.cache.IgniteCacheTxLocalInvokeTest; import org.apache.ignite.internal.processors.cache.IgniteCacheTxNearEnabledInvokeTest; import org.apache.ignite.internal.processors.cache.IgniteClientAffinityAssignmentSelfTest; +import org.apache.ignite.internal.processors.cache.IgniteGetNonPlainKeyReadThroughSelfTest; import org.apache.ignite.internal.processors.cache.IgniteIncompleteCacheObjectSelfTest; import org.apache.ignite.internal.processors.cache.IgnitePutAllLargeBatchSelfTest; import org.apache.ignite.internal.processors.cache.IgnitePutAllUpdateNonPreloadedPartitionSelfTest; @@ -366,6 +367,8 @@ public class IgniteCacheTestSuite extends TestSuite { suite.addTestSuite(BinaryMetadataRegistrationInsideEntryProcessorTest.class); + suite.addTestSuite(IgniteGetNonPlainKeyReadThroughSelfTest.class); + return suite; } }
