Committed by
Gerrit Code Review
Use a low raft leader election timeout when cluster size is one
Change-Id: I0755411f0b20b8e4cd8f8f2fa58e173add4f32dc
Showing
1 changed file
with
13 additions
and
6 deletions
... | @@ -85,8 +85,7 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -85,8 +85,7 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
85 | public static final String BASE_PARTITION_NAME = "p0"; | 85 | public static final String BASE_PARTITION_NAME = "p0"; |
86 | 86 | ||
87 | private static final int DATABASE_STARTUP_TIMEOUT_SEC = 60; | 87 | private static final int DATABASE_STARTUP_TIMEOUT_SEC = 60; |
88 | - private static final int RAFT_ELECTION_TIMEOUT = 3000; | 88 | + private static final int RAFT_ELECTION_TIMEOUT_MILLIS = 3000; |
89 | - private static final int RAFT_HEARTBEAT_TIMEOUT = 1500; | ||
90 | private static final int DATABASE_OPERATION_TIMEOUT_MILLIS = 5000; | 89 | private static final int DATABASE_OPERATION_TIMEOUT_MILLIS = 5000; |
91 | 90 | ||
92 | private ClusterCoordinator coordinator; | 91 | private ClusterCoordinator coordinator; |
... | @@ -132,8 +131,8 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -132,8 +131,8 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
132 | 131 | ||
133 | ClusterConfig clusterConfig = new ClusterConfig() | 132 | ClusterConfig clusterConfig = new ClusterConfig() |
134 | .withProtocol(newNettyProtocol()) | 133 | .withProtocol(newNettyProtocol()) |
135 | - .withElectionTimeout(RAFT_ELECTION_TIMEOUT) | 134 | + .withElectionTimeout(electionTimeoutMillis(activeNodeUris)) |
136 | - .withHeartbeatInterval(RAFT_HEARTBEAT_TIMEOUT) | 135 | + .withHeartbeatInterval(heartbeatTimeoutMillis(activeNodeUris)) |
137 | .withMembers(activeNodeUris) | 136 | .withMembers(activeNodeUris) |
138 | .withLocalMember(localNodeUri); | 137 | .withLocalMember(localNodeUri); |
139 | 138 | ||
... | @@ -264,14 +263,22 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -264,14 +263,22 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
264 | private DatabaseConfig newDatabaseConfig(String name, Log log, String[] replicas) { | 263 | private DatabaseConfig newDatabaseConfig(String name, Log log, String[] replicas) { |
265 | return new DatabaseConfig() | 264 | return new DatabaseConfig() |
266 | .withName(name) | 265 | .withName(name) |
267 | - .withElectionTimeout(RAFT_ELECTION_TIMEOUT) | 266 | + .withElectionTimeout(electionTimeoutMillis(replicas)) |
268 | - .withHeartbeatInterval(RAFT_HEARTBEAT_TIMEOUT) | 267 | + .withHeartbeatInterval(heartbeatTimeoutMillis(replicas)) |
269 | .withConsistency(Consistency.STRONG) | 268 | .withConsistency(Consistency.STRONG) |
270 | .withLog(log) | 269 | .withLog(log) |
271 | .withDefaultSerializer(new DatabaseSerializer()) | 270 | .withDefaultSerializer(new DatabaseSerializer()) |
272 | .withReplicas(replicas); | 271 | .withReplicas(replicas); |
273 | } | 272 | } |
274 | 273 | ||
274 | + private long electionTimeoutMillis(String[] replicas) { | ||
275 | + return replicas.length == 1 ? 10L : RAFT_ELECTION_TIMEOUT_MILLIS; | ||
276 | + } | ||
277 | + | ||
278 | + private long heartbeatTimeoutMillis(String[] replicas) { | ||
279 | + return electionTimeoutMillis(replicas) / 2; | ||
280 | + } | ||
281 | + | ||
275 | /** | 282 | /** |
276 | * Maps a Raft Database object to a PartitionInfo object. | 283 | * Maps a Raft Database object to a PartitionInfo object. |
277 | * | 284 | * | ... | ... |
-
Please register or login to post a comment