pool

package
v2.0.0-...-2a4499d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2023 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package with methods to work with a Tarantool cluster considering master discovery.

Main features:

- Return available connection from pool according to round-robin strategy.

- Automatic master discovery by mode parameter.

Since: 1.6.0

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyAddrs        = errors.New("addrs (first argument) should not be empty")
	ErrWrongCheckTimeout = errors.New("wrong check timeout, must be greater than 0")
	ErrNoConnection      = errors.New("no active connections")
	ErrTooManyArgs       = errors.New("too many arguments")
	ErrIncorrectResponse = errors.New("incorrect response format")
	ErrIncorrectStatus   = errors.New("incorrect instance status: status should be `running`")
	ErrNoRwInstance      = errors.New("can't find rw instance in pool")
	ErrNoRoInstance      = errors.New("can't find ro instance in pool")
	ErrNoHealthyInstance = errors.New("can't find healthy instance in pool")
	ErrExists            = errors.New("endpoint exists")
	ErrClosed            = errors.New("pool is closed")
	ErrUnknownRequest    = errors.New("the passed connected request doesn't belong to " +
		"the current connection pool")
)

Functions

This section is empty.

Types

type ConnectionHandler

type ConnectionHandler interface {
	// Discovered is called when a connection with a role has been detected
	// (for the first time or when a role of a connection has been changed),
	// but is not yet available to send requests. It allows for a client to
	// initialize the connection before using it in a pool.
	//
	// The client code may cancel adding a connection to the pool. The client
	// need to return an error from the Discovered call for that. In this case
	// the pool will close connection and will try to reopen it later.
	Discovered(conn *tarantool.Connection, role Role) error
	// Deactivated is called when a connection with a role has become
	// unavaileble to send requests. It happens if the connection is closed or
	// the connection role is switched.
	//
	// So if a connection switches a role, a pool calls:
	// Deactivated() + Discovered().
	//
	// Deactivated will not be called if a previous Discovered() call returns
	// an error. Because in this case, the connection does not become available
	// for sending requests.
	Deactivated(conn *tarantool.Connection, role Role) error
}

ConnectionHandler provides callbacks for components interested in handling changes of connections in a ConnectionPool.

type ConnectionInfo

type ConnectionInfo struct {
	ConnectedNow bool
	ConnRole     Role
}

ConnectionInfo structure for information about connection statuses:

- ConnectedNow reports if connection is established at the moment.

- ConnRole reports master/replica role of instance.

type ConnectionPool

type ConnectionPool struct {
	// contains filtered or unexported fields
}

Main features:

- Return available connection from pool according to round-robin strategy.

- Automatic master discovery by mode parameter.

func Connect

func Connect(addrs []string, connOpts tarantool.Opts) (*ConnectionPool, error)

ConnectWithOpts creates pool for instances with addresses addrs.

It is useless to set up tarantool.Opts.Reconnect value for a connection. The connection pool has its own reconnection logic. See Opts.CheckTimeout description.

func ConnectWithOpts

func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts Opts) (*ConnectionPool, error)

ConnectWithOpts creates pool for instances with addresses addrs with options opts.

func (*ConnectionPool) Add

func (p *ConnectionPool) Add(addr string) error

Add adds a new endpoint with the address into the pool. This function adds the endpoint only after successful connection.

func (*ConnectionPool) Call deprecated

func (p *ConnectionPool) Call(functionName string, args interface{},
	userMode Mode) (*tarantool.Response, error)

Call calls registered Tarantool function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a CallRequest object + Do() instead.

func (*ConnectionPool) Call16 deprecated

func (p *ConnectionPool) Call16(functionName string, args interface{},
	userMode Mode) (*tarantool.Response, error)

Call16 calls registered Tarantool function. It uses request code for Tarantool 1.6, result is an array of arrays. Deprecated since Tarantool 1.7.2.

Deprecated: the method will be removed in the next major version, use a Call16Request object + Do() instead.

func (*ConnectionPool) Call16Async deprecated

func (p *ConnectionPool) Call16Async(functionName string, args interface{},
	userMode Mode) *tarantool.Future

Call16Async sends a call to registered Tarantool function and returns Future. It uses request code for Tarantool 1.6, so future's result is an array of arrays. Deprecated since Tarantool 1.7.2.

Deprecated: the method will be removed in the next major version, use a Call16Request object + Do() instead.

func (*ConnectionPool) Call16Typed deprecated

func (p *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{},
	userMode Mode) error

Call16Typed calls registered function. It uses request code for Tarantool 1.6, result is an array of arrays. Deprecated since Tarantool 1.7.2.

Deprecated: the method will be removed in the next major version, use a Call16Request object + Do() instead.

func (*ConnectionPool) Call17 deprecated

func (p *ConnectionPool) Call17(functionName string, args interface{},
	userMode Mode) (*tarantool.Response, error)

Call17 calls registered Tarantool function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a Call17Request object + Do() instead.

func (*ConnectionPool) Call17Async deprecated

func (p *ConnectionPool) Call17Async(functionName string, args interface{},
	userMode Mode) *tarantool.Future

Call17Async sends a call to registered Tarantool function and returns Future. It uses request code for Tarantool >= 1.7, future's result is an array.

Deprecated: the method will be removed in the next major version, use a Call17Request object + Do() instead.

func (*ConnectionPool) Call17Typed deprecated

func (p *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{},
	userMode Mode) error

Call17Typed calls registered function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a Call17Request object + Do() instead.

func (*ConnectionPool) CallAsync deprecated

func (p *ConnectionPool) CallAsync(functionName string, args interface{},
	userMode Mode) *tarantool.Future

CallAsync sends a call to registered Tarantool function and returns Future. It uses request code for Tarantool >= 1.7, future's result is an array.

Deprecated: the method will be removed in the next major version, use a CallRequest object + Do() instead.

func (*ConnectionPool) CallTyped deprecated

func (p *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{},
	userMode Mode) error

CallTyped calls registered function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a CallRequest object + Do() instead.

func (*ConnectionPool) Close

func (p *ConnectionPool) Close() []error

Close closes connections in the ConnectionPool.

func (*ConnectionPool) CloseGraceful

func (p *ConnectionPool) CloseGraceful() []error

CloseGraceful closes connections in the ConnectionPool gracefully. It waits for all requests to complete.

Example (Force)

ExampleConnectionPool_CloseGraceful_force demonstrates how to force close a connection pool with graceful close in progress after a while.

connPool, err := examplePool(testRoles, connOpts)
if err != nil {
	fmt.Println(err)
	return
}

eval := `local fiber = require('fiber')
	local time = ...
	fiber.sleep(time)
`
req := tarantool.NewEvalRequest(eval).Args([]interface{}{10})
fut := connPool.Do(req, pool.ANY)

done := make(chan struct{})
go func() {
	connPool.CloseGraceful()
	fmt.Println("ConnectionPool.CloseGraceful() done!")
	close(done)
}()

select {
case <-done:
case <-time.After(3 * time.Second):
	fmt.Println("Force ConnectionPool.Close()!")
	connPool.Close()
}
<-done

fmt.Println("Result:")
fmt.Println(fut.Get())
Output:

Force ConnectionPool.Close()!
ConnectionPool.CloseGraceful() done!
Result:
<nil> connection closed by client (0x4001)

func (*ConnectionPool) ConfiguredTimeout

func (p *ConnectionPool) ConfiguredTimeout(mode Mode) (time.Duration, error)

ConfiguredTimeout gets timeout of current connection.

func (*ConnectionPool) ConnectedNow

func (p *ConnectionPool) ConnectedNow(mode Mode) (bool, error)

ConnectedNow gets connected status of pool.

func (*ConnectionPool) Delete deprecated

func (p *ConnectionPool) Delete(space, index interface{}, key interface{},
	userMode ...Mode) (*tarantool.Response, error)

Delete performs deletion of a tuple by key. Result will contain array with deleted tuple.

Deprecated: the method will be removed in the next major version, use a DeleteRequest object + Do() instead.

func (*ConnectionPool) DeleteAsync deprecated

func (p *ConnectionPool) DeleteAsync(space, index interface{}, key interface{},
	userMode ...Mode) *tarantool.Future

DeleteAsync sends deletion action to Tarantool and returns Future. Future's result will contain array with deleted tuple.

Deprecated: the method will be removed in the next major version, use a DeleteRequest object + Do() instead.

func (*ConnectionPool) DeleteTyped deprecated

func (p *ConnectionPool) DeleteTyped(space, index interface{}, key interface{}, result interface{},
	userMode ...Mode) error

DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple.

Deprecated: the method will be removed in the next major version, use a DeleteRequest object + Do() instead.

func (*ConnectionPool) Do

func (p *ConnectionPool) Do(req tarantool.Request, userMode Mode) *tarantool.Future

Do sends the request and returns a future. For requests that belong to the only one connection (e.g. Unprepare or ExecutePrepared) the argument of type Mode is unused.

Example
connPool, err := examplePool(testRoles, connOpts)
if err != nil {
	fmt.Println(err)
}
defer connPool.Close()

modes := []pool.Mode{
	pool.ANY,
	pool.RW,
	pool.RO,
	pool.PreferRW,
	pool.PreferRO,
}
for _, m := range modes {
	// It could be any request object.
	req := tarantool.NewPingRequest()
	_, err := connPool.Do(req, m).Get()
	fmt.Println("Ping Error", err)
}
Output:

Ping Error <nil>
Ping Error <nil>
Ping Error <nil>
Ping Error <nil>
Ping Error <nil>

func (*ConnectionPool) Eval deprecated

func (p *ConnectionPool) Eval(expr string, args interface{},
	userMode Mode) (*tarantool.Response, error)

Eval passes lua expression for evaluation.

Deprecated: the method will be removed in the next major version, use an EvalRequest object + Do() instead.

func (*ConnectionPool) EvalAsync deprecated

func (p *ConnectionPool) EvalAsync(expr string, args interface{},
	userMode Mode) *tarantool.Future

EvalAsync sends a lua expression for evaluation and returns Future.

Deprecated: the method will be removed in the next major version, use an EvalRequest object + Do() instead.

func (*ConnectionPool) EvalTyped deprecated

func (p *ConnectionPool) EvalTyped(expr string, args interface{}, result interface{},
	userMode Mode) error

EvalTyped passes lua expression for evaluation.

Deprecated: the method will be removed in the next major version, use an EvalRequest object + Do() instead.

func (*ConnectionPool) Execute deprecated

func (p *ConnectionPool) Execute(expr string, args interface{},
	userMode Mode) (*tarantool.Response, error)

Execute passes sql expression to Tarantool for execution.

Deprecated: the method will be removed in the next major version, use an ExecuteRequest object + Do() instead.

func (*ConnectionPool) ExecuteAsync deprecated

func (p *ConnectionPool) ExecuteAsync(expr string, args interface{},
	userMode Mode) *tarantool.Future

ExecuteAsync sends sql expression to Tarantool for execution and returns Future.

Deprecated: the method will be removed in the next major version, use an ExecuteRequest object + Do() instead.

func (*ConnectionPool) ExecuteTyped deprecated

func (p *ConnectionPool) ExecuteTyped(expr string, args interface{}, result interface{},
	userMode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)

ExecuteTyped passes sql expression to Tarantool for execution.

Deprecated: the method will be removed in the next major version, use an ExecuteRequest object + Do() instead.

func (*ConnectionPool) GetAddrs

func (p *ConnectionPool) GetAddrs() []string

GetAddrs gets addresses of connections in pool.

func (*ConnectionPool) GetPoolInfo

func (p *ConnectionPool) GetPoolInfo() map[string]*ConnectionInfo

GetPoolInfo gets information of connections (connected status, ro/rw role).

func (*ConnectionPool) GetTyped deprecated

func (p *ConnectionPool) GetTyped(space, index interface{}, key interface{}, result interface{},
	userMode ...Mode) error

GetTyped performs select (with limit = 1 and offset = 0) to box space and fills typed result.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectionPool) Insert deprecated

func (p *ConnectionPool) Insert(space interface{}, tuple interface{},
	userMode ...Mode) (*tarantool.Response, error)

Insert performs insertion to box space. Tarantool will reject Insert when tuple with same primary key exists.

Deprecated: the method will be removed in the next major version, use an InsertRequest object + Do() instead.

func (*ConnectionPool) InsertAsync deprecated

func (p *ConnectionPool) InsertAsync(space interface{}, tuple interface{},
	userMode ...Mode) *tarantool.Future

InsertAsync sends insert action to Tarantool and returns Future. Tarantool will reject Insert when tuple with same primary key exists.

Deprecated: the method will be removed in the next major version, use an InsertRequest object + Do() instead.

func (*ConnectionPool) InsertTyped deprecated

func (p *ConnectionPool) InsertTyped(space interface{}, tuple interface{}, result interface{},
	userMode ...Mode) error

InsertTyped performs insertion to box space. Tarantool will reject Insert when tuple with same primary key exists.

Deprecated: the method will be removed in the next major version, use an InsertRequest object + Do() instead.

func (*ConnectionPool) NewPrepared

func (p *ConnectionPool) NewPrepared(expr string, userMode Mode) (*tarantool.Prepared, error)

NewPrepared passes a sql statement to Tarantool for preparation synchronously.

Example
connPool, err := examplePool(testRoles, connOpts)
if err != nil {
	fmt.Println(err)
}
defer connPool.Close()

stmt, err := connPool.NewPrepared("SELECT 1", pool.ANY)
if err != nil {
	fmt.Println(err)
}

executeReq := tarantool.NewExecutePreparedRequest(stmt)
unprepareReq := tarantool.NewUnprepareRequest(stmt)

_, err = connPool.Do(executeReq, pool.ANY).Get()
if err != nil {
	fmt.Printf("Failed to execute prepared stmt")
}
_, err = connPool.Do(unprepareReq, pool.ANY).Get()
if err != nil {
	fmt.Printf("Failed to prepare")
}
Output:

func (*ConnectionPool) NewStream

func (p *ConnectionPool) NewStream(userMode Mode) (*tarantool.Stream, error)

NewStream creates new Stream object for connection selected by userMode from pool.

Since v. 2.10.0, Tarantool supports streams and interactive transactions over them. To use interactive transactions, memtx_use_mvcc_engine box option should be set to true. Since 1.7.0

func (*ConnectionPool) NewWatcher

func (p *ConnectionPool) NewWatcher(key string,
	callback tarantool.WatchCallback, mode Mode) (tarantool.Watcher, error)

NewWatcher creates a new Watcher object for the connection pool.

You need to require WatchersFeature to use watchers, see examples for the function.

The behavior is same as if Connection.NewWatcher() called for each connection with a suitable role.

Keep in mind that garbage collection of a watcher handle doesn’t lead to the watcher’s destruction. In this case, the watcher remains registered. You need to call Unregister() directly.

Unregister() guarantees that there will be no the watcher's callback calls after it, but Unregister() call from the callback leads to a deadlock.

See: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_events/#box-watchers

Since 1.10.0

Example
const key = "foo"
const value = "bar"

opts := connOpts.Clone()
opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{
	tarantool.WatchersFeature,
}

connPool, err := examplePool(testRoles, connOpts)
if err != nil {
	fmt.Println(err)
}
defer connPool.Close()

callback := func(event tarantool.WatchEvent) {
	fmt.Printf("event connection: %s\n", event.Conn.Addr())
	fmt.Printf("event key: %s\n", event.Key)
	fmt.Printf("event value: %v\n", event.Value)
}
mode := pool.ANY
watcher, err := connPool.NewWatcher(key, callback, mode)
if err != nil {
	fmt.Printf("Unexpected error: %s\n", err)
	return
}
defer watcher.Unregister()

connPool.Do(tarantool.NewBroadcastRequest(key).Value(value), mode).Get()
time.Sleep(time.Second)
Output:

Example (NoWatchersFeature)
const key = "foo"

opts := connOpts.Clone()
opts.RequiredProtocolInfo.Features = []tarantool.ProtocolFeature{}

connPool, err := examplePool(testRoles, connOpts)
if err != nil {
	fmt.Println(err)
}
defer connPool.Close()

callback := func(event tarantool.WatchEvent) {}
watcher, err := connPool.NewWatcher(key, callback, pool.ANY)
fmt.Println(watcher)
fmt.Println(err)
Output:

<nil>
the feature WatchersFeature must be required by connection options to create a watcher

func (*ConnectionPool) Ping deprecated

func (p *ConnectionPool) Ping(userMode Mode) (*tarantool.Response, error)

Ping sends empty request to Tarantool to check connection.

Deprecated: the method will be removed in the next major version, use a PingRequest object + Do() instead.

func (*ConnectionPool) Remove

func (p *ConnectionPool) Remove(addr string) error

Remove removes an endpoint with the address from the pool. The call closes an active connection gracefully.

func (*ConnectionPool) Replace deprecated

func (p *ConnectionPool) Replace(space interface{}, tuple interface{},
	userMode ...Mode) (*tarantool.Response, error)

Replace performs "insert or replace" action to box space. If tuple with same primary key exists, it will be replaced.

Deprecated: the method will be removed in the next major version, use a ReplaceRequest object + Do() instead.

func (*ConnectionPool) ReplaceAsync deprecated

func (p *ConnectionPool) ReplaceAsync(space interface{}, tuple interface{},
	userMode ...Mode) *tarantool.Future

ReplaceAsync sends "insert or replace" action to Tarantool and returns Future. If tuple with same primary key exists, it will be replaced.

Deprecated: the method will be removed in the next major version, use a ReplaceRequest object + Do() instead.

func (*ConnectionPool) ReplaceTyped deprecated

func (p *ConnectionPool) ReplaceTyped(space interface{}, tuple interface{}, result interface{},
	userMode ...Mode) error

ReplaceTyped performs "insert or replace" action to box space. If tuple with same primary key exists, it will be replaced.

Deprecated: the method will be removed in the next major version, use a ReplaceRequest object + Do() instead.

func (*ConnectionPool) Select deprecated

func (p *ConnectionPool) Select(space, index interface{},
	offset, limit uint32,
	iterator tarantool.Iter, key interface{}, userMode ...Mode) (*tarantool.Response, error)

Select performs select to box space.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectionPool) SelectAsync deprecated

func (p *ConnectionPool) SelectAsync(space, index interface{},
	offset, limit uint32,
	iterator tarantool.Iter, key interface{}, userMode ...Mode) *tarantool.Future

SelectAsync sends select request to Tarantool and returns Future.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectionPool) SelectTyped deprecated

func (p *ConnectionPool) SelectTyped(space, index interface{},
	offset, limit uint32,
	iterator tarantool.Iter, key interface{}, result interface{}, userMode ...Mode) error

SelectTyped performs select to box space and fills typed result.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectionPool) Update deprecated

func (p *ConnectionPool) Update(space, index interface{}, key, ops interface{},
	userMode ...Mode) (*tarantool.Response, error)

Update performs update of a tuple by key. Result will contain array with updated tuple.

Deprecated: the method will be removed in the next major version, use a UpdateRequest object + Do() instead.

func (*ConnectionPool) UpdateAsync deprecated

func (p *ConnectionPool) UpdateAsync(space, index interface{}, key, ops interface{},
	userMode ...Mode) *tarantool.Future

UpdateAsync sends deletion of a tuple by key and returns Future. Future's result will contain array with updated tuple.

Deprecated: the method will be removed in the next major version, use a UpdateRequest object + Do() instead.

func (*ConnectionPool) UpdateTyped deprecated

func (p *ConnectionPool) UpdateTyped(space, index interface{}, key, ops interface{},
	result interface{}, userMode ...Mode) error

UpdateTyped performs update of a tuple by key and fills result with updated tuple.

Deprecated: the method will be removed in the next major version, use a UpdateRequest object + Do() instead.

func (*ConnectionPool) Upsert deprecated

func (p *ConnectionPool) Upsert(space interface{}, tuple, ops interface{},
	userMode ...Mode) (*tarantool.Response, error)

Upsert performs "update or insert" action of a tuple by key. Result will not contain any tuple.

Deprecated: the method will be removed in the next major version, use a UpsertRequest object + Do() instead.

func (*ConnectionPool) UpsertAsync deprecated

func (p *ConnectionPool) UpsertAsync(space interface{}, tuple interface{}, ops interface{},
	userMode ...Mode) *tarantool.Future

UpsertAsync sends "update or insert" action to Tarantool and returns Future. Future's sesult will not contain any tuple.

Deprecated: the method will be removed in the next major version, use a UpsertRequest object + Do() instead.

type ConnectorAdapter

type ConnectorAdapter struct {
	// contains filtered or unexported fields
}

ConnectorAdapter allows to use Pooler as Connector.

Example
connPool, err := examplePool(testRoles, connOpts)
if err != nil {
	fmt.Println(err)
}
defer connPool.Close()

adapter := pool.NewConnectorAdapter(connPool, pool.RW)
var connector tarantool.Connector = adapter

// Ping an RW instance to check connection.
resp, err := connector.Do(tarantool.NewPingRequest()).Get()
fmt.Println("Ping Code", resp.Code)
fmt.Println("Ping Data", resp.Data)
fmt.Println("Ping Error", err)
Output:

Ping Code 0
Ping Data []
Ping Error <nil>

func NewConnectorAdapter

func NewConnectorAdapter(pool Pooler, mode Mode) *ConnectorAdapter

NewConnectorAdapter creates a new ConnectorAdapter object for a pool and with a mode. All requests to the pool will be executed in the specified mode.

func (*ConnectorAdapter) Call deprecated

func (c *ConnectorAdapter) Call(functionName string,
	args interface{}) (*tarantool.Response, error)

Call calls registered Tarantool function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a CallRequest object + Do() instead.

func (*ConnectorAdapter) Call16 deprecated

func (c *ConnectorAdapter) Call16(functionName string,
	args interface{}) (*tarantool.Response, error)

Call16 calls registered Tarantool function. It uses request code for Tarantool 1.6, result is an array of arrays. Deprecated since Tarantool 1.7.2.

Deprecated: the method will be removed in the next major version, use a Call16Request object + Do() instead.

func (*ConnectorAdapter) Call16Async deprecated

func (c *ConnectorAdapter) Call16Async(functionName string,
	args interface{}) *tarantool.Future

Call16Async sends a call to registered Tarantool function and returns Future. It uses request code for Tarantool 1.6, so future's result is an array of arrays. Deprecated since Tarantool 1.7.2.

Deprecated: the method will be removed in the next major version, use a Call16Request object + Do() instead.

func (*ConnectorAdapter) Call16Typed deprecated

func (c *ConnectorAdapter) Call16Typed(functionName string,
	args interface{}, result interface{}) error

Call16Typed calls registered function. It uses request code for Tarantool 1.6, result is an array of arrays. Deprecated since Tarantool 1.7.2.

Deprecated: the method will be removed in the next major version, use a Call16Request object + Do() instead.

func (*ConnectorAdapter) Call17 deprecated

func (c *ConnectorAdapter) Call17(functionName string,
	args interface{}) (*tarantool.Response, error)

Call17 calls registered Tarantool function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a Call17Request object + Do() instead.

func (*ConnectorAdapter) Call17Async deprecated

func (c *ConnectorAdapter) Call17Async(functionName string,
	args interface{}) *tarantool.Future

Call17Async sends a call to registered Tarantool function and returns Future. It uses request code for Tarantool >= 1.7, future's result is an array.

Deprecated: the method will be removed in the next major version, use a Call17Request object + Do() instead.

func (*ConnectorAdapter) Call17Typed deprecated

func (c *ConnectorAdapter) Call17Typed(functionName string,
	args interface{}, result interface{}) error

Call17Typed calls registered function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a Call17Request object + Do() instead.

func (*ConnectorAdapter) CallAsync deprecated

func (c *ConnectorAdapter) CallAsync(functionName string,
	args interface{}) *tarantool.Future

CallAsync sends a call to registered Tarantool function and returns Future. It uses request code for Tarantool >= 1.7, future's result is an array.

Deprecated: the method will be removed in the next major version, use a CallRequest object + Do() instead.

func (*ConnectorAdapter) CallTyped deprecated

func (c *ConnectorAdapter) CallTyped(functionName string,
	args interface{}, result interface{}) error

CallTyped calls registered function. It uses request code for Tarantool >= 1.7, result is an array.

Deprecated: the method will be removed in the next major version, use a CallRequest object + Do() instead.

func (*ConnectorAdapter) Close

func (c *ConnectorAdapter) Close() error

ClosedNow reports if the connector is closed by user or all connections in the specified mode closed.

func (*ConnectorAdapter) ConfiguredTimeout

func (c *ConnectorAdapter) ConfiguredTimeout() time.Duration

ConfiguredTimeout returns a timeout from connections config.

func (*ConnectorAdapter) ConnectedNow

func (c *ConnectorAdapter) ConnectedNow() bool

ConnectedNow reports if connections is established at the moment.

func (*ConnectorAdapter) Delete deprecated

func (c *ConnectorAdapter) Delete(space, index interface{},
	key interface{}) (*tarantool.Response, error)

Delete performs deletion of a tuple by key.

Deprecated: the method will be removed in the next major version, use a DeleteRequest object + Do() instead.

func (*ConnectorAdapter) DeleteAsync deprecated

func (c *ConnectorAdapter) DeleteAsync(space, index interface{},
	key interface{}) *tarantool.Future

DeleteAsync sends deletion action to Tarantool and returns Future.

Deprecated: the method will be removed in the next major version, use a DeleteRequest object + Do() instead.

func (*ConnectorAdapter) DeleteTyped deprecated

func (c *ConnectorAdapter) DeleteTyped(space, index interface{},
	key interface{}, result interface{}) error

DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple.

Deprecated: the method will be removed in the next major version, use a DeleteRequest object + Do() instead.

func (*ConnectorAdapter) Do

func (c *ConnectorAdapter) Do(req tarantool.Request) *tarantool.Future

Do performs a request asynchronously on the connection.

func (*ConnectorAdapter) Eval deprecated

func (c *ConnectorAdapter) Eval(expr string,
	args interface{}) (*tarantool.Response, error)

Eval passes Lua expression for evaluation.

Deprecated: the method will be removed in the next major version, use an EvalRequest object + Do() instead.

func (*ConnectorAdapter) EvalAsync deprecated

func (c *ConnectorAdapter) EvalAsync(expr string,
	args interface{}) *tarantool.Future

EvalAsync sends a Lua expression for evaluation and returns Future.

Deprecated: the method will be removed in the next major version, use an EvalRequest object + Do() instead.

func (*ConnectorAdapter) EvalTyped deprecated

func (c *ConnectorAdapter) EvalTyped(expr string, args interface{},
	result interface{}) error

EvalTyped passes Lua expression for evaluation.

Deprecated: the method will be removed in the next major version, use an EvalRequest object + Do() instead.

func (*ConnectorAdapter) Execute deprecated

func (c *ConnectorAdapter) Execute(expr string,
	args interface{}) (*tarantool.Response, error)

Execute passes sql expression to Tarantool for execution.

Deprecated: the method will be removed in the next major version, use an ExecuteRequest object + Do() instead.

func (*ConnectorAdapter) ExecuteAsync deprecated

func (c *ConnectorAdapter) ExecuteAsync(expr string,
	args interface{}) *tarantool.Future

ExecuteAsync sends a sql expression for execution and returns Future.

Deprecated: the method will be removed in the next major version, use an EvalRequest object + Do() instead.

func (*ConnectorAdapter) ExecuteTyped deprecated

func (c *ConnectorAdapter) ExecuteTyped(expr string, args interface{},
	result interface{}) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)

ExecuteTyped passes sql expression to Tarantool for execution.

Deprecated: the method will be removed in the next major version, use an ExecuteRequest object + Do() instead.

func (*ConnectorAdapter) GetTyped deprecated

func (c *ConnectorAdapter) GetTyped(space, index interface{},
	key interface{}, result interface{}) error

GetTyped performs select (with limit = 1 and offset = 0) to box space and fills typed result.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectorAdapter) Insert deprecated

func (c *ConnectorAdapter) Insert(space interface{},
	tuple interface{}) (*tarantool.Response, error)

Insert performs insertion to box space.

Deprecated: the method will be removed in the next major version, use an InsertRequest object + Do() instead.

func (*ConnectorAdapter) InsertAsync deprecated

func (c *ConnectorAdapter) InsertAsync(space interface{},
	tuple interface{}) *tarantool.Future

InsertAsync sends insert action to Tarantool and returns Future.

Deprecated: the method will be removed in the next major version, use an InsertRequest object + Do() instead.

func (*ConnectorAdapter) InsertTyped deprecated

func (c *ConnectorAdapter) InsertTyped(space interface{},
	tuple interface{}, result interface{}) error

InsertTyped performs insertion to box space.

Deprecated: the method will be removed in the next major version, use an InsertRequest object + Do() instead.

func (*ConnectorAdapter) NewPrepared

func (c *ConnectorAdapter) NewPrepared(expr string) (*tarantool.Prepared, error)

NewPrepared passes a sql statement to Tarantool for preparation synchronously.

func (*ConnectorAdapter) NewStream

func (c *ConnectorAdapter) NewStream() (*tarantool.Stream, error)

NewStream creates new Stream object for connection.

Since v. 2.10.0, Tarantool supports streams and interactive transactions over them. To use interactive transactions, memtx_use_mvcc_engine box option should be set to true. Since 1.7.0

func (*ConnectorAdapter) NewWatcher

func (c *ConnectorAdapter) NewWatcher(key string,
	callback tarantool.WatchCallback) (tarantool.Watcher, error)

NewWatcher creates new Watcher object for the pool

Since 1.10.0

func (*ConnectorAdapter) Ping deprecated

func (c *ConnectorAdapter) Ping() (*tarantool.Response, error)

Ping sends empty request to Tarantool to check connection.

Deprecated: the method will be removed in the next major version, use a PingRequest object + Do() instead.

func (*ConnectorAdapter) Replace deprecated

func (c *ConnectorAdapter) Replace(space interface{},
	tuple interface{}) (*tarantool.Response, error)

Replace performs "insert or replace" action to box space.

Deprecated: the method will be removed in the next major version, use a ReplaceRequest object + Do() instead.

func (*ConnectorAdapter) ReplaceAsync deprecated

func (c *ConnectorAdapter) ReplaceAsync(space interface{},
	tuple interface{}) *tarantool.Future

ReplaceAsync sends "insert or replace" action to Tarantool and returns Future.

Deprecated: the method will be removed in the next major version, use a ReplaceRequest object + Do() instead.

func (*ConnectorAdapter) ReplaceTyped deprecated

func (c *ConnectorAdapter) ReplaceTyped(space interface{},
	tuple interface{}, result interface{}) error

ReplaceTyped performs "insert or replace" action to box space.

Deprecated: the method will be removed in the next major version, use a ReplaceRequest object + Do() instead.

func (*ConnectorAdapter) Select deprecated

func (c *ConnectorAdapter) Select(space, index interface{},
	offset, limit uint32, iterator tarantool.Iter,
	key interface{}) (*tarantool.Response, error)

Select performs select to box space.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectorAdapter) SelectAsync deprecated

func (c *ConnectorAdapter) SelectAsync(space, index interface{},
	offset, limit uint32, iterator tarantool.Iter, key interface{}) *tarantool.Future

SelectAsync sends select request to Tarantool and returns Future.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectorAdapter) SelectTyped deprecated

func (c *ConnectorAdapter) SelectTyped(space, index interface{},
	offset, limit uint32, iterator tarantool.Iter,
	key interface{}, result interface{}) error

SelectTyped performs select to box space and fills typed result.

Deprecated: the method will be removed in the next major version, use a SelectRequest object + Do() instead.

func (*ConnectorAdapter) Update deprecated

func (c *ConnectorAdapter) Update(space, index interface{},
	key, ops interface{}) (*tarantool.Response, error)

Update performs update of a tuple by key.

Deprecated: the method will be removed in the next major version, use a UpdateRequest object + Do() instead.

func (*ConnectorAdapter) UpdateAsync deprecated

func (c *ConnectorAdapter) UpdateAsync(space, index interface{},
	key, ops interface{}) *tarantool.Future

Update sends deletion of a tuple by key and returns Future.

Deprecated: the method will be removed in the next major version, use a UpdateRequest object + Do() instead.

func (*ConnectorAdapter) UpdateTyped deprecated

func (c *ConnectorAdapter) UpdateTyped(space, index interface{},
	key, ops interface{}, result interface{}) error

UpdateTyped performs update of a tuple by key and fills result with updated tuple.

Deprecated: the method will be removed in the next major version, use a UpdateRequest object + Do() instead.

func (*ConnectorAdapter) Upsert deprecated

func (c *ConnectorAdapter) Upsert(space interface{},
	tuple, ops interface{}) (*tarantool.Response, error)

Upsert performs "update or insert" action of a tuple by key.

Deprecated: the method will be removed in the next major version, use a UpsertRequest object + Do() instead.

func (*ConnectorAdapter) UpsertAsync deprecated

func (c *ConnectorAdapter) UpsertAsync(space interface{}, tuple interface{},
	ops interface{}) *tarantool.Future

UpsertAsync sends "update or insert" action to Tarantool and returns Future.

Deprecated: the method will be removed in the next major version, use a UpsertRequest object + Do() instead.

type Mode

type Mode uint32

Default mode for each request table:

  Request   Default mode
---------- --------------
| call    | no default  |
| eval    | no default  |
| execute | no default  |
| ping    | no default  |
| insert  | RW          |
| delete  | RW          |
| replace | RW          |
| update  | RW          |
| upsert  | RW          |
| select  | ANY         |
| get     | ANY         |
const (
	ANY      Mode = iota // The request can be executed on any instance (master or replica).
	RW                   // The request can only be executed on master.
	RO                   // The request can only be executed on replica.
	PreferRW             // If there is one, otherwise fallback to a writeable one (master).
	PreferRO             // If there is one, otherwise fallback to a read only one (replica).
)

type Opts

type Opts struct {
	// Timeout for timer to reopen connections that have been closed by some
	// events and to relocate connection between subpools if ro/rw role has
	// been updated.
	CheckTimeout time.Duration
	// ConnectionHandler provides an ability to handle connection updates.
	ConnectionHandler ConnectionHandler
}

Opts provides additional options (configurable via ConnectWithOpts).

type Pooler

type Pooler interface {
	ConnectedNow(mode Mode) (bool, error)
	Close() []error
	ConfiguredTimeout(mode Mode) (time.Duration, error)
	NewPrepared(expr string, mode Mode) (*tarantool.Prepared, error)
	NewStream(mode Mode) (*tarantool.Stream, error)
	NewWatcher(key string, callback tarantool.WatchCallback,
		mode Mode) (tarantool.Watcher, error)
	Do(req tarantool.Request, mode Mode) (fut *tarantool.Future)

	// Deprecated: the method will be removed in the next major version,
	// use a PingRequest object + Do() instead.
	Ping(mode Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a SelectRequest object + Do() instead.
	Select(space, index interface{}, offset, limit uint32, iterator tarantool.Iter,
		key interface{}, mode ...Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use an InsertRequest object + Do() instead.
	Insert(space interface{}, tuple interface{},
		mode ...Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a ReplaceRequest object + Do() instead.
	Replace(space interface{}, tuple interface{},
		mode ...Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a DeleteRequest object + Do() instead.
	Delete(space, index interface{}, key interface{},
		mode ...Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a UpdateRequest object + Do() instead.
	Update(space, index interface{}, key, ops interface{},
		mode ...Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a UpsertRequest object + Do() instead.
	Upsert(space interface{}, tuple, ops interface{},
		mode ...Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a CallRequest object + Do() instead.
	Call(functionName string, args interface{},
		mode Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a Call16Request object + Do() instead.
	Call16(functionName string, args interface{},
		mode Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use a Call17Request object + Do() instead.
	Call17(functionName string, args interface{},
		mode Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use an EvalRequest object + Do() instead.
	Eval(expr string, args interface{},
		mode Mode) (*tarantool.Response, error)
	// Deprecated: the method will be removed in the next major version,
	// use an ExecuteRequest object + Do() instead.
	Execute(expr string, args interface{},
		mode Mode) (*tarantool.Response, error)

	// Deprecated: the method will be removed in the next major version,
	// use a SelectRequest object + Do() instead.
	GetTyped(space, index interface{}, key interface{}, result interface{},
		mode ...Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use a SelectRequest object + Do() instead.
	SelectTyped(space, index interface{}, offset, limit uint32, iterator tarantool.Iter,
		key interface{}, result interface{}, mode ...Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use an InsertRequest object + Do() instead.
	InsertTyped(space interface{}, tuple interface{}, result interface{},
		mode ...Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use a ReplaceRequest object + Do() instead.
	ReplaceTyped(space interface{}, tuple interface{}, result interface{},
		mode ...Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use a DeleteRequest object + Do() instead.
	DeleteTyped(space, index interface{}, key interface{}, result interface{},
		mode ...Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use a UpdateRequest object + Do() instead.
	UpdateTyped(space, index interface{}, key, ops interface{},
		result interface{}, mode ...Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use a CallRequest object + Do() instead.
	CallTyped(functionName string, args interface{}, result interface{},
		mode Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use a Call16Request object + Do() instead.
	Call16Typed(functionName string, args interface{}, result interface{},
		mode Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use a Call17Request object + Do() instead.
	Call17Typed(functionName string, args interface{}, result interface{},
		mode Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use an EvalRequest object + Do() instead.
	EvalTyped(expr string, args interface{}, result interface{},
		mode Mode) error
	// Deprecated: the method will be removed in the next major version,
	// use an ExecuteRequest object + Do() instead.
	ExecuteTyped(expr string, args interface{}, result interface{},
		mode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)

	// Deprecated: the method will be removed in the next major version,
	// use a SelectRequest object + Do() instead.
	SelectAsync(space, index interface{}, offset, limit uint32, iterator tarantool.Iter,
		key interface{}, mode ...Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use an InsertRequest object + Do() instead.
	InsertAsync(space interface{}, tuple interface{},
		mode ...Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use a ReplaceRequest object + Do() instead.
	ReplaceAsync(space interface{}, tuple interface{},
		mode ...Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use a DeleteRequest object + Do() instead.
	DeleteAsync(space, index interface{}, key interface{},
		mode ...Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use a UpdateRequest object + Do() instead.
	UpdateAsync(space, index interface{}, key, ops interface{},
		mode ...Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use a UpsertRequest object + Do() instead.
	UpsertAsync(space interface{}, tuple interface{}, ops interface{},
		mode ...Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use a CallRequest object + Do() instead.
	CallAsync(functionName string, args interface{},
		mode Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use a Call16Request object + Do() instead.
	Call16Async(functionName string, args interface{},
		mode Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use a Call17Request object + Do() instead.
	Call17Async(functionName string, args interface{},
		mode Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use an EvalRequest object + Do() instead.
	EvalAsync(expr string, args interface{},
		mode Mode) *tarantool.Future
	// Deprecated: the method will be removed in the next major version,
	// use an ExecuteRequest object + Do() instead.
	ExecuteAsync(expr string, args interface{},
		mode Mode) *tarantool.Future
}

Pooler is the interface that must be implemented by a connection pool.

type Role

type Role uint32

Role describes a role of an instance by its mode.

const (
	UnknownRole Role = iota // A connection pool failed to discover mode of the instance.
	MasterRole              // The instance is read-write mode.
	ReplicaRole             // The instance is in read-only mode.
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL