Merge "Fixing PacketCable user guide formatting" into stable/lithium
[docs.git] / manuals / user-guide / src / main / asciidoc / ch-clustering.adoc
1 == Setting Up Clustering on an OpenDaylight Controller
2
3 //* <<Clustering Overview>>
4 //* <<Single Node Clustering>>
5 //* <<Multiple Node Clustering>>
6 //** <<Deployment Considerations>>
7 //** <<Setting Up a Multiple Node Cluster>>
8 //*** <<Enabling HA on a Multiple Node Cluster>>
9
10 === Clustering Overview
11
12 Clustering is a mechanism that enables multiple processes and programs to work together as one entity.  For example, when you go to google.com and search for something, it may seem like your search request is processed by only one web server. In reality, your search request is processed by thousands of web servers connected in a cluster. Similarly, you can have multiple instances of the OpenDaylight controller working together as one entity. There are a number of uses for clustering:
13
14 * Scaling: If you have multiple controllers running, you can potentially do more work with or store more data on those controllers if they are clustered. You can also break up your data into smaller chunks (known as shards) and either distribute that data across the cluster or perform certain operations on certain members of the cluster.
15
16 * High Availability: If you have multiple controllers running and one of them crashes, you would still have the other instances working and available.
17
18 * Data Persistence: You will not lose any data gathered by your controller after a manual restart or a crash.
19
20 The following sections describe how to set up clustering on both individual and multiple OpenDaylight controllers.
21
22 === Single Node Clustering
23 To enable clustering on a single OpenDaylight controller, do the following:
24
25 '''
26
27 . Download and unzip a base controller distribution. You must use the new OpenFlow plugin, so download a distribution where the new OpenFlow plugin is either the default or can be enabled.
28 . Navigate to the _<Karaf-distribution-location>_/bin directory.
29 . Run Karaf: *./karaf*
30 . Install the clustering feature: *feature:install odl-mdsal-clustering*
31 . If you are using the integration distribution of Karaf, you should also install the open flow plugin flow services: *feature:install odl-openflowplugin-flow-services*
32 . Install the Jolokia bundle: *install -s mvn:org.jolokia/jolokia-osgi/1.1.5*
33
34 '''
35
36 After enabling the DistributedDataStore feature in a single instance, you can access the following features:
37
38 * Data Sharding: The in-memory MD-SAL tree is broken up into a number of smaller sub-trees (inventory, topology, and default).
39 * Data Persistence: All of the data available on defined data shards is stored on a disk. By restarting the controller, you can use the persisted data to reinstate those shards to their previous state.
40
41 === Multiple Node Clustering
42
43 The following sections describe how to set up multiple node clusters in OpenDaylight.
44
45 ==== Deployment Considerations
46
47 Here is some information to keep in mind when you implement clustering:
48
49 * When setting up a cluster with multiple nodes, we recommend that you do so with a minimum of three machines. You can set up with a cluster with just two nodes. However, if one of those two nodes go down, the controller will no longer be operational.
50
51 * Every device that belongs to a cluster needs to have an identifier. For this purpose, OpenDaylight uses the node&#8217;s role. After you define the first node&#8217;s role as _member-1_ in the akka.conf file, OpenDaylight uses _member-1_ to identify that node.
52
53 * Data shards are used to house all or a certain segment of a module&#8217;s data. For example, one shard can contain all of a module&#8217;s inventory data while another shard contains all of it&#8217;s topology data. If you do not specify a module in the modules.conf file and do not specify a shard in module-shards.conf, then (by default) all the data is places onto the default shard (which must also be defined in module-shards.conf file). Each shard has replicas configured, and the module-shards.conf file is where you can specify where these replicas reside.
54
55 * Say you have a three node cluster on which HA is enabled. A replica of every defined data shard must be running on all three cluster nodes. This is because OpenDaylight&#8217;s clustering implementation requires a majority of the defined shard replicas to be running in order to function. If you only define data shard replicas on two of the cluster nodes and one of those nodes goes down, the corresponding data shards will not function.
56
57 * If you have a three node cluster and have defined replicas for a data shard on each of those nodes, that shard will still function even if only two of the cluster nodes are running. Note that if one of those two nodes go down, your controller will no longer be operational.
58
59 *What considerations need to be made when setting the seed nodes for each member? Why are we referring to multiple seed nodes when you set only one IP address? Can you set multiple seed nodes for functional testing?*
60
61 We recommend that you have multiple seed nodes configured. After a cluster member is started, it sends a message to all of its seed nodes. The cluster member then sends a join command to the first seed node that responds. If none of its seed nodes reply, the cluster member repeats this process until it successfully establishes a connection or it is shutdown.
62
63 *What happens after one node becomes unreachable? Do the other two nodes function normally? When the first node reconnects, does it automatically synchronize with the other nodes?*
64
65 After a node becomes unreachable, it remains down for configurable period of time (10 seconds, by default). Once a node goes down, you need to restart it so that it can rejoin the cluster. Once a restarted node joins a cluster, it will synchronize with the lead node automatically.
66
67 *Can you run a two node cluster for functional testing?*
68
69 For functional testing, yes. For HA testing, you need to run all three nodes.
70
71 ==== Setting Up a Multiple Node Cluster
72
73 To run an OpenDaylight controller in a three node cluster, do the following:
74
75 '''
76
77 . Determine the three machines that will make up the cluster and copy the controller distribution to each of those machines.
78 . Unzip the controller distribution.
79 . Navigate to the _<Karaf-distribution-location>_/bin directory.
80 . Run Karaf: *./karaf*
81 . Install the clustering feature: *feature:install odl-mdsal-clustering*
82
83 NOTE: To run clustering, you must install the odl-mdsal-clustering feature on each of your nodes.
84
85 [start=6]
86 . If you are using the integration distribution of Karaf, you should also install the open flow plugin flow services: *feature:install odl-openflowplugin-flow-services*
87 . Install the Jolokia bundle: *install -s mvn:org.jolokia/jolokia-osgi/1.1.5*
88 . On each node, open the following .conf files:
89
90 * configuration/initial/akka.conf
91 * configuration/initial/module-shards.conf
92
93 . In each configuration file, make the following changes:
94
95 .. Find every instance of the following lines and replace _127.0.0.1_ with the hostname or IP address of the machine on which the controller will run:
96
97      netty.tcp {
98        hostname = "127.0.0.1"
99
100 NOTE: The value you need to specify will be different for each node in the cluster.
101
102 [start=2]
103 .. Find the following lines and replace _127.0.0.1_ with the hostname or IP address of any of the machines that will be part of the cluster:
104
105    cluster {
106      seed-nodes = ["akka.tcp://opendaylight-cluster-data@127.0.0.1:2550"]
107
108 .. Find the following section and specify the role for each member node. For example, you could assign the first node with the _member-1_ role, the second node with the _member-2_ role, and the third node with the _member-3_ role.
109
110
111      roles = [
112        "member-1"
113      ]
114
115 .. Open the configuration/initial/module-shards.conf file and update the items listed in the following section so that the replicas match roles defined in this host&#8217;s akka.conf file.
116
117                replicas = [
118                    "member-1"
119                ]
120
121 For reference, view a sample akka.conf file here: https://gist.github.com/moizr/88f4bd4ac2b03cfa45f0
122
123 [start=5]
124 .. Run the following commands on each of your cluster&#8217;s nodes:
125
126 * *JAVA_MAX_MEM=4G JAVA_MAX_PERM_MEM=512m ./karaf*
127
128 * *JAVA_MAX_MEM=4G JAVA_MAX_PERM_MEM=512m ./karaf*
129
130 * *JAVA_MAX_MEM=4G JAVA_MAX_PERM_MEM=512m ./karaf*
131
132 '''
133
134 The OpenDaylight controller can now run in a three node cluster. Use any of the three member nodes to access the data residing in the datastore.
135
136 Say you want to view information about shard designated as _member-1_ on a node. To do so, query the shard&#8217;s data by making the following HTTP request:
137
138 '''
139
140 *GET http://_<host>_:8181/jolokia/read/org.opendaylight.controller:Category=Shards,name=member-1-shard-inventory-config,type=DistributedConfigDatastore*
141
142 NOTE: If prompted, enter _admin_ as both the username and password.
143
144 '''
145
146 This request should return the following information:
147
148    {
149        "timestamp": 1410524741,
150        "status": 200,
151        "request": {
152        "mbean": "org.opendaylight.controller:Category=Shards,name=member-1-shard-inventory-config,type=DistributedConfigDatastore",
153        "type": "read"
154        },
155        "value": {
156        "ReadWriteTransactionCount": 0,
157        "LastLogIndex": -1,
158        "MaxNotificationMgrListenerQueueSize": 1000,
159        "ReadOnlyTransactionCount": 0,
160        "LastLogTerm": -1,
161        "CommitIndex": -1,
162        "CurrentTerm": 1,
163        "FailedReadTransactionsCount": 0,
164        "Leader": "member-1-shard-inventory-config",
165        "ShardName": "member-1-shard-inventory-config",
166        "DataStoreExecutorStats": {
167        "activeThreadCount": 0,
168        "largestQueueSize": 0,
169        "currentThreadPoolSize": 1,
170        "maxThreadPoolSize": 1,
171        "totalTaskCount": 1,
172        "largestThreadPoolSize": 1,
173        "currentQueueSize": 0,
174        "completedTaskCount": 1,
175        "rejectedTaskCount": 0,
176        "maxQueueSize": 5000
177        },
178        "FailedTransactionsCount": 0,
179        "CommittedTransactionsCount": 0,
180        "NotificationMgrExecutorStats": {
181        "activeThreadCount": 0,
182        "largestQueueSize": 0,
183        "currentThreadPoolSize": 0,
184        "maxThreadPoolSize": 20,
185        "totalTaskCount": 0,
186        "largestThreadPoolSize": 0,
187        "currentQueueSize": 0,
188        "completedTaskCount": 0,
189        "rejectedTaskCount": 0,
190        "maxQueueSize": 1000
191        },
192        "LastApplied": -1,
193        "AbortTransactionsCount": 0,
194        "WriteOnlyTransactionCount": 0,
195        "LastCommittedTransactionTime": "1969-12-31 16:00:00.000",
196        "RaftState": "Leader",
197        "CurrentNotificationMgrListenerQueueStats": []
198        }
199    }
200
201 The key thing here is the name of the shard. Shard names are structured as follows:
202
203 _<member-name>_-shard-_<shard-name-as-per-configuration>_-_<store-type>_
204
205 Here are a couple sample data short names:
206
207 * member-1-shard-topology-config
208 * member-2-shard-default-operational
209
210 ===== Enabling HA on a Multiple Node Cluster
211
212 To enable HA in a three node cluster:
213
214 '''
215
216 . Open the configuration/initial/module-shards.conf file on each cluster node.
217 . Add _member-2_ and _member-3_ to the replica list for each data shard.
218 . Restart all of the nodes. The nodes should automatically sync up with member-1. After some time, the cluster should be ready for operation.
219
220 '''
221
222 When HA is enabled, you must have at least three replicas of every shard. Each node&#8217;s configuration files should look something like this:
223
224    module-shards = [
225        {
226            name = "default"
227            shards = [
228                {
229                    name="default"
230                    replicas = [
231                        "member-1",
232                        "member-2",
233                        "member-3"
234                    ]
235                }
236            ]
237        },
238        {
239            name = "topology"
240            shards = [
241                {
242                    name="topology"
243                    replicas = [
244                        "member-1",
245                        "member-2",
246                        "member-3"
247                    ]
248                }
249            ]
250        },
251        {
252            name = "inventory"
253            shards = [
254                {
255                    name="inventory"
256                    replicas = [
257                        "member-1",
258                        "member-2",
259                        "member-3"
260                    ]
261                }
262            ]
263        },
264        {
265             name = "toaster"
266             shards = [
267                 {
268                     name="toaster"
269                     replicas = [
270                        "member-1",
271                        "member-2",
272                        "member-3"
273                     ]
274                 }
275             ]
276        }
277    ]
278
279 When HA is enabled on multiple nodes, shards will replicate the data for those nodes. Whenever the lead replica on a data shard is brought down, another replica takes its place. As a result, the cluster should remain available. To determine which replica is acting as the lead on a data shard, make an HTTP request to obtain the information for a data shard on any of the nodes. The resulting information will indicate which replica is acting as the lead.
280