Categorygithub.com/FZambia/tarantool
modulepackage
0.3.1
Repository: https://github.com/fzambia/tarantool.git
Documentation: pkg.go.dev

# README

Build Status GoDoc

Tarantool client in Go language

The tarantool package allows communicating with Tarantool 1.7.1+.

This is an opinionated modification of github.com/tarantool/go-tarantool package. The original license kept unchanged here at the moment.

Differences from the original package

  • API changed, some non-obvious (mostly to me personally) API removed.
  • This package uses the latest msgpack library github.com/vmihailenco/msgpack/v5 instead of v2 in original.
  • Uses UseArrayEncodedStructs(true) for msgpack.Encoder by default so there is no need to define msgpack:",as_array" struct tags. If you need to disable this (for example when using nested structs) then this behavior can be disabled using DisableArrayEncodedStructs option.
  • Uses UseLooseInterfaceDecoding(true) for msgpack.Decoder to decode response into untyped []interface{} result. See decoding rules.
  • Supports out-of-bound pushes (see box.session.push)
  • Adds optional support for context.Context (though performance will suffer a bit, if you want a maximum performance then use non-context methods which use per-connection timeout). Context cancellation does not cancel a query (Tarantool has no such functionality) - just stops waiting for request future resolving.
  • Uses sync.Pool for *msgpack.Decoder to reduce allocations on decoding stage a bit. Actually this package allocates a bit more than the original one, but allocations are small and overall performance is comparable to the original (based on observations from internal benchmarks).
  • No multi and queue packages.
  • Only one version of Call which uses Tarantool 1.7 request code.
  • Modified connection address behavior: refer to Connect function docs to see details.
  • Per-request timeout detached from underlying connection read and write timeouts.
  • Op type to express different update/upsert operations.
  • Some other cosmetic changes including several linter fixes.
  • No default Logger – developer needs to provide custom implementation explicitly.

The networking core of github.com/tarantool/go-tarantool kept mostly unchanged at the moment so this package should behave in similar way.

Installation

$ go get github.com/FZambia/tarantool

Status

This library is a prototype for Centrifuge/Centrifugo ongoing Tarantool Engine experiment.

API is not stable here and can have changes as experiment evolves. Also, there are no concrete plans at the moment regarding the package maintenance.

The versioning politics before v1 will be the following: patch version updates will only contain backwards compatible changes, minor version updates may have backwards incompatible changes.

Quick start

Create example.lua file with content:

box.cfg{listen = 3301}
box.schema.space.create('examples', {id = 999})
box.space.examples:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}})
box.schema.user.grant('guest', 'read,write', 'space', 'examples')

Run it with Tarantool:

tarantool example.lua

Then create main.go file:

package main

import (
	"log"
	"time"

	"github.com/FZambia/tarantool"
)

type Row struct {
	ID    uint64
	Value string
}

func main() {
	opts := tarantool.Opts{
		RequestTimeout: 500 * time.Millisecond,
		User:           "guest",
	}
	conn, err := tarantool.Connect("127.0.0.1:3301", opts)
	if err != nil {
		log.Fatalf("Connection refused: %v", err)
	}
	defer func() { _ = conn.Close() }()

	_, err = conn.Exec(tarantool.Insert("examples", Row{ID: 999, Value: "hello"}))
	if err != nil {
		log.Fatalf("Insert failed: %v", err)
	}
	log.Println("Insert succeeded")
}

Finally, run it with:

go run main.go

# Functions

Call sends a call to registered Tarantool function.
Connect creates and configures new Connection.
Delete sends deletion action to Tarantool.
Eval sends a lua expression for evaluation.
Insert sends insert action to Tarantool.
OpAdd ...
OpAssign ...
OpBitAND ...
OpBitOR ...
OpBitXOR ...
OpDelete ...
OpInsert ...
OpSplice ...
OpSub ...
Ping sends empty request to Tarantool to check connection.
Replace sends "insert or replace" action to Tarantool.
Select sends select request to Tarantool.
Update sends deletion of a tuple by key.
Upsert sends "update or insert" action to Tarantool.

# Constants

Request code possible values.
Request code possible values.
Closed means either reconnect attempts exhausted, or explicit Close is called.
Connected signals that connection is established or reestablished.
DefaultConnectTimeout to Tarantool.
DefaultReadTimeout to Tarantool.
DefaultWriteTimeout to Tarantool.
Request code possible values.
Disconnected signals that connection is broken.
%s access denied for user '%s'.
Operation is not permitted when there is an active transaction.
Can't modify space '%s': %s.
Argument type in operation '%c' on field %u does not match field type: expected a %s.
Attempt to modify a tuple field which is part of index '%s' in space '%s'.
Incorrect value for option '%s': %s.
Can't reset cluster id: it is already assigned.
Cluster id of the replica %s doesn't match cluster id of the master %s.
Tarantool client error codes.
Tarantool client error codes.
Failed to create function '%s': %s.
Failed to create role '%s': %s.
Failed to create space '%s': %s.
Failed to create user '%s': %s.
A multi-statement transaction can not use multiple storage engines.
Can't drop function %u: %s.
Can't drop primary key in space '%s' while secondary keys exist.
Can't drop space '%s': %s.
Failed to drop user '%s': %s.
Invalid key part count in an exact match (expected %u, got %u).
Can not create a new fiber: recursion limit reached.
Tuple field %u type does not match one required by operation: expected %s.
Ambiguous field type in index '%s', key part %u.
%s access denied for user '%s' to function '%s'.
Function '%s' already exists.
Unsupported language '%s' specified for function '%s'.
A limit on the total number of functions has been reached: %u.
Incorrect grant arguments: %s.
Setting password for guest user has no effect.
Invalid identifier '%s' (expected letters, digits or an underscore).
Illegal parameters, %s.
Index '%s' already exists.
Tuple field count %u is less than required by a defined index (expected %u).
Unsupported index type supplied for index '%s' in space '%s'.
Error injection '%s'.
Invalid MsgPack - %s.
Invalid LSN order for server %u: previous LSN = %llu, new lsn = %llu.
Invalid UUID: %s.
Failed to read xlog: %lld.
Invalid xlog name: expected %lld got %lld.
Invalid xlog order: %lld and %lld.
Unknown iterator type '%s'.
Invalid key part count (expected [0..%u], got %u).
Supplied key type of part %u does not match index part type: expected %s.
Can't drop the primary key in a system space, space '%s'.
Failed to dynamically load function '%s': %s.
Local server is not active.
Failed to allocate %u bytes in %s for %s.
Missing mandatory field '%s' in request.
Can't find snapshot.
Can't create or modify index '%s' in space '%s': %s.
More than one tuple found by GetContext().
Operation is not permitted when there is no active transaction.
Connection is not established.
Can't modify data on a replication slave.
Space engine '%s' does not exist.
Field %d was not found in the tuple.
Function '%s' does not exist.
No index #%u is defined in space '%s'.
Procedure '%.*s' is not defined.
Role '%s' is not found.
Space '%s' does not exist.
Trigger is not found.
User '%s' is not found.
Incorrect password supplied for user '%s'.
User '%s' already has %s access on %s '%s'.
User '%s' does not have %s access on %s '%s'.
???.
%s.
msgpack.encode: can not encode Lua type '%s'.
%s.
Tarantool client error codes.
Tarantool client error codes.
Can't modify data because this server is in read-only mode.
Can't set option '%s' dynamically.
Replica count limit reached: %u.
Reserved66.
Role '%s' already exists.
User '%s' already has role '%s'.
Granting role '%s' to role '%s' would create a loop.
User '%s' does not have role '%s'.
RTree: %s must be an array with %u (point) or %u (rectangle/box) numeric coordinates.
Can't initialize server id with a reserved value %u.
Failed to allocate %u bytes for tuple in the slab allocator: tuple is too large.
%s.
%s access denied for user '%s' to space '%s'.
Space '%s' already exists.
Tuple field count %u does not match space '%s' field count %u.
SPLICE error on field %u: %s.
Tarantool client error codes.
Timeout exceeded.
Transaction has been aborted by conflict.
Tuple format limit reached: %u.
Duplicate key exists in unique index '%s' in space '%s'.
Tuple is too long %u.
Tuple/Key must be MsgPack array.
Tuple doesn't exist in index '%s' in space '%s'.
Tuple reference counter overflow.
Unknown error.
Unknown request type %u.
Unknown RTREE index distance type %s.
Unknown object type '%s'.
Server %s is not registered with the cluster.
Unknown UPDATE operation.
%s does not support %s.
Unsupported role privilege '%s'.
Field %u UPDATE error: %s.
Integer overflow when performing '%c' operation on field %u.
Space %s has a unique secondary index and does not support UPSERT.
User '%s' already exists.
A limit on the total number of users has been reached: %u.
Failed to write to disk.
Wrong index options (field %u): %s.
Wrong index parts (field %u): %s; expected field1 id (number), field1 type (string), ...
Wrong record in _index space: got {%s}, expected {%s}.
Wrong schema version, current: %d, in request: %u.
Request code possible values.
Request code possible values.
all tuples.
all bits are not set.
all bits from x are set in key.
at least one x's bit is set.
key == x ASC order.
key >= x.
key > x.
key <= x.
key < x.
key == x DESC order.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
Key possible values.
LogLastReconnectFailed is logged when last reconnect attempt failed, connection will be closed after that.
LogReconnectFailed is logged when reconnect attempt failed.
LogUnexpectedResultID is logged when response with unknown id were received.
Request code possible values.
ReconnectFailed signals that attempt to reconnect has failed.
Request code possible values.
RLimit possible values.
RLimit possible values.
Request code possible values.
Request code possible values.
Request code possible values.

# Structs

ClientError is connection produced by this client – i.e.
Connection to Tarantool.
ConnEvent is sent throw Notify channel specified in Opts.
Error is wrapper around error returned by Tarantool.
No description provided by the author
Greeting is a message sent by tarantool on connect.
Index contains information about index.
No description provided by the author
IntIntKey is utility type for passing two integer keys to Select, Update and Delete.
IntKey is utility type for passing integer key to Select, Update and Delete.
No description provided by the author
Opts is a way to configure Connection.
Request to be executed in Tarantool.
Schema contains information about spaces and indexes.
Space contains information about tarantool space.
StringKey is utility type for passing string key to Select, Update and Delete.
UintKey is utility type for passing unsigned integer key to Select, Update and Delete.

# Interfaces

Future allows to extract response from server as soon as it's ready.
FutureContext allows extracting response from server as soon as it's ready with Context.
Logger is logger type expected to be passed in options.

# Type aliases

No description provided by the author
No description provided by the author