@@ -39,6 +39,10 @@ func indexOf(sstring string, data []string) int {
39
39
return - 1
40
40
}
41
41
42
+ // ConnectionMulti is a handle with connections to a number of Tarantool instances.
43
+ //
44
+ // It is created and configured with Connect function, and could not be
45
+ // reconfigured later.
42
46
type ConnectionMulti struct {
43
47
addrs []string
44
48
connOpts tarantool.Opts
@@ -54,12 +58,20 @@ type ConnectionMulti struct {
54
58
55
59
var _ = tarantool .Connector (& ConnectionMulti {}) // check compatibility with connector interface
56
60
61
+ // OptsMulti is a way to configure Connection with multiconnect-specific options.
57
62
type OptsMulti struct {
58
- CheckTimeout time.Duration
63
+ // CheckTimeout is a time interval to check for connection timeout and try to
64
+ // switch connection.
65
+ CheckTimeout time.Duration
66
+ // NodesGetFunctionName is a server Lua function name to call for getting
67
+ // address list.
59
68
NodesGetFunctionName string
69
+ // ClusterDiscoveryTime is a time interval to ask server for updated address
70
+ // list (works on with NodesGetFunctionName set).
60
71
ClusterDiscoveryTime time.Duration
61
72
}
62
73
74
+ // Connect creates and configures new ConnectionMulti with multiconnection options.
63
75
func ConnectWithOpts (addrs []string , connOpts tarantool.Opts , opts OptsMulti ) (connMulti * ConnectionMulti , err error ) {
64
76
if len (addrs ) == 0 {
65
77
return nil , ErrEmptyAddrs
@@ -91,6 +103,7 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsMulti) (c
91
103
return connMulti , nil
92
104
}
93
105
106
+ // Connect creates and configures new ConnectionMulti.
94
107
func Connect (addrs []string , connOpts tarantool.Opts ) (connMulti * ConnectionMulti , err error ) {
95
108
opts := OptsMulti {
96
109
CheckTimeout : 1 * time .Second ,
@@ -235,10 +248,13 @@ func (connMulti *ConnectionMulti) getCurrentConnection() *tarantool.Connection {
235
248
return connMulti .fallback
236
249
}
237
250
251
+ // ConnectedNow reports if connection is established at the moment.
238
252
func (connMulti * ConnectionMulti ) ConnectedNow () bool {
239
253
return connMulti .getState () == connConnected && connMulti .getCurrentConnection ().ConnectedNow ()
240
254
}
241
255
256
+ // Close closes Connection.
257
+ // After this method called, there is no way to reopen this Connection.
242
258
func (connMulti * ConnectionMulti ) Close () (err error ) {
243
259
connMulti .mutex .Lock ()
244
260
defer connMulti .mutex .Unlock ()
@@ -260,118 +276,174 @@ func (connMulti *ConnectionMulti) Close() (err error) {
260
276
return
261
277
}
262
278
279
+ // Ping sends empty request to Tarantool to check connection.
263
280
func (connMulti * ConnectionMulti ) Ping () (resp * tarantool.Response , err error ) {
264
281
return connMulti .getCurrentConnection ().Ping ()
265
282
}
266
283
284
+ // ConfiguredTimeout returns a timeout from connection config.
267
285
func (connMulti * ConnectionMulti ) ConfiguredTimeout () time.Duration {
268
286
return connMulti .getCurrentConnection ().ConfiguredTimeout ()
269
287
}
270
288
289
+ // Select performs select to box space.
271
290
func (connMulti * ConnectionMulti ) Select (space , index interface {}, offset , limit , iterator uint32 , key interface {}) (resp * tarantool.Response , err error ) {
272
291
return connMulti .getCurrentConnection ().Select (space , index , offset , limit , iterator , key )
273
292
}
274
293
294
+ // Insert performs insertion to box space.
295
+ // Tarantool will reject Insert when tuple with same primary key exists.
275
296
func (connMulti * ConnectionMulti ) Insert (space interface {}, tuple interface {}) (resp * tarantool.Response , err error ) {
276
297
return connMulti .getCurrentConnection ().Insert (space , tuple )
277
298
}
278
299
300
+ // Replace performs "insert or replace" action to box space.
301
+ // If tuple with same primary key exists, it will be replaced.
279
302
func (connMulti * ConnectionMulti ) Replace (space interface {}, tuple interface {}) (resp * tarantool.Response , err error ) {
280
303
return connMulti .getCurrentConnection ().Replace (space , tuple )
281
304
}
282
305
306
+ // Delete performs deletion of a tuple by key.
307
+ // Result will contain array with deleted tuple.
283
308
func (connMulti * ConnectionMulti ) Delete (space , index interface {}, key interface {}) (resp * tarantool.Response , err error ) {
284
309
return connMulti .getCurrentConnection ().Delete (space , index , key )
285
310
}
286
311
312
+ // Update performs update of a tuple by key.
313
+ // Result will contain array with updated tuple.
287
314
func (connMulti * ConnectionMulti ) Update (space , index interface {}, key , ops interface {}) (resp * tarantool.Response , err error ) {
288
315
return connMulti .getCurrentConnection ().Update (space , index , key , ops )
289
316
}
290
317
318
+ // Upsert performs "update or insert" action of a tuple by key.
319
+ // Result will not contain any tuple.
291
320
func (connMulti * ConnectionMulti ) Upsert (space interface {}, tuple , ops interface {}) (resp * tarantool.Response , err error ) {
292
321
return connMulti .getCurrentConnection ().Upsert (space , tuple , ops )
293
322
}
294
323
324
+ // Call calls registered Tarantool function.
325
+ // It uses request code for Tarantool 1.6, so result is converted to array of
326
+ // arrays.
295
327
func (connMulti * ConnectionMulti ) Call (functionName string , args interface {}) (resp * tarantool.Response , err error ) {
296
328
return connMulti .getCurrentConnection ().Call (functionName , args )
297
329
}
298
330
331
+ // Call17 calls registered Tarantool function.
332
+ // It uses request code for Tarantool 1.7, so result is not converted
333
+ // (though, keep in mind, result is always array).
299
334
func (connMulti * ConnectionMulti ) Call17 (functionName string , args interface {}) (resp * tarantool.Response , err error ) {
300
335
return connMulti .getCurrentConnection ().Call17 (functionName , args )
301
336
}
302
337
338
+ // Eval passes Lua expression for evaluation.
303
339
func (connMulti * ConnectionMulti ) Eval (expr string , args interface {}) (resp * tarantool.Response , err error ) {
304
340
return connMulti .getCurrentConnection ().Eval (expr , args )
305
341
}
306
342
343
+ // GetTyped performs select (with limit = 1 and offset = 0) to box space and
344
+ // fills typed result.
307
345
func (connMulti * ConnectionMulti ) GetTyped (space , index interface {}, key interface {}, result interface {}) (err error ) {
308
346
return connMulti .getCurrentConnection ().GetTyped (space , index , key , result )
309
347
}
310
348
349
+ // SelectTyped performs select to box space and fills typed result.
311
350
func (connMulti * ConnectionMulti ) SelectTyped (space , index interface {}, offset , limit , iterator uint32 , key interface {}, result interface {}) (err error ) {
312
351
return connMulti .getCurrentConnection ().SelectTyped (space , index , offset , limit , iterator , key , result )
313
352
}
314
353
354
+ // InsertTyped performs insertion to box space.
355
+ // Tarantool will reject Insert when tuple with same primary key exists.
315
356
func (connMulti * ConnectionMulti ) InsertTyped (space interface {}, tuple interface {}, result interface {}) (err error ) {
316
357
return connMulti .getCurrentConnection ().InsertTyped (space , tuple , result )
317
358
}
318
359
360
+ // ReplaceTyped performs "insert or replace" action to box space.
361
+ // If tuple with same primary key exists, it will be replaced.
319
362
func (connMulti * ConnectionMulti ) ReplaceTyped (space interface {}, tuple interface {}, result interface {}) (err error ) {
320
363
return connMulti .getCurrentConnection ().ReplaceTyped (space , tuple , result )
321
364
}
322
365
366
+ // DeleteTyped performs deletion of a tuple by key and fills result with
367
+ // deleted tuple.
323
368
func (connMulti * ConnectionMulti ) DeleteTyped (space , index interface {}, key interface {}, result interface {}) (err error ) {
324
369
return connMulti .getCurrentConnection ().DeleteTyped (space , index , key , result )
325
370
}
326
371
372
+ // UpdateTyped performs update of a tuple by key and fills result with updated
373
+ // tuple.
327
374
func (connMulti * ConnectionMulti ) UpdateTyped (space , index interface {}, key , ops interface {}, result interface {}) (err error ) {
328
375
return connMulti .getCurrentConnection ().UpdateTyped (space , index , key , ops , result )
329
376
}
330
377
378
+ // CallTyped calls registered function.
379
+ // It uses request code for Tarantool 1.6, so result is converted to array of
380
+ // arrays.
331
381
func (connMulti * ConnectionMulti ) CallTyped (functionName string , args interface {}, result interface {}) (err error ) {
332
382
return connMulti .getCurrentConnection ().CallTyped (functionName , args , result )
333
383
}
334
384
385
+ // Call17Typed calls registered function.
386
+ // It uses request code for Tarantool 1.7, so result is not converted (though,
387
+ // keep in mind, result is always array)
335
388
func (connMulti * ConnectionMulti ) Call17Typed (functionName string , args interface {}, result interface {}) (err error ) {
336
389
return connMulti .getCurrentConnection ().Call17Typed (functionName , args , result )
337
390
}
338
391
392
+ // EvalTyped passes Lua expression for evaluation.
339
393
func (connMulti * ConnectionMulti ) EvalTyped (expr string , args interface {}, result interface {}) (err error ) {
340
394
return connMulti .getCurrentConnection ().EvalTyped (expr , args , result )
341
395
}
342
396
397
+ // SelectAsync sends select request to Tarantool and returns Future.
343
398
func (connMulti * ConnectionMulti ) SelectAsync (space , index interface {}, offset , limit , iterator uint32 , key interface {}) * tarantool.Future {
344
399
return connMulti .getCurrentConnection ().SelectAsync (space , index , offset , limit , iterator , key )
345
400
}
346
401
402
+ // InsertAsync sends insert action to Tarantool and returns Future.
403
+ // Tarantool will reject Insert when tuple with same primary key exists.
347
404
func (connMulti * ConnectionMulti ) InsertAsync (space interface {}, tuple interface {}) * tarantool.Future {
348
405
return connMulti .getCurrentConnection ().InsertAsync (space , tuple )
349
406
}
350
407
408
+ // ReplaceAsync sends "insert or replace" action to Tarantool and returns Future.
409
+ // If tuple with same primary key exists, it will be replaced.
351
410
func (connMulti * ConnectionMulti ) ReplaceAsync (space interface {}, tuple interface {}) * tarantool.Future {
352
411
return connMulti .getCurrentConnection ().ReplaceAsync (space , tuple )
353
412
}
354
413
414
+ // DeleteAsync sends deletion action to Tarantool and returns Future.
415
+ // Future's result will contain array with deleted tuple.
355
416
func (connMulti * ConnectionMulti ) DeleteAsync (space , index interface {}, key interface {}) * tarantool.Future {
356
417
return connMulti .getCurrentConnection ().DeleteAsync (space , index , key )
357
418
}
358
419
420
+ // Update sends deletion of a tuple by key and returns Future.
421
+ // Future's result will contain array with updated tuple.
359
422
func (connMulti * ConnectionMulti ) UpdateAsync (space , index interface {}, key , ops interface {}) * tarantool.Future {
360
423
return connMulti .getCurrentConnection ().UpdateAsync (space , index , key , ops )
361
424
}
362
425
426
+ // UpsertAsync sends "update or insert" action to Tarantool and returns Future.
427
+ // Future's sesult will not contain any tuple.
363
428
func (connMulti * ConnectionMulti ) UpsertAsync (space interface {}, tuple interface {}, ops interface {}) * tarantool.Future {
364
429
return connMulti .getCurrentConnection ().UpsertAsync (space , tuple , ops )
365
430
}
366
431
432
+ // CallAsync sends a call to registered Tarantool function and returns Future.
433
+ // It uses request code for Tarantool 1.6, so future's result is always array
434
+ // of arrays.
367
435
func (connMulti * ConnectionMulti ) CallAsync (functionName string , args interface {}) * tarantool.Future {
368
436
return connMulti .getCurrentConnection ().CallAsync (functionName , args )
369
437
}
370
438
439
+ // Call17Async sends a call to registered Tarantool function and returns Future.
440
+ // It uses request code for Tarantool 1.7, so future's result will not be converted
441
+ // (though, keep in mind, result is always array).
371
442
func (connMulti * ConnectionMulti ) Call17Async (functionName string , args interface {}) * tarantool.Future {
372
443
return connMulti .getCurrentConnection ().Call17Async (functionName , args )
373
444
}
374
445
446
+ // EvalAsync passes Lua expression for evaluation.
375
447
func (connMulti * ConnectionMulti ) EvalAsync (expr string , args interface {}) * tarantool.Future {
376
448
return connMulti .getCurrentConnection ().EvalAsync (expr , args )
377
449
}
0 commit comments