BUG 1853 : Clustered Data Store causes Out of Memory
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / DefaultConfigParamsImpl.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.raft;
9
10 import scala.concurrent.duration.FiniteDuration;
11
12 import java.util.concurrent.TimeUnit;
13
14 /**
15  * Default implementation of the ConfigParams
16  *
17  * If no implementation is provided for ConfigParams, then this will be used.
18  */
19 public class DefaultConfigParamsImpl implements ConfigParams {
20
21     private static final int SNAPSHOT_BATCH_COUNT = 20000;
22
23     /**
24      * The maximum election time variance
25      */
26     private static final int ELECTION_TIME_MAX_VARIANCE = 100;
27
28     private final int SNAPSHOT_CHUNK_SIZE = 2048 * 1000; //2MB
29
30
31     /**
32      * The interval at which a heart beat message will be sent to the remote
33      * RaftActor
34      * <p/>
35      * Since this is set to 100 milliseconds the Election timeout should be
36      * at least 200 milliseconds
37      */
38     public static final FiniteDuration HEART_BEAT_INTERVAL =
39         new FiniteDuration(100, TimeUnit.MILLISECONDS);
40
41
42     @Override
43     public long getSnapshotBatchCount() {
44         return SNAPSHOT_BATCH_COUNT;
45     }
46
47     @Override
48     public FiniteDuration getHeartBeatInterval() {
49         return HEART_BEAT_INTERVAL;
50     }
51
52
53     @Override
54     public FiniteDuration getElectionTimeOutInterval() {
55         // returns 2 times the heart beat interval
56         return getHeartBeatInterval().$times(2);
57     }
58
59     @Override
60     public int getElectionTimeVariance() {
61         return ELECTION_TIME_MAX_VARIANCE;
62     }
63
64     @Override
65     public int getSnapshotChunkSize() {
66         return SNAPSHOT_CHUNK_SIZE;
67     }
68 }