You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "VolkodamovDaniil (via GitHub)" <gi...@apache.org> on 2026/05/25 13:46:02 UTC
[PR] Incremental snapshot thin client ordering problem [ignite]
VolkodamovDaniil opened a new pull request, #13178:
URL: https://github.com/apache/ignite/pull/13178
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
### The Contribution Checklist
- [ ] There is a single JIRA ticket related to the pull request.
- [ ] The web-link to the pull request is attached to the JIRA ticket.
- [ ] The JIRA ticket has the _Patch Available_ state.
- [ ] The pull request body describes changes that have been made.
The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
- [ ] The pull request title is treated as the final commit message.
The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
- [ ] A reviewer has been mentioned through the JIRA comments
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers))
- [ ] The pull request has been checked by the Teamcity Bot and
the `green visa` attached to the JIRA ticket (see tab `PR Check` at [TC.Bot - Instance 1](https://tcbot2.sbt-ignite-dev.ru/prs.html) or [TC.Bot - Instance 2](https://mtcga.gridgain.com/prs.html))
### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Incremental snapshot thin client ordering problem [ignite]
Posted by "timoninmaxim (via GitHub)" <gi...@apache.org>.
timoninmaxim commented on code in PR #13178:
URL: https://github.com/apache/ignite/pull/13178#discussion_r3299656398
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/incremental/IncrementalSnapshotOrderingTest.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.persistence.snapshot.incremental;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientTransaction;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.cluster.NodeOrderComparator;
+import org.apache.ignite.internal.managers.discovery.CustomMessageWrapper;
+import org.apache.ignite.internal.util.distributed.InitMessage;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT;
+
+/**
+ * Test reproducing transaction ordering violation during incremental snapshot with thin client.
+ */
+public class IncrementalSnapshotOrderingTest extends AbstractIncrementalSnapshotTest {
+ /** Latch to block InitMessage on nodes 2 and 3. */
+ private static volatile CountDownLatch blockInitMsgLatch;
+
+ /** Node indices where InitMessage is blocked. */
+ private static final Set<Integer> BLOCKED_NODES = new HashSet<>(Arrays.asList(2, 3));
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+ CacheConfiguration<Integer, Integer> cacheCfg = cacheConfiguration(CACHE);
+ cacheCfg.setAffinity(new SimpleAffinity());
+ cfg.setCacheConfiguration(cacheCfg);
+
+ int nodeIdx = getTestIgniteInstanceIndex(instanceName);
+ if (BLOCKED_NODES.contains(nodeIdx)) {
+ cfg.setDiscoverySpi(new BlockingInitMessageDiscoverySpi()
+ .setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder()));
+ }
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ cleanPersistenceDir();
+
+ startGrids(nodes());
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ grid(0).snapshot().createSnapshot(SNP).get();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ blockInitMsgLatch = null;
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int nodes() {
+ return 4;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int backups() {
+ return 0;
+ }
+
+ /**
+ * Reproduces the ordering violation.
+ */
+ @Test
+ public void testIncrementalSnapshotOrderingProblem() throws Exception {
+ blockInitMsgLatch = new CountDownLatch(1);
+
+ IgniteFuture<Void> snpFut = grid(0).snapshot().createIncrementalSnapshot(SNP);
+
+ boolean started = GridTestUtils.waitForCondition(() -> {
+ UUID id = snp(grid(0)).incrementalSnapshotId();
+ return id != null;
+ }, 10_000);
+ assertTrue("Snapshot did not start on node 0", started);
+
+ int clientPort = grid(0).localNode().<Integer>attribute(CLIENT_LISTENER_PORT);
+ ClientConfiguration clientCfg = new ClientConfiguration()
+ .setAddresses("127.0.0.1:" + clientPort);
+
+ try (IgniteClient thinClient = Ignition.startClient(clientCfg)) {
+ ClientCache<Integer, Integer> cache = thinClient.cache(CACHE);
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(1, 100);
+ cache.put(2, 200);
+ tx.commit();
+ }
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(3, 300);
+ cache.put(4, 400);
+ tx.commit();
+ }
+ }
+
+ assertTrue("Snapshot started on node 2 prematurely", snp(grid(2)).incrementalSnapshotId() == null);
+ blockInitMsgLatch.countDown();
+
+ snpFut.get(getTestTimeout());
+
+ restartWithCleanPersistence(nodes(), Collections.singletonList(CACHE));
+ grid(0).snapshot().restoreSnapshot(SNP, null, 1).get(getTestTimeout());
+
+ Integer val1 = (Integer)grid(0).cache(CACHE).get(1);
+ Integer val3 = (Integer)grid(2).cache(CACHE).get(3);
+
+ if (val1 == null && val3 != null) {
+ fail("Incremental snapshot ordering violation detected: " +
+ "tx1 is missing (should be present as it was committed before tx2), " +
+ "but tx2 (key3=" + val3 + ") is present.");
+ }
+ }
+
+ /** Discovery SPI that blocks InitMessage processing on certain nodes. */
+ private static class BlockingInitMessageDiscoverySpi extends TcpDiscoverySpi {
+ /** {@inheritDoc} */
+ @Override protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
+ if (msg instanceof TcpDiscoveryCustomEventMessage && blockInitMsgLatch != null) {
+ TcpDiscoveryCustomEventMessage m = (TcpDiscoveryCustomEventMessage)msg;
+
+ try {
+ CustomMessageWrapper m0 = (CustomMessageWrapper)m.message(
+ marshaller(), U.resolveClassLoader(ignite().configuration()));
+
+ if (m0.delegate() instanceof InitMessage) {
+ try {
+ blockInitMsgLatch.await();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ catch (Throwable ignored) {
+ // No-op
+ }
+ }
+
+ super.startMessageProcess(msg);
+ }
+ }
+
+ /** Simple affinity mapping key N to node N-1. */
+ private static class SimpleAffinity implements AffinityFunction {
Review Comment:
Please, use GridCommonAbstractTest#keyForNode instead - it will make the test more user friendly for a reviewer
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/incremental/IncrementalSnapshotOrderingTest.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.persistence.snapshot.incremental;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientTransaction;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.cluster.NodeOrderComparator;
+import org.apache.ignite.internal.managers.discovery.CustomMessageWrapper;
+import org.apache.ignite.internal.util.distributed.InitMessage;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT;
+
+/**
+ * Test reproducing transaction ordering violation during incremental snapshot with thin client.
+ */
+public class IncrementalSnapshotOrderingTest extends AbstractIncrementalSnapshotTest {
+ /** Latch to block InitMessage on nodes 2 and 3. */
+ private static volatile CountDownLatch blockInitMsgLatch;
+
+ /** Node indices where InitMessage is blocked. */
+ private static final Set<Integer> BLOCKED_NODES = new HashSet<>(Arrays.asList(2, 3));
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+ CacheConfiguration<Integer, Integer> cacheCfg = cacheConfiguration(CACHE);
+ cacheCfg.setAffinity(new SimpleAffinity());
+ cfg.setCacheConfiguration(cacheCfg);
+
+ int nodeIdx = getTestIgniteInstanceIndex(instanceName);
+ if (BLOCKED_NODES.contains(nodeIdx)) {
+ cfg.setDiscoverySpi(new BlockingInitMessageDiscoverySpi()
+ .setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder()));
+ }
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ cleanPersistenceDir();
+
+ startGrids(nodes());
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ grid(0).snapshot().createSnapshot(SNP).get();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ blockInitMsgLatch = null;
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int nodes() {
+ return 4;
Review Comment:
Why do you need 4 nodes, why 2 is not enough?
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/incremental/IncrementalSnapshotOrderingTest.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.persistence.snapshot.incremental;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientTransaction;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.cluster.NodeOrderComparator;
+import org.apache.ignite.internal.managers.discovery.CustomMessageWrapper;
+import org.apache.ignite.internal.util.distributed.InitMessage;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT;
+
+/**
+ * Test reproducing transaction ordering violation during incremental snapshot with thin client.
+ */
+public class IncrementalSnapshotOrderingTest extends AbstractIncrementalSnapshotTest {
+ /** Latch to block InitMessage on nodes 2 and 3. */
+ private static volatile CountDownLatch blockInitMsgLatch;
+
+ /** Node indices where InitMessage is blocked. */
+ private static final Set<Integer> BLOCKED_NODES = new HashSet<>(Arrays.asList(2, 3));
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+ CacheConfiguration<Integer, Integer> cacheCfg = cacheConfiguration(CACHE);
+ cacheCfg.setAffinity(new SimpleAffinity());
+ cfg.setCacheConfiguration(cacheCfg);
+
+ int nodeIdx = getTestIgniteInstanceIndex(instanceName);
+ if (BLOCKED_NODES.contains(nodeIdx)) {
+ cfg.setDiscoverySpi(new BlockingInitMessageDiscoverySpi()
+ .setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder()));
+ }
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ cleanPersistenceDir();
+
+ startGrids(nodes());
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ grid(0).snapshot().createSnapshot(SNP).get();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ blockInitMsgLatch = null;
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int nodes() {
+ return 4;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int backups() {
+ return 0;
+ }
+
+ /**
+ * Reproduces the ordering violation.
+ */
+ @Test
+ public void testIncrementalSnapshotOrderingProblem() throws Exception {
+ blockInitMsgLatch = new CountDownLatch(1);
+
+ IgniteFuture<Void> snpFut = grid(0).snapshot().createIncrementalSnapshot(SNP);
+
+ boolean started = GridTestUtils.waitForCondition(() -> {
+ UUID id = snp(grid(0)).incrementalSnapshotId();
+ return id != null;
+ }, 10_000);
+ assertTrue("Snapshot did not start on node 0", started);
+
+ int clientPort = grid(0).localNode().<Integer>attribute(CLIENT_LISTENER_PORT);
+ ClientConfiguration clientCfg = new ClientConfiguration()
+ .setAddresses("127.0.0.1:" + clientPort);
+
+ try (IgniteClient thinClient = Ignition.startClient(clientCfg)) {
+ ClientCache<Integer, Integer> cache = thinClient.cache(CACHE);
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(1, 100);
+ cache.put(2, 200);
+ tx.commit();
+ }
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(3, 300);
+ cache.put(4, 400);
+ tx.commit();
+ }
+ }
+
+ assertTrue("Snapshot started on node 2 prematurely", snp(grid(2)).incrementalSnapshotId() == null);
+ blockInitMsgLatch.countDown();
+
+ snpFut.get(getTestTimeout());
+
+ restartWithCleanPersistence(nodes(), Collections.singletonList(CACHE));
+ grid(0).snapshot().restoreSnapshot(SNP, null, 1).get(getTestTimeout());
+
+ Integer val1 = (Integer)grid(0).cache(CACHE).get(1);
+ Integer val3 = (Integer)grid(2).cache(CACHE).get(3);
+
+ if (val1 == null && val3 != null) {
+ fail("Incremental snapshot ordering violation detected: " +
+ "tx1 is missing (should be present as it was committed before tx2), " +
+ "but tx2 (key3=" + val3 + ") is present.");
Review Comment:
Misleading log - key3 = val3
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/incremental/IncrementalSnapshotOrderingTest.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.persistence.snapshot.incremental;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientTransaction;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.cluster.NodeOrderComparator;
+import org.apache.ignite.internal.managers.discovery.CustomMessageWrapper;
+import org.apache.ignite.internal.util.distributed.InitMessage;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT;
+
+/**
+ * Test reproducing transaction ordering violation during incremental snapshot with thin client.
+ */
+public class IncrementalSnapshotOrderingTest extends AbstractIncrementalSnapshotTest {
+ /** Latch to block InitMessage on nodes 2 and 3. */
+ private static volatile CountDownLatch blockInitMsgLatch;
+
+ /** Node indices where InitMessage is blocked. */
+ private static final Set<Integer> BLOCKED_NODES = new HashSet<>(Arrays.asList(2, 3));
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+ CacheConfiguration<Integer, Integer> cacheCfg = cacheConfiguration(CACHE);
+ cacheCfg.setAffinity(new SimpleAffinity());
+ cfg.setCacheConfiguration(cacheCfg);
+
+ int nodeIdx = getTestIgniteInstanceIndex(instanceName);
+ if (BLOCKED_NODES.contains(nodeIdx)) {
+ cfg.setDiscoverySpi(new BlockingInitMessageDiscoverySpi()
+ .setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder()));
+ }
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ cleanPersistenceDir();
+
+ startGrids(nodes());
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ grid(0).snapshot().createSnapshot(SNP).get();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ blockInitMsgLatch = null;
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int nodes() {
+ return 4;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int backups() {
+ return 0;
+ }
+
+ /**
+ * Reproduces the ordering violation.
+ */
+ @Test
+ public void testIncrementalSnapshotOrderingProblem() throws Exception {
+ blockInitMsgLatch = new CountDownLatch(1);
+
+ IgniteFuture<Void> snpFut = grid(0).snapshot().createIncrementalSnapshot(SNP);
+
+ boolean started = GridTestUtils.waitForCondition(() -> {
+ UUID id = snp(grid(0)).incrementalSnapshotId();
+ return id != null;
+ }, 10_000);
+ assertTrue("Snapshot did not start on node 0", started);
+
+ int clientPort = grid(0).localNode().<Integer>attribute(CLIENT_LISTENER_PORT);
+ ClientConfiguration clientCfg = new ClientConfiguration()
+ .setAddresses("127.0.0.1:" + clientPort);
+
+ try (IgniteClient thinClient = Ignition.startClient(clientCfg)) {
+ ClientCache<Integer, Integer> cache = thinClient.cache(CACHE);
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(1, 100);
+ cache.put(2, 200);
+ tx.commit();
+ }
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(3, 300);
+ cache.put(4, 400);
+ tx.commit();
+ }
+ }
+
+ assertTrue("Snapshot started on node 2 prematurely", snp(grid(2)).incrementalSnapshotId() == null);
Review Comment:
Sometimes your test fails here. For a clean reproducer you must guarantee that the test passes this condition. Tip: go deeper to the `txStart` method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Incremental snapshot thin client ordering problem [ignite]
Posted by "timoninmaxim (via GitHub)" <gi...@apache.org>.
timoninmaxim commented on code in PR #13178:
URL: https://github.com/apache/ignite/pull/13178#discussion_r3299683607
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/incremental/IncrementalSnapshotOrderingTest.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.persistence.snapshot.incremental;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.cache.affinity.AffinityFunction;
+import org.apache.ignite.cache.affinity.AffinityFunctionContext;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.client.ClientTransaction;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.cluster.NodeOrderComparator;
+import org.apache.ignite.internal.managers.discovery.CustomMessageWrapper;
+import org.apache.ignite.internal.util.distributed.InitMessage;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLIENT_LISTENER_PORT;
+
+/**
+ * Test reproducing transaction ordering violation during incremental snapshot with thin client.
+ */
+public class IncrementalSnapshotOrderingTest extends AbstractIncrementalSnapshotTest {
+ /** Latch to block InitMessage on nodes 2 and 3. */
+ private static volatile CountDownLatch blockInitMsgLatch;
+
+ /** Node indices where InitMessage is blocked. */
+ private static final Set<Integer> BLOCKED_NODES = new HashSet<>(Arrays.asList(2, 3));
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String instanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+ CacheConfiguration<Integer, Integer> cacheCfg = cacheConfiguration(CACHE);
+ cacheCfg.setAffinity(new SimpleAffinity());
+ cfg.setCacheConfiguration(cacheCfg);
+
+ int nodeIdx = getTestIgniteInstanceIndex(instanceName);
+ if (BLOCKED_NODES.contains(nodeIdx)) {
+ cfg.setDiscoverySpi(new BlockingInitMessageDiscoverySpi()
+ .setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder()));
+ }
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ cleanPersistenceDir();
+
+ startGrids(nodes());
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ grid(0).snapshot().createSnapshot(SNP).get();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ blockInitMsgLatch = null;
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int nodes() {
+ return 4;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int backups() {
+ return 0;
+ }
+
+ /**
+ * Reproduces the ordering violation.
+ */
+ @Test
+ public void testIncrementalSnapshotOrderingProblem() throws Exception {
+ blockInitMsgLatch = new CountDownLatch(1);
+
+ IgniteFuture<Void> snpFut = grid(0).snapshot().createIncrementalSnapshot(SNP);
+
+ boolean started = GridTestUtils.waitForCondition(() -> {
+ UUID id = snp(grid(0)).incrementalSnapshotId();
+ return id != null;
+ }, 10_000);
+ assertTrue("Snapshot did not start on node 0", started);
+
+ int clientPort = grid(0).localNode().<Integer>attribute(CLIENT_LISTENER_PORT);
+ ClientConfiguration clientCfg = new ClientConfiguration()
+ .setAddresses("127.0.0.1:" + clientPort);
+
+ try (IgniteClient thinClient = Ignition.startClient(clientCfg)) {
+ ClientCache<Integer, Integer> cache = thinClient.cache(CACHE);
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(1, 100);
+ cache.put(2, 200);
+ tx.commit();
+ }
+
+ try (ClientTransaction tx = thinClient.transactions().txStart()) {
+ cache.put(3, 300);
+ cache.put(4, 400);
+ tx.commit();
+ }
+ }
+
+ assertTrue("Snapshot started on node 2 prematurely", snp(grid(2)).incrementalSnapshotId() == null);
+ blockInitMsgLatch.countDown();
+
+ snpFut.get(getTestTimeout());
+
+ restartWithCleanPersistence(nodes(), Collections.singletonList(CACHE));
+ grid(0).snapshot().restoreSnapshot(SNP, null, 1).get(getTestTimeout());
+
+ Integer val1 = (Integer)grid(0).cache(CACHE).get(1);
+ Integer val3 = (Integer)grid(2).cache(CACHE).get(3);
+
+ if (val1 == null && val3 != null) {
+ fail("Incremental snapshot ordering violation detected: " +
+ "tx1 is missing (should be present as it was committed before tx2), " +
+ "but tx2 (key3=" + val3 + ") is present.");
+ }
+ }
+
+ /** Discovery SPI that blocks InitMessage processing on certain nodes. */
+ private static class BlockingInitMessageDiscoverySpi extends TcpDiscoverySpi {
+ /** {@inheritDoc} */
+ @Override protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
+ if (msg instanceof TcpDiscoveryCustomEventMessage && blockInitMsgLatch != null) {
+ TcpDiscoveryCustomEventMessage m = (TcpDiscoveryCustomEventMessage)msg;
+
+ try {
+ CustomMessageWrapper m0 = (CustomMessageWrapper)m.message(
Review Comment:
This doesn't compile
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org