2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
10 import java.util.concurrent.TimeUnit;
11 import scala.concurrent.duration.FiniteDuration;
14 * Default implementation of the ConfigParams
16 * If no implementation is provided for ConfigParams, then this will be used.
18 public class DefaultConfigParamsImpl implements ConfigParams {
20 private static final int SNAPSHOT_BATCH_COUNT = 20000;
22 private static final int JOURNAL_RECOVERY_LOG_BATCH_SIZE = 1000;
25 * The maximum election time variance
27 private static final int ELECTION_TIME_MAX_VARIANCE = 100;
29 private static final int SNAPSHOT_CHUNK_SIZE = 2048 * 1000; //2MB
33 * The interval at which a heart beat message will be sent to the remote
36 * Since this is set to 100 milliseconds the Election timeout should be
37 * at least 200 milliseconds
39 public static final FiniteDuration HEART_BEAT_INTERVAL =
40 new FiniteDuration(100, TimeUnit.MILLISECONDS);
42 private FiniteDuration heartBeatInterval = HEART_BEAT_INTERVAL;
43 private long snapshotBatchCount = SNAPSHOT_BATCH_COUNT;
44 private int journalRecoveryLogBatchSize = JOURNAL_RECOVERY_LOG_BATCH_SIZE;
45 private long isolatedLeaderCheckInterval = HEART_BEAT_INTERVAL.$times(1000).toMillis();
46 private FiniteDuration electionTimeOutInterval;
48 // 12 is just an arbitrary percentage. This is the amount of the total memory that a raft actor's
49 // in-memory journal can use before it needs to snapshot
50 private int snapshotDataThresholdPercentage = 12;
52 private long electionTimeoutFactor = 2;
54 public void setHeartBeatInterval(FiniteDuration heartBeatInterval) {
55 this.heartBeatInterval = heartBeatInterval;
56 electionTimeOutInterval = null;
59 public void setSnapshotBatchCount(long snapshotBatchCount) {
60 this.snapshotBatchCount = snapshotBatchCount;
63 public void setSnapshotDataThresholdPercentage(int snapshotDataThresholdPercentage){
64 this.snapshotDataThresholdPercentage = snapshotDataThresholdPercentage;
67 public void setJournalRecoveryLogBatchSize(int journalRecoveryLogBatchSize) {
68 this.journalRecoveryLogBatchSize = journalRecoveryLogBatchSize;
71 public void setIsolatedLeaderCheckInterval(FiniteDuration isolatedLeaderCheckInterval) {
72 this.isolatedLeaderCheckInterval = isolatedLeaderCheckInterval.toMillis();
75 public void setElectionTimeoutFactor(long electionTimeoutFactor){
76 this.electionTimeoutFactor = electionTimeoutFactor;
77 electionTimeOutInterval = null;
81 public long getSnapshotBatchCount() {
82 return snapshotBatchCount;
86 public int getSnapshotDataThresholdPercentage() {
87 return snapshotDataThresholdPercentage;
92 public FiniteDuration getHeartBeatInterval() {
93 return heartBeatInterval;
97 public FiniteDuration getElectionTimeOutInterval() {
98 if(electionTimeOutInterval == null) {
99 electionTimeOutInterval = getHeartBeatInterval().$times(electionTimeoutFactor);
102 return electionTimeOutInterval;
106 public int getElectionTimeVariance() {
107 return ELECTION_TIME_MAX_VARIANCE;
111 public int getSnapshotChunkSize() {
112 return SNAPSHOT_CHUNK_SIZE;
116 public int getJournalRecoveryLogBatchSize() {
117 return journalRecoveryLogBatchSize;
121 public long getIsolatedCheckIntervalInMillis() {
122 return isolatedLeaderCheckInterval;
126 public long getElectionTimeoutFactor() {
127 return electionTimeoutFactor;