You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "chunxiaozheng (via GitHub)" <gi...@apache.org> on 2023/08/10 07:28:46 UTC

[GitHub] [ratis] chunxiaozheng opened a new pull request, #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

chunxiaozheng opened a new pull request, #901:
URL: https://github.com/apache/ratis/pull/901

   ## What changes were proposed in this pull request?
   
   By reading the code related to updating peers, I found that the currentConf in the ConfigurationManager class maintains the current peers information, and  a TreeMap object maintains the historical peers information, the TreeMap object uses the log entry index as the key. Normally, if the index of the newly added Configuration is the largest, the currentConf will be set to the latest added configuration information.  Therefore, as long as modify the raft-meta.conf, follow the above rules, set the appropriate index and the latest peering information, we can solve the problem raised in RATIS-1860.
   Through analysis, reading the index in old raft-meta.conf and add 1 as the new index is a suitable choice.  If we directly use the index in the old raft-meta.conf, an exception will be throw during Preconditions.assertTrue(found.equals(conf)).If we directly set a larger value, such as Long.MAX_Value, an exception will be throw when switch leader.
   
   In this PR, a ratis-shell cmd has been added, which will read raft-meta.conf in the specified path, get the log entry index and construct a new index(old index + 1), then use the new index and the newly passed peers to construct a new raft-meta.conf file to support normal startup when moving log entries and checkpoints to other nodes.
   In addition, it is also supported to directly pass an new index, which can be used directly when generating a new raft-meta.conf file. However, this method requires observing the old index. If the input index is inappropriate, it may also cause the new node to not start properly.
   
   ## What is the link to the Apache JIRA
   
   (Please create an issue in ASF JIRA before opening a pull request,
   and you need to set the title of the pull request which starts with
   the corresponding JIRA issue number. (e.g. RATIS-XXXX. Fix a typo in YYY.)
   
   Please replace this section with the link to the Apache JIRA)
   
   ## How was this patch tested?
   
   (Please explain how this patch was tested. Ex: unit tests, manual tests)
   (If this patch involves UI changes, please attach a screen-shot; otherwise, remove this)
   


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1689228264

   @chunxiaozheng , don't worry.  Thank you!


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1689207503

   > @chunxiaozheng , I see. What username have you submitted?
   
   @szetszwo I'm very sorry, I just saw the email, my registered username is `chunxiaozheng`, and I have seen your reply. Thank you very much!


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on a diff in pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #901:
URL: https://github.com/apache/ratis/pull/901#discussion_r1297949719


##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.ratis.shell.cli.sh.local;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Command for generate a new raft-meta.conf file based on original raft-meta.conf and new peers,
+ * which is used to move a raft node to a new node.
+ */
+public class RaftMetaConfCommand extends AbstractRatisCommand {

Review Comment:
   @chunxiaozheng , thanks a lot for the update.  If we implement a local command, we should not extend `AbstractRatisCommand` since it will connect to remote servers.



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1674130353

   @codings-dan Can you help me review this PR? Thanks!


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] codings-dan commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "codings-dan (via GitHub)" <gi...@apache.org>.
codings-dan commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1679920874

   @szetszwo Could you help take a look at the pull request? Thanks in advance


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1685296428

   @szetszwo I have updated the PR according to the comments,thanks for your review!


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on a diff in pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on code in PR #901:
URL: https://github.com/apache/ratis/pull/901#discussion_r1298067059


##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.ratis.shell.cli.sh.local;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Command for generate a new raft-meta.conf file based on original raft-meta.conf and new peers,
+ * which is used to move a raft node to a new node.
+ */
+public class RaftMetaConfCommand extends AbstractRatisCommand {

Review Comment:
   @szetszwo Thanks for your review! I have updated this PR.  
   In addition, `AbstractParentCommand` should not extends `AbstractRatisCommand` too, since the commands that extends `AbstractParentCommand` means that it is a parent command, it does not need to connect to remote servers too.
   



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] codings-dan merged pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "codings-dan (via GitHub)" <gi...@apache.org>.
codings-dan merged PR #901:
URL: https://github.com/apache/ratis/pull/901


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1686686161

   @chunxiaozheng , thanks again for working on this!  Could you post a comment on RATIS-1860 so that we can assign the JIRA to you?


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1679907646

   > Thanks for the update! Could you add some doc about this command? see https://github.com/apache/ratis/blob/master/ratis-docs/src/site/markdown/cli.md
   
   Thanks for your review, i have updated the cli.md.


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on a diff in pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #901:
URL: https://github.com/apache/ratis/pull/901#discussion_r1298868774


##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractCommand.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.ratis.shell.cli.sh.command;
+
+import org.apache.ratis.shell.cli.Command;
+
+import java.net.InetSocketAddress;
+
+/**
+ * The base class for all the ratis shell {@link Command} classes.
+ */
+public abstract class AbstractCommand implements Command {
+
+  public static InetSocketAddress parseInetSocketAddress(String address) {

Review Comment:
   Let's also move the `Context` and `PrintStream` related code from `AbstractRatisCommand` to `AbstractCommand`.



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.ratis.shell.cli.sh.local;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractCommand;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Command for generate a new raft-meta.conf file based on original raft-meta.conf and new peers,
+ * which is used to move a raft node to a new node.
+ */
+public class RaftMetaConfCommand extends AbstractCommand {
+  public static final String PEER_OPTION_NAME = "peers";
+  public static final String PATH_OPTION_NAME = "path";
+
+  private static final String RAFT_META_CONF = "raft-meta.conf";
+  private static final String NEW_RAFT_META_CONF = "new-raft-meta.conf";
+
+  public RaftMetaConfCommand() {
+  }
+
+  @Override
+  public String getCommandName() {
+    return "raftMetaConf";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    String peersStr = cl.getOptionValue(PEER_OPTION_NAME);
+    String path = cl.getOptionValue(PATH_OPTION_NAME);
+    if (peersStr == null || path == null || peersStr.isEmpty() || path.isEmpty()) {
+      System.out.println("peers or path can't be empty.");
+      return -1;
+    }
+    List<RaftProtos.RaftPeerProto> raftPeerProtos = new ArrayList<>();
+    for (String address : peersStr.split(",")) {
+      String peerId = RaftUtils.getPeerId(parseInetSocketAddress(address)).toString();
+      raftPeerProtos.add(RaftProtos.RaftPeerProto.newBuilder()
+          .setId(ByteString.copyFrom(peerId.getBytes(StandardCharsets.UTF_8))).setAddress(address)
+          .setStartupRole(RaftProtos.RaftPeerRole.FOLLOWER).build());
+    }
+    try (InputStream in = new FileInputStream(new File(path, RAFT_META_CONF));
+         OutputStream out = new FileOutputStream(new File(path, NEW_RAFT_META_CONF))) {

Review Comment:
   Use the `Files` api instead.



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.ratis.shell.cli.sh.local;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;

Review Comment:
   Let's import the inner classes.  Then, the code is easier to read.
   ```java
   import org.apache.ratis.proto.RaftProtos.LogEntryProto;
   import org.apache.ratis.proto.RaftProtos.RaftConfigurationProto;
   import org.apache.ratis.proto.RaftProtos.RaftPeerProto;
   import org.apache.ratis.proto.RaftProtos.RaftPeerRole;
   ```
   



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractParentCommand.java:
##########
@@ -24,13 +24,13 @@
 import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
-public abstract class AbstractParentCommand extends AbstractRatisCommand{
+public abstract class AbstractParentCommand implements Command {
   private final Map<String, Command> subs;
 
   public AbstractParentCommand(Context context, List<Function<Context, AbstractRatisCommand>> subCommandConstructors) {

Review Comment:
   Let's change the `Function` to `Function<Context, Command>`.  Then, the new `LocalCommand` can also use it.



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.ratis.shell.cli.sh.local;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.shell.cli.RaftUtils;
+import org.apache.ratis.shell.cli.sh.command.AbstractCommand;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Command for generate a new raft-meta.conf file based on original raft-meta.conf and new peers,
+ * which is used to move a raft node to a new node.
+ */
+public class RaftMetaConfCommand extends AbstractCommand {
+  public static final String PEER_OPTION_NAME = "peers";
+  public static final String PATH_OPTION_NAME = "path";
+
+  private static final String RAFT_META_CONF = "raft-meta.conf";
+  private static final String NEW_RAFT_META_CONF = "new-raft-meta.conf";
+
+  public RaftMetaConfCommand() {
+  }
+
+  @Override
+  public String getCommandName() {
+    return "raftMetaConf";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    String peersStr = cl.getOptionValue(PEER_OPTION_NAME);
+    String path = cl.getOptionValue(PATH_OPTION_NAME);
+    if (peersStr == null || path == null || peersStr.isEmpty() || path.isEmpty()) {
+      System.out.println("peers or path can't be empty.");

Review Comment:
   We should use the `PrintStream` from `Context` instead of `System.out`.



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1681074819

   @codings-dan , sure, will review this.


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1681621417

   > 
   
   @szetszwo Thanks for your review! But I have a question, if we put this command in the ratis-tool module, how should we use it? 


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1682716254

   @chunxiaozheng , do you mean how to run it?  We may run it directly with the class (or using maven).
   
   Another option is to add a new parent command, say `local`, and add the new `raftMetaConf` under it.  Then, it may be easier to run it.  Later on, we may include the log dump tool as a subcommand.
   ```
    [local [raftMetaConf] [dumpLog]
   ```
   


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1683274358

   > @chunxiaozheng , do you mean how to run it? We may run it directly with the class (or using maven).
   > 
   > Another option is to add a new parent command, say `local`, and add the new `raftMetaConf` under it. Then, it may be easier to run it. Later on, we may include the log dump tool as a subcommand.
   > 
   > ```
   >  [local [raftMetaConf] [dumpLog]
   > ```
   
   @szetszwo Thanks! Adding a local command is a good idea, which makes it very easy to use this tool, and I have already followed this approach to modify PR.


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] codings-dan commented on a diff in pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "codings-dan (via GitHub)" <gi...@apache.org>.
codings-dan commented on code in PR #901:
URL: https://github.com/apache/ratis/pull/901#discussion_r1295308829


##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/generation/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.ratis.shell.cli.sh.generation;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+public class RaftMetaConfCommand extends AbstractRatisCommand {
+  public static final String PATH_OPTION_NAME = "path";
+
+  private static final String RAFT_META_CONF = "raft-meta.conf";
+  private static final String NEW_RAFT_META_CONF = "new-raft-meta.conf";
+
+  /**
+   * @param context command context
+   */
+  public RaftMetaConfCommand(Context context) {
+    super(context);
+  }
+
+  @Override
+  public String getCommandName() {
+    return "raftMetaConf";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    String peersStr = cl.getOptionValue(PEER_OPTION_NAME);
+    String path = cl.getOptionValue(PATH_OPTION_NAME);
+    List<RaftProtos.RaftPeerProto> raftPeerProtos = new ArrayList<>();
+    for (String peer : peersStr.split(",")) {
+      String[] peerInfos = peer.split(":");
+      String peerId = peerInfos[0] + "_" + peerInfos[1];

Review Comment:
   final InetSocketAddress serverAddress = parseInetSocketAddress(address);
   final String peerId = RaftUtils.getPeerId(serverAddress);



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/generation/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.ratis.shell.cli.sh.generation;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+public class RaftMetaConfCommand extends AbstractRatisCommand {
+  public static final String PATH_OPTION_NAME = "path";
+
+  private static final String RAFT_META_CONF = "raft-meta.conf";
+  private static final String NEW_RAFT_META_CONF = "new-raft-meta.conf";
+
+  /**
+   * @param context command context
+   */
+  public RaftMetaConfCommand(Context context) {
+    super(context);
+  }
+
+  @Override
+  public String getCommandName() {
+    return "raftMetaConf";
+  }
+
+  @Override
+  public int run(CommandLine cl) throws IOException {
+    String peersStr = cl.getOptionValue(PEER_OPTION_NAME);
+    String path = cl.getOptionValue(PATH_OPTION_NAME);

Review Comment:
   `peersStr` and `path` need check not null.
   



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/generation/RaftMetaConfCommand.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.ratis.shell.cli.sh.generation;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.shell.cli.sh.command.AbstractRatisCommand;
+import org.apache.ratis.shell.cli.sh.command.Context;
+import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+public class RaftMetaConfCommand extends AbstractRatisCommand {

Review Comment:
   How about use `GroupCommand` as the parent command? BTW, please add some necessary notes.



-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] chunxiaozheng commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "chunxiaozheng (via GitHub)" <gi...@apache.org>.
chunxiaozheng commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1687577134

   
   
   
   > @chunxiaozheng , thanks again for working on this! Could you post a comment on [RATIS-1860](https://issues.apache.org/jira/browse/RATIS-1860) so that we can assign the JIRA to you?
   
   @szetszwo of course, but the page display `Public signup for this instance is disabled`. I have submitted the request to create jira account and i am waiting for a review.


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ratis] szetszwo commented on pull request #901: RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf.

Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #901:
URL: https://github.com/apache/ratis/pull/901#issuecomment-1687916037

   @chunxiaozheng , I see.  What username have you submitted?


-- 
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: issues-unsubscribe@ratis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org