You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/09/14 11:33:03 UTC
[GitHub] [ignite-3] vldpyatkov commented on a diff in pull request #1066: IGNITE-17445 RocksDbKeyValueStorage recreates DB on start, so data ca…
vldpyatkov commented on code in PR #1066:
URL: https://github.com/apache/ignite-3/pull/1066#discussion_r970659546
##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/ItJraftCounterServerTest.java:
##########
@@ -709,6 +733,85 @@ public void testTimerThreadsCount() {
"All timer threads: " + timerThreads.toString());
}
+ /**
+ * The test shows that all committed updates are applied after a RAFT group restart automatically.
+ * Actual data be available to read from state storage (not a state machine) directly just after the RAFT node started.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testApplyUpdatesOutOfSnapshot() throws Exception {
Review Comment:
It might, but in the case, I will be needed to copy methods to start/stop raft nodes and raft clients.
##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/snasphot/UpdateCountRaftListener.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.raft.server.snasphot;
+
+
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.raft.client.Command;
+import org.apache.ignite.raft.client.ReadCommand;
+import org.apache.ignite.raft.client.WriteCommand;
+import org.apache.ignite.raft.client.service.CommandClosure;
+import org.apache.ignite.raft.client.service.RaftGroupListener;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * The RAFT state machine counts applied write commands and stores the result into {@link java.util.concurrent.atomic.AtomicLong} that is
+ * passed through constructor.
+ * {@see org.apache.ignite.raft.locked.TestWriteCommand}
+ */
+public class UpdateCountRaftListener implements RaftGroupListener {
+
+ /** The logger. */
+ private static IgniteLogger LOG = Loggers.forClass(UpdateCountRaftListener.class);
+
+ /** Counter of received updates. */
+ private final AtomicInteger counter;
+
+ /** Storage to persist a state of the listener on snapshot. */
+ private final HashMap<Path, Integer> snapshotDataStorage;
Review Comment:
It is a place where is used interface better than implementation.
But I thought it is a test and fewer imports is better...
Ok, I fixed it.
##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/ItJraftCounterServerTest.java:
##########
@@ -709,6 +733,85 @@ public void testTimerThreadsCount() {
"All timer threads: " + timerThreads.toString());
}
+ /**
+ * The test shows that all committed updates are applied after a RAFT group restart automatically.
+ * Actual data be available to read from state storage (not a state machine) directly just after the RAFT node started.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testApplyUpdatesOutOfSnapshot() throws Exception {
+ HashMap<Integer, AtomicInteger> counters = new HashMap<>(3);
Review Comment:
Because I use the implementation here.
Using interfaces is helpfully for the case when you receive an implementation from other code.
##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/ItJraftCounterServerTest.java:
##########
@@ -709,6 +733,85 @@ public void testTimerThreadsCount() {
"All timer threads: " + timerThreads.toString());
}
+ /**
+ * The test shows that all committed updates are applied after a RAFT group restart automatically.
+ * Actual data be available to read from state storage (not a state machine) directly just after the RAFT node started.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testApplyUpdatesOutOfSnapshot() throws Exception {
+ HashMap<Integer, AtomicInteger> counters = new HashMap<>(3);
+ HashMap<Path, Integer> snapshotDataStorage = new HashMap<>(3);
+ HashMap<String, SnapshotMeta> snapshotMetaStorage = new HashMap<>(3);
+
+ for (int i = 0; i < 3; i++) {
+ var counter = counters.computeIfAbsent(i, (key) -> new AtomicInteger());
+
+ startServer(i, raftServer -> {
+ raftServer.startRaftGroup("test_raft_group", new UpdateCountRaftListener(counter, snapshotDataStorage), INITIAL_CONF,
+ defaults().snapshotStorageFactory(new SnapshotInMemoryStorageFactory(snapshotMetaStorage)));
+ }, opts -> {
+ });
+ }
+
+ var raftClient = startClient("test_raft_group");
+
+ raftClient.refreshMembers(true).get();
+ var peers = raftClient.peers();
+
+ raftClient.run(new TestWriteCommand());
+
+ assertTrue(TestUtils.waitForCondition(() -> counters.get(0).get() == 1, 10_000));
+
+ raftClient.snapshot(peers.get(0)).get();
+
+ raftClient.run(new TestWriteCommand());
+
+ assertTrue(TestUtils.waitForCondition(() -> counters.get(1).get() == 2, 10_000));
+
+ raftClient.snapshot(peers.get(1)).get();
+
+ raftClient.run(new TestWriteCommand());
+
+ for (AtomicInteger counter : counters.values()) {
+ assertTrue(TestUtils.waitForCondition(() -> counter.get() == 3, 10_000));
+ }
+
+ shutdownCluster();
+
+ Path peer0SnapPath = dataPath.resolve("node" + 0)
+ .resolve("test_raft_group" + "_" + peers.get(0).address().toString().replace(':', '_')).resolve("snapshot");
Review Comment:
I did not find a method, but I can write it int the test class.
##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/ItJraftCounterServerTest.java:
##########
@@ -270,21 +286,25 @@ private void startCluster() throws Exception {
startServer(i, raftServer -> {
raftServer.startRaftGroup(COUNTER_GROUP_0, listenerFactory.get(), INITIAL_CONF, defaults());
raftServer.startRaftGroup(COUNTER_GROUP_1, listenerFactory.get(), INITIAL_CONF, defaults());
- }, opts -> {});
+ }, opts -> {
Review Comment:
Yes, it is. I return it to the old variant.
##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java:
##########
@@ -1033,6 +1034,33 @@ public boolean init(final NodeOptions opts) {
// Adds metric registry to RPC service.
this.options.setMetricRegistry(this.metrics.getMetricRegistry());
+ //Wait committed
+ long commitIdx = logManager.getLastLogIndex();
+
+ if (commitIdx > fsmCaller.getLastAppliedIndex()) {
+ CountDownLatch applyCommitLatch = new CountDownLatch(1);
+
+ LastAppliedLogIndexListener lnsr = lastAppliedLogIndex -> {
+ if (lastAppliedLogIndex >= commitIdx) {
+ applyCommitLatch.countDown();
+ }
+ };
+
+ fsmCaller.addLastAppliedLogIndexListener(lnsr);
+
+ fsmCaller.onCommitted(commitIdx);
+
+ try {
+ applyCommitLatch.await();
Review Comment:
I hope this change will not have significant effect, but I understand the pure RAFT test become longer.
We can do this feature is configurable if it will be required in the future.
##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/snasphot/UpdateCountRaftListener.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.raft.server.snasphot;
+
+
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.raft.client.Command;
+import org.apache.ignite.raft.client.ReadCommand;
+import org.apache.ignite.raft.client.WriteCommand;
+import org.apache.ignite.raft.client.service.CommandClosure;
+import org.apache.ignite.raft.client.service.RaftGroupListener;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * The RAFT state machine counts applied write commands and stores the result into {@link java.util.concurrent.atomic.AtomicLong} that is
+ * passed through constructor.
+ * {@see org.apache.ignite.raft.locked.TestWriteCommand}
+ */
+public class UpdateCountRaftListener implements RaftGroupListener {
+
Review Comment:
removed.
##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/ItJraftCounterServerTest.java:
##########
@@ -709,6 +733,85 @@ public void testTimerThreadsCount() {
"All timer threads: " + timerThreads.toString());
}
+ /**
+ * The test shows that all committed updates are applied after a RAFT group restart automatically.
+ * Actual data be available to read from state storage (not a state machine) directly just after the RAFT node started.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testApplyUpdatesOutOfSnapshot() throws Exception {
+ HashMap<Integer, AtomicInteger> counters = new HashMap<>(3);
+ HashMap<Path, Integer> snapshotDataStorage = new HashMap<>(3);
+ HashMap<String, SnapshotMeta> snapshotMetaStorage = new HashMap<>(3);
+
+ for (int i = 0; i < 3; i++) {
+ var counter = counters.computeIfAbsent(i, (key) -> new AtomicInteger());
Review Comment:
Fixed.
--
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