Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.ratis.conf;

import org.apache.ratis.thirdparty.com.google.common.collect.Maps;
import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.ReflectionUtils;
import org.apache.ratis.util.SizeInBytes;
Expand All @@ -33,6 +34,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -53,6 +55,10 @@ public class RaftProperties {
public RaftProperties() {
}

public RaftProperties(Properties properties) {
this.properties.putAll(Maps.fromProperties(properties));
}

/**
* A new RaftProperties with the same settings cloned from another.
*
Expand Down Expand Up @@ -124,6 +130,24 @@ private static int[] findSubVariable(String eval) {
return result;
}

/**
* Merge two raft properties.
*
* <p>
* Properties in {@code p2} overwrite those in {@code p1} if they have
* the same key.
* </p>
*
* @param p1 first properties
* @param p2 second properties
* @return merged properties
*/
public static RaftProperties merge(RaftProperties p1, RaftProperties p2) {
RaftProperties result = new RaftProperties(p1);
result.properties.putAll(p2.properties);
return result;
}

/**
* Attempts to repeatedly expand the value {@code expr} by replacing the
* left-most substring of the form "${var}" in the following precedence order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ public static RaftPeerId getPeerId(String host, int port) {
* @return return a raft client
*/
public static RaftClient createClient(RaftGroup raftGroup) {
RaftProperties properties = new RaftProperties();
RaftClientConfigKeys.Rpc.setRequestTimeout(properties,
RaftProperties defaults = new RaftProperties();
RaftClientConfigKeys.Rpc.setRequestTimeout(defaults,
TimeDuration.valueOf(15, TimeUnit.SECONDS));

// Since ratis-shell support GENERIC_COMMAND_OPTIONS, here we should
// merge these options to raft properties to make it work.
RaftProperties systems = new RaftProperties(System.getProperties());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AngersZhuuuu , let's simply use forEach instead of changing RaftProperties.

@@ -67,6 +68,12 @@ public final class RaftUtils {
     RaftProperties properties = new RaftProperties();
     RaftClientConfigKeys.Rpc.setRequestTimeout(properties,
         TimeDuration.valueOf(15, TimeUnit.SECONDS));
+
+    // Since ratis-shell support GENERIC_COMMAND_OPTIONS, here we should
+    // merge these options to raft properties to make it work.
+    final Properties sys = System.getProperties();
+    sys.stringPropertyNames().forEach(key -> properties.set(key, sys.getProperty(key)));
+
     ExponentialBackoffRetry retryPolicy = ExponentialBackoffRetry.newBuilder()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOne

ExponentialBackoffRetry retryPolicy = ExponentialBackoffRetry.newBuilder()
.setBaseSleepTime(TimeDuration.valueOf(1000, TimeUnit.MILLISECONDS))
.setMaxAttempts(10)
Expand All @@ -75,7 +79,7 @@ public static RaftClient createClient(RaftGroup raftGroup) {
.build();
return RaftClient.newBuilder()
.setRaftGroup(raftGroup)
.setProperties(properties)
.setProperties(RaftProperties.merge(defaults, systems))
.setRetryPolicy(retryPolicy)
.build();
}
Expand Down