@@ -17,6 +17,7 @@ To get the Java connector for Tarantool 1.6.9, visit
17
17
18
18
## Table of contents
19
19
* [ Getting started] ( #getting-started )
20
+ * [ Cluster support] ( #cluster-support )
20
21
* [ Where to get help] ( #where-to-get-help )
21
22
22
23
## Getting started
@@ -156,6 +157,88 @@ System.out.println(template.query("select * from hello_world where hello=:id", C
156
157
157
158
For more implementation details, see [ API documentation] ( http://tarantool.github.io/tarantool-java/apidocs/index.html ) .
158
159
160
+ ## Cluster support
161
+
162
+ To be more fault-tolerant the connector provides cluster extensions. In
163
+ particular ` TarantoolClusterClientImpl ` and built-in ` RoundRobinSocketProviderImpl `
164
+ used as a default ` SocketProvider ` implementation. When currently connected
165
+ instance is down then the client will try to reconnect to the first available
166
+ instance using strategy defined in a socket provider. You need to supply
167
+ a list of nodes which will be used by the cluster client to provide such
168
+ ability. Also you can prefer to use a [ discovery mechanism] ( #auto-discovery )
169
+ in order to dynamically fetch and apply the node list.
170
+
171
+ #### Basic cluster client usage
172
+
173
+ 1 . Configure ` TarantoolClusterClientConfig ` :
174
+
175
+ ``` java
176
+ TarantoolClusterClientConfig config = new TarantoolClusterClientConfig ();
177
+ // fill other settings
178
+ config. operationExpiryTimeMillis = 2000 ;
179
+ config. executor = Executors . newSingleThreadExecutor();
180
+ ```
181
+
182
+ 2 . Create an instance of ` TarantoolClusterClientImpl ` . You need to provide
183
+ an initial list of nodes:
184
+
185
+ ``` java
186
+ String [] nodes = new String [] { " myHost1:3301" , " myHost2:3302" , " myHost3:3301" };
187
+ TarantoolClusterClient client = new TarantoolClusterClient (config, nodes);
188
+ ```
189
+
190
+ 3 . Work with the client using same API as defined in ` TarantoolClient ` :
191
+
192
+ ``` java
193
+ client. syncOps(). insert(23 , Arrays . asList(1 , 1 ));
194
+ ```
195
+
196
+ #### Auto-discovery
197
+
198
+ Auto-discovery feature allows a cluster client to fetch addresses of
199
+ cluster nodes to reflect changes related to the cluster topology. To achieve
200
+ this you have to create a LUA function on the server side which returns
201
+ a single array result. Client periodically pools the server to obtain a
202
+ fresh list and apply it if its content changes.
203
+
204
+ 1 . On the server side create a function which returns nodes:
205
+
206
+ ``` bash
207
+ tarantool> function getClusterNodes() return { ' host1' , ' host2' , ' host3' } end
208
+ ` ` `
209
+
210
+ 2. On the client side configure discovery settings in ` TarantoolClusterClientConfig` :
211
+
212
+ ` ` ` java
213
+ TarantoolClusterClientConfig config = new TarantoolClusterClientConfig ();
214
+ // fill other settings
215
+ config.clusterDiscoveryEntryInstance = " 10.0.0.15:3301" ; // target discovery server
216
+ config.clusterDiscoveryEntryFunction = " myDiscoveryFunction" ; // discovery function used to fetch nodes
217
+ config.clusterDiscoveryDelayMillis = 60_000; // how often client polls the discovery server
218
+ ` ` `
219
+
220
+ See [TarantoolClientConfig](http://tarantool.github.io/tarantool-java/apidocs/index.html? org/tarantool/TarantoolClientConfig.html)
221
+ javadoc for more information.
222
+
223
+ # ### Auto-discovery caveats
224
+
225
+ * You need to supply both ` clusterDiscoveryEntryInstance` and ` clusterDiscoveryEntryFunction`
226
+ to enable auto-discovery feature.
227
+ * There are only two cases when a discovery task runs: just after initialization of the cluster
228
+ client and a periodical scheduler timeout defined in ` TarantoolClusterClientConfig.clusterDiscoveryDelayMillis` .
229
+ * It' s possible both provide an initial node list and enable auto-discovery.
230
+ In this way client will establish first connection to the Tarantool server using
231
+ the initial list and when the client receives a new list it will replace the list if required.
232
+ * When auto-discovery is enabled but the initial node list isn' t provided the client
233
+ will wait for the list obtained from the discovery server. If fetching and connection
234
+ take more than ` TarantoolClientConfig.initTimeoutMillis` then client will be closed
235
+ by timeout.
236
+ * It' s possible to obtain a list which does NOT contain the node we are currently
237
+ connected to. It leads the client to try to reconnect to another node from the
238
+ new list. It may take some time to gracefully disconnect from the current node.
239
+ The client does its best to catch the moment when no messages are pending by the
240
+ client.
241
+
159
242
## Where to get help
160
243
161
244
Got problems or questions? Post them on
@@ -164,6 +247,7 @@ Got problems or questions? Post them on
164
247
base for possible answers and solutions.
165
248
166
249
## Building
250
+
167
251
To run tests
168
252
```
169
253
./mvnw clean test
0 commit comments