BUG 2185 : Make the Custom Raft Policy externally configurable
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / policy / TwoNodeClusterRaftPolicy.java
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/policy/TwoNodeClusterRaftPolicy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/policy/TwoNodeClusterRaftPolicy.java
new file mode 100644 (file)
index 0000000..695f4f7
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.cluster.datastore.policy;
+
+import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
+
+/**
+ * The TwoNodeClusterRaftPolicy is intended to be used in a two node deployment where when one instance
+ * of the controller goes down the other instance is to take over and move the state forward.
+ * When a TwoNodeClusterRaftPolicy is used Raft elections are disabled. This is primarily because we would
+ * need to specify the leader externally. Also since we want one node to continue to function while the other
+ * node is down we would need to apply a modification to the state before consensus occurs.
+ */
+public class TwoNodeClusterRaftPolicy implements RaftPolicy {
+    @Override
+    public boolean automaticElectionsEnabled() {
+        return false;
+    }
+
+    @Override
+    public boolean applyModificationToStateBeforeConsensus() {
+        return true;
+    }
+}