This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 593e1756 RATIS-1637. Improve the log message with fallback value in
conf. (#695)
593e1756 is described below
commit 593e1756d8d1fc005482eda443915bffa7d6084f
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Mon Jul 25 03:42:58 2022 -0700
RATIS-1637. Improve the log message with fallback value in conf. (#695)
---
.../main/java/org/apache/ratis/conf/ConfUtils.java | 19 ++++++++++++++-----
.../java/org/apache/ratis/grpc/GrpcConfigKeys.java | 8 ++++----
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java
b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java
index b21cc642..681c0dc6 100644
--- a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java
+++ b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java
@@ -48,6 +48,12 @@ public interface ConfUtils {
}
}
+ static <T> void logFallback(String key, String fallbackKey, T fallbackValue,
Consumer<String> logger) {
+ if (logger != null) {
+ logger.accept(String.format("%s = %s (fallback to %s)", key,
fallbackValue, fallbackKey));
+ }
+ }
+
static void logSet(String key, Object value) {
LOG.debug("set {} = {}", key, value);
}
@@ -156,9 +162,9 @@ public interface ConfUtils {
@SafeVarargs
static int getInt(
BiFunction<String, Integer, Integer> integerGetter,
- String key, int defaultValue, int fallbackValue,
+ String key, int defaultValue, String fallbackKey, int fallbackValue,
Consumer<String> logger, BiConsumer<String, Integer>... assertions) {
- return get(integerGetter, key, defaultValue, fallbackValue, logger,
assertions);
+ return get(integerGetter, key, defaultValue, fallbackKey, fallbackValue,
logger, assertions);
}
@SafeVarargs
@@ -225,11 +231,14 @@ public interface ConfUtils {
@SafeVarargs
static <T> T get(BiFunction<String, T, T> getter,
- String key, T defaultValue, T fallbackValue,
+ String key, T defaultValue, String fallbackKey, T fallbackValue,
Consumer<String> logger, BiConsumer<String, T>... assertions) {
T value = get(getter, key, defaultValue, null, assertions);
- value = value != defaultValue ? value : fallbackValue;
- logGet(key, value, defaultValue, logger);
+ if (value != defaultValue) {
+ logGet(key, value, defaultValue, logger);
+ } else {
+ logFallback(key, fallbackKey, fallbackValue, logger);
+ }
return value;
}
diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
index 0ba995de..b227dfb3 100644
--- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
+++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcConfigKeys.java
@@ -101,8 +101,8 @@ public interface GrpcConfigKeys {
int PORT_DEFAULT = -1;
static int port(RaftProperties properties) {
final int fallbackServerPort = Server.port(properties, null);
- return getInt(properties::getInt,
- PORT_KEY, PORT_DEFAULT, fallbackServerPort, getDefaultLog(),
requireMin(-1), requireMax(65536));
+ return getInt(properties::getInt, PORT_KEY, PORT_DEFAULT,
Server.PORT_KEY, fallbackServerPort,
+ getDefaultLog(), requireMin(-1), requireMax(65536));
}
static void setPort(RaftProperties properties, int port) {
setInt(properties::setInt, PORT_KEY, port);
@@ -125,8 +125,8 @@ public interface GrpcConfigKeys {
int PORT_DEFAULT = -1;
static int port(RaftProperties properties) {
final int fallbackServerPort = Server.port(properties, null);
- return getInt(properties::getInt,
- PORT_KEY, PORT_DEFAULT, fallbackServerPort, getDefaultLog(),
requireMin(-1), requireMax(65536));
+ return getInt(properties::getInt, PORT_KEY, PORT_DEFAULT,
Server.PORT_KEY, fallbackServerPort,
+ getDefaultLog(), requireMin(-1), requireMax(65536));
}
static void setPort(RaftProperties properties, int port) {
setInt(properties::setInt, PORT_KEY, port);