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 31430b722d9 IGNITE-29227 Fix lost continuous query events with an
unregistered transformer result class on an ATOMIC cache (#13769)
31430b722d9 is described below
commit 31430b722d928b69cfe04bba76eb395555a636c3
Author: Reza Taroosheh <[email protected]>
AuthorDate: Fri Nov 6 06:08:02 2026 +0100
IGNITE-29227 Fix lost continuous query events with an unregistered
transformer result class on an ATOMIC cache (#13769)
---
.../continuous/CacheContinuousQueryHandler.java | 78 +++++++++---
...inuousWithTransformerUnregisteredClassTest.java | 137 +++++++++++++++++++++
.../testsuites/IgniteCacheQuerySelfTestSuite6.java | 2 +
3 files changed, 197 insertions(+), 20 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
index 204f9f76eb3..60e50ecda95 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java
@@ -50,6 +50,8 @@ import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.MarshallableMessage;
import org.apache.ignite.internal.Marshalled;
import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.UnregisteredBinaryTypeException;
+import org.apache.ignite.internal.UnregisteredClassException;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
import
org.apache.ignite.internal.managers.communication.CommunicationMarshalling;
import org.apache.ignite.internal.managers.communication.GridIoPolicy;
@@ -1196,21 +1198,9 @@ public final class CacheContinuousQueryHandler<K, V>
extends AbstractMessage imp
notifyLocalListener(F.asList(evt), trans);
}
else {
- if (!entry.isFiltered()) {
- if (trans != null)
- entry = transformToEntry(trans, evt);
-
- prepareEntry(cctx, nodeId, entry);
- }
-
- Object entryOrList = handleEntry(cctx, entry);
-
- if (entryOrList != null) {
- if (log.isDebugEnabled())
- log.debug("Send the following event to listener: " +
entryOrList);
+ Object transVal = trans != null && !entry.isFiltered() ?
transform(trans, evt) : null;
- ctx.continuous().addNotification(nodeId, routineId,
entryOrList, topic, sync, true);
- }
+ notifyRemoteListener(cctx, evt, trans != null, transVal);
}
}
catch (ClusterTopologyCheckedException ex) {
@@ -1259,6 +1249,56 @@ public final class CacheContinuousQueryHandler<K, V>
extends AbstractMessage imp
}
}
+ /**
+ * Converts the event for the listener on another node and sends it.
+ *
+ * @param cctx Cache context.
+ * @param evt Event.
+ * @param transformed Whether the query has a transformer.
+ * @param transVal Transformer result.
+ */
+ private void notifyRemoteListener(GridCacheContext<K, V> cctx,
CacheContinuousQueryEvent<K, V> evt,
+ boolean transformed, @Nullable Object transVal) {
+ try {
+ CacheContinuousQueryEntry entry = evt.entry();
+
+ if (!entry.isFiltered()) {
+ if (transformed) {
+ try {
+ entry = transformToEntry(transVal, evt);
+ }
+ catch (UnregisteredClassException |
UnregisteredBinaryTypeException ex) {
+ // Registration is not allowed under the topology
lock, so retry in the async callback pool.
+ ctx.pools().asyncCallbackPool().execute(
+ () -> notifyRemoteListener(cctx, evt, true,
transVal),
+ evt.partitionId());
+
+ return;
+ }
+ }
+
+ prepareEntry(cctx, nodeId, entry);
+ }
+
+ Object entryOrList = handleEntry(cctx, entry);
+
+ if (entryOrList != null) {
+ if (log.isDebugEnabled())
+ log.debug("Send the following event to listener: " +
entryOrList);
+
+ ctx.continuous().addNotification(nodeId, routineId,
entryOrList, topic, sync, true);
+ }
+ }
+ catch (ClusterTopologyCheckedException ex) {
+ if (log.isDebugEnabled())
+ log.debug("Failed to send event notification to node, node
left cluster " +
+ "[node=" + nodeId + ", err=" + ex + ']');
+ }
+ catch (Exception ex) {
+ U.error(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), "Failed to send
event notification to node: " + nodeId, ex);
+ }
+ }
+
/**
* Notifies local listener.
*
@@ -1707,17 +1747,15 @@ public final class CacheContinuousQueryHandler<K, V>
extends AbstractMessage imp
}
/**
- * Transform event data with {@link #getTransformer()} if exists.
+ * Creates an entry that holds the transformer result instead of the event
data.
*
- * @param trans Transformer.
+ * @param transVal Transformer result.
* @param evt Event to transform.
- * @return Entry contains only transformed data if transformer exists.
Unchanged event if transformer is not set.
+ * @return Entry contains only transformed data if transformer exists.
* @see #getTransformer()
*/
- private CacheContinuousQueryEntry
transformToEntry(IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?>
trans,
+ private CacheContinuousQueryEntry transformToEntry(@Nullable Object
transVal,
CacheContinuousQueryEvent<? extends K, ? extends V> evt) {
- Object transVal = transform(trans, evt);
-
CacheObject cacheObj = transVal == null ? null :
cacheContext(ctx).toCacheObject(transVal);
EventType type = evt.entry().eventType();
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousWithTransformerUnregisteredClassTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousWithTransformerUnregisteredClassTest.java
new file mode 100644
index 00000000000..03542e186e7
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousWithTransformerUnregisteredClassTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.query.continuous;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.event.CacheEntryEvent;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.query.ContinuousQueryWithTransformer;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Checks that {@link ContinuousQueryWithTransformer} on an ATOMIC cache
delivers events transformed on a remote node
+ * when the class of the transformer result is not registered yet.
+ */
+public class CacheContinuousWithTransformerUnregisteredClassTest extends
GridCommonAbstractTest {
+
+ /** */
+ private static final int DFLT_SERVER_NODE_CNT = 2;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ CacheConfiguration<Integer, Object> ccfg = new
CacheConfiguration<>(DEFAULT_CACHE_NAME);
+
+ ccfg.setCacheMode(CacheMode.PARTITIONED);
+ ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+ ccfg.setBackups(1);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ grid(0).cache(DEFAULT_CACHE_NAME).removeAll();
+
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGrids(DFLT_SERVER_NODE_CNT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids(true);
+
+ super.afterTestsStopped();
+ }
+
+ /** */
+ @Test
+ public void testUnregisteredResultClassOnAtomicCache() throws Exception {
+ List<Object> received = Collections.synchronizedList(new
ArrayList<>());
+
+ ContinuousQueryWithTransformer<Integer, Object, Person> qry = new
ContinuousQueryWithTransformer<>();
+
+ qry.setRemoteTransformerFactory(FactoryBuilder.factoryOf(new
ToPerson()));
+
+ qry.setLocalListener(evts -> {
+ for (Object e : evts)
+ received.add(e);
+ });
+
+ IgniteCache<Integer, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
+
+ int rmtKey = primaryKey(grid(1).cache(DEFAULT_CACHE_NAME));
+
+ try (QueryCursor<?> ignored = cache.query(qry)) {
+ cache.put(rmtKey, 1);
+ cache.put(rmtKey, 2);
+ cache.put(rmtKey, 3);
+
+ boolean allReceived = GridTestUtils.waitForCondition(() ->
received.size() == 3, 5_000);
+
+ assertTrue("Received: " + received, allReceived);
+
+ for (int i = 0; i < received.size(); i++) {
+ Object o = received.get(i);
+
+ assertTrue("Unexpected class: " + o.getClass().getName(), o
instanceof Person);
+
+ assertEquals(i + 1, ((Person)o).id);
+ }
+ }
+ }
+
+ /** */
+ private static class Person {
+ /** */
+ final int id;
+
+ /** */
+ Person(int id) {
+ this.id = id;
+ }
+ }
+
+ /** */
+ private static class ToPerson implements IgniteClosure<CacheEntryEvent<?
extends Integer, ?>, Person> {
+ /** {@inheritDoc} */
+ @Override public Person apply(CacheEntryEvent<? extends Integer, ?>
evt) {
+ return new Person((Integer)evt.getValue());
+ }
+ }
+}
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java
index 60d7e9954dd..6471274dfa7 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite6.java
@@ -30,6 +30,7 @@ import
org.apache.ignite.internal.processors.cache.query.continuous.CacheContinu
import
org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryRandomOperationsTest;
import
org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousWithTransformerPartitionedSelfTest;
import
org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousWithTransformerRandomOperationsTest;
+import
org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousWithTransformerUnregisteredClassTest;
import
org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationNearEnabledTest;
import
org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationStoreEnabledTest;
import
org.apache.ignite.internal.processors.cache.query.continuous.CacheKeepBinaryIterationTest;
@@ -61,6 +62,7 @@ import org.junit.runners.Suite;
IgniteInsertNullableDuplicatesSqlTest.class,
GridCacheContinuousQueryPartitionAtomicOneNodeTest.class,
CacheContinuousWithTransformerPartitionedSelfTest.class,
+ CacheContinuousWithTransformerUnregisteredClassTest.class,
GridCacheContinuousQueryReplicatedAtomicOneNodeTest.class,
ContinuousQueryMarshallerTest.class,
GridCacheContinuousQueryReplicatedAtomicSelfTest.class,