From dfa38542a98ed189282c7c4bcd9b05b66ee44bb5 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Tue, 17 Sep 2024 16:05:52 +0300 Subject: [PATCH] IGNITE-23211 Fix AssertionError on IgniteCache#get (#11537) --- .../distributed/near/GridNearTxLocal.java | 28 +++++----- .../RemoveEntryProcessorTransactionTest.java | 53 +++++++++++++++++++ .../GridCacheAbstractFullApiSelfTest.java | 2 +- .../testsuites/IgniteCacheTestSuite.java | 2 + 4 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/RemoveEntryProcessorTransactionTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java index a3205a8a5a01f..6798c08fc9e4a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java @@ -2306,19 +2306,21 @@ private Collection enlistRead( if (!F.isEmpty(txEntry.entryProcessors())) val = txEntry.applyEntryProcessors(val); - cacheCtx.addResult(map, - key, - val, - skipVals, - keepCacheObjects, - deserializeBinary, - false, - getRes, - readVer, - 0, - 0, - needVer, - U.deploymentClassLoader(cctx.kernalContext(), deploymentLdrId)); + if (val != null) { + cacheCtx.addResult(map, + key, + val, + skipVals, + keepCacheObjects, + deserializeBinary, + false, + getRes, + readVer, + 0, + 0, + needVer, + U.deploymentClassLoader(cctx.kernalContext(), deploymentLdrId)); + } } else missed.put(key, txEntry.cached().version()); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/RemoveEntryProcessorTransactionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/RemoveEntryProcessorTransactionTest.java new file mode 100644 index 0000000000000..1b3ebfb1485d7 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/RemoveEntryProcessorTransactionTest.java @@ -0,0 +1,53 @@ +/* + * 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; + +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest.RemoveAndReturnNullEntryProcessor; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionConcurrency; +import org.apache.ignite.transactions.TransactionIsolation; +import org.junit.Test; + +/** */ +public class RemoveEntryProcessorTransactionTest extends GridCommonAbstractTest { + /** */ + @Test + public void testDelete() throws Exception { + var c = startGrid(0).createCache(new CacheConfiguration() + .setName(DEFAULT_CACHE_NAME) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + ); + + for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) { + for (TransactionIsolation txIsolation : TransactionIsolation.values()) { + c.put("key", 1); + + try (Transaction tx = grid(0).transactions().txStart(txConcurrency, txIsolation)) { + c.invoke("key", new RemoveAndReturnNullEntryProcessor()); + + assertNull(c.get("key")); + } + + } + } + + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index 0218587cd9e76..8ae56fc07a4ad 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -6695,7 +6695,7 @@ private static class PrintIteratorStateTask extends TestIgniteIdxCallable /** * */ - private static class RemoveAndReturnNullEntryProcessor implements + public static class RemoveAndReturnNullEntryProcessor implements EntryProcessor, Serializable { /** {@inheritDoc} */ 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 868c442d5eda1..e5c3c6b44a978 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 @@ -37,6 +37,7 @@ import org.apache.ignite.cache.store.jdbc.GridCacheJdbcBlobStoreMultithreadedSelfTest; import org.apache.ignite.cache.store.jdbc.GridCacheJdbcBlobStoreSelfTest; import org.apache.ignite.cache.store.jdbc.JdbcTypesDefaultTransformerTest; +import org.apache.ignite.internal.RemoveEntryProcessorTransactionTest; import org.apache.ignite.internal.processors.cache.CacheAffinityCallSelfTest; import org.apache.ignite.internal.processors.cache.CacheAffinityKeyConfigurationMismatchTest; import org.apache.ignite.internal.processors.cache.CacheEntryProcessorCopySelfTest; @@ -134,6 +135,7 @@ public static List> suite(Collection ignoredTests) { GridTestUtils.addTestIfNeeded(suite, CacheEntryProcessorNonSerializableTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, CacheEntryProcessorExternalizableFailedTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, IgniteCacheEntryProcessorCallTest.class, ignoredTests); + GridTestUtils.addTestIfNeeded(suite, RemoveEntryProcessorTransactionTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, IgniteCacheTxNearEnabledInvokeTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, IgniteCrossCacheTxStoreSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, IgniteCacheEntryProcessorSequentialCallTest.class, ignoredTests);