Documentation
¶
Index ¶
- Constants
- Variables
- func VersionID(major, minor, patch uint32) uint32
- type AnonSlave
- type AsyncResult
- type Auth
- type BinaryPacket
- func (pp *BinaryPacket) Bytes() []byte
- func (pp *BinaryPacket) ReadFrom(r io.Reader) (n int64, err error)
- func (pp *BinaryPacket) Release()
- func (pp *BinaryPacket) Reset()
- func (pp *BinaryPacket) Result() *Result
- func (pp *BinaryPacket) Unmarshal() error
- func (pp *BinaryPacket) UnmarshalCustomBody(um UnmarshalBinaryBodyFunc) (err error)
- func (pp *BinaryPacket) WriteTo(w io.Writer) (n int64, err error)
- type BinaryPacketPool
- type Box
- func (box *Box) Addr() string
- func (box *Box) Close()
- func (box *Box) Connect(options *Options) (*Connection, error)
- func (box *Box) IsStopped() bool
- func (box *Box) Start() error
- func (box *Box) StartWithLua(luaTransform func(string) string) error
- func (box *Box) Stop()
- func (box *Box) Version() (string, error)
- type BoxOptions
- type Bytes
- type Call
- type Call17
- type Connection
- func (conn *Connection) Close()
- func (conn *Connection) Exec(ctx context.Context, q Query, options ...ExecOption) (result *Result)
- func (conn *Connection) ExecAsync(ctx context.Context, q Query, opaque interface{}, replyChan chan *AsyncResult, ...) error
- func (conn *Connection) Execute(q Query) ([][]interface{}, error)
- func (conn *Connection) GetPerf() PerfCount
- func (conn *Connection) GetPrimaryKeyFields(space interface{}) ([]int, bool)
- func (conn *Connection) InstanceUUID() string
- func (conn *Connection) IsClosed() bool
- func (conn *Connection) String() string
- type ConnectionError
- type Connector
- type ContextError
- type CountedReader
- type CountedWriter
- type Delete
- type Error
- type Eval
- type ExecOption
- type FetchSnapshot
- type Greeting
- type Insert
- type IprotoServer
- type IprotoServerOptions
- type Iterator
- type Join
- type OnShutdownCallback
- type OpAdd
- type OpAssign
- type OpBitAND
- type OpBitOR
- type OpBitXOR
- type OpDelete
- type OpInsert
- type OpSplice
- type OpSub
- type Operator
- type Options
- type Packet
- func (pack *Packet) String() string
- func (pack *Packet) UnmarshalBinary(data []byte) error
- func (pack *Packet) UnmarshalBinaryBody(data []byte) (buf []byte, err error)
- func (pack *Packet) UnmarshalBinaryHeader(data []byte) (buf []byte, err error)
- func (pack *Packet) UnmarshalMsg(data []byte) (buf []byte, err error)
- type PacketIterator
- type PerfCount
- type Ping
- type Query
- type QueryCompleteFn
- type QueryError
- type QueryHandler
- type Register
- type Replace
- type ReplicaSet
- type Result
- type Select
- type Slave
- func (s *Slave) Attach(out ...chan *Packet) (it PacketIterator, err error)
- func (s *Slave) Close() error
- func (s *Slave) Err() error
- func (s *Slave) HasNext() bool
- func (s *Slave) IsInReplicaSet() bool
- func (s *Slave) Join() (err error)
- func (s *Slave) JoinWithSnap(out ...chan *Packet) (it PacketIterator, err error)
- func (s *Slave) LastSnapVClock() (VectorClock, error)
- func (s *Slave) Next() (*Packet, error)
- func (s *Slave) Packet() *Packet
- func (s *Slave) Subscribe(lsns ...uint64) (it PacketIterator, err error)
- func (s *Slave) Version() uint32
- type Subscribe
- type SubscribeResponse
- type Tuple
- type UnexpectedReplicaSetUUIDError
- type UnmarshalBinaryBodyFunc
- type Update
- type Upsert
- type VClock
- func (p *VClock) GetCommandID() uint
- func (p *VClock) MarshalMsg(b []byte) ([]byte, error)
- func (p *VClock) String() string
- func (p *VClock) UnmarshalBinaryBody(data []byte) (buf []byte, err error)
- func (p *VClock) UnmarshalBinaryHeader(data []byte) (buf []byte, err error)
- func (p *VClock) UnmarshalMsg(data []byte) (buf []byte, err error)
- type VectorClock
Examples ¶
Constants ¶
const ( OKCommand = uint(0) SelectCommand = uint(1) InsertCommand = uint(2) ReplaceCommand = uint(3) UpdateCommand = uint(4) DeleteCommand = uint(5) CallCommand = uint(6) AuthCommand = uint(7) EvalCommand = uint(8) UpsertCommand = uint(9) Call17Command = uint(10) // Tarantool >= 1.7.2 PingCommand = uint(64) JoinCommand = uint(65) SubscribeCommand = uint(66) VoteCommand = uint(68) // Tarantool >= 1.9.0 FetchSnapshotCommand = uint(69) // for starting anonymous replication. Tarantool >= 2.3.1 RegisterCommand = uint(70) // for leaving anonymous replication (anon => normal replica). Tarantool >= 2.3.1 ErrorFlag = uint(0x8000) )
const ( KeyCode = uint(0x00) KeySync = uint(0x01) KeyInstanceID = uint(0x02) KeyLSN = uint(0x03) KeyTimestamp = uint(0x04) KeySchemaID = uint(0x05) KeyVersionID = uint(0x06) KeySpaceNo = uint(0x10) KeyIndexNo = uint(0x11) KeyLimit = uint(0x12) KeyOffset = uint(0x13) KeyIterator = uint(0x14) KeyKey = uint(0x20) KeyTuple = uint(0x21) KeyFunctionName = uint(0x22) KeyUserName = uint(0x23) KeyInstanceUUID = uint(0x24) KeyReplicaSetUUID = uint(0x25) KeyVClock = uint(0x26) KeyExpression = uint(0x27) KeyDefTuple = uint(0x28) KeyBallot = uint(0x29) // Tarantool >= 1.9.0 KeyData = uint(0x30) KeyError = uint(0x31) KeyReplicaAnon = uint(0x50) // Tarantool >= 2.3.1 )
const ( // https://github.com/fl00r/go-tarantool-1.6/issues/2 IterEq = uint8(0) // key == x ASC order IterReq = uint8(1) // key == x DESC order IterAll = uint8(2) // all tuples IterLt = uint8(3) // key < x IterLe = uint8(4) // key <= x IterGe = uint8(5) // key >= x IterGt = uint8(6) // key > x IterBitsAllSet = uint8(7) // all bits from x are set in key IterBitsAnySet = uint8(8) // at least one x's bit is set IterBitsAllNotSet = uint8(9) // all bits are not set )
const ( SchemaKeyClusterUUID = "cluster" ReplicaSetMaxSize = 32 VClockMax = ReplicaSetMaxSize UUIDStrLength = 36 )
const ( SpaceSchema = uint(272) SpaceSpace = uint(280) ViewSpace = uint(281) SpaceIndex = uint(288) ViewIndex = uint(289) SpaceFunc = uint(296) SpaceUser = uint(304) SpacePriv = uint(312) SpaceCluster = uint(320) SpaceSystemMax = uint(511) )
const ( ErrUnknown = uint(0x00) // Unknown error ErrIllegalParams = uint(0x01) // Illegal parameters, %s ErrMemoryIssue = uint(0x02) // Failed to allocate %u bytes in %s for %s ErrTupleFound = uint(0x03) // Duplicate key exists in unique index '%s' in space '%s' ErrTupleNotFound = uint(0x04) // Tuple doesn't exist in index '%s' in space '%s' ErrUnsupported = uint(0x05) // %s does not support %s ErrNonmaster = uint(0x06) // Can't modify data on a replication slave. My master is: %s ErrReadonly = uint(0x07) // Can't modify data because this server is in read-only mode. ErrInjection = uint(0x08) // Error injection '%s' ErrCreateSpace = uint(0x09) // Failed to create space '%s': %s ErrSpaceExists = uint(0x0a) // Space '%s' already exists ErrDropSpace = uint(0x0b) // Can't drop space '%s': %s ErrAlterSpace = uint(0x0c) // Can't modify space '%s': %s ErrIndexType = uint(0x0d) // Unsupported index type supplied for index '%s' in space '%s' ErrModifyIndex = uint(0x0e) // Can't create or modify index '%s' in space '%s': %s ErrLastDrop = uint(0x0f) // Can't drop the primary key in a system space, space '%s' ErrTupleFormatLimit = uint(0x10) // Tuple format limit reached: %u ErrDropPrimaryKey = uint(0x11) // Can't drop primary key in space '%s' while secondary keys exist ErrKeyPartType = uint(0x12) // Supplied key type of part %u does not match index part type: expected %s ErrExactMatch = uint(0x13) // Invalid key part count in an exact match (expected %u, got %u) ErrInvalidMsgpack = uint(0x14) // Invalid MsgPack - %s ErrProcRet = uint(0x15) // msgpack.encode: can not encode Lua type '%s' ErrTupleNotArray = uint(0x16) // Tuple/Key must be MsgPack array ErrFieldType = uint(0x17) // Tuple field %u type does not match one required by operation: expected %s ErrFieldTypeMismatch = uint(0x18) // Ambiguous field type in index '%s', key part %u. Requested type is %s but the field has previously been defined as %s ErrSplice = uint(0x19) // SPLICE error on field %u: %s ErrArgType = uint(0x1a) // Argument type in operation '%c' on field %u does not match field type: expected a %s ErrTupleIsTooLong = uint(0x1b) // Tuple is too long %u ErrUnknownUpdateOp = uint(0x1c) // Unknown UPDATE operation ErrUpdateField = uint(0x1d) // Field %u UPDATE error: %s ErrFiberStack = uint(0x1e) // Can not create a new fiber: recursion limit reached ErrKeyPartCount = uint(0x1f) // Invalid key part count (expected [0..%u], got %u) ErrProcLua = uint(0x20) // %s ErrNoSuchProc = uint(0x21) // Procedure '%.*s' is not defined ErrNoSuchTrigger = uint(0x22) // Trigger is not found ErrNoSuchIndex = uint(0x23) // No index #%u is defined in space '%s' ErrNoSuchSpace = uint(0x24) // Space '%s' does not exist ErrNoSuchField = uint(0x25) // Field %d was not found in the tuple ErrSpaceFieldCount = uint(0x26) // Tuple field count %u does not match space '%s' field count %u ErrIndexFieldCount = uint(0x27) // Tuple field count %u is less than required by a defined index (expected %u) ErrWalIo = uint(0x28) // Failed to write to disk ErrMoreThanOneTuple = uint(0x29) // More than one tuple found by get() ErrAccessDenied = uint(0x2a) // %s access denied for user '%s' ErrCreateUser = uint(0x2b) // Failed to create user '%s': %s ErrDropUser = uint(0x2c) // Failed to drop user '%s': %s ErrNoSuchUser = uint(0x2d) // User '%s' is not found ErrUserExists = uint(0x2e) // User '%s' already exists ErrCredsMismatch = uint(0x2f) // User not found or supplied credentials are invalid ErrUnknownRequestType = uint(0x30) // Unknown request type %u ErrUnknownSchemaObject = uint(0x31) // Unknown object type '%s' ErrCreateFunction = uint(0x32) // Failed to create function '%s': %s ErrNoSuchFunction = uint(0x33) // Function '%s' does not exist ErrFunctionExists = uint(0x34) // Function '%s' already exists ErrFunctionAccessDenied = uint(0x35) // %s access denied for user '%s' to function '%s' ErrFunctionMax = uint(0x36) // A limit on the total number of functions has been reached: %u ErrSpaceAccessDenied = uint(0x37) // %s access denied for user '%s' to space '%s' ErrUserMax = uint(0x38) // A limit on the total number of users has been reached: %u ErrNoSuchEngine = uint(0x39) // Space engine '%s' does not exist ErrReloadCfg = uint(0x3a) // Can't set option '%s' dynamically ErrCfg = uint(0x3b) // Incorrect value for option '%s': %s ErrSophia = uint(0x3c) // %s ErrLocalServerIsNotActive = uint(0x3d) // Local server is not active ErrUnknownServer = uint(0x3e) // Server %s is not registered with the cluster ErrClusterIDMismatch = uint(0x3f) // Cluster id of the replica %s doesn't match cluster id of the master %s ErrInvalidUUID = uint(0x40) // Invalid UUID: %s ErrClusterIDIsRo = uint(0x41) // Can't reset cluster id: it is already assigned ErrReserved66 = uint(0x42) // Reserved66 ErrServerIDIsReserved = uint(0x43) // Can't initialize server id with a reserved value %u ErrInvalidOrder = uint(0x44) // Invalid LSN order for server %u: previous LSN = %llu, new lsn = %llu ErrMissingRequestField = uint(0x45) // Missing mandatory field '%s' in request ErrIdentifier = uint(0x46) // Invalid identifier '%s' (expected letters, digits or an underscore) ErrDropFunction = uint(0x47) // Can't drop function %u: %s ErrIteratorType = uint(0x48) // Unknown iterator type '%s' ErrReplicaMax = uint(0x49) // Replica count limit reached: %u ErrInvalidXlog = uint(0x4a) // Failed to read xlog: %lld ErrInvalidXlogName = uint(0x4b) // Invalid xlog name: expected %lld got %lld ErrInvalidXlogOrder = uint(0x4c) // Invalid xlog order: %lld and %lld ErrNoConnection = uint(0x4d) // Connection is not established ErrTimeout = uint(0x4e) // Timeout exceeded ErrActiveTransaction = uint(0x4f) // Operation is not permitted when there is an active transaction ErrNoActiveTransaction = uint(0x50) // Operation is not permitted when there is no active transaction ErrCrossEngineTransaction = uint(0x51) // A multi-statement transaction can not use multiple storage engines ErrNoSuchRole = uint(0x52) // Role '%s' is not found ErrRoleExists = uint(0x53) // Role '%s' already exists ErrCreateRole = uint(0x54) // Failed to create role '%s': %s ErrIndexExists = uint(0x55) // Index '%s' already exists ErrTupleRefOverflow = uint(0x56) // Tuple reference counter overflow ErrRoleLoop = uint(0x57) // Granting role '%s' to role '%s' would create a loop ErrGrant = uint(0x58) // Incorrect grant arguments: %s ErrPrivGranted = uint(0x59) // User '%s' already has %s access on %s '%s' ErrRoleGranted = uint(0x5a) // User '%s' already has role '%s' ErrPrivNotGranted = uint(0x5b) // User '%s' does not have %s access on %s '%s' ErrRoleNotGranted = uint(0x5c) // User '%s' does not have role '%s' ErrMissingSnapshot = uint(0x5d) // Can't find snapshot ErrCantUpdatePrimaryKey = uint(0x5e) // Attempt to modify a tuple field which is part of index '%s' in space '%s' ErrUpdateIntegerOverflow = uint(0x5f) // Integer overflow when performing '%c' operation on field %u ErrGuestUserPassword = uint(0x60) // Setting password for guest user has no effect ErrTransactionConflict = uint(0x61) // Transaction has been aborted by conflict ErrUnsupportedRolePriv = uint(0x62) // Unsupported role privilege '%s' ErrLoadFunction = uint(0x63) // Failed to dynamically load function '%s': %s ErrFunctionLanguage = uint(0x64) // Unsupported language '%s' specified for function '%s' ErrRtreeRect = uint(0x65) // RTree: %s must be an array with %u (point) or %u (rectangle/box) numeric coordinates ErrProcC = uint(0x66) // ??? ErrUnknownRtreeIndexDistanceType = uint(0x67) //Unknown RTREE index distance type %s ErrProtocol = uint(0x68) // %s ErrUpsertUniqueSecondaryKey = uint(0x69) // Space %s has a unique secondary index and does not support UPSERT ErrWrongIndexRecord = uint(0x6a) // Wrong record in _index space: got {%s}, expected {%s} ErrWrongIndexParts = uint(0x6b) // Wrong index parts (field %u): %s; expected field1 id (number), field1 type (string), ... ErrWrongIndexOptions = uint(0x6c) // Wrong index options (field %u): %s ErrWrongSchemaVaersion = uint(0x6d) // Wrong schema version, current: %d, in request: %u ErrMemtxMaxTupleSize = uint(0x6e) // "Failed to allocate %u bytes for tuple: tuple is too large. Check 'memtx_max_tuple_size' configuration option." ErrWrongSpaceOptions = uint(0x6f) // "Wrong space options: %s" ErrUnsupportedIndexFeature = uint(0x70) // "Index '%s' (%s) of space '%s' (%s) does not support %s" ErrViewIsRo = uint(0x71) // "View '%s' is read-only" ErrNoTransaction = uint(0x72) // "No active transaction" ErrSystem = uint(0x73) // "%s" ErrLoading = uint(0x74) // "Instance bootstrap hasn't finished yet" ErrConnectionToSelf = uint(0x75) // "Connection to self" ErrKeyPartIsTooLong = uint(0x76) // "Key part is too long: %u of %u bytes" ErrCompression = uint(0x77) // "Compression error: %s" ErrCheckpointInProgress = uint(0x78) // "Snapshot is already in progress" ErrSubStmtMax = uint(0x79) // "Can not execute a nested statement: nesting limit reached" ErrCommitInSubStmt = uint(0x7a) // "Can not commit transaction in a nested statement" ErrRollbackInSubStmt = uint(0x7b) // "Rollback called in a nested statement" ErrDecompression = uint(0x7c) // "Decompression error: %s" ErrInvalidXlogType = uint(0x7d) // "Invalid xlog type: expected %s, got %s" ErrAlreadyRunning = uint(0x7e) // "Failed to lock WAL directory %s and hot_standby mode is off" ErrIndexFieldCountLimit = uint(0x7f) // "Indexed field count limit reached: %d indexed fields" ErrLocalInstanceIdIsReadOn = uint(0x80) // "The local instance id %u is read-only"ly ErrBackupInProgress = uint(0x81) // "Backup is already in progress" ErrReadViewAborted = uint(0x82) // "The read view is aborted" ErrInvalidIndexFile = uint(0x83) // "Invalid INDEX file %s: %s" ErrInvalidRunFile = uint(0x84) // "Invalid RUN file: %s" ErrInvalidVylogFile = uint(0x85) // "Invalid VYLOG file: %s" ErrCascadeRollback = uint(0x86) // "WAL has a rollback in progress" ErrVyQuotaTimeout = uint(0x87) // "Timed out waiting for Vinyl memory quota" ErrPartialKey = uint(0x88) // "%s index does not support selects via a partial key (expected %u parts, got %u). Please Consider changing index type to TREE." ErrTruncateSystemSpace = uint(0x89) // "Can't truncate a system space, space '%s'" ErrLoadModule = uint(0x8a) // "Failed to dynamically load module '%.*s': %s" ErrVinylMaxTupleSize = uint(0x8b) // "Failed to allocate %u bytes for tuple: tuple is too large. Check 'vinyl_max_tuple_size' configuration option." ErrWrongDdVersion = uint(0x8c) // "Wrong _schema version: expected 'major.minor[.patch]'" ErrWrongSpaceFormat = uint(0x8d) // "Wrong space format field %u: %s" ErrCreateSequence = uint(0x8e) // "Failed to create sequence '%s': %s" ErrAlterSequence = uint(0x8f) // "Can't modify sequence '%s': %s" ErrDropSequence = uint(0x90) // "Can't drop sequence '%s': %s" ErrNoSuchSequence = uint(0x91) // "Sequence '%s' does not exist" ErrSequenceExists = uint(0x92) // "Sequence '%s' already exists" ErrSequenceOverflow = uint(0x93) // "Sequence '%s' has overflowed" ErrNoSuchIndexName = uint(0x94) // "No index '%s' is defined in space '%s'" ErrSpaceFieldIsDuplicate = uint(0x95) // "Space field '%s' is duplicate" ErrCantCreateCollation = uint(0x96) // "Failed to initialize collation: %s." ErrWrongCollationOptions = uint(0x97) // "Wrong collation options: %s" ErrNullablePrimary = uint(0x98) // "Primary index of space '%s' can not contain nullable parts" ErrNoSuchFieldNameInSpace = uint(0x99) // "Field '%s' was not found in space '%s' format" ErrTransactionYield = uint(0x9a) // "Transaction has been aborted by a fiber yield" ErrNoSuchGroup = uint(0x9b) // "Replication group '%s' does not exist" ErrSqlBindValue = uint(0x9c) // "Bind value for parameter %s is out of range for type %s" ErrSqlBindType = uint(0x9d) // "Bind value type %s for parameter %s is not supported" ErrSqlBindParameterMax = uint(0x9e) // "SQL bind parameter limit reached: %d" ErrSqlExecute = uint(0x9f) // "Failed to execute SQL statement: %s" ErrUpdateDecimalOverflow = uint(0xa0) // "Decimal overflow when performing operation '%c' on field %s" ErrSqlBindNotFound = uint(0xa1) // "Parameter %s was not found in the statement" ErrActionMismatch = uint(0xa2) // "Field %s contains %s on conflict action, but %s in index parts" ErrViewMissingSql = uint(0xa3) // "Space declared as a view must have SQL statement" ErrForeignKeyConstraint = uint(0xa4) // "Can not commit transaction: deferred foreign keys violations are not resolved" ErrNoSuchModule = uint(0xa5) // "Module '%s' does not exist" ErrNoSuchCollation = uint(0xa6) // "Collation '%s' does not exist" ErrCreateFkConstraint = uint(0xa7) // "Failed to create foreign key constraint '%s': %s" ErrDropFkConstraint = uint(0xa8) // "Failed to drop foreign key constraint '%s': %s" ErrNoSuchConstraint = uint(0xa9) // "Constraint '%s' does not exist in space '%s'" ErrConstraintExists = uint(0xaa) // "%s constraint '%s' already exists in space '%s'" ErrSqlTypeMismatch = uint(0xab) // "Type mismatch: can not convert %s to %s" ErrRowidOverflow = uint(0xac) // "Rowid is overflowed: too many entries in ephemeral space" ErrDropCollation = uint(0xad) // "Can't drop collation %s : %s" ErrIllegalCollationMix = uint(0xae) // "Illegal mix of collations" ErrSqlNoSuchPragma = uint(0xaf) // "Pragma '%s' does not exist" ErrSqlCantResolveField = uint(0xb0) // "Can’t resolve field '%s'" ErrIndexExistsInSpace = uint(0xb1) // "Index '%s' already exists in space '%s'" ErrInconsistentTypes = uint(0xb2) // "Inconsistent types: expected %s got %s" ErrSqlSyntaxWithPos = uint(0xb3) // "Syntax error at line %d at or near position %d: %s" ErrSqlStackOverflow = uint(0xb4) // "Failed to parse SQL statement: parser stack limit reached" ErrSqlSelectWildcard = uint(0xb5) // "Failed to expand '*' in SELECT statement without FROM clause" ErrSqlStatementEmpty = uint(0xb6) // "Failed to execute an empty SQL statement" ErrSqlKeywordIsReserved = uint(0xb7) // "At line %d at or near position %d: keyword '%.*s' is reserved. Please use double quotes if '%.*s' is an identifier." ErrSqlSyntaxNearToken = uint(0xb8) // "Syntax error at line %d near '%.*s'" ErrSqlUnknownToken = uint(0xb9) // "At line %d at or near position %d: unrecognized token '%.*s'" ErrSqlParserGeneric = uint(0xba) // "%s" ErrSqlAnalyzeArgument = uint(0xbb) // "ANALYZE statement argument %s is not a base table" ErrSqlColumnCountMax = uint(0xbc) // "Failed to create space '%s': space column count %d exceeds the limit (%d)" ErrHexLiteralMax = uint(0xbd) // "Hex literal %s%s length %d exceeds the supported limit (%d)" ErrIntLiteralMax = uint(0xbe) // "Integer literal %s%s exceeds the supported range [-9223372036854775808, 18446744073709551615]" ErrSqlParserLimit = uint(0xbf) // "%s %d exceeds the limit (%d)" ErrIndexDefUnsupported = uint(0xc0) // "%s are prohibited in an index definition" ErrCkDefUnsupported = uint(0xc1) // "%s are prohibited in a ck constraint definition" ErrMultikeyIndexMismatch = uint(0xc2) // "Field %s is used as multikey in one index and as single key in another" ErrCreateCkConstraint = uint(0xc3) // "Failed to create check constraint '%s': %s" ErrCkConstraintFailed = uint(0xc4) // "Check constraint failed '%s': %s" ErrSqlColumnCount = uint(0xc5) // "Unequal number of entries in row expression: left side has %u, but right side - %u" ErrFuncIndexFunc = uint(0xc6) // "Failed to build a key for functional index '%s' of space '%s': %s" ErrFuncIndexFormat = uint(0xc7) // "Key format doesn't match one defined in functional index '%s' of space '%s': %s" ErrFuncIndexParts = uint(0xc8) // "Wrong functional index definition: %s" ErrNoSuchFieldName = uint(0xc9) // "Field '%s' was not found in the tuple" ErrFuncWrongArgCount = uint(0xca) // "Wrong number of arguments is passed to %s(): expected %s, got %d" ErrBootstrapReadonly = uint(0xcb) // "Trying to bootstrap a local read-only instance as master" ErrSqlFuncWrongRetCount = uint(0xcc) // "SQL expects exactly one argument returned from %s, got %d" ErrFuncInvalidReturnType = uint(0xcd) // "Function '%s' returned value of invalid type: expected %s got %s" ErrSqlParserGenericWithPos = uint(0xce) // "At line %d at or near position %d: %s" ErrReplicaNotAnon = uint(0xcf) // "Replica '%s' is not anonymous and cannot register." ErrCannotRegister = uint(0xd0) // "Couldn't find an instance to register this replica on." ErrSessionSettingInvalidVa = uint(0xd1) // "Session setting %s expected a value of type %s"lue ErrSqlPrepare = uint(0xd2) // "Failed to prepare SQL statement: %s" ErrWrongQueryId = uint(0xd3) // "Prepared statement with id %u does not exist" ErrSequenceNotStarted = uint(0xd4) // "Sequence '%s' is not started" ErrNoSuchSessionSetting = uint(0xd5) // "Session setting %s doesn't exist" ErrUncommittedForeignSyncT = uint(0xd6) // "Found uncommitted sync transactions from other instance with id %u"xns ErrSyncMasterMismatch = uint(0xd7) // "CONFIRM message arrived for an unknown master id %d, expected %d" ErrSyncQuorumTimeout = uint(0xd8) // "Quorum collection for a synchronous transaction is timed out" ErrSyncRollback = uint(0xd9) // "A rollback for a synchronous transaction is received" ErrTupleMetadataIsTooBig = uint(0xda) // "Can't create tuple: metadata size %u is too big" ErrXlogGap = uint(0xdb) // "Missing .xlog file between LSN %lld %s and %lld %s" ErrTooEarlySubscribe = uint(0xdc) // "Can't subscribe non-anonymous replica %s until join is done" ErrSqlCantAddAutoinc = uint(0xdd) // "Can't add AUTOINCREMENT: space %s can't feature more than one AUTOINCREMENT field" ErrQuorumWait = uint(0xde) // "Couldn't wait for quorum %d: %s" ErrInterferingPromote = uint(0xdf) // "Instance with replica id %u was promoted first" ErrElectionDisabled = uint(0xe0) // "Elections were turned off" ErrTxnRollback = uint(0xe1) // "Transaction was rolled back" ErrNotLeader = uint(0xe2) // "The instance is not a leader. New leader is %u" ErrSyncQueueUnclaimed = uint(0xe3) // "The synchronous transaction queue doesn't belong to any instance" ErrSyncQueueForeign = uint(0xe4) // "The synchronous transaction queue belongs to other instance with id %u" ErrUnableToProcessInStream = uint(0xe5) // "Unable to process %s request in stream" ErrUnableToProcessOutOfStr = uint(0xe6) // "Unable to process %s request out of stream"eam ErrTransactionTimeout = uint(0xe7) // "Transaction has been aborted by timeout" ErrActiveTimer = uint(0xe8) // "Operation is not permitted if timer is already running" ErrTupleFieldCountLimit = uint(0xe9) // "Tuple field count limit reached: see box.schema.FIELD_MAX" ErrCreateConstraint = uint(0xea) // "Failed to create constraint '%s' in space '%s': %s" ErrFieldConstraintFailed = uint(0xeb) // "Check constraint '%s' failed for field '%s'" ErrTupleConstraintFailed = uint(0xec) // "Check constraint '%s' failed for tuple" ErrCreateForeignKey = uint(0xed) // "Failed to create foreign key '%s' in space '%s': %s" ErrForeignKeyIntegrity = uint(0xee) // "Foreign key '%s' integrity check failed: %s" ErrFieldForeignKeyFailed = uint(0xef) // "Foreign key constraint '%s' failed for field '%s': %s" ErrComplexForeignKeyFailed = uint(0xf0) // "Foreign key constraint '%s' failed: %s" ErrWrongSpaceUpgradeOption = uint(0xf1) // "Wrong space upgrade options: %s"s ErrNoElectionQuorum = uint(0xf2) // "Not enough peers connected to start elections: %d out of minimal required %d" ErrSsl = uint(0xf3) // "%s" ErrSplitBrain = uint(0xf4) // "Split-Brain discovered: %s" ErrOldTerm = uint(0xf5) // "The term is outdated: old - %llu, new - %llu" ErrInterferingElections = uint(0xf6) // "Interfering elections started" ErrIteratorPosition = uint(0xf7) // "Iterator position is invalid" ErrDefaultValueType = uint(0xf8) // "Type of the default value does not match tuple field %s type: expected %s, got %s" ErrUnknownAuthMethod = uint(0xf9) // "Unknown authentication method '%s'" ErrInvalidAuthData = uint(0xfa) // "Invalid '%s' data: %s" ErrInvalidAuthRequest = uint(0xfb) // "Invalid '%s' request: %s" ErrWeakPassword = uint(0xfc) // "Password doesn't meet security requirements: %s" ErrOldPassword = uint(0xfd) // "Password must differ from last %d passwords" ErrNoSuchSession = uint(0xfe) // "Session %llu does not exist" ErrWrongSessionType = uint(0xff) // "Session '%s' is not supported" ErrPasswordExpired = uint(0x100) // "Password expired" ErrAuthDelay = uint(0x101) // "Too many authentication attempts" ErrAuthRequired = uint(0x102) // "Authentication required" ErrSqlSeqScan = uint(0x103) // "Scanning is not allowed for %s" ErrNoSuchEvent = uint(0x104) // "Unknown event %s" ErrBootstrapNotUnanimous = uint(0x105) // "Replica %s chose a different bootstrap leader %s" ErrCantCheckBootstrapLeade = uint(0x106) // "Can't check who replica %s chose its bootstrap leader"r ErrBootstrapConnectionNotT = uint(0x107) // "Some replica set members were not specified in box.cfg.replication"oAll ErrNilUuid = uint(0x108) // "Nil UUID is reserved and can't be used in replication" ErrWrongFunctionOptions = uint(0x109) // "Wrong function options: %s" ErrMissingSystemSpaces = uint(0x10a) // "Snapshot has no system spaces" ErrClusterNameMismatch = uint(0x10b) // "Cluster name mismatch: expected %s, got %s" ErrReplicasetNameMismatch = uint(0x10c) // "Replicaset name mismatch: expected %s, got %s" ErrInstanceNameDuplicate = uint(0x10d) // "Duplicate replica name %s, already occupied by %s" ErrInstanceNameMismatch = uint(0x10e) // "Instance name mismatch: expected %s, got %s" ErrSchemaNeedsUpgrade = uint(0x10f) // "Your schema version is %u.%u.%u while Tarantool %s requires a more recent schema version. Please, consider using box.schema.upgrade()." ErrSchemaUpgradeInProgress = uint(0x110) // "Schema upgrade is already in progress" )
Tarantool server error codes
const ( ResultDefaultMode resultUnmarshalMode = iota ResultAsRawData ResultAsDataWithFallback ResultAsData = ResultDefaultMode )
const (
DefaultIndex = "primary"
)
const (
GreetingSize = 128
)
const (
ServerIdent = "Tarantool 1.6.8 (Binary)"
)
Variables ¶
var ( ErrInvalidGreeting = errors.New("invalid greeting") ErrEmptyDefaultSpace = errors.New("zero-length default space or unnecessary slash in dsn.path") ErrSyncFailed = errors.New("SYNC failed") )
var ( DefaultLimit = 250 DefaultConnectTimeout = time.Second DefaultQueryTimeout = time.Second DefaultReaderBufSize = 16 * 1024 DefaultWriterBufSize = 4 * 1024 DefaultMaxPoolPacketSize = 64 * 1024 )
var ( // ErrNotSupported is returned when an unimplemented query type or operation is encountered. ErrNotSupported = NewQueryError(ErrUnsupported, "not supported yet") // ErrNotInReplicaSet means that join operation can not be performed on a replica set due to missing parameters. ErrNotInReplicaSet = NewQueryError(0, "Full Replica Set params hasn't been set") // ErrBadResult means that query result was of invalid type or length. ErrBadResult = NewQueryError(0, "invalid result") // ErrVectorClock is returns in case of bad manipulation with vector clock. ErrVectorClock = NewQueryError(0, "vclock manipulation") // ErrUnknownError is returns when ErrorCode isn't OK but Error is nil in Result. ErrUnknownError = NewQueryError(ErrUnknown, "unknown error") // ErrOldVersionAnon is returns when tarantool version doesn't support anonymous replication. ErrOldVersionAnon = errors.New("tarantool version is too old for anonymous replication. Min version is 2.3.1") // ErrConnectionClosed returns when connection is no longer alive. ErrConnectionClosed = errors.New("connection closed") )
var ( ExecResultAsRawData = ResultModeExecOption(ResultAsRawData) ExecResultAsDataWithFallback = ResultModeExecOption(ResultAsDataWithFallback) )
var (
ErrPortAlreadyInUse = errors.New("port already in use")
)
Functions ¶
Types ¶
type AnonSlave ¶
type AnonSlave struct {
Slave
}
AnonSlave connects to Tarantool >= 2.3.1 instance and subscribes for changes as anonymous replica. Tarantool instance acting as a master sees AnonSlave like anonymous replica. AnonSlave can't be used concurrently, route responses from returned channel instead.
func NewAnonSlave ¶
NewAnonSlave returns new AnonSlave instance. URI is parsed by url package and therefore should contains any scheme supported by net.Dial.
func (*AnonSlave) Attach ¶
func (s *AnonSlave) Attach(out ...chan *Packet) (it PacketIterator, err error)
Attach AnonSlave to Replica Set as an anonymous and subscribe for the new(!) DML requests. Attach calls Join and then Subscribe with VClock = s.VClock[1:]... If didn't call Join before Attach then you need to set VClock first either manually or using JoinWithSnap. Use out chan for asynchronous packet receiving or synchronous PacketIterator otherwise. If you need all requests in chan use JoinWithSnap(chan) and then s.Subscribe(s.VClock[1:]...).
func (*AnonSlave) JoinWithSnap ¶
func (s *AnonSlave) JoinWithSnap(out ...chan *Packet) (it PacketIterator, err error)
JoinWithSnap fetch snapshots from Master instance. Snapshot logs is available through the given out channel or returned PacketIterator. (In truth, Slave itself is returned in PacketIterator wrapper)
func (*AnonSlave) Subscribe ¶
func (s *AnonSlave) Subscribe(lsns ...uint64) (it PacketIterator, err error)
Subscribe for DML requests (insert, update, delete, replace, upsert) since vector clock. Variadic lsn is start vector clock. Each lsn is one clock in vector (sequentially). One lsn is enough for master-slave replica set. Subscribe sends requests asynchronously to out channel specified or use synchronous PacketIterator otherwise. For anonymous replica it is not necessary to call Join or JoinWithSnap before Subscribe.
type AsyncResult ¶
type AsyncResult struct { ErrorCode uint Error error BinaryPacket *BinaryPacket Connection *Connection Opaque interface{} }
type Auth ¶
func (*Auth) GetCommandID ¶
func (*Auth) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type BinaryPacket ¶
type BinaryPacket struct {
// contains filtered or unexported fields
}
func (*BinaryPacket) Bytes ¶
func (pp *BinaryPacket) Bytes() []byte
func (*BinaryPacket) ReadFrom ¶
func (pp *BinaryPacket) ReadFrom(r io.Reader) (n int64, err error)
ReadFrom implements the io.ReaderFrom interface
func (*BinaryPacket) Release ¶
func (pp *BinaryPacket) Release()
func (*BinaryPacket) Reset ¶
func (pp *BinaryPacket) Reset()
func (*BinaryPacket) Result ¶
func (pp *BinaryPacket) Result() *Result
func (*BinaryPacket) Unmarshal ¶
func (pp *BinaryPacket) Unmarshal() error
func (*BinaryPacket) UnmarshalCustomBody ¶
func (pp *BinaryPacket) UnmarshalCustomBody(um UnmarshalBinaryBodyFunc) (err error)
type BinaryPacketPool ¶
type BinaryPacketPool struct {
// contains filtered or unexported fields
}
func (*BinaryPacketPool) Close ¶
func (p *BinaryPacketPool) Close()
func (*BinaryPacketPool) Get ¶
func (p *BinaryPacketPool) Get() *BinaryPacket
func (*BinaryPacketPool) GetWithID ¶
func (p *BinaryPacketPool) GetWithID(requestID uint64) (pp *BinaryPacket)
func (*BinaryPacketPool) Put ¶
func (p *BinaryPacketPool) Put(pp *BinaryPacket)
type Box ¶
type Box struct { Root string WorkDir string Port uint Listen string // contains filtered or unexported fields }
Box is tarantool instance. For start/stop tarantool in tests
type BoxOptions ¶
type Call ¶
type Call struct { Name string Tuple []interface{} }
func (*Call) GetCommandID ¶
func (*Call) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Call17 ¶
type Call17 struct { Name string Tuple []interface{} }
Call17 is available since Tarantool >= 1.7.2
func (*Call17) GetCommandID ¶
func (*Call17) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func Connect ¶
func Connect(dsnString string, options *Options) (conn *Connection, err error)
Connect to tarantool instance with options
func ConnectContext ¶
func ConnectContext(ctx context.Context, dsnString string, options *Options) (conn *Connection, err error)
Connect to tarantool instance with options using the provided context. Returned Connection can be used to execute queries.
func (*Connection) Close ¶
func (conn *Connection) Close()
func (*Connection) Exec ¶
func (conn *Connection) Exec(ctx context.Context, q Query, options ...ExecOption) (result *Result)
func (*Connection) ExecAsync ¶
func (conn *Connection) ExecAsync( ctx context.Context, q Query, opaque interface{}, replyChan chan *AsyncResult, options ...ExecOption, ) error
func (*Connection) Execute ¶
func (conn *Connection) Execute(q Query) ([][]interface{}, error)
func (*Connection) GetPerf ¶
func (conn *Connection) GetPerf() PerfCount
func (*Connection) GetPrimaryKeyFields ¶
func (conn *Connection) GetPrimaryKeyFields(space interface{}) ([]int, bool)
func (*Connection) InstanceUUID ¶ added in v1.2.2
func (conn *Connection) InstanceUUID() string
func (*Connection) IsClosed ¶
func (conn *Connection) IsClosed() bool
func (*Connection) String ¶
func (conn *Connection) String() string
type ConnectionError ¶
type ConnectionError struct {
// contains filtered or unexported fields
}
ConnectionError is returned when something have been happened with connection.
func ConnectionClosedError ¶
func ConnectionClosedError(con *Connection) *ConnectionError
ConnectionClosedError returns ConnectionError with message about closed connection or error depending on the connection state. It is also has remoteAddr in error text.
func NewConnectionError ¶
func NewConnectionError(con *Connection, err error) *ConnectionError
NewConnectionError returns ConnectionError, which contains wrapped with remoteAddr error.
func (*ConnectionError) Temporary ¶
func (e *ConnectionError) Temporary() bool
Temporary implements Error interface.
func (*ConnectionError) Timeout ¶
func (e *ConnectionError) Timeout() bool
Timeout implements net.Error interface.
func (*ConnectionError) Unwrap ¶ added in v1.1.4
func (e *ConnectionError) Unwrap() error
type Connector ¶
func (*Connector) Connect ¶
func (c *Connector) Connect() (conn *Connection, err error)
Connect returns existing connection or will establish another one.
func (*Connector) ConnectContext ¶
func (c *Connector) ConnectContext(ctx context.Context) (conn *Connection, err error)
Connect returns existing connection or will establish another one using the provided context.
type ContextError ¶
type ContextError struct { CtxErr error // contains filtered or unexported fields }
ContextError is returned when request has been ended with context timeout or cancel.
func NewContextError ¶
func NewContextError(ctx context.Context, con *Connection, message string) *ContextError
NewContextError returns ContextError with message and remoteAddr in error text. It is also has context error itself in CtxErr.
func (*ContextError) Temporary ¶
func (e *ContextError) Temporary() bool
Temporary implements Error interface.
func (*ContextError) Timeout ¶
func (e *ContextError) Timeout() bool
Timeout implements net.Error interface.
func (*ContextError) Unwrap ¶ added in v1.1.4
func (e *ContextError) Unwrap() error
type CountedReader ¶
type CountedReader struct {
// contains filtered or unexported fields
}
func NewCountedReader ¶
func NewCountedReader(r io.Reader, c *expvar.Int) *CountedReader
type CountedWriter ¶
type CountedWriter struct {
// contains filtered or unexported fields
}
func NewCountedWriter ¶
func NewCountedWriter(w io.Writer, c *expvar.Int) *CountedWriter
type Delete ¶
type Delete struct { Space interface{} Index interface{} Key interface{} KeyTuple []interface{} }
func (*Delete) GetCommandID ¶
func (*Delete) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Error ¶
Error has Temporary method which returns true if error is temporary. It is useful to quickly decide retry or not retry.
type Eval ¶
type Eval struct { Expression string Tuple []interface{} }
Eval query
func (*Eval) GetCommandID ¶
func (*Eval) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type ExecOption ¶
type ExecOption interface {
// contains filtered or unexported methods
}
func OpaqueExecOption ¶
func OpaqueExecOption(opaque interface{}) ExecOption
func ResultModeExecOption ¶ added in v1.2.0
func ResultModeExecOption(mode resultUnmarshalMode) ExecOption
type FetchSnapshot ¶
type FetchSnapshot struct{}
FetchSnapshot is the FETCH_SNAPSHOT command
func (*FetchSnapshot) GetCommandID ¶
func (q *FetchSnapshot) GetCommandID() uint
func (*FetchSnapshot) MarshalMsg ¶
func (q *FetchSnapshot) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (*FetchSnapshot) UnmarshalMsg ¶
func (q *FetchSnapshot) UnmarshalMsg([]byte) (buf []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type Insert ¶
type Insert struct { Space interface{} Tuple []interface{} }
func (*Insert) GetCommandID ¶
func (*Insert) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type IprotoServer ¶
func NewIprotoServer ¶
func NewIprotoServer(uuid string, handler QueryHandler, onShutdown OnShutdownCallback) *IprotoServer
func (*IprotoServer) Accept ¶
func (s *IprotoServer) Accept(conn net.Conn)
func (*IprotoServer) CheckAuth ¶
func (s *IprotoServer) CheckAuth(hash []byte, password string) bool
func (*IprotoServer) Shutdown ¶
func (s *IprotoServer) Shutdown() error
func (*IprotoServer) WithOptions ¶
func (s *IprotoServer) WithOptions(opts *IprotoServerOptions) *IprotoServer
type IprotoServerOptions ¶
type IprotoServerOptions struct { Perf PerfCount GetPingStatus func(*IprotoServer) uint }
type Join ¶
type Join struct {
UUID string
}
Join is the JOIN command
func (*Join) GetCommandID ¶
func (*Join) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type OnShutdownCallback ¶
type OnShutdownCallback func(err error)
type Options ¶
type Options struct { ConnectTimeout time.Duration QueryTimeout time.Duration DefaultSpace string User string Password string UUID string ReplicaSetUUID string Perf PerfCount // PoolMaxPacketSize describes maximum size of packet buffer // that can be added to packet pool. // If the packet size is 0, option is ignored. PoolMaxPacketSize int ResultUnmarshalMode resultUnmarshalMode // Result unmarshal mode for user made requests }
type Packet ¶
type Packet struct { Cmd uint LSN uint64 SchemaID uint64 InstanceID uint32 Timestamp time.Time Request Query Result *Result ResultUnmarshalMode resultUnmarshalMode // contains filtered or unexported fields }
func (*Packet) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*Packet) UnmarshalBinaryBody ¶
func (*Packet) UnmarshalBinaryHeader ¶
type PacketIterator ¶
PacketIterator is a wrapper around Slave provided iteration over new Packets functionality.
type Ping ¶
type Ping struct { }
func (*Ping) GetCommandID ¶
func (*Ping) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type QueryCompleteFn ¶
type QueryError ¶
type QueryError struct { Code uint // contains filtered or unexported fields }
QueryError is returned when query error has been happened. It has error Code.
func NewQueryError ¶
func NewQueryError(code uint, message string) *QueryError
NewQueryError returns QueryError with message and Code.
func (*QueryError) Temporary ¶
func (e *QueryError) Temporary() bool
Temporary implements Error interface.
func (*QueryError) Timeout ¶
func (e *QueryError) Timeout() bool
Timeout implements net.Error interface.
func (*QueryError) Unwrap ¶ added in v1.1.4
func (e *QueryError) Unwrap() error
type Register ¶
type Register struct { UUID string VClock VectorClock }
Register is the REGISTER command
func (*Register) GetCommandID ¶
func (*Register) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Replace ¶
type Replace struct { Space interface{} Tuple []interface{} }
func (*Replace) GetCommandID ¶
func (*Replace) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type ReplicaSet ¶
type ReplicaSet struct { UUID string Instances []string // Instances is read-only set of the instances uuid }
ReplicaSet is used to store params of the Replica Set.
func (*ReplicaSet) Has ¶
func (rs *ReplicaSet) Has(id uint32) bool
Has ReplicaSet specified instance?
func (*ReplicaSet) SetInstance ¶
func (rs *ReplicaSet) SetInstance(id uint32, uuid string) bool
SetInstance uuid in instance set.
type Result ¶
type Result struct { ErrorCode uint Error error // Data is a parsed array of tuples. // Keep in mind that by default if original data structure it's unmarhsalled from // has a different type it's forcefully wrapped to become array of tuples. This might be // the case for call17 or eval commands. You may overwrite this behavior by specifying // desired unmarshal mode. Data [][]interface{} RawData interface{} // contains filtered or unexported fields }
func (*Result) GetCommandID ¶
func (*Result) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Result) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
type Select ¶
type Select struct { Space interface{} Index interface{} Offset uint32 Limit uint32 Iterator uint8 Key interface{} KeyTuple []interface{} }
func (*Select) GetCommandID ¶
func (*Select) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Slave ¶
type Slave struct { UUID string VClock VectorClock ReplicaSet ReplicaSet // contains filtered or unexported fields }
Slave connects to Tarantool 1.6, 1.7 or 1.10 instance and subscribes for changes. Tarantool instance acting as a master sees Slave like any replica in replication set. Slave can't be used concurrently, route responses from returned channel instead.
Example (SubscribeExisted) ¶
package main import ( "log" "strings" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Subscribe for master's changes synchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("127.0.0.1:8000", tnt16.Options{ User: "username", Password: "password", // UUID of the instance in replica set. Required UUID: "7c025e42-2394-11e7-aacf-0242ac110002", // UUID of the Replica Set. Required ReplicaSetUUID: "3b39c6a4-f2da-4d81-a43b-103e5b1c16a1"}) if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // let's start from the beginning var lsn uint64 = 0 it, err := s.Subscribe(lsn) if err != nil { log.Printf("Tnt Slave subscribing error:%v", err) return } // print snapshot var p *tnt16.Packet var hr = strings.Repeat("-", 80) // iterate over master's changes permanently for { p, err = it.Next() if err != nil { log.Printf("Tnt Slave iterating error:%v", err) return } log.Println(p) log.Println(hr) } }
Output:
Example (SubscribeNew) ¶
package main import ( "log" "strings" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Silently join slave to Replica Set and consume master's changes synchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("username:password@127.0.0.1:8000") if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // let's start from the beginning it, err := s.Attach() if err != nil { log.Printf("Tnt Slave subscribing error:%v", err) return } // print snapshot var p *tnt16.Packet var hr = strings.Repeat("-", 80) // iterate over master's changes permanently for { p, err = it.Next() if err != nil { log.Printf("Tnt Slave iterating error:%v", err) return } log.Println(p) log.Println(hr) } }
Output:
func NewSlave ¶
NewSlave instance with tarantool master uri. URI is parsed by url package and therefore should contains any scheme supported by net.Dial.
func (*Slave) Attach ¶
func (s *Slave) Attach(out ...chan *Packet) (it PacketIterator, err error)
Attach Slave to Replica Set and subscribe for the new(!) DML requests. Use out chan for asynchronous packet receiving or synchronous PacketIterator otherwise. If you need all requests in chan use JoinWithSnap(chan) and then s.Subscribe(s.VClock[1:]...).
Example (Async) ¶
package main import ( "log" "strings" "sync" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Silently join slave to Replica Set and consume master's changes asynchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("username:password@127.0.0.1:8000") if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // chan for snapshot's packets xlogChan := make(chan *tnt16.Packet, 128) wg := &sync.WaitGroup{} // run xlog printer before subscribing command wg.Add(1) go func(in <-chan *tnt16.Packet, wg *sync.WaitGroup) { defer wg.Done() var hr = strings.Repeat("-", 80) for p := range in { log.Println(hr) switch q := p.Request.(type) { case *tnt16.Insert: switch q.Space { case tnt16.SpaceIndex, tnt16.SpaceSpace: // short default format log.Printf("Insert LSN:%v, Space:%v InstanceID:%v\n", p.LSN, q.Space, p.InstanceID) default: log.Printf("%v", p) } default: log.Printf("%v", p) } } }(xlogChan, wg) // let's start from the beginning _, err = s.Attach(xlogChan) if err != nil { log.Printf("Tnt Slave subscribing error:%v", err) return } // consume master's changes permanently wg.Wait() }
Output:
Example (Sync) ¶
package main import ( "log" "strings" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Silently join slave to Replica Set and consume master's changes synchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("username:password@127.0.0.1:8000") if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // let's start from the beginning it, err := s.Attach() if err != nil { log.Printf("Tnt Slave subscribing error:%v", err) return } // print snapshot var p *tnt16.Packet var hr = strings.Repeat("-", 80) // consume master's changes permanently for { p, err = it.Next() if err != nil { log.Printf("Tnt Slave consuming error:%v", err) return } log.Println(hr) switch q := p.Request.(type) { case *tnt16.Insert: switch q.Space { case tnt16.SpaceIndex, tnt16.SpaceSpace: // short default format log.Printf("Insert LSN:%v, Space:%v InstanceID:%v\n", p.LSN, q.Space, p.InstanceID) default: log.Printf("%v", p) } default: log.Printf("%v", p) } } }
Output:
func (*Slave) IsInReplicaSet ¶
IsInReplicaSet checks whether Slave has Replica Set params or not.
func (*Slave) Join ¶
Join the Replica Set using Master instance.
Example ¶
package main import ( "log" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Silently join slave to Replica Set // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("username:password@127.0.0.1:8000") if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() if err = s.Join(); err != nil { log.Printf("Tnt Slave joining error:%v", err) return } log.Printf("UUID=%#v Replica Set UUID=%#v\n", s.UUID, s.ReplicaSet.UUID) }
Output:
func (*Slave) JoinWithSnap ¶
func (s *Slave) JoinWithSnap(out ...chan *Packet) (it PacketIterator, err error)
JoinWithSnap the Replica Set using Master instance. Snapshot logs is available through the given out channel or returned PacketIterator. (In truth, Slave itself is returned in PacketIterator wrapper)
Example (Async) ¶
package main import ( "log" "strings" "sync" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Join slave to Replica Set with iterating snapshot asynchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("username:password@127.0.0.1:8000") if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // chan for snapshot's packets snapChan := make(chan *tnt16.Packet, 128) wg := &sync.WaitGroup{} // run snapshot printer before join command wg.Add(1) go func(in <-chan *tnt16.Packet, wg *sync.WaitGroup) { defer wg.Done() var hr = strings.Repeat("-", 80) for p := range in { log.Println(hr) switch q := p.Request.(type) { case *tnt16.Insert: switch q.Space { case tnt16.SpaceIndex, tnt16.SpaceSpace: // short default format log.Printf("Insert LSN:%v, Space:%v InstanceID:%v\n", p.LSN, q.Space, p.InstanceID) default: log.Printf("%v", p) } default: log.Printf("%v", p) } } }(snapChan, wg) _, err = s.JoinWithSnap(snapChan) if err != nil { log.Printf("Tnt Slave joining error:%v", err) return } wg.Wait() log.Printf("UUID=%#v Replica Set UUID=%#v\n", s.UUID, s.ReplicaSet.UUID) }
Output:
Example (Sync) ¶
package main import ( "log" "strings" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Join slave to Replica Set with iterating snapshot synchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("username:password@127.0.0.1:8000") if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // skip returned iterator; will be using self bufio.scanner-style iterator instead _, err = s.JoinWithSnap() if err != nil { log.Printf("Tnt Slave joining error:%v", err) return } // print snapshot var p *tnt16.Packet var hr = strings.Repeat("-", 80) for s.HasNext() { p = s.Packet() // print request log.Println(hr) switch q := p.Request.(type) { case *tnt16.Insert: switch q.Space { case tnt16.SpaceIndex, tnt16.SpaceSpace: // short default format log.Printf("Insert LSN:%v, Space:%v InstanceID:%v\n", p.LSN, q.Space, p.InstanceID) default: log.Printf("%v", p) } default: log.Printf("%v", p) } } // always checks for errors after iteration cycle if s.Err() != nil { log.Printf("Tnt Slave joining error:%v", err) return } log.Printf("UUID=%#v Replica Set UUID=%#v\n", s.UUID, s.ReplicaSet.UUID) }
Output:
func (*Slave) LastSnapVClock ¶
func (s *Slave) LastSnapVClock() (VectorClock, error)
func (*Slave) Subscribe ¶
func (s *Slave) Subscribe(lsns ...uint64) (it PacketIterator, err error)
Subscribe for DML requests (insert, update, delete, replace, upsert) since vector clock. Variadic lsn is start vector clock. Each lsn is one clock in vector (sequentially). One lsn is enough for master-slave replica set. Replica Set and self UUID should be set before call subscribe. Use options in New or Join for it. Subscribe sends requests asynchronously to out channel specified or use synchronous PacketIterator otherwise.
Example (Async) ¶
package main import ( "log" "strings" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Subscribe for master's changes asynchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("127.0.0.1:8000", tnt16.Options{ User: "username", Password: "password", // UUID of the instance in replica set. Required UUID: "7c025e42-2394-11e7-aacf-0242ac110002", // UUID of the Replica Set. Required ReplicaSetUUID: "3b39c6a4-f2da-4d81-a43b-103e5b1c16a1"}) if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // chan for snapshot's packets xlogChan := make(chan *tnt16.Packet, 128) // run xlog printer before subscribing command go func(in <-chan *tnt16.Packet) { var hr = strings.Repeat("-", 80) for p := range in { log.Println(hr) switch q := p.Request.(type) { case *tnt16.Insert: switch q.Space { case tnt16.SpaceIndex, tnt16.SpaceSpace: // short default format log.Printf("Insert LSN:%v, Space:%v InstanceID:%v\n", p.LSN, q.Space, p.InstanceID) default: log.Printf("%v", p) } default: log.Printf("%v", p) } } }(xlogChan) // let's start from the beginning var lsn uint64 = 0 it, err := s.Subscribe(lsn) if err != nil { log.Printf("Tnt Slave subscribing error:%v", err) return } // consume requests infinitely var p *tnt16.Packet for { p, err = it.Next() if err != nil { close(xlogChan) log.Printf("Tnt Slave consuming error:%v", err) return } xlogChan <- p } }
Output:
Example (Sync) ¶
package main import ( "log" "strings" tnt16 "github.com/viciious/go-tarantool" ) func main() { // Subscribe for master's changes synchronously // new slave instance connects to provided dsn instantly s, err := tnt16.NewSlave("127.0.0.1:8000", tnt16.Options{ User: "username", Password: "password", // UUID of the instance in replica set. Required UUID: "7c025e42-2394-11e7-aacf-0242ac110002", // UUID of the Replica Set. Required ReplicaSetUUID: "3b39c6a4-f2da-4d81-a43b-103e5b1c16a1"}) if err != nil { log.Printf("Tnt Slave creating error:%v", err) return } // always close slave to preserve socket descriptor defer s.Close() // let's start from the beginning var lsn uint64 = 0 it, err := s.Subscribe(lsn) if err != nil { log.Printf("Tnt Slave subscribing error:%v", err) return } // print snapshot var p *tnt16.Packet var hr = strings.Repeat("-", 80) // consume master's changes permanently for { p, err = it.Next() if err != nil { log.Printf("Tnt Slave consuming error:%v", err) return } log.Println(hr) switch q := p.Request.(type) { case *tnt16.Insert: switch q.Space { case tnt16.SpaceIndex, tnt16.SpaceSpace: // short default format log.Printf("Insert LSN:%v, Space:%v InstanceID:%v\n", p.LSN, q.Space, p.InstanceID) default: log.Printf("%v", p) } default: log.Printf("%v", p) } } }
Output:
type Subscribe ¶
type Subscribe struct { UUID string ReplicaSetUUID string VClock VectorClock Anon bool }
Subscribe is the SUBSCRIBE command
func (*Subscribe) GetCommandID ¶
func (*Subscribe) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type SubscribeResponse ¶
type SubscribeResponse struct { ReplicaSetUUID string VClock VectorClock }
func (*SubscribeResponse) UnmarshalMsg ¶
func (sr *SubscribeResponse) UnmarshalMsg(data []byte) (buf []byte, err error)
UnmarshalMsg implements msgp.Unmarshaller
type UnexpectedReplicaSetUUIDError ¶
type UnexpectedReplicaSetUUIDError struct { QueryError Expected string Got string }
UnexpectedReplicaSetUUIDError is returned when ReplicaSetUUID set in Options.ReplicaSetUUID is not equal to ReplicaSetUUID received during Join or JoinWithSnap. It is only an AnonSlave error!
func NewUnexpectedReplicaSetUUIDError ¶
func NewUnexpectedReplicaSetUUIDError(expected string, got string) *UnexpectedReplicaSetUUIDError
NewUnexpectedReplicaSetUUIDError returns UnexpectedReplicaSetUUIDError.
func (*UnexpectedReplicaSetUUIDError) Is ¶
func (e *UnexpectedReplicaSetUUIDError) Is(target error) bool
Is for errors comparison
func (*UnexpectedReplicaSetUUIDError) Unwrap ¶ added in v1.1.4
func (e *UnexpectedReplicaSetUUIDError) Unwrap() error
type UnmarshalBinaryBodyFunc ¶
type Update ¶
type Update struct { Space interface{} Index interface{} Key interface{} KeyTuple []interface{} Set []Operator }
func (*Update) GetCommandID ¶
func (*Update) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Upsert ¶
type Upsert struct { Space interface{} Tuple []interface{} Set []Operator }
func (*Upsert) GetCommandID ¶
func (*Upsert) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type VClock ¶
type VClock struct { RequestID uint64 // RequestID is SYNC field; InstanceID uint32 VClock VectorClock }
VClock response (in OK). Similar to Result struct
func (*VClock) GetCommandID ¶
func (*VClock) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*VClock) UnmarshalBinaryBody ¶
func (*VClock) UnmarshalBinaryHeader ¶
type VectorClock ¶
type VectorClock []uint64
VectorClock is used to store logical clocks (direct dependency clock implementation). Zero index is always reserved for internal use. You can get any lsn indexing VectorClock by instance ID directly (without any index offset). One can count instances in vector just using built-in len function.
func NewVectorClock ¶
func NewVectorClock(lsns ...uint64) VectorClock
NewVectorClock returns VectorClock with clocks equal to the given lsn elements sequentially. Empty VectorClock would be returned if no lsn elements is given.
func (VectorClock) Clone ¶
func (vc VectorClock) Clone() VectorClock
Source Files
¶
- anon_slave.go
- auth.go
- binpacket.go
- binpacket_pool.go
- box.go
- call.go
- call17.go
- connection.go
- connector.go
- const.go
- countio.go
- defaults.go
- delete.go
- error.go
- eval.go
- execute.go
- fetch_snapshot.go
- insert.go
- iterator.go
- join.go
- operator.go
- pack_data.go
- packet.go
- ping.go
- query.go
- register.go
- replace.go
- request_map.go
- request_pool.go
- result.go
- select.go
- server.go
- slave.go
- subscribe.go
- tnt.go
- tuple.go
- update.go
- upsert.go
- vclock.go