Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

fix: validate the client config value #153

Merged
merged 6 commits into from
Apr 1, 2021
Merged
Changes from all 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
26 changes: 17 additions & 9 deletions src/main/java/com/xiaomi/infra/pegasus/client/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
validatePositiveNum(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) {
validatePositiveNum(asyncWorkers);
this.asyncWorkers = asyncWorkers;
return this;
}
Expand Down Expand Up @@ -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) {
validatePositiveNum(falconPushInterval.toMillis());
this.falconPushInterval = falconPushInterval;
return this;
}
Expand All @@ -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) {
validatePositiveNum(metaQueryTimeout.toMillis());
this.metaQueryTimeout = metaQueryTimeout;
return this;
}
Expand Down Expand Up @@ -369,6 +373,10 @@ public Builder credential(Credential credential) {
public ClientOptions build() {
return new ClientOptions(this);
}

private static void validatePositiveNum(long value) {
assert value > 0 : String.format("must pass positive value: %d", value);
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
Expand Down