Skip to content

Commit

Permalink
RATIS-1865. Add leader lease bound ratio configuration (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
SzyWilliam committed Sep 11, 2023
1 parent b8ce6d1 commit 078b115
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
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 @@ -192,6 +192,18 @@ 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 ReadAfterWriteConsistent {
String PREFIX = RaftServerConfigKeys.PREFIX + ".read-after-write-consistent";

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

0 comments on commit 078b115

Please sign in to comment.