Skip to content

Commit cc56b78

Browse files
committed
multi: add documentation comments
Part of #123
1 parent 676c5ab commit cc56b78

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

multi/multi.go

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func indexOf(sstring string, data []string) int {
4040
return -1
4141
}
4242

43+
// ConnectionMulti is a handle with connections to a number of Tarantool instances.
44+
//
45+
// It is created and configured with Connect function, and could not be
46+
// reconfigured later.
4347
type ConnectionMulti struct {
4448
addrs []string
4549
connOpts tarantool.Opts
@@ -55,12 +59,19 @@ type ConnectionMulti struct {
5559

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

62+
// OptsMulti is a way to configure Connection with multiconnect-specific options.
5863
type OptsMulti struct {
59-
CheckTimeout time.Duration
64+
// CheckTimeout is a time interval to check for connection timeout and try to
65+
// switch connection.
66+
CheckTimeout time.Duration
67+
// Lua function name of the server called to retrieve the address list.
6068
NodesGetFunctionName string
69+
// Time interval to ask the server for an updated address list (works
70+
// if NodesGetFunctionName is set).
6171
ClusterDiscoveryTime time.Duration
6272
}
6373

74+
// Connect creates and configures new ConnectionMulti with multiconnection options.
6475
func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsMulti) (connMulti *ConnectionMulti, err error) {
6576
if len(addrs) == 0 {
6677
return nil, ErrEmptyAddrs
@@ -92,6 +103,7 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsMulti) (c
92103
return connMulti, nil
93104
}
94105

106+
// Connect creates and configures new ConnectionMulti.
95107
func Connect(addrs []string, connOpts tarantool.Opts) (connMulti *ConnectionMulti, err error) {
96108
opts := OptsMulti{
97109
CheckTimeout: 1 * time.Second,
@@ -236,10 +248,13 @@ func (connMulti *ConnectionMulti) getCurrentConnection() *tarantool.Connection {
236248
return connMulti.fallback
237249
}
238250

251+
// ConnectedNow reports if connection is established at the moment.
239252
func (connMulti *ConnectionMulti) ConnectedNow() bool {
240253
return connMulti.getState() == connConnected && connMulti.getCurrentConnection().ConnectedNow()
241254
}
242255

256+
// Close closes Connection.
257+
// After this method called, there is no way to reopen this Connection.
243258
func (connMulti *ConnectionMulti) Close() (err error) {
244259
connMulti.mutex.Lock()
245260
defer connMulti.mutex.Unlock()
@@ -261,118 +276,174 @@ func (connMulti *ConnectionMulti) Close() (err error) {
261276
return
262277
}
263278

279+
// Ping sends empty request to Tarantool to check connection.
264280
func (connMulti *ConnectionMulti) Ping() (resp *tarantool.Response, err error) {
265281
return connMulti.getCurrentConnection().Ping()
266282
}
267283

284+
// ConfiguredTimeout returns a timeout from connection config.
268285
func (connMulti *ConnectionMulti) ConfiguredTimeout() time.Duration {
269286
return connMulti.getCurrentConnection().ConfiguredTimeout()
270287
}
271288

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

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

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

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

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

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

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

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).
300334
func (connMulti *ConnectionMulti) Call17(functionName string, args interface{}) (resp *tarantool.Response, err error) {
301335
return connMulti.getCurrentConnection().Call17(functionName, args)
302336
}
303337

338+
// Eval passes Lua expression for evaluation.
304339
func (connMulti *ConnectionMulti) Eval(expr string, args interface{}) (resp *tarantool.Response, err error) {
305340
return connMulti.getCurrentConnection().Eval(expr, args)
306341
}
307342

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

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

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

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

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

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

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

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)
336388
func (connMulti *ConnectionMulti) Call17Typed(functionName string, args interface{}, result interface{}) (err error) {
337389
return connMulti.getCurrentConnection().Call17Typed(functionName, args, result)
338390
}
339391

392+
// EvalTyped passes Lua expression for evaluation.
340393
func (connMulti *ConnectionMulti) EvalTyped(expr string, args interface{}, result interface{}) (err error) {
341394
return connMulti.getCurrentConnection().EvalTyped(expr, args, result)
342395
}
343396

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

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

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

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

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

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

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.
368435
func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future {
369436
return connMulti.getCurrentConnection().CallAsync(functionName, args)
370437
}
371438

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).
372442
func (connMulti *ConnectionMulti) Call17Async(functionName string, args interface{}) *tarantool.Future {
373443
return connMulti.getCurrentConnection().Call17Async(functionName, args)
374444
}
375445

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

0 commit comments

Comments
 (0)