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 ¶
- Variables
- type ConnectionHandler
- type ConnectionInfo
- type ConnectionPool
- func (pool *ConnectionPool) Add(addr string) error
- func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) Call16(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) Call16Async(functionName string, args interface{}, userMode Mode) *tarantool.Future
- func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error)
- func (connPool *ConnectionPool) Call17(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) Call17Async(functionName string, args interface{}, userMode Mode) *tarantool.Future
- func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error)
- func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, userMode Mode) *tarantool.Future
- func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error)
- func (pool *ConnectionPool) Close() []error
- func (pool *ConnectionPool) CloseGraceful() []error
- func (connPool *ConnectionPool) ConfiguredTimeout(mode Mode) (time.Duration, error)
- func (connPool *ConnectionPool) ConnectedNow(mode Mode) (bool, error)
- func (connPool *ConnectionPool) Delete(space, index interface{}, key interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) DeleteAsync(space, index interface{}, key interface{}, userMode ...Mode) *tarantool.Future
- func (connPool *ConnectionPool) DeleteTyped(space, index interface{}, key interface{}, result interface{}, ...) (err error)
- func (connPool *ConnectionPool) Do(req tarantool.Request, userMode Mode) *tarantool.Future
- func (connPool *ConnectionPool) Eval(expr string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) EvalAsync(expr string, args interface{}, userMode Mode) *tarantool.Future
- func (connPool *ConnectionPool) EvalTyped(expr string, args interface{}, result interface{}, userMode Mode) (err error)
- func (connPool *ConnectionPool) Execute(expr string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) ExecuteAsync(expr string, args interface{}, userMode Mode) *tarantool.Future
- func (connPool *ConnectionPool) ExecuteTyped(expr string, args interface{}, result interface{}, userMode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)
- func (pool *ConnectionPool) GetAddrs() []string
- func (pool *ConnectionPool) GetPoolInfo() map[string]*ConnectionInfo
- func (connPool *ConnectionPool) GetTyped(space, index interface{}, key interface{}, result interface{}, ...) (err error)
- func (connPool *ConnectionPool) Insert(space interface{}, tuple interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) InsertAsync(space interface{}, tuple interface{}, userMode ...Mode) *tarantool.Future
- func (connPool *ConnectionPool) InsertTyped(space interface{}, tuple interface{}, result interface{}, userMode ...Mode) (err error)
- func (connPool *ConnectionPool) NewPrepared(expr string, userMode Mode) (*tarantool.Prepared, error)
- func (connPool *ConnectionPool) NewStream(userMode Mode) (*tarantool.Stream, error)
- func (pool *ConnectionPool) NewWatcher(key string, callback tarantool.WatchCallback, mode Mode) (tarantool.Watcher, error)
- func (connPool *ConnectionPool) Ping(userMode Mode) (*tarantool.Response, error)
- func (pool *ConnectionPool) Remove(addr string) error
- func (connPool *ConnectionPool) Replace(space interface{}, tuple interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) ReplaceAsync(space interface{}, tuple interface{}, userMode ...Mode) *tarantool.Future
- func (connPool *ConnectionPool) ReplaceTyped(space interface{}, tuple interface{}, result interface{}, userMode ...Mode) (err error)
- func (connPool *ConnectionPool) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}, ...) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}, ...) *tarantool.Future
- func (connPool *ConnectionPool) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, ...) (err error)
- func (connPool *ConnectionPool) Update(space, index interface{}, key, ops interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) UpdateAsync(space, index interface{}, key, ops interface{}, userMode ...Mode) *tarantool.Future
- func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}, ...) (err error)
- func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
- func (connPool *ConnectionPool) UpsertAsync(space interface{}, tuple interface{}, ops interface{}, userMode ...Mode) *tarantool.Future
- type ConnectorAdapter
- func (c *ConnectorAdapter) Call(functionName string, args interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) Call16(functionName string, args interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) Call16Async(functionName string, args interface{}) *tarantool.Future
- func (c *ConnectorAdapter) Call16Typed(functionName string, args interface{}, result interface{}) error
- func (c *ConnectorAdapter) Call17(functionName string, args interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) Call17Async(functionName string, args interface{}) *tarantool.Future
- func (c *ConnectorAdapter) Call17Typed(functionName string, args interface{}, result interface{}) error
- func (c *ConnectorAdapter) CallAsync(functionName string, args interface{}) *tarantool.Future
- func (c *ConnectorAdapter) CallTyped(functionName string, args interface{}, result interface{}) error
- func (c *ConnectorAdapter) Close() error
- func (c *ConnectorAdapter) ConfiguredTimeout() time.Duration
- func (c *ConnectorAdapter) ConnectedNow() bool
- func (c *ConnectorAdapter) Delete(space, index interface{}, key interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) DeleteAsync(space, index interface{}, key interface{}) *tarantool.Future
- func (c *ConnectorAdapter) DeleteTyped(space, index interface{}, key interface{}, result interface{}) error
- func (c *ConnectorAdapter) Do(req tarantool.Request) *tarantool.Future
- func (c *ConnectorAdapter) Eval(expr string, args interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) EvalAsync(expr string, args interface{}) *tarantool.Future
- func (c *ConnectorAdapter) EvalTyped(expr string, args interface{}, result interface{}) error
- func (c *ConnectorAdapter) Execute(expr string, args interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) ExecuteAsync(expr string, args interface{}) *tarantool.Future
- func (c *ConnectorAdapter) ExecuteTyped(expr string, args interface{}, result interface{}) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)
- func (c *ConnectorAdapter) GetTyped(space, index interface{}, key interface{}, result interface{}) error
- func (c *ConnectorAdapter) Insert(space interface{}, tuple interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) InsertAsync(space interface{}, tuple interface{}) *tarantool.Future
- func (c *ConnectorAdapter) InsertTyped(space interface{}, tuple interface{}, result interface{}) error
- func (c *ConnectorAdapter) NewPrepared(expr string) (*tarantool.Prepared, error)
- func (c *ConnectorAdapter) NewStream() (*tarantool.Stream, error)
- func (c *ConnectorAdapter) NewWatcher(key string, callback tarantool.WatchCallback) (tarantool.Watcher, error)
- func (c *ConnectorAdapter) Ping() (*tarantool.Response, error)
- func (c *ConnectorAdapter) Replace(space interface{}, tuple interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) ReplaceAsync(space interface{}, tuple interface{}) *tarantool.Future
- func (c *ConnectorAdapter) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) error
- func (c *ConnectorAdapter) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *tarantool.Future
- func (c *ConnectorAdapter) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, ...) error
- func (c *ConnectorAdapter) Update(space, index interface{}, key, ops interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) UpdateAsync(space, index interface{}, key, ops interface{}) *tarantool.Future
- func (c *ConnectorAdapter) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) error
- func (c *ConnectorAdapter) Upsert(space interface{}, tuple, ops interface{}) (*tarantool.Response, error)
- func (c *ConnectorAdapter) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *tarantool.Future
- type Mode
- type OptsPool
- type Pooler
- type Role
- type RoundRobinStrategy
- func (r *RoundRobinStrategy) AddConn(addr string, conn *tarantool.Connection)
- func (r *RoundRobinStrategy) DeleteConnByAddr(addr string) *tarantool.Connection
- func (r *RoundRobinStrategy) GetConnByAddr(addr string) *tarantool.Connection
- func (r *RoundRobinStrategy) GetConnections() []*tarantool.Connection
- func (r *RoundRobinStrategy) GetNextConnection() *tarantool.Connection
- func (r *RoundRobinStrategy) IsEmpty() bool
Examples ¶
- ConnectionPool.Call
- ConnectionPool.CloseGraceful (Force)
- ConnectionPool.Delete
- ConnectionPool.Do
- ConnectionPool.Eval
- ConnectionPool.Insert
- ConnectionPool.NewPrepared
- ConnectionPool.NewWatcher
- ConnectionPool.NewWatcher (NoWatchersFeature)
- ConnectionPool.Ping
- ConnectionPool.Replace
- ConnectionPool.Select
- ConnectionPool.SelectAsync
- ConnectionPool.SelectAsync (Err)
- ConnectionPool.SelectTyped
- ConnectionPool.Update
- ConnectorAdapter
Constants ¶
This section is empty.
Variables ¶
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") )
Functions ¶
This section is empty.
Types ¶
type ConnectionHandler ¶ added in v1.9.0
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 ¶
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) (connPool *ConnectionPool, err 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 OptsPool.CheckTimeout description.
func ConnectWithOpts ¶
func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsPool) (connPool *ConnectionPool, err error)
ConnectWithOpts creates pool for instances with addresses addrs with options opts.
func (*ConnectionPool) Add ¶ added in v1.12.0
func (pool *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 ¶
func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
Call16 calls registered Tarantool function. It uses request code for Tarantool >= 1.7 if go-tarantool was build with go_tarantool_call_17 tag. Otherwise, uses request code for Tarantool 1.6.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Call a function 'simple_incr' with arguments. resp, err := pool.Call17("simple_incr", []interface{}{1}, connection_pool.PreferRW) fmt.Println("Call simple_incr()") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data)
Output: Call simple_incr() Error <nil> Code 0 Data [2]
func (*ConnectionPool) Call16 ¶ added in v1.7.0
func (connPool *ConnectionPool) Call16(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
Call16 calls registered Tarantool function. It uses request code for Tarantool 1.6, so result is converted to array of arrays. Deprecated since Tarantool 1.7.2.
func (*ConnectionPool) Call16Async ¶ added in v1.7.0
func (connPool *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 always array of arrays. Deprecated since Tarantool 1.7.2.
func (*ConnectionPool) Call16Typed ¶ added in v1.7.0
func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error)
Call16Typed calls registered function. It uses request code for Tarantool 1.6, so result is converted to array of arrays. Deprecated since Tarantool 1.7.2.
func (*ConnectionPool) Call17 ¶
func (connPool *ConnectionPool) Call17(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
Call17 calls registered Tarantool function. It uses request code for Tarantool >= 1.7, so result is not converted (though, keep in mind, result is always array).
func (*ConnectionPool) Call17Async ¶
func (connPool *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, so future's result will not be converted (though, keep in mind, result is always array).
func (*ConnectionPool) Call17Typed ¶
func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error)
Call17Typed calls registered function. It uses request code for Tarantool >= 1.7, so result is not converted (though, keep in mind, result is always array).
func (*ConnectionPool) CallAsync ¶
func (connPool *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 if go-tarantool was build with go_tarantool_call_17 tag. Otherwise, uses request code for Tarantool 1.6.
func (*ConnectionPool) CallTyped ¶
func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error)
CallTyped calls registered function. It uses request code for Tarantool >= 1.7 if go-tarantool was build with go_tarantool_call_17 tag. Otherwise, uses request code for Tarantool 1.6.
func (*ConnectionPool) Close ¶
func (pool *ConnectionPool) Close() []error
Close closes connections in the ConnectionPool.
func (*ConnectionPool) CloseGraceful ¶ added in v1.12.0
func (pool *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.
pool, 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 := pool.Do(req, connection_pool.ANY) done := make(chan struct{}) go func() { pool.CloseGraceful() fmt.Println("ConnectionPool.CloseGraceful() done!") close(done) }() select { case <-done: case <-time.After(3 * time.Second): fmt.Println("Force ConnectionPool.Close()!") pool.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 (connPool *ConnectionPool) ConfiguredTimeout(mode Mode) (time.Duration, error)
ConfiguredTimeout gets timeout of current connection.
func (*ConnectionPool) ConnectedNow ¶
func (connPool *ConnectionPool) ConnectedNow(mode Mode) (bool, error)
ConnectedNow gets connected status of pool.
func (*ConnectionPool) Delete ¶
func (connPool *ConnectionPool) Delete(space, index interface{}, key interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
Delete performs deletion of a tuple by key. Result will contain array with deleted tuple.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance conn, err := tarantool.Connect(servers[2], connOpts) if err != nil || conn == nil { fmt.Printf("failed to connect to %s", servers[2]) return } // Insert a new tuple {"key1", "value1"}. _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Insert a new tuple {"key2", "value2"}. _, err = conn.Insert(spaceNo, []interface{}{"key2", "value2"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Delete tuple with primary key {"key1"}. resp, err := pool.Delete(spaceNo, indexNo, []interface{}{"key1"}) fmt.Println("Delete key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) // Delete tuple with primary key { "key2" }. resp, err = pool.Delete(spaceName, indexName, []interface{}{"key2"}, connection_pool.PreferRW) fmt.Println("Delete key2") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data)
Output: Delete key1 Error <nil> Code 0 Data [[key1 value1]] Delete key2 Error <nil> Code 0 Data [[key2 value2]]
func (*ConnectionPool) DeleteAsync ¶
func (connPool *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.
func (*ConnectionPool) DeleteTyped ¶
func (connPool *ConnectionPool) DeleteTyped(space, index interface{}, key interface{}, result interface{}, userMode ...Mode) (err error)
DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple.
func (*ConnectionPool) Do ¶ added in v1.7.0
func (connPool *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 ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Ping a Tarantool instance to check connection. req := tarantool.NewPingRequest() resp, err := pool.Do(req, connection_pool.ANY).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 (*ConnectionPool) Eval ¶
func (connPool *ConnectionPool) Eval(expr string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
Eval passes lua expression for evaluation.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Run raw Lua code. resp, err := pool.Eval("return 1 + 2", []interface{}{}, connection_pool.PreferRW) fmt.Println("Eval 'return 1 + 2'") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data)
Output: Eval 'return 1 + 2' Error <nil> Code 0 Data [3]
func (*ConnectionPool) EvalAsync ¶
func (connPool *ConnectionPool) EvalAsync(expr string, args interface{}, userMode Mode) *tarantool.Future
EvalAsync sends a lua expression for evaluation and returns Future.
func (*ConnectionPool) EvalTyped ¶
func (connPool *ConnectionPool) EvalTyped(expr string, args interface{}, result interface{}, userMode Mode) (err error)
EvalTyped passes lua expression for evaluation.
func (*ConnectionPool) Execute ¶ added in v1.9.0
func (connPool *ConnectionPool) Execute(expr string, args interface{}, userMode Mode) (resp *tarantool.Response, err error)
Execute passes sql expression to Tarantool for execution.
func (*ConnectionPool) ExecuteAsync ¶ added in v1.9.0
func (connPool *ConnectionPool) ExecuteAsync(expr string, args interface{}, userMode Mode) *tarantool.Future
ExecuteAsync sends sql expression to Tarantool for execution and returns Future.
func (*ConnectionPool) ExecuteTyped ¶ added in v1.9.0
func (connPool *ConnectionPool) ExecuteTyped(expr string, args interface{}, result interface{}, userMode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)
ExecuteTyped passes sql expression to Tarantool for execution.
func (*ConnectionPool) GetAddrs ¶
func (pool *ConnectionPool) GetAddrs() []string
GetAddrs gets addresses of connections in pool.
func (*ConnectionPool) GetPoolInfo ¶
func (pool *ConnectionPool) GetPoolInfo() map[string]*ConnectionInfo
GetPoolInfo gets information of connections (connected status, ro/rw role).
func (*ConnectionPool) GetTyped ¶
func (connPool *ConnectionPool) GetTyped(space, index interface{}, key interface{}, result interface{}, userMode ...Mode) (err error)
GetTyped performs select (with limit = 1 and offset = 0) to box space and fills typed result.
func (*ConnectionPool) Insert ¶
func (connPool *ConnectionPool) Insert(space interface{}, tuple interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
Insert performs insertion to box space. Tarantool will reject Insert when tuple with same primary key exists.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Insert a new tuple {"key1", "value1"}. resp, err := pool.Insert(spaceNo, []interface{}{"key1", "value1"}) fmt.Println("Insert key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) // Insert a new tuple {"key2", "value2"}. resp, err = pool.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}, connection_pool.PreferRW) fmt.Println("Insert key2") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) // Connect to servers[2] to check if tuple // was inserted on RW instance conn, err := tarantool.Connect(servers[2], connOpts) if err != nil || conn == nil { fmt.Printf("failed to connect to %s", servers[2]) return } // Delete tuple with primary key "key1". _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) } // Delete tuple with primary key "key2". _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) }
Output: Insert key1 Error <nil> Code 0 Data [[key1 value1]] Insert key2 Error <nil> Code 0 Data [[key2 value2]]
func (*ConnectionPool) InsertAsync ¶
func (connPool *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.
func (*ConnectionPool) InsertTyped ¶
func (connPool *ConnectionPool) InsertTyped(space interface{}, tuple interface{}, result interface{}, userMode ...Mode) (err error)
InsertTyped performs insertion to box space. Tarantool will reject Insert when tuple with same primary key exists.
func (*ConnectionPool) NewPrepared ¶ added in v1.7.0
func (connPool *ConnectionPool) NewPrepared(expr string, userMode Mode) (*tarantool.Prepared, error)
NewPrepared passes a sql statement to Tarantool for preparation synchronously.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() stmt, err := pool.NewPrepared("SELECT 1", connection_pool.ANY) if err != nil { fmt.Println(err) } executeReq := tarantool.NewExecutePreparedRequest(stmt) unprepareReq := tarantool.NewUnprepareRequest(stmt) _, err = pool.Do(executeReq, connection_pool.ANY).Get() if err != nil { fmt.Printf("Failed to execute prepared stmt") } _, err = pool.Do(unprepareReq, connection_pool.ANY).Get() if err != nil { fmt.Printf("Failed to prepare") }
Output:
func (*ConnectionPool) NewStream ¶ added in v1.7.0
func (connPool *ConnectionPool) NewStream(userMode Mode) (*tarantool.Stream, error)
NewStream creates new Stream object for connection selected by userMode from connPool.
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 ¶ added in v1.10.0
func (pool *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, } pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.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 := connection_pool.ANY watcher, err := pool.NewWatcher(key, callback, mode) if err != nil { fmt.Printf("Unexpected error: %s\n", err) return } defer watcher.Unregister() pool.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{} pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() callback := func(event tarantool.WatchEvent) {} watcher, err := pool.NewWatcher(key, callback, connection_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 ¶
func (connPool *ConnectionPool) Ping(userMode Mode) (*tarantool.Response, error)
Ping sends empty request to Tarantool to check connection.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Ping a Tarantool instance to check connection. resp, err := pool.Ping(connection_pool.ANY) 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 (*ConnectionPool) Remove ¶ added in v1.12.0
func (pool *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 ¶
func (connPool *ConnectionPool) Replace(space interface{}, tuple interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
Replace performs "insert or replace" action to box space. If tuple with same primary key exists, it will be replaced.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance conn, err := tarantool.Connect(servers[2], connOpts) if err != nil || conn == nil { fmt.Printf("failed to connect to %s", servers[2]) return } // Insert a new tuple {"key1", "value1"}. _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Replace a tuple with primary key ""key1. // Note, Tuple is defined within tests, and has EncdodeMsgpack and // DecodeMsgpack methods. resp, err := pool.Replace(spaceNo, []interface{}{"key1", "new_value"}) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) resp, err = pool.Replace(spaceName, []interface{}{"key1", "another_value"}) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) resp, err = pool.Replace(spaceName, &Tuple{Key: "key1", Value: "value2"}) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) resp, err = pool.Replace(spaceName, &Tuple{Key: "key1", Value: "new_value2"}, connection_pool.PreferRW) fmt.Println("Replace key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) // Delete tuple with primary key "key1". _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) }
Output: Replace key1 Error <nil> Code 0 Data [[key1 new_value]] Replace key1 Error <nil> Code 0 Data [[key1 another_value]] Replace key1 Error <nil> Code 0 Data [[key1 value2]] Replace key1 Error <nil> Code 0 Data [[key1 new_value2]]
func (*ConnectionPool) ReplaceAsync ¶
func (connPool *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.
func (*ConnectionPool) ReplaceTyped ¶
func (connPool *ConnectionPool) ReplaceTyped(space interface{}, tuple interface{}, result interface{}, userMode ...Mode) (err error)
ReplaceTyped performs "insert or replace" action to box space. If tuple with same primary key exists, it will be replaced.
func (*ConnectionPool) Select ¶
func (connPool *ConnectionPool) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
Select performs select to box space.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance conn, err := tarantool.Connect(servers[2], connOpts) if err != nil || conn == nil { fmt.Printf("failed to connect to %s", servers[2]) return } // Insert a new tuple {"key1", "value1"}. _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Insert a new tuple {"key2", "value2"}. _, err = conn.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } resp, err := pool.Select( spaceNo, indexNo, 0, 100, tarantool.IterEq, []interface{}{"key1"}, connection_pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %#v\n", resp.Data) resp, err = pool.Select( spaceNo, indexNo, 0, 100, tarantool.IterEq, []interface{}{"key2"}, connection_pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %#v\n", resp.Data) // Delete tuple with primary key "key1". _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) } // Delete tuple with primary key "key2". _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) }
Output: response is []interface {}{[]interface {}{"key1", "value1"}} response is []interface {}{[]interface {}{"key2", "value2"}}
func (*ConnectionPool) SelectAsync ¶
func (connPool *ConnectionPool) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}, userMode ...Mode) *tarantool.Future
SelectAsync sends select request to Tarantool and returns Future.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance conn, err := tarantool.Connect(servers[2], connOpts) if err != nil || conn == nil { fmt.Printf("failed to connect to %s", servers[2]) return } // Insert a new tuple {"key1", "value1"}. _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Insert a new tuple {"key2", "value2"}. _, err = conn.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Insert a new tuple {"key3", "value3"}. _, err = conn.Insert(spaceNo, []interface{}{"key3", "value3"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } var futs [3]*tarantool.Future futs[0] = pool.SelectAsync( spaceName, indexName, 0, 2, tarantool.IterEq, []interface{}{"key1"}, connection_pool.PreferRW) futs[1] = pool.SelectAsync( spaceName, indexName, 0, 1, tarantool.IterEq, []interface{}{"key2"}, connection_pool.RW) futs[2] = pool.SelectAsync( spaceName, indexName, 0, 1, tarantool.IterEq, []interface{}{"key3"}, connection_pool.RW) var t []Tuple err = futs[0].GetTyped(&t) fmt.Println("Future", 0, "Error", err) fmt.Println("Future", 0, "Data", t) resp, err := futs[1].Get() fmt.Println("Future", 1, "Error", err) fmt.Println("Future", 1, "Data", resp.Data) resp, err = futs[2].Get() fmt.Println("Future", 2, "Error", err) fmt.Println("Future", 2, "Data", resp.Data) // Delete tuple with primary key "key1". _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) } // Delete tuple with primary key "key2". _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) } // Delete tuple with primary key "key3". _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key3"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) }
Output: Future 0 Error <nil> Future 0 Data [{{} key1 value1}] Future 1 Error <nil> Future 1 Data [[key2 value2]] Future 2 Error <nil> Future 2 Data [[key3 value3]]
Example (Err) ¶
roles := []bool{true, true, true, true, true} pool, err := examplePool(roles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() var futs [3]*tarantool.Future futs[0] = pool.SelectAsync( spaceName, indexName, 0, 2, tarantool.IterEq, []interface{}{"key1"}, connection_pool.RW) err = futs[0].Err() fmt.Println("Future", 0, "Error", err)
Output: Future 0 Error can't find rw instance in pool
func (*ConnectionPool) SelectTyped ¶
func (connPool *ConnectionPool) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}, userMode ...Mode) (err error)
SelectTyped performs select to box space and fills typed result.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance conn, err := tarantool.Connect(servers[2], connOpts) if err != nil || conn == nil { fmt.Printf("failed to connect to %s", servers[2]) return } // Insert a new tuple {"key1", "value1"}. _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Insert a new tuple {"key2", "value2"}. _, err = conn.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } var res []Tuple err = pool.SelectTyped( spaceNo, indexNo, 0, 100, tarantool.IterEq, []interface{}{"key1"}, &res, connection_pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %v\n", res) err = pool.SelectTyped( spaceName, indexName, 0, 100, tarantool.IterEq, []interface{}{"key2"}, &res, connection_pool.PreferRW) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %v\n", res) // Delete tuple with primary key "key1". _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) } // Delete tuple with primary key "key2". _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) }
Output: response is [{{} key1 value1}] response is [{{} key2 value2}]
func (*ConnectionPool) Update ¶
func (connPool *ConnectionPool) Update(space, index interface{}, key, ops interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
Update performs update of a tuple by key. Result will contain array with updated tuple.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() // Connect to servers[2] to check if tuple // was inserted on RW instance conn, err := tarantool.Connect(servers[2], connOpts) if err != nil || conn == nil { fmt.Printf("failed to connect to %s", servers[2]) return } // Insert a new tuple {"key1", "value1"}. _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) if err != nil { fmt.Printf("Failed to insert: %s", err.Error()) return } // Update tuple with primary key { "key1" }. resp, err := pool.Update( spaceName, indexName, []interface{}{"key1"}, []interface{}{[]interface{}{"=", 1, "new_value"}}, connection_pool.PreferRW) fmt.Println("Update key1") fmt.Println("Error", err) fmt.Println("Code", resp.Code) fmt.Println("Data", resp.Data) // Delete tuple with primary key "key1". _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) if err != nil { fmt.Printf("Failed to delete: %s", err.Error()) }
Output: Update key1 Error <nil> Code 0 Data [[key1 new_value]]
func (*ConnectionPool) UpdateAsync ¶
func (connPool *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.
func (*ConnectionPool) UpdateTyped ¶
func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}, userMode ...Mode) (err error)
UpdateTyped performs update of a tuple by key and fills result with updated tuple.
func (*ConnectionPool) Upsert ¶
func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{}, userMode ...Mode) (resp *tarantool.Response, err error)
Upsert performs "update or insert" action of a tuple by key. Result will not contain any tuple.
func (*ConnectionPool) UpsertAsync ¶
func (connPool *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.
type ConnectorAdapter ¶ added in v1.9.0
type ConnectorAdapter struct {
// contains filtered or unexported fields
}
ConnectorAdapter allows to use Pooler as Connector.
Example ¶
pool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer pool.Close() adapter := connection_pool.NewConnectorAdapter(pool, connection_pool.RW) var connector tarantool.Connector = adapter // Ping an RW instance to check connection. resp, err := connector.Ping() 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 ¶ added in v1.9.0
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 ¶ added in v1.9.0
func (c *ConnectorAdapter) Call(functionName string, args interface{}) (*tarantool.Response, error)
Call calls registered Tarantool function. It uses request code for Tarantool >= 1.7 if go-tarantool was build with go_tarantool_call_17 tag. Otherwise, uses request code for Tarantool 1.6.
func (*ConnectorAdapter) Call16 ¶ added in v1.9.0
func (c *ConnectorAdapter) Call16(functionName string, args interface{}) (*tarantool.Response, error)
Call16 calls registered Tarantool function. It uses request code for Tarantool 1.6, so result is converted to array of arrays Deprecated since Tarantool 1.7.2.
func (*ConnectorAdapter) Call16Async ¶ added in v1.9.0
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 always array of arrays. Deprecated since Tarantool 1.7.2.
func (*ConnectorAdapter) Call16Typed ¶ added in v1.9.0
func (c *ConnectorAdapter) Call16Typed(functionName string, args interface{}, result interface{}) error
Call16Typed calls registered function. It uses request code for Tarantool 1.6, so result is converted to array of arrays Deprecated since Tarantool 1.7.2.
func (*ConnectorAdapter) Call17 ¶ added in v1.9.0
func (c *ConnectorAdapter) Call17(functionName string, args interface{}) (*tarantool.Response, error)
Call17 calls registered Tarantool function. It uses request code for Tarantool >= 1.7, so result is not converted (though, keep in mind, result is always array)
func (*ConnectorAdapter) Call17Async ¶ added in v1.9.0
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, so future's result will not be converted (though, keep in mind, result is always array)
func (*ConnectorAdapter) Call17Typed ¶ added in v1.9.0
func (c *ConnectorAdapter) Call17Typed(functionName string, args interface{}, result interface{}) error
Call17Typed calls registered function. It uses request code for Tarantool >= 1.7, so result is not converted (though, keep in mind, result is always array)
func (*ConnectorAdapter) CallAsync ¶ added in v1.9.0
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 if go-tarantool was build with go_tarantool_call_17 tag. Otherwise, uses request code for Tarantool 1.6.
func (*ConnectorAdapter) CallTyped ¶ added in v1.9.0
func (c *ConnectorAdapter) CallTyped(functionName string, args interface{}, result interface{}) error
CallTyped calls registered function. It uses request code for Tarantool >= 1.7 if go-tarantool was build with go_tarantool_call_17 tag. Otherwise, uses request code for Tarantool 1.6.
func (*ConnectorAdapter) Close ¶ added in v1.9.0
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 ¶ added in v1.9.0
func (c *ConnectorAdapter) ConfiguredTimeout() time.Duration
ConfiguredTimeout returns a timeout from connections config.
func (*ConnectorAdapter) ConnectedNow ¶ added in v1.9.0
func (c *ConnectorAdapter) ConnectedNow() bool
ConnectedNow reports if connections is established at the moment.
func (*ConnectorAdapter) Delete ¶ added in v1.9.0
func (c *ConnectorAdapter) Delete(space, index interface{}, key interface{}) (*tarantool.Response, error)
Delete performs deletion of a tuple by key.
func (*ConnectorAdapter) DeleteAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) DeleteAsync(space, index interface{}, key interface{}) *tarantool.Future
DeleteAsync sends deletion action to Tarantool and returns Future.
func (*ConnectorAdapter) DeleteTyped ¶ added in v1.9.0
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.
func (*ConnectorAdapter) Do ¶ added in v1.9.0
func (c *ConnectorAdapter) Do(req tarantool.Request) *tarantool.Future
Do performs a request asynchronously on the connection.
func (*ConnectorAdapter) Eval ¶ added in v1.9.0
func (c *ConnectorAdapter) Eval(expr string, args interface{}) (*tarantool.Response, error)
Eval passes Lua expression for evaluation.
func (*ConnectorAdapter) EvalAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) EvalAsync(expr string, args interface{}) *tarantool.Future
EvalAsync sends a Lua expression for evaluation and returns Future.
func (*ConnectorAdapter) EvalTyped ¶ added in v1.9.0
func (c *ConnectorAdapter) EvalTyped(expr string, args interface{}, result interface{}) error
EvalTyped passes Lua expression for evaluation.
func (*ConnectorAdapter) Execute ¶ added in v1.9.0
func (c *ConnectorAdapter) Execute(expr string, args interface{}) (*tarantool.Response, error)
Execute passes sql expression to Tarantool for execution.
func (*ConnectorAdapter) ExecuteAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) ExecuteAsync(expr string, args interface{}) *tarantool.Future
ExecuteAsync sends a sql expression for execution and returns Future.
func (*ConnectorAdapter) ExecuteTyped ¶ added in v1.9.0
func (c *ConnectorAdapter) ExecuteTyped(expr string, args interface{}, result interface{}) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)
ExecuteTyped passes sql expression to Tarantool for execution.
func (*ConnectorAdapter) GetTyped ¶ added in v1.9.0
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.
func (*ConnectorAdapter) Insert ¶ added in v1.9.0
func (c *ConnectorAdapter) Insert(space interface{}, tuple interface{}) (*tarantool.Response, error)
Insert performs insertion to box space.
func (*ConnectorAdapter) InsertAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) InsertAsync(space interface{}, tuple interface{}) *tarantool.Future
InsertAsync sends insert action to Tarantool and returns Future.
func (*ConnectorAdapter) InsertTyped ¶ added in v1.9.0
func (c *ConnectorAdapter) InsertTyped(space interface{}, tuple interface{}, result interface{}) error
InsertTyped performs insertion to box space.
func (*ConnectorAdapter) NewPrepared ¶ added in v1.9.0
func (c *ConnectorAdapter) NewPrepared(expr string) (*tarantool.Prepared, error)
NewPrepared passes a sql statement to Tarantool for preparation synchronously.
func (*ConnectorAdapter) NewStream ¶ added in v1.9.0
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 ¶ added in v1.10.0
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 ¶ added in v1.9.0
func (c *ConnectorAdapter) Ping() (*tarantool.Response, error)
Ping sends empty request to Tarantool to check connection.
func (*ConnectorAdapter) Replace ¶ added in v1.9.0
func (c *ConnectorAdapter) Replace(space interface{}, tuple interface{}) (*tarantool.Response, error)
Replace performs "insert or replace" action to box space.
func (*ConnectorAdapter) ReplaceAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) ReplaceAsync(space interface{}, tuple interface{}) *tarantool.Future
ReplaceAsync sends "insert or replace" action to Tarantool and returns Future.
func (*ConnectorAdapter) ReplaceTyped ¶ added in v1.9.0
func (c *ConnectorAdapter) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) error
ReplaceTyped performs "insert or replace" action to box space.
func (*ConnectorAdapter) Select ¶ added in v1.9.0
func (c *ConnectorAdapter) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (*tarantool.Response, error)
Select performs select to box space.
func (*ConnectorAdapter) SelectAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *tarantool.Future
SelectAsync sends select request to Tarantool and returns Future.
func (*ConnectorAdapter) SelectTyped ¶ added in v1.9.0
func (c *ConnectorAdapter) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}) error
SelectTyped performs select to box space and fills typed result.
func (*ConnectorAdapter) Update ¶ added in v1.9.0
func (c *ConnectorAdapter) Update(space, index interface{}, key, ops interface{}) (*tarantool.Response, error)
Update performs update of a tuple by key.
func (*ConnectorAdapter) UpdateAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) UpdateAsync(space, index interface{}, key, ops interface{}) *tarantool.Future
Update sends deletion of a tuple by key and returns Future.
func (*ConnectorAdapter) UpdateTyped ¶ added in v1.9.0
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.
func (*ConnectorAdapter) Upsert ¶ added in v1.9.0
func (c *ConnectorAdapter) Upsert(space interface{}, tuple, ops interface{}) (*tarantool.Response, error)
Upsert performs "update or insert" action of a tuple by key.
func (*ConnectorAdapter) UpsertAsync ¶ added in v1.9.0
func (c *ConnectorAdapter) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *tarantool.Future
UpsertAsync sends "update or insert" action to Tarantool and returns Future.
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 OptsPool ¶
type OptsPool 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 }
OptsPool provides additional options (configurable via ConnectWithOpts).
type Pooler ¶ added in v1.9.0
type Pooler interface { ConnectedNow(mode Mode) (bool, error) Close() []error Ping(mode Mode) (*tarantool.Response, error) ConfiguredTimeout(mode Mode) (time.Duration, error) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}, mode ...Mode) (*tarantool.Response, error) Insert(space interface{}, tuple interface{}, mode ...Mode) (*tarantool.Response, error) Replace(space interface{}, tuple interface{}, mode ...Mode) (*tarantool.Response, error) Delete(space, index interface{}, key interface{}, mode ...Mode) (*tarantool.Response, error) Update(space, index interface{}, key, ops interface{}, mode ...Mode) (*tarantool.Response, error) Upsert(space interface{}, tuple, ops interface{}, mode ...Mode) (*tarantool.Response, error) Call(functionName string, args interface{}, mode Mode) (*tarantool.Response, error) Call16(functionName string, args interface{}, mode Mode) (*tarantool.Response, error) Call17(functionName string, args interface{}, mode Mode) (*tarantool.Response, error) Eval(expr string, args interface{}, mode Mode) (*tarantool.Response, error) Execute(expr string, args interface{}, mode Mode) (*tarantool.Response, error) GetTyped(space, index interface{}, key interface{}, result interface{}, mode ...Mode) error SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}, mode ...Mode) error InsertTyped(space interface{}, tuple interface{}, result interface{}, mode ...Mode) error ReplaceTyped(space interface{}, tuple interface{}, result interface{}, mode ...Mode) error DeleteTyped(space, index interface{}, key interface{}, result interface{}, mode ...Mode) error UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}, mode ...Mode) error CallTyped(functionName string, args interface{}, result interface{}, mode Mode) error Call16Typed(functionName string, args interface{}, result interface{}, mode Mode) error Call17Typed(functionName string, args interface{}, result interface{}, mode Mode) error EvalTyped(expr string, args interface{}, result interface{}, mode Mode) error ExecuteTyped(expr string, args interface{}, result interface{}, mode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}, mode ...Mode) *tarantool.Future InsertAsync(space interface{}, tuple interface{}, mode ...Mode) *tarantool.Future ReplaceAsync(space interface{}, tuple interface{}, mode ...Mode) *tarantool.Future DeleteAsync(space, index interface{}, key interface{}, mode ...Mode) *tarantool.Future UpdateAsync(space, index interface{}, key, ops interface{}, mode ...Mode) *tarantool.Future UpsertAsync(space interface{}, tuple interface{}, ops interface{}, mode ...Mode) *tarantool.Future CallAsync(functionName string, args interface{}, mode Mode) *tarantool.Future Call16Async(functionName string, args interface{}, mode Mode) *tarantool.Future Call17Async(functionName string, args interface{}, mode Mode) *tarantool.Future EvalAsync(expr string, args interface{}, mode Mode) *tarantool.Future ExecuteAsync(expr string, args interface{}, mode Mode) *tarantool.Future 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) }
Pooler is the interface that must be implemented by a connection pool.
type RoundRobinStrategy ¶
type RoundRobinStrategy struct {
// contains filtered or unexported fields
}
func NewEmptyRoundRobin ¶
func NewEmptyRoundRobin(size int) *RoundRobinStrategy
func (*RoundRobinStrategy) AddConn ¶
func (r *RoundRobinStrategy) AddConn(addr string, conn *tarantool.Connection)
func (*RoundRobinStrategy) DeleteConnByAddr ¶
func (r *RoundRobinStrategy) DeleteConnByAddr(addr string) *tarantool.Connection
func (*RoundRobinStrategy) GetConnByAddr ¶
func (r *RoundRobinStrategy) GetConnByAddr(addr string) *tarantool.Connection
func (*RoundRobinStrategy) GetConnections ¶ added in v1.10.0
func (r *RoundRobinStrategy) GetConnections() []*tarantool.Connection
func (*RoundRobinStrategy) GetNextConnection ¶
func (r *RoundRobinStrategy) GetNextConnection() *tarantool.Connection
func (*RoundRobinStrategy) IsEmpty ¶
func (r *RoundRobinStrategy) IsEmpty() bool