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 07:13:49 UTC

[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1066: IGNITE-17445 RocksDbKeyValueStorage recreates DB on start, so data ca…

ibessonov commented on code in PR #1066:
URL: https://github.com/apache/ignite-3/pull/1066#discussion_r970406596


##########
modules/raft/src/integrationTest/java/org/apache/ignite/raft/server/ItJraftCounterServerTest.java:
##########
@@ -193,20 +214,15 @@ protected void after() throws Exception {
             server.stop();
         }
 
-        IgniteUtils.shutdownAndAwaitTermination(executor, 10, TimeUnit.SECONDS);
-
-        TestUtils.assertAllJraftThreadsStopped();
-
-        LOG.info(">>>>>>>>>>>>>>> End test method: {}", testInfo.getTestMethod().orElseThrow().getName());
+        servers.clear();
     }
 
     /**
      * Starts server.
      *
-     * @param idx The index.
-     * @param clo Init closure.
+     * @param idx  The index.

Review Comment:
   Our code style doesn't force us to have padding for parameters, as far as I remember



##########
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:
   Same question here, what's the point of declaring it as `HashMap`?



##########
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

Review Comment:
   ```suggestion
           // Wait committed.
   ```



##########
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:
   This empty line shouldn't be here probably



##########
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:
   Is it possible to write a unit test instead of integration one?



##########
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:
   Old code looked better. You probably used auto-formatting for the entire file, right?



##########
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:
   This can be a simple `put`, right?



##########
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:
   Why do you declare variables like `HashMap` and not `Map`? This looks very out of place



##########
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:
   Is there a helper method somewhere to mask special characters?



##########
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:
   How long would it take? Did it affect the duration of current tests?
   I hope we start these nodes in parallel at least.



-- 
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