Skip to content

Commit 200dc9d

Browse files
committed
multi: add documentation comments
Part of #123
1 parent a44b50d commit 200dc9d

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

multi/multi.go

+73-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func indexOf(sstring string, data []string) int {
3939
return -1
4040
}
4141

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.
4246
type ConnectionMulti struct {
4347
addrs []string
4448
connOpts tarantool.Opts
@@ -54,12 +58,20 @@ type ConnectionMulti struct {
5458

5559
var _ = tarantool.Connector(&ConnectionMulti{}) // check compatibility with connector interface
5660

61+
// OptsMulti is a way to configure Connection with multiconnect-specific options.
5762
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.
5968
NodesGetFunctionName string
69+
// ClusterDiscoveryTime is a time interval to ask server for updated address
70+
// list (works on with NodesGetFunctionName set).
6071
ClusterDiscoveryTime time.Duration
6172
}
6273

74+
// Connect creates and configures new ConnectionMulti with multiconnection options.
6375
func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsMulti) (connMulti *ConnectionMulti, err error) {
6476
if len(addrs) == 0 {
6577
return nil, ErrEmptyAddrs
@@ -91,6 +103,7 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsMulti) (c
91103
return connMulti, nil
92104
}
93105

106+
// Connect creates and configures new ConnectionMulti.
94107
func Connect(addrs []string, connOpts tarantool.Opts) (connMulti *ConnectionMulti, err error) {
95108
opts := OptsMulti{
96109
CheckTimeout: 1 * time.Second,
@@ -235,10 +248,13 @@ func (connMulti *ConnectionMulti) getCurrentConnection() *tarantool.Connection {
235248
return connMulti.fallback
236249
}
237250

251+
// ConnectedNow reports if connection is established at the moment.
238252
func (connMulti *ConnectionMulti) ConnectedNow() bool {
239253
return connMulti.getState() == connConnected && connMulti.getCurrentConnection().ConnectedNow()
240254
}
241255

256+
// Close closes Connection.
257+
// After this method called, there is no way to reopen this Connection.
242258
func (connMulti *ConnectionMulti) Close() (err error) {
243259
connMulti.mutex.Lock()
244260
defer connMulti.mutex.Unlock()
@@ -260,118 +276,174 @@ func (connMulti *ConnectionMulti) Close() (err error) {
260276
return
261277
}
262278

279+
// Ping sends empty request to Tarantool to check connection.
263280
func (connMulti *ConnectionMulti) Ping() (resp *tarantool.Response, err error) {
264281
return connMulti.getCurrentConnection().Ping()
265282
}
266283

284+
// ConfiguredTimeout returns a timeout from connection config.
267285
func (connMulti *ConnectionMulti) ConfiguredTimeout() time.Duration {
268286
return connMulti.getCurrentConnection().ConfiguredTimeout()
269287
}
270288

289+
// Select performs select to box space.
271290
func (connMulti *ConnectionMulti) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (resp *tarantool.Response, err error) {
272291
return connMulti.getCurrentConnection().Select(space, index, offset, limit, iterator, key)
273292
}
274293

294+
// Insert performs insertion to box space.
295+
// Tarantool will reject Insert when tuple with same primary key exists.
275296
func (connMulti *ConnectionMulti) Insert(space interface{}, tuple interface{}) (resp *tarantool.Response, err error) {
276297
return connMulti.getCurrentConnection().Insert(space, tuple)
277298
}
278299

300+
// Replace performs "insert or replace" action to box space.
301+
// If tuple with same primary key exists, it will be replaced.
279302
func (connMulti *ConnectionMulti) Replace(space interface{}, tuple interface{}) (resp *tarantool.Response, err error) {
280303
return connMulti.getCurrentConnection().Replace(space, tuple)
281304
}
282305

306+
// Delete performs deletion of a tuple by key.
307+
// Result will contain array with deleted tuple.
283308
func (connMulti *ConnectionMulti) Delete(space, index interface{}, key interface{}) (resp *tarantool.Response, err error) {
284309
return connMulti.getCurrentConnection().Delete(space, index, key)
285310
}
286311

312+
// Update performs update of a tuple by key.
313+
// Result will contain array with updated tuple.
287314
func (connMulti *ConnectionMulti) Update(space, index interface{}, key, ops interface{}) (resp *tarantool.Response, err error) {
288315
return connMulti.getCurrentConnection().Update(space, index, key, ops)
289316
}
290317

318+
// Upsert performs "update or insert" action of a tuple by key.
319+
// Result will not contain any tuple.
291320
func (connMulti *ConnectionMulti) Upsert(space interface{}, tuple, ops interface{}) (resp *tarantool.Response, err error) {
292321
return connMulti.getCurrentConnection().Upsert(space, tuple, ops)
293322
}
294323

324+
// Call calls registered Tarantool function.
325+
// It uses request code for Tarantool 1.6, so result is converted to array of
326+
// arrays.
295327
func (connMulti *ConnectionMulti) Call(functionName string, args interface{}) (resp *tarantool.Response, err error) {
296328
return connMulti.getCurrentConnection().Call(functionName, args)
297329
}
298330

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).
299334
func (connMulti *ConnectionMulti) Call17(functionName string, args interface{}) (resp *tarantool.Response, err error) {
300335
return connMulti.getCurrentConnection().Call17(functionName, args)
301336
}
302337

338+
// Eval passes Lua expression for evaluation.
303339
func (connMulti *ConnectionMulti) Eval(expr string, args interface{}) (resp *tarantool.Response, err error) {
304340
return connMulti.getCurrentConnection().Eval(expr, args)
305341
}
306342

343+
// GetTyped performs select (with limit = 1 and offset = 0) to box space and
344+
// fills typed result.
307345
func (connMulti *ConnectionMulti) GetTyped(space, index interface{}, key interface{}, result interface{}) (err error) {
308346
return connMulti.getCurrentConnection().GetTyped(space, index, key, result)
309347
}
310348

349+
// SelectTyped performs select to box space and fills typed result.
311350
func (connMulti *ConnectionMulti) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}) (err error) {
312351
return connMulti.getCurrentConnection().SelectTyped(space, index, offset, limit, iterator, key, result)
313352
}
314353

354+
// InsertTyped performs insertion to box space.
355+
// Tarantool will reject Insert when tuple with same primary key exists.
315356
func (connMulti *ConnectionMulti) InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error) {
316357
return connMulti.getCurrentConnection().InsertTyped(space, tuple, result)
317358
}
318359

360+
// ReplaceTyped performs "insert or replace" action to box space.
361+
// If tuple with same primary key exists, it will be replaced.
319362
func (connMulti *ConnectionMulti) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error) {
320363
return connMulti.getCurrentConnection().ReplaceTyped(space, tuple, result)
321364
}
322365

366+
// DeleteTyped performs deletion of a tuple by key and fills result with
367+
// deleted tuple.
323368
func (connMulti *ConnectionMulti) DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error) {
324369
return connMulti.getCurrentConnection().DeleteTyped(space, index, key, result)
325370
}
326371

372+
// UpdateTyped performs update of a tuple by key and fills result with updated
373+
// tuple.
327374
func (connMulti *ConnectionMulti) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error) {
328375
return connMulti.getCurrentConnection().UpdateTyped(space, index, key, ops, result)
329376
}
330377

378+
// CallTyped calls registered function.
379+
// It uses request code for Tarantool 1.6, so result is converted to array of
380+
// arrays.
331381
func (connMulti *ConnectionMulti) CallTyped(functionName string, args interface{}, result interface{}) (err error) {
332382
return connMulti.getCurrentConnection().CallTyped(functionName, args, result)
333383
}
334384

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)
335388
func (connMulti *ConnectionMulti) Call17Typed(functionName string, args interface{}, result interface{}) (err error) {
336389
return connMulti.getCurrentConnection().Call17Typed(functionName, args, result)
337390
}
338391

392+
// EvalTyped passes Lua expression for evaluation.
339393
func (connMulti *ConnectionMulti) EvalTyped(expr string, args interface{}, result interface{}) (err error) {
340394
return connMulti.getCurrentConnection().EvalTyped(expr, args, result)
341395
}
342396

397+
// SelectAsync sends select request to Tarantool and returns Future.
343398
func (connMulti *ConnectionMulti) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *tarantool.Future {
344399
return connMulti.getCurrentConnection().SelectAsync(space, index, offset, limit, iterator, key)
345400
}
346401

402+
// InsertAsync sends insert action to Tarantool and returns Future.
403+
// Tarantool will reject Insert when tuple with same primary key exists.
347404
func (connMulti *ConnectionMulti) InsertAsync(space interface{}, tuple interface{}) *tarantool.Future {
348405
return connMulti.getCurrentConnection().InsertAsync(space, tuple)
349406
}
350407

408+
// ReplaceAsync sends "insert or replace" action to Tarantool and returns Future.
409+
// If tuple with same primary key exists, it will be replaced.
351410
func (connMulti *ConnectionMulti) ReplaceAsync(space interface{}, tuple interface{}) *tarantool.Future {
352411
return connMulti.getCurrentConnection().ReplaceAsync(space, tuple)
353412
}
354413

414+
// DeleteAsync sends deletion action to Tarantool and returns Future.
415+
// Future's result will contain array with deleted tuple.
355416
func (connMulti *ConnectionMulti) DeleteAsync(space, index interface{}, key interface{}) *tarantool.Future {
356417
return connMulti.getCurrentConnection().DeleteAsync(space, index, key)
357418
}
358419

420+
// Update sends deletion of a tuple by key and returns Future.
421+
// Future's result will contain array with updated tuple.
359422
func (connMulti *ConnectionMulti) UpdateAsync(space, index interface{}, key, ops interface{}) *tarantool.Future {
360423
return connMulti.getCurrentConnection().UpdateAsync(space, index, key, ops)
361424
}
362425

426+
// UpsertAsync sends "update or insert" action to Tarantool and returns Future.
427+
// Future's sesult will not contain any tuple.
363428
func (connMulti *ConnectionMulti) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *tarantool.Future {
364429
return connMulti.getCurrentConnection().UpsertAsync(space, tuple, ops)
365430
}
366431

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.
367435
func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future {
368436
return connMulti.getCurrentConnection().CallAsync(functionName, args)
369437
}
370438

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).
371442
func (connMulti *ConnectionMulti) Call17Async(functionName string, args interface{}) *tarantool.Future {
372443
return connMulti.getCurrentConnection().Call17Async(functionName, args)
373444
}
374445

446+
// EvalAsync passes Lua expression for evaluation.
375447
func (connMulti *ConnectionMulti) EvalAsync(expr string, args interface{}) *tarantool.Future {
376448
return connMulti.getCurrentConnection().EvalAsync(expr, args)
377449
}

0 commit comments

Comments
 (0)