@@ -56,7 +56,7 @@ SocketChannelProvider socketChannelProvider = new SingleSocketChannelProviderImp
56
56
TarantoolClient client = new TarantoolClientImpl (socketChannelProvider, config);
57
57
```
58
58
59
- You could implement your own ` SocketChannelProvider ` . It should return
59
+ You could implement your own ` SocketChannelProvider ` . It should return
60
60
a connected ` SocketChannel ` . Feel free to implement ` get(int retryNumber, Throwable lastError) `
61
61
using your appropriate strategy to obtain the channel. The strategy can take into
62
62
account current attempt number (retryNumber) and the last transient error occurred on
@@ -177,7 +177,7 @@ Supported options are follow:
177
177
13 . ` retryCount ` is a hint and can be passed to the socket providers which
178
178
implement ` ConfigurableSocketChannelProvider ` interface. This hint should be
179
179
interpreter as a maximal number of attempts to connect to Tarantool instance.
180
- Default value is ` 3 ` .
180
+ Default value is ` 3 ` .
181
181
14 . ` operationExpiryTimeMillis ` is a default request timeout in ms.
182
182
Default value is ` 1000 ` (1 second).
183
183
@@ -283,6 +283,31 @@ order in which they were added to the batch"
283
283
- The driver continues processing the remaining commands in a batch once execution
284
284
of a command fails.
285
285
286
+ ### Connection Fail-over
287
+
288
+ To enable simple connection fail-over you can specify multiple nodes (host and port pairs) in the connection url. The
289
+ driver will try to once connect to each of them in order until the connection succeeds. If none succeed, a normal
290
+ connection exception is thrown.
291
+
292
+ The syntax for the connection url is:
293
+
294
+ jdbc:tarantool://[ user-info@] [ nodes ] [ ?parameters]
295
+
296
+ where
297
+ * ` user-info ` is an optional colon separated username and password like ` admin:secret ` ;
298
+ * ` nodes ` is a set of comma separated pairs like ` host1[:port1][,host2[:port2] ... ] ` ;
299
+ * ` parameters ` is a set of optional cluster parameters (in addition to other ones) such as
300
+ ` clusterDiscoveryEntryFunction ` and ` clusterDiscoveryDelayMillis ` (see [ Cluster support] ( #cluster-support ) for more
301
+ details).
302
+
303
+ For instance,
304
+
305
+ jdbc:postgresql://tnt-node-1:3301,tnt-node2,tnt-node-3:3302?clusterDiscoveryEntryFunction=fetchNodes
306
+
307
+ will try to connect to the Tarantool servers using initial set of nodes in the order they were listed in the URL. Also,
308
+ there is ` clusterDiscoveryEntryFunction ` parameter specified to enable cluster nodes discovery that can refresh the list
309
+ of available nodes.
310
+
286
311
## Cluster support
287
312
288
313
To be more fault-tolerant the connector provides cluster extensions. In
@@ -307,7 +332,7 @@ connection to _one instance_ before failing an attempt. The provider requires
307
332
positive retry count to work properly. The socket timeout is used to limit
308
333
an interval between connections attempts per instance. In other words, the provider
309
334
follows a pattern _ connection should succeed after N attempts with M interval between
310
- them at max_ .
335
+ them at max_ .
311
336
312
337
### Basic cluster client usage
313
338
@@ -326,7 +351,7 @@ an initial list of nodes:
326
351
``` java
327
352
String [] nodes = new String [] { " myHost1:3301" , " myHost2:3302" , " myHost3:3301" };
328
353
TarantoolClusterClient client = new TarantoolClusterClient (config, nodes);
329
- ```
354
+ ```
330
355
331
356
3 . Work with the client using same API as defined in ` TarantoolClient ` :
332
357
@@ -336,10 +361,10 @@ client.syncOps().insert(23, Arrays.asList(1, 1));
336
361
337
362
### Auto-discovery
338
363
339
- Auto-discovery feature allows a cluster client to fetch addresses of
364
+ Auto-discovery feature allows a cluster client to fetch addresses of
340
365
cluster nodes to reflect changes related to the cluster topology. To achieve
341
- this you have to create a Lua function on the server side which returns
342
- a single array result. Client periodically polls the server to obtain a
366
+ this you have to create a Lua function on the server side which returns
367
+ a single array result. Client periodically polls the server to obtain a
343
368
fresh list and apply it if its content changes.
344
369
345
370
1 . On the server side create a function which returns nodes:
@@ -356,20 +381,20 @@ You need to pay attention to a function contract we are currently supporting:
356
381
and an optional colon followed by digits of the port). Also, the port must be
357
382
in a range between 1 and 65535 if one is presented.
358
383
* A discovery function _may_ return multi-results but the client takes
359
- into account only first of them (i.e. ` return {' host:3301' }, discovery_delay` , where
384
+ into account only first of them (i.e. ` return {' host:3301' }, discovery_delay` , where
360
385
the second result is unused). Even more, any extra results __are reserved__ by the client
361
386
in order to extend its contract with a backward compatibility.
362
387
* A discovery function _should NOT_ return no results, empty result, wrong type result,
363
388
and Lua errors. The client discards such kinds of results but it does not affect the discovery
364
- process for next scheduled tasks.
389
+ process for next scheduled tasks.
365
390
366
391
2. On the client side configure discovery settings in ` TarantoolClusterClientConfig` :
367
392
368
393
` ` ` java
369
394
TarantoolClusterClientConfig config = new TarantoolClusterClientConfig ();
370
395
// fill other settings
371
- config.clusterDiscoveryEntryFunction = " get_cluster_nodes" ; // discovery function used to fetch nodes
372
- config.clusterDiscoveryDelayMillis = 60_000; // how often client polls the discovery server
396
+ config.clusterDiscoveryEntryFunction = " get_cluster_nodes" ; // discovery function used to fetch nodes
397
+ config.clusterDiscoveryDelayMillis = 60_000; // how often client polls the discovery server
373
398
` ` `
374
399
375
400
3. Create a client using the config made above.
@@ -383,21 +408,21 @@ client.syncOps().insert(45, Arrays.asList(1, 1));
383
408
384
409
* You need to set _not empty_ value to ` clusterDiscoveryEntryFunction` to enable auto-discovery feature.
385
410
* There are only two cases when a discovery task runs: just after initialization of the cluster
386
- client and a periodical scheduler timeout defined in ` TarantoolClusterClientConfig.clusterDiscoveryDelayMillis` .
411
+ client and a periodical scheduler timeout defined in ` TarantoolClusterClientConfig.clusterDiscoveryDelayMillis` .
387
412
* A discovery task always uses an active client connection to get the nodes list.
388
413
It' s in your responsibility to provide a function availability as well as a consistent
389
414
nodes list on all instances you initially set or obtain from the task.
390
415
* Every address which is unmatched with `host[:port]` pattern will be filtered out from
391
416
the target addresses list.
392
417
* If some error occurs while a discovery task is running then this task
393
- will be aborted without any after-effects for next task executions. These cases, for instance, are
394
- a wrong function result (see discovery function contract) or a broken connection.
418
+ will be aborted without any after-effects for next task executions. These cases, for instance, are
419
+ a wrong function result (see discovery function contract) or a broken connection.
395
420
There is an exception if the client is closed then discovery process will stop permanently.
396
421
* It' s possible to obtain a list which does NOT contain the node we are currently
397
- connected to. It leads the client to try to reconnect to another node from the
422
+ connected to. It leads the client to try to reconnect to another node from the
398
423
new list. It may take some time to graceful disconnect from the current node.
399
424
The client does its best to catch the moment when there are no pending responses
400
- and perform a reconnection.
425
+ and perform a reconnection.
401
426
402
427
# ## Cluster client config options
403
428
@@ -425,7 +450,7 @@ directly via SLF4J interface.
425
450
The logging facade offers several ways in integrate its internal logging with foreign one in order:
426
451
427
452
* Using system property ` org.tarantool.logging.provider` . Supported values are * jdk* and * slf4j*
428
- for the java util logging and SLF4J/Logback respectively. For instance, use
453
+ for the java util logging and SLF4J/Logback respectively. For instance, use
429
454
` java -Dorg.tarantool.logging.provider=slf4j < ...> ` .
430
455
431
456
* Using Java SPI mechanism. Implement your own provider org.tarantool.logging.LoggerProvider
@@ -437,7 +462,7 @@ cat META-INF/services/org.tarantool.logging.LoggerProvider
437
462
org.mydomain.MySimpleLoggerProvider
438
463
` ` `
439
464
440
- * CLASSPATH exploring. Now, the connector will use SLF4J if Logback is also in use.
465
+ * CLASSPATH exploring. Now, the connector will use SLF4J if Logback is also in use.
441
466
442
467
* If nothing is successful JUL will be used by default.
443
468
@@ -452,10 +477,10 @@ org.mydomain.MySimpleLoggerProvider
452
477
# # Building
453
478
454
479
To run unit tests use:
455
-
480
+
456
481
` ` ` bash
457
482
./mvnw clean test
458
- ` ` `
483
+ ` ` `
459
484
460
485
To run integration tests use:
461
486
0 commit comments