From 1596adafeccd1c68b339e7b7b982aca0120fae7e Mon Sep 17 00:00:00 2001 From: jiashuo Date: Thu, 1 Apr 2021 17:12:48 +0800 Subject: [PATCH 1/4] fix --- .../infra/pegasus/client/ClientOptions.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java index 2494eaed..88cd94e9 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java @@ -248,26 +248,28 @@ public Builder metaServers(String metaServers) { } /** - * The timeout for failing to finish an operation. Defaults to {@literal 1000ms}, see {@link - * #DEFAULT_OPERATION_TIMEOUT}. + * The timeout for failing to finish an operation, must be positive. Defaults to {@literal + * 1000ms}, see {@link #DEFAULT_OPERATION_TIMEOUT}. * * @param operationTimeout operationTimeout * @return {@code this} */ public Builder operationTimeout(Duration operationTimeout) { + validatePositive(operationTimeout.toMillis()); this.operationTimeout = operationTimeout; return this; } /** - * The number of background worker threads. Internally it is the number of Netty NIO threads for - * handling RPC events between client and Replica Servers. Defaults to {@literal 4}, see {@link - * #DEFAULT_ASYNC_WORKERS}. + * The number of background worker threads, must be positive. Internally it is the number of + * Netty NIO threads for handling RPC events between client and Replica Servers. Defaults to + * {@literal 4}, see {@link #DEFAULT_ASYNC_WORKERS}. * * @param asyncWorkers asyncWorkers thread number * @return {@code this} */ public Builder asyncWorkers(int asyncWorkers) { + validatePositive(asyncWorkers); this.asyncWorkers = asyncWorkers; return this; } @@ -299,13 +301,14 @@ public Builder falconPerfCounterTags(String falconPerfCounterTags) { } /** - * The interval to report metrics to local falcon agent. Defaults to {@literal 10s}, see {@link - * #DEFAULT_FALCON_PUSH_INTERVAL}. + * The interval to report metrics to local falcon agent, must be positive. Defaults to {@literal + * 10s}, see {@link #DEFAULT_FALCON_PUSH_INTERVAL}. * * @param falconPushInterval falconPushInterval * @return {@code this} */ public Builder falconPushInterval(Duration falconPushInterval) { + validatePositive(falconPushInterval.toMillis()); this.falconPushInterval = falconPushInterval; return this; } @@ -324,13 +327,14 @@ public Builder enableWriteLimit(boolean enableWriteLimit) { } /** - * The timeout for query meta server. Defaults to {@literal 5000ms}, see {@link - * #DEFAULT_META_QUERY_TIMEOUT}. + * The timeout for query meta server, must be positive. Defaults to {@literal 5000ms}, see + * {@link #DEFAULT_META_QUERY_TIMEOUT}. * * @param metaQueryTimeout metaQueryTimeout * @return {@code this} */ public Builder metaQueryTimeout(Duration metaQueryTimeout) { + validatePositive(metaQueryTimeout.toMillis()); this.metaQueryTimeout = metaQueryTimeout; return this; } @@ -369,6 +373,10 @@ public Builder credential(Credential credential) { public ClientOptions build() { return new ClientOptions(this); } + + private void validatePositive(long value) { + assert value > 0 : String.format("must pass positive value: %d", value); + } } /** From 7d7ed3dfc5de2d216927bf1084c478df37eb76db Mon Sep 17 00:00:00 2001 From: jiashuo Date: Thu, 1 Apr 2021 17:23:34 +0800 Subject: [PATCH 2/4] fix --- src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java index 88cd94e9..14a81ec0 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java @@ -245,6 +245,7 @@ protected Builder() {} public Builder metaServers(String metaServers) { this.metaServers = metaServers; return this; + } /** From a3cfff15010e9b9ebb1d36240afb97bfcd9dc1b5 Mon Sep 17 00:00:00 2001 From: jiashuo Date: Thu, 1 Apr 2021 17:23:42 +0800 Subject: [PATCH 3/4] fix --- src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java index 14a81ec0..88cd94e9 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java @@ -245,7 +245,6 @@ protected Builder() {} public Builder metaServers(String metaServers) { this.metaServers = metaServers; return this; - } /** From c8c24444d43197114214198583da2987fba6517b Mon Sep 17 00:00:00 2001 From: jiashuo Date: Thu, 1 Apr 2021 18:38:12 +0800 Subject: [PATCH 4/4] fix --- .../com/xiaomi/infra/pegasus/client/ClientOptions.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java index 88cd94e9..a9f1aef5 100644 --- a/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java +++ b/src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java @@ -255,7 +255,7 @@ public Builder metaServers(String metaServers) { * @return {@code this} */ public Builder operationTimeout(Duration operationTimeout) { - validatePositive(operationTimeout.toMillis()); + validatePositiveNum(operationTimeout.toMillis()); this.operationTimeout = operationTimeout; return this; } @@ -269,7 +269,7 @@ public Builder operationTimeout(Duration operationTimeout) { * @return {@code this} */ public Builder asyncWorkers(int asyncWorkers) { - validatePositive(asyncWorkers); + validatePositiveNum(asyncWorkers); this.asyncWorkers = asyncWorkers; return this; } @@ -308,7 +308,7 @@ public Builder falconPerfCounterTags(String falconPerfCounterTags) { * @return {@code this} */ public Builder falconPushInterval(Duration falconPushInterval) { - validatePositive(falconPushInterval.toMillis()); + validatePositiveNum(falconPushInterval.toMillis()); this.falconPushInterval = falconPushInterval; return this; } @@ -334,7 +334,7 @@ public Builder enableWriteLimit(boolean enableWriteLimit) { * @return {@code this} */ public Builder metaQueryTimeout(Duration metaQueryTimeout) { - validatePositive(metaQueryTimeout.toMillis()); + validatePositiveNum(metaQueryTimeout.toMillis()); this.metaQueryTimeout = metaQueryTimeout; return this; } @@ -374,7 +374,7 @@ public ClientOptions build() { return new ClientOptions(this); } - private void validatePositive(long value) { + private static void validatePositiveNum(long value) { assert value > 0 : String.format("must pass positive value: %d", value); } }