apache-ignite
193 строки · 9.3 Кб
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15= ZooKeeper Discovery
16
17Ignite's default TCP/IP Discovery organizes cluster nodes into a ring topology that has advantages and
18disadvantages. For instance, on topologies with hundreds of cluster
19nodes, it can take many seconds for a system message to traverse through
20all the nodes. As a result, the basic processing of events such as
21joining of new nodes or detecting the failed ones can take a while,
22affecting the overall cluster responsiveness and performance.
23
24ZooKeeper Discovery is designed for massive deployments that
25need to preserve ease of scalability and linear performance.
26However, using both Ignite and ZooKeeper requires configuring and managing two
27distributed systems, which can be challenging.
28Therefore, we recommend that you use ZooKeeper Discovery only if you plan to scale to 100s or 1000s nodes.
29Otherwise, it is best to use link:clustering/tcp-ip-discovery[TCP/IP Discovery].
30
31ZooKeeper Discovery uses ZooKeeper as a single point of synchronization
32and to organize the cluster into a star-shaped topology where a
33ZooKeeper cluster sits in the center and the Ignite nodes exchange
34discovery events through it.
35
36image::images/zookeeper.png[Zookeeper]
37
38It is worth mentioning that ZooKeeper Discovery is an alternative implementation of the Discovery SPI and doesn’t affect the Communication SPI.
39Once the nodes discover each other via ZooKeeper Discovery, they use Communication SPI for peer-to-peer communication.
40////////////////////////////////////////////////////////////////////////////////
41TODO: explain what it means
42////////////////////////////////////////////////////////////////////////////////
43
44== Configuration
45
46To enable ZooKeeper Discovery, you need to configure `ZookeeperDiscoverySpi` in a way similar to this:
47
48
49[tabs]
50--
51tab:XML[]
52[source,xml]
53----
54<bean class="org.apache.ignite.configuration.IgniteConfiguration">
55
56<property name="discoverySpi">
57<bean class="org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi">
58<property name="zkConnectionString" value="127.0.0.1:34076,127.0.0.1:43310,127.0.0.1:36745"/>
59<property name="sessionTimeout" value="30000"/>
60<property name="zkRootPath" value="/apacheIgnite"/>
61<property name="joinTimeout" value="10000"/>
62</bean>
63</property>
64</bean>
65----
66tab:Java[]
67[source,java]
68----
69include::{javaCodeDir}/ZookeeperDiscovery.java[tag=cfg,indent=0]
70----
71tab:.NET[unsupported]
72tab:C++[unsupported]
73--
74
75The following parameters are required (other parameters are optional):
76
77* `zkConnectionString` - keeps the list of addresses of ZooKeeper
78servers.
79* `sessionTimeout` - specifies the time after which an Ignite node is considered disconnected if it doesn’t react to events exchanged via Discovery SPI.
80
81== Failures and Split Brain Handling
82
83In case of network partitioning, some of the nodes cannot communicate to each other because they are located in separated network segments, which may lead to failure to process user requests or inconsistent data modification.
84
85ZooKeeper Discovery approaches network partitioning (aka. split brain)
86and communication failures between individual nodes in the following
87way:
88
89[CAUTION]
90====
91It is assumed that the ZooKeeper cluster is always visible to all the
92nodes in the cluster. In fact, if a node disconnects from ZooKeeper, it
93shuts down and other nodes treat it as failed or disconnected.
94====
95
96Whenever a node discovers that it cannot connect to some of the other
97nodes in the cluster, it initiates a communication failure resolution
98process by publishing special requests to the ZooKeeper cluster. When
99the process is started, all nodes try to connect to each other and send
100the results of the connection attempts to the node that coordinates the
101process (_the coordinator node_). Based on this information, the
102coordinator node creates a connectivity graph that represents the
103network situation in the cluster. Further actions depend on the type of
104network segmentation. The following sections discuss possible scenarios.
105
106=== Cluster is split into several disjoint components
107
108If the cluster is split into several independent components, each
109component (being a cluster) may think of itself as a master cluster and
110continue to process user requests, resulting in data inconsistency. To
111avoid this, only the component with the largest number of nodes is kept
112alive; and the nodes from the other components are brought down.
113
114image::images/network_segmentation.png[Network Segmentation]
115
116The image above shows a case where the cluster network is split into 2 segments.
117The nodes from the smaller cluster (right-hand segment) are terminated.
118
119image::images/segmentation_resolved.png[Segmentation Resolved]
120
121When there are multiple largest components, the one that has the largest
122number of clients is kept alive, and the others are shut down.
123
124=== Several links between nodes are missing
125
126Some nodes cannot connect to some other nodes, which means the nodes are
127not completely disconnected from the cluster but can’t exchange data
128with some of the nodes and, therefore, cannot be part of the cluster. In
129the image below, one node cannot connect to two other nodes.
130
131image::images/split_brain.png[Split-brain]
132
133In this case, the task is to find the largest component in which every
134node can connect to every other node, which, in the general case, is a
135difficult problem and cannot be solved in an acceptable amount of time. The
136coordinator node uses a heuristic algorithm to find the best approximate
137solution. The nodes that are left out of the solution are shut down.
138
139image::images/split_brain_resolved.png[Split-brain Resolved]
140
141=== ZooKeeper cluster segmentation
142
143In large-scale deployments where the ZooKeeper cluster can span multiple data centers and geographically diverse locations, it can split into multiple segments due to network segmentation.
144If this occurs, ZooKeeper checks if there is a segment that contains more than a half of all ZooKeeper nodes (ZooKeeper requires this many nodes to continue its operation), and, if found, this segment takes over managing the Ignite cluster, while other segments are shut down.
145If there is no such segment, ZooKeeper shuts down all its nodes.
146
147In case of ZooKeeper cluster segmentation, the Ignite cluster may or may not be split.
148In any case, when the ZooKeeper nodes are shut down, the corresponding Ignite nodes try to connect to available ZooKeeper nodes and shut down if unable to do so.
149
150The following image is an example of network segmentation that splits both the Ignite cluster and ZooKeeper cluster into two segments.
151This may happen if your clusters are deployed in two data centers.
152In this case, the ZooKeeper node located in Data Center B shuts itself down.
153The Ignite nodes located in Data Center B are not able to connect to the remaining ZooKeeper nodes and shut themselves down as well.
154
155image::images/zookeeper_split.png[Zookeeper Split]
156
157== Custom Discovery Events
158
159Changing a ring-shaped topology to the star-shaped one affects the way
160custom discovery events are handled by the Discovery SPI component. Since
161the ring topology is linear, it means that each discovery message is
162processed by nodes sequentially.
163
164With ZooKeeper Discovery, the coordinator sends discovery messages to
165all nodes simultaneously resulting in the messages to be processed in
166parallel. As a result, ZooKeeper Discovery prohibits custom discovery events from being changed. For instance, the nodes are not allowed to add any payload to discovery messages.
167
168== Ignite and ZooKeeper Configuration Considerations
169
170When using ZooKeeper Discovery, you need to make sure that the configuration parameters of the ZooKeeper cluster and Ignite cluster match each other.
171
172Consider a sample ZooKeeper configuration, as follows:
173
174[source,shell]
175----
176# The number of milliseconds of each tick
177tickTime=2000
178
179# The number of ticks that can pass between sending a request and getting an acknowledgement
180syncLimit=5
181----
182
183Configured this way, ZooKeeper server detects its own segmentation from the rest of the ZooKeeper cluster only after `tickTime * syncLimit` elapses.
184Until this event is detected at ZooKeeper level, all Ignite nodes connected to the segmented ZooKeeper server do not try to reconnect to the other ZooKeeper servers.
185
186On the other hand, there is a `sessionTimeout` parameter on the Ignite
187side that defines how soon ZooKeeper closes an Ignite node’s session if
188the node gets disconnected from the ZooKeeper cluster.
189If `sessionTimeout` is smaller than `tickTime * syncLimit` , then the
190Ignite node is notified by the segmented ZooKeeper server too
191late — its session expires before it tries to reconnect to other ZooKeeper servers.
192
193To avoid this situation, `sessionTimeout` should be bigger than `tickTime * syncLimit`.
194