Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions ratis-docs/src/site/markdown/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@ First election timeout is introduced to reduce unavailable time when a RaftGroup
| **Type** | TimeDuration |
| **Default** | 10s |


| **Property** | `raft.server.leaderelection.leader.lease.timeout-bound.ratio` |
|:----------------|:--------------------------------------------------------------|
| **Description** | maximum bound ratio of leader lease timeout |
| **Type** | int, ranging from (0,100] |
| **Default** | 90 |


| **Property** | `raft.server.leaderelection.pre-vote` |
|:----------------|:--------------------------------------|
| **Description** | enable pre-vote |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ default int maxRpcTimeoutMs() {
return maxRpcTimeout().toIntExact(TimeUnit.MILLISECONDS);
}

/** @return the bound of leader lease timeout */
TimeDuration leaderLeaseTimeout();

/** @return the bound of leader lease timeout in milliseconds */
default int leaderLeaseTimeoutMs() {
return leaderLeaseTimeout().toIntExact(TimeUnit.MILLISECONDS);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be internal use only. Let's not add it ratis-server-api?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/** @return the rpc sleep time period. */
TimeDuration rpcSleepTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,18 @@ static TimeDuration slownessTimeout(RaftProperties properties) {
static void setSlownessTimeout(RaftProperties properties, TimeDuration expiryTime) {
setTimeDuration(properties::setTimeDuration, SLOWNESS_TIMEOUT_KEY, expiryTime);
}

String LEADER_LEASE_TIMEOUT_BOUND_RATIO_KEY = PREFIX + ".leader.lease.timeout-bound.ratio";
int LEADER_LEASE_TIMEOUT_BOUND_RATIO_DEFAULT = 90;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Since this is Read related, let's move it to RaftServerConfigKeys.Read.
  • How about calling it PREFIX + ".leader.lease.timeout.ratio"?
  • Let's use double (0 < x <= 1)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

static int leaderLeaseTimeoutBoundRatio(RaftProperties properties) {
return getInt(properties::getInt, LEADER_LEASE_TIMEOUT_BOUND_RATIO_KEY,
LEADER_LEASE_TIMEOUT_BOUND_RATIO_DEFAULT, getDefaultLog(),
requireMin(0), requireMax(100));
}

static void setLeaderLeaseTimeoutBoundRatio(RaftProperties properties, int ratio) {
setInt(properties::setInt, LEADER_LEASE_TIMEOUT_BOUND_RATIO_KEY, ratio);
}
}

/** server retry cache related */
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 leaderLeaseBoundRatio = RaftServerConfigKeys.Rpc.leaderLeaseTimeoutBoundRatio(properties) * 1.0 / 100;
this.leaderLeaseTimeout = this.rpcTimeoutMin.multiply(leaderLeaseBoundRatio);
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;
}

@Override
public TimeDuration leaderLeaseTimeout() {
return leaderLeaseTimeout;
}

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