Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ static BiConsumer<String, Integer> requireMax(int max) {
};
}

static BiConsumer<String, Double> requireMin(double min) {
return (key, value) -> {
if (value < min) {
throw new IllegalArgumentException(
key + " = " + value + " < min = " + min);
}
};
}

static BiConsumer<String, Double> requireMax(double max) {
return (key, value) -> {
if (value > max) {
Expand Down
7 changes: 7 additions & 0 deletions ratis-docs/src/site/markdown/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ treat the peer as caught-up. Increase this number when write throughput is high.

--------------------------------------------------------------------------------

| **Property** | `raft.server.read.leader.lease.timeout.ratio` |
|:----------------|:----------------------------------------------|
| **Description** | maximum timeout ratio of leader lease |
| **Type** | double, ranging from (0.0,1.0) |
| **Default** | 0.9 |


### Write - Configurations related to write requests.

* Limits on pending write requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ static Option option(RaftProperties properties) {
static void setOption(RaftProperties properties, Option option) {
set(properties::setEnum, OPTION_KEY, option);
}

String LEADER_LEASE_TIMEOUT_RATIO_KEY = PREFIX + ".leader.lease.timeout.ratio";
double LEADER_LEASE_TIMEOUT_RATIO_DEFAULT = 0.9;
static double leaderLeaseTimeoutRatio(RaftProperties properties) {
return getDouble(properties::getDouble, LEADER_LEASE_TIMEOUT_RATIO_KEY,
LEADER_LEASE_TIMEOUT_RATIO_DEFAULT, getDefaultLog(),
requireMin(0.0), requireMax(1.0));
}

static void setLeaderLeaseTimeoutRatio(RaftProperties properties, double ratio) {
setDouble(properties::setDouble, LEADER_LEASE_TIMEOUT_RATIO_KEY, ratio);
}
}

interface Write {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ class DivisionPropertiesImpl implements DivisionProperties {
private final TimeDuration rpcTimeoutMax;
private final TimeDuration rpcSleepTime;
private final TimeDuration rpcSlownessTimeout;
private final TimeDuration leaderLeaseTimeout;

DivisionPropertiesImpl(RaftProperties properties) {
this.rpcTimeoutMin = RaftServerConfigKeys.Rpc.timeoutMin(properties);
this.rpcTimeoutMax = RaftServerConfigKeys.Rpc.timeoutMax(properties);
Preconditions.assertTrue(rpcTimeoutMax.compareTo(rpcTimeoutMin) >= 0,
"rpcTimeoutMax = %s < rpcTimeoutMin = %s", rpcTimeoutMax, rpcTimeoutMin);

final double leaderLeaseTimeoutRatio = RaftServerConfigKeys.Read.leaderLeaseTimeoutRatio(properties);
this.leaderLeaseTimeout = this.rpcTimeoutMin.multiply(leaderLeaseTimeoutRatio);
Preconditions.assertTrue(rpcTimeoutMin.compareTo(leaderLeaseTimeout) >= 0,
"rpcTimeoutMin = %s < leaderLeaseTimeout = %s", rpcTimeoutMin, leaderLeaseTimeout);

this.rpcSleepTime = RaftServerConfigKeys.Rpc.sleepTime(properties);
this.rpcSlownessTimeout = RaftServerConfigKeys.Rpc.slownessTimeout(properties);
}
Expand All @@ -49,6 +55,11 @@ public TimeDuration maxRpcTimeout() {
return rpcTimeoutMax;
}

/** @return the ratio of leader lease timeout */
public TimeDuration leaderLeaseTimeout() {
return leaderLeaseTimeout;
}

@Override
public TimeDuration rpcSleepTime() {
return rpcSleepTime;
Expand Down