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/06/29 21:17:43 UTC

[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #908: IGNITE-17198 Minimal implementation of pure in-memory storage (with in-memory RAFT)

SammyVimes commented on code in PR #908:
URL: https://github.com/apache/ignite-3/pull/908#discussion_r910375827


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JraftServerImpl.java:
##########
@@ -339,13 +351,20 @@ public synchronized boolean startRaftGroup(String groupId, @NotNull RaftGroupEve
             throw new IgniteInternalException(e);
         }
 
-        nodeOptions.setRaftMetaUri(serverDataPath.resolve("meta").toString());
+        if (!groupOptions.volatileStores()) {
+            nodeOptions.setRaftMetaUri(serverDataPath.resolve("meta").toString());
+        }
         nodeOptions.setSnapshotUri(serverDataPath.resolve("snapshot").toString());
 
         nodeOptions.setFsm(new DelegatingStateMachine(lsnr));
 
         nodeOptions.setRaftGrpEvtsLsnr(evLsnr);
 
+        if (groupOptions.volatileStores()) {
+            // override to volatile stores

Review Comment:
   This comment looks a bit obvious, I think



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -500,6 +502,10 @@ private void updateAssignmentInternal(ConfigurationNotificationEvent<byte[]> ass
         CompletableFuture.allOf(futures).join();
     }
 
+    private RaftGroupOptions groupOptionsForInternalTable(InternalTable internalTbl) {
+        return new RaftGroupOptions(internalTbl.storage().isVolatile());

Review Comment:
   Is it possible that there is going to be more options inside the RaftGroupOptions? Maybe it's not a good idea to use constructor here and you already have factory methods. Maybe you can add some new method like "RaftGroupOptions#optionsForTable(isVolatile)"? Does it make sense?



##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/storage/impl/VolatileRaftMetaStorage.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.jraft.storage.impl;
+
+import org.apache.ignite.raft.jraft.entity.PeerId;
+import org.apache.ignite.raft.jraft.option.RaftMetaStorageOptions;
+import org.apache.ignite.raft.jraft.storage.RaftMetaStorage;
+import org.apache.ignite.raft.jraft.storage.VolatileStorage;
+
+/**
+ * Volatile (in-memory) implementation of {@link RaftMetaStorage}. Used for Raft groups storing partition data of
+ * volatile (in-memory) storages.

Review Comment:
   I think this `(in-memory)` can be omitted 



##########
modules/raft/src/integrationTest/java/org/apache/ignite/internal/raft/ItLozaTest.java:
##########
@@ -66,7 +67,7 @@ public class ItLozaTest {
      */
     private RaftGroupService startClient(String groupId, ClusterNode node, Loza loza) throws Exception {
         return loza.prepareRaftGroup(groupId,
-                List.of(node), () -> mock(RaftGroupListener.class)
+                List.of(node), () -> mock(RaftGroupListener.class), RaftGroupOptions.defaults()

Review Comment:
   Sometimes you use static import for `RaftGroupOptions.defaults()`, and sometimes you don't. Is there some logic behind it?



##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/VolatileJRaftServiceFactory.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.jraft.core;
+
+import org.apache.ignite.raft.jraft.JRaftServiceFactory;
+import org.apache.ignite.raft.jraft.entity.codec.LogEntryCodecFactory;
+import org.apache.ignite.raft.jraft.entity.codec.v1.LogEntryV1CodecFactory;
+import org.apache.ignite.raft.jraft.option.RaftOptions;
+import org.apache.ignite.raft.jraft.storage.LogStorage;
+import org.apache.ignite.raft.jraft.storage.RaftMetaStorage;
+import org.apache.ignite.raft.jraft.storage.SnapshotStorage;
+import org.apache.ignite.raft.jraft.storage.impl.LocalLogStorage;
+import org.apache.ignite.raft.jraft.storage.impl.VolatileRaftMetaStorage;
+import org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotStorage;
+import org.apache.ignite.raft.jraft.util.Requires;
+import org.apache.ignite.raft.jraft.util.StringUtils;
+import org.apache.ignite.raft.jraft.util.timer.DefaultRaftTimerFactory;
+import org.apache.ignite.raft.jraft.util.timer.RaftTimerFactory;
+
+/**
+ * The factory for JRaft services producing volatile stores. Useful for Raft groups hosting partitions of in-memory tables.
+ */
+public class VolatileJRaftServiceFactory implements JRaftServiceFactory {
+    @Override public LogStorage createLogStorage(final String groupId, final RaftOptions raftOptions) {
+        Requires.requireTrue(StringUtils.isNotBlank(groupId), "Blank group id.");
+
+        return new LocalLogStorage(raftOptions);
+    }
+
+    @Override public SnapshotStorage createSnapshotStorage(final String uri, final RaftOptions raftOptions) {
+        Requires.requireTrue(!StringUtils.isBlank(uri), "Blank snapshot storage uri.");
+
+        // TODO: IGNITE-17083 - return an in-memory store here (or get rid of SnapshotStorage)
+
+        return new LocalSnapshotStorage(uri, raftOptions);
+    }
+
+    @Override public RaftMetaStorage createRaftMetaStorage(final String uri, final RaftOptions raftOptions) {
+        return new VolatileRaftMetaStorage();
+    }
+
+    @Override public LogEntryCodecFactory createLogEntryCodecFactory() {
+        return LogEntryV1CodecFactory.getInstance();

Review Comment:
   Probably should be default or something. I don't see that we are ever going to use different codecs (probably just the implementation of this one)



##########
.idea/codeStyles/codeStyleConfig.xml:
##########
@@ -1,5 +1,5 @@
 <component name="ProjectCodeStyleConfiguration">
   <state>
-    <option name="PREFERRED_PROJECT_CODE_STYLE" value="GoogleStyle" />
+    <option name="PREFERRED_PROJECT_CODE_STYLE" value="Ignite 3" />

Review Comment:
   looks suspicious, will it break other developers' setups?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/server/RaftGroupOptions.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.raft.server;
+
+/**
+ * Options specific to a Raft group that is being started.
+ */
+public class RaftGroupOptions {
+    private final boolean volatileStores;

Review Comment:
   I always forget: we can omit comments for private members, right? 



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/server/RaftGroupOptions.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.raft.server;
+
+/**
+ * Options specific to a Raft group that is being started.
+ */
+public class RaftGroupOptions {
+    private final boolean volatileStores;
+
+    public static RaftGroupOptions defaults() {
+        return forPersistentStores();
+    }
+
+    public static RaftGroupOptions forPersistentStores() {
+        return new RaftGroupOptions(false);
+    }
+
+    public static RaftGroupOptions forVolatileStores() {
+        return new RaftGroupOptions(true);
+    }
+
+    public RaftGroupOptions(boolean volatileStores) {

Review Comment:
   Probably can be private



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