Skip to content

Commit

Permalink
api: remove unnecessary IPROTO constants
Browse files Browse the repository at this point in the history
We will have a separate package for it [1].

1. #267

Part of #158
  • Loading branch information
oleg-jukovec committed Apr 20, 2023
1 parent fa1a093 commit 656a8f4
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 236 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- pool/RoundRobinStrategy (#158)
- DeadlineIO (#158)
- UUID_extId (#158)
- IPROTO constants (#158)

### Fixed

Expand Down
16 changes: 8 additions & 8 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type Connection struct {
opts Opts
state uint32
dec *msgpack.Decoder
lenbuf [PacketLengthBytes]byte
lenbuf [packetLengthBytes]byte

lastStreamId uint64

Expand Down Expand Up @@ -405,8 +405,8 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
ter, ok := err.(Error)
if conn.opts.Reconnect <= 0 {
return nil, err
} else if ok && (ter.Code == ErrNoSuchUser ||
ter.Code == ErrPasswordMismatch) {
} else if ok && (ter.Code == errNoSuchUser ||
ter.Code == errPasswordMismatch) {
// Reported auth errors immediately.
return nil, err
} else {
Expand Down Expand Up @@ -583,7 +583,7 @@ func pack(h *smallWBuf, enc *msgpack.Encoder, reqid uint32,
hMapLen := byte(0x82) // 2 element map.
if streamId != ignoreStreamId {
hMapLen = byte(0x83) // 3 element map.
streamBytes[0] = KeyStreamId
streamBytes[0] = keyStreamId
if streamId > math.MaxUint32 {
streamBytesLen = streamBytesLenUint64
streamBytes[1] = uint64Code
Expand All @@ -598,8 +598,8 @@ func pack(h *smallWBuf, enc *msgpack.Encoder, reqid uint32,
hBytes := append([]byte{
uint32Code, 0, 0, 0, 0, // Length.
hMapLen,
KeyCode, byte(req.Code()), // Request code.
KeySync, uint32Code,
keyCode, byte(req.Code()), // Request code.
keySync, uint32Code,
byte(reqid >> 24), byte(reqid >> 16),
byte(reqid >> 8), byte(reqid),
}, streamBytes[:streamBytesLen]...)
Expand Down Expand Up @@ -802,12 +802,12 @@ func readWatchEvent(reader io.Reader) (connWatchEvent, error) {
}

switch cd {
case KeyEvent:
case keyEvent:
if event.key, err = d.DecodeString(); err != nil {
return event, err
}
keyExist = true
case KeyEventData:
case keyEventData:
if event.value, err = d.DecodeInterface(); err != nil {
return event, err
}
Expand Down
95 changes: 44 additions & 51 deletions const.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
package tarantool

const (
packetLengthBytes = 5
)

const (
keyCode = 0x00
keySync = 0x01
keyStreamId = 0x0a
keySpaceNo = 0x10
keyIndexNo = 0x11
keyLimit = 0x12
keyOffset = 0x13
keyIterator = 0x14
keyFetchPos = 0x1f
keyKey = 0x20
keyTuple = 0x21
keyFunctionName = 0x22
keyUserName = 0x23
keyExpression = 0x27
keyAfterPos = 0x2e
keyAfterTuple = 0x2f
keyDefTuple = 0x28
keyData = 0x30
keyError24 = 0x31 /* Error in pre-2.4 format. */
keyMetaData = 0x32
keyBindCount = 0x34
keyPos = 0x35
keySQLText = 0x40
keySQLBind = 0x41
keySQLInfo = 0x42
keyStmtID = 0x43
keyError = 0x52 /* Extended error in >= 2.4 format. */
keyVersion = 0x54
keyFeatures = 0x55
keyTimeout = 0x56
keyEvent = 0x57
keyEventData = 0x58
keyTxnIsolation = 0x59
keyAuthType = 0x5b
)

const (
SelectRequestCode = 1
InsertRequestCode = 2
Expand All @@ -23,50 +64,6 @@ const (
UnwatchRequestCode = 75
CallRequestCode = Call17RequestCode

KeyCode = 0x00
KeySync = 0x01
KeyStreamId = 0x0a
KeySpaceNo = 0x10
KeyIndexNo = 0x11
KeyLimit = 0x12
KeyOffset = 0x13
KeyIterator = 0x14
KeyFetchPos = 0x1f
KeyKey = 0x20
KeyTuple = 0x21
KeyFunctionName = 0x22
KeyUserName = 0x23
KeyExpression = 0x27
KeyAfterPos = 0x2e
KeyAfterTuple = 0x2f
KeyDefTuple = 0x28
KeyData = 0x30
KeyError24 = 0x31 /* Error in pre-2.4 format. */
KeyMetaData = 0x32
KeyBindCount = 0x34
KeyPos = 0x35
KeySQLText = 0x40
KeySQLBind = 0x41
KeySQLInfo = 0x42
KeyStmtID = 0x43
KeyError = 0x52 /* Extended error in >= 2.4 format. */
KeyVersion = 0x54
KeyFeatures = 0x55
KeyTimeout = 0x56
KeyEvent = 0x57
KeyEventData = 0x58
KeyTxnIsolation = 0x59
KeyAuthType = 0x5b

KeyFieldName = 0x00
KeyFieldType = 0x01
KeyFieldColl = 0x02
KeyFieldIsNullable = 0x03
KeyIsAutoincrement = 0x04
KeyFieldSpan = 0x05
KeySQLInfoRowCount = 0x00
KeySQLInfoAutoincrementIds = 0x01

// https://github.com/fl00r/go-tarantool-1.6/issues/2

IterEq = uint32(0) // key == x ASC order
Expand All @@ -83,11 +80,7 @@ const (
RLimitDrop = 1
RLimitWait = 2

OkCode = uint32(0)
EventCode = uint32(0x4c)
PushCode = uint32(0x80)
ErrorCodeBit = 0x8000
PacketLengthBytes = 5
ErSpaceExistsCode = 0xa
IteratorCode = 0x14
OkCode = uint32(0)
EventCode = uint32(0x4c)
PushCode = uint32(0x80)
)
4 changes: 2 additions & 2 deletions dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func identify(w writeFlusher, r io.Reader) (ProtocolInfo, error) {

resp, err := readResponse(r)
if err != nil {
if resp.Code == ErrUnknownRequestType {
if resp.Code == errUnknownRequestType {
// IPROTO_ID requests are not supported by server.
return info, nil
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func writeRequest(w writeFlusher, req Request) error {

// readResponse reads a response from the reader.
func readResponse(r io.Reader) (Response, error) {
var lenbuf [PacketLengthBytes]byte
var lenbuf [packetLengthBytes]byte

respBytes, err := read(r, lenbuf[:])
if err != nil {
Expand Down
115 changes: 4 additions & 111 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,115 +60,8 @@ const (

// Tarantool server error codes.
const (
ErrUnknown = 0 // Unknown error
ErrIllegalParams = 1 // Illegal parameters, %s
ErrMemoryIssue = 2 // Failed to allocate %u bytes in %s for %s
ErrTupleFound = 3 // Duplicate key exists in unique index '%s' in space '%s'
ErrTupleNotFound = 4 // Tuple doesn't exist in index '%s' in space '%s'
ErrUnsupported = 5 // %s does not support %s
ErrNonmaster = 6 // Can't modify data on a replication slave. My master is: %s
ErrReadonly = 7 // Can't modify data because this server is in read-only mode.
ErrInjection = 8 // Error injection '%s'
ErrCreateSpace = 9 // Failed to create space '%s': %s
ErrSpaceExists = 10 // Space '%s' already exists
ErrDropSpace = 11 // Can't drop space '%s': %s
ErrAlterSpace = 12 // Can't modify space '%s': %s
ErrIndexType = 13 // Unsupported index type supplied for index '%s' in space '%s'
ErrModifyIndex = 14 // Can't create or modify index '%s' in space '%s': %s
ErrLastDrop = 15 // Can't drop the primary key in a system space, space '%s'
ErrTupleFormatLimit = 16 // Tuple format limit reached: %u
ErrDropPrimaryKey = 17 // Can't drop primary key in space '%s' while secondary keys exist
ErrKeyPartType = 18 // Supplied key type of part %u does not match index part type: expected %s
ErrExactMatch = 19 // Invalid key part count in an exact match (expected %u, got %u)
ErrInvalidMsgpack = 20 // Invalid MsgPack - %s
ErrProcRet = 21 // msgpack.encode: can not encode Lua type '%s'
ErrTupleNotArray = 22 // Tuple/Key must be MsgPack array
ErrFieldType = 23 // Tuple field %u type does not match one required by operation: expected %s
ErrFieldTypeMismatch = 24 // Ambiguous field type in index '%s', key part %u. Requested type is %s but the field has previously been defined as %s
ErrSplice = 25 // SPLICE error on field %u: %s
ErrArgType = 26 // Argument type in operation '%c' on field %u does not match field type: expected a %s
ErrTupleIsTooLong = 27 // Tuple is too long %u
ErrUnknownUpdateOp = 28 // Unknown UPDATE operation
ErrUpdateField = 29 // Field %u UPDATE error: %s
ErrFiberStack = 30 // Can not create a new fiber: recursion limit reached
ErrKeyPartCount = 31 // Invalid key part count (expected [0..%u], got %u)
ErrProcLua = 32 // %s
ErrNoSuchProc = 33 // Procedure '%.*s' is not defined
ErrNoSuchTrigger = 34 // Trigger is not found
ErrNoSuchIndex = 35 // No index #%u is defined in space '%s'
ErrNoSuchSpace = 36 // Space '%s' does not exist
ErrNoSuchField = 37 // Field %d was not found in the tuple
ErrSpaceFieldCount = 38 // Tuple field count %u does not match space '%s' field count %u
ErrIndexFieldCount = 39 // Tuple field count %u is less than required by a defined index (expected %u)
ErrWalIo = 40 // Failed to write to disk
ErrMoreThanOneTuple = 41 // More than one tuple found by get()
ErrAccessDenied = 42 // %s access denied for user '%s'
ErrCreateUser = 43 // Failed to create user '%s': %s
ErrDropUser = 44 // Failed to drop user '%s': %s
ErrNoSuchUser = 45 // User '%s' is not found
ErrUserExists = 46 // User '%s' already exists
ErrPasswordMismatch = 47 // Incorrect password supplied for user '%s'
ErrUnknownRequestType = 48 // Unknown request type %u
ErrUnknownSchemaObject = 49 // Unknown object type '%s'
ErrCreateFunction = 50 // Failed to create function '%s': %s
ErrNoSuchFunction = 51 // Function '%s' does not exist
ErrFunctionExists = 52 // Function '%s' already exists
ErrFunctionAccessDenied = 53 // %s access denied for user '%s' to function '%s'
ErrFunctionMax = 54 // A limit on the total number of functions has been reached: %u
ErrSpaceAccessDenied = 55 // %s access denied for user '%s' to space '%s'
ErrUserMax = 56 // A limit on the total number of users has been reached: %u
ErrNoSuchEngine = 57 // Space engine '%s' does not exist
ErrReloadCfg = 58 // Can't set option '%s' dynamically
ErrCfg = 59 // Incorrect value for option '%s': %s
ErrSophia = 60 // %s
ErrLocalServerIsNotActive = 61 // Local server is not active
ErrUnknownServer = 62 // Server %s is not registered with the cluster
ErrClusterIdMismatch = 63 // Cluster id of the replica %s doesn't match cluster id of the master %s
ErrInvalidUUID = 64 // Invalid UUID: %s
ErrClusterIdIsRo = 65 // Can't reset cluster id: it is already assigned
ErrReserved66 = 66 // Reserved66
ErrServerIdIsReserved = 67 // Can't initialize server id with a reserved value %u
ErrInvalidOrder = 68 // Invalid LSN order for server %u: previous LSN = %llu, new lsn = %llu
ErrMissingRequestField = 69 // Missing mandatory field '%s' in request
ErrIdentifier = 70 // Invalid identifier '%s' (expected letters, digits or an underscore)
ErrDropFunction = 71 // Can't drop function %u: %s
ErrIteratorType = 72 // Unknown iterator type '%s'
ErrReplicaMax = 73 // Replica count limit reached: %u
ErrInvalidXlog = 74 // Failed to read xlog: %lld
ErrInvalidXlogName = 75 // Invalid xlog name: expected %lld got %lld
ErrInvalidXlogOrder = 76 // Invalid xlog order: %lld and %lld
ErrNoConnection = 77 // Connection is not established
ErrTimeout = 78 // Timeout exceeded
ErrActiveTransaction = 79 // Operation is not permitted when there is an active transaction
ErrNoActiveTransaction = 80 // Operation is not permitted when there is no active transaction
ErrCrossEngineTransaction = 81 // A multi-statement transaction can not use multiple storage engines
ErrNoSuchRole = 82 // Role '%s' is not found
ErrRoleExists = 83 // Role '%s' already exists
ErrCreateRole = 84 // Failed to create role '%s': %s
ErrIndexExists = 85 // Index '%s' already exists
ErrTupleRefOverflow = 86 // Tuple reference counter overflow
ErrRoleLoop = 87 // Granting role '%s' to role '%s' would create a loop
ErrGrant = 88 // Incorrect grant arguments: %s
ErrPrivGranted = 89 // User '%s' already has %s access on %s '%s'
ErrRoleGranted = 90 // User '%s' already has role '%s'
ErrPrivNotGranted = 91 // User '%s' does not have %s access on %s '%s'
ErrRoleNotGranted = 92 // User '%s' does not have role '%s'
ErrMissingSnapshot = 93 // Can't find snapshot
ErrCantUpdatePrimaryKey = 94 // Attempt to modify a tuple field which is part of index '%s' in space '%s'
ErrUpdateIntegerOverflow = 95 // Integer overflow when performing '%c' operation on field %u
ErrGuestUserPassword = 96 // Setting password for guest user has no effect
ErrTransactionConflict = 97 // Transaction has been aborted by conflict
ErrUnsupportedRolePriv = 98 // Unsupported role privilege '%s'
ErrLoadFunction = 99 // Failed to dynamically load function '%s': %s
ErrFunctionLanguage = 100 // Unsupported language '%s' specified for function '%s'
ErrRtreeRect = 101 // RTree: %s must be an array with %u (point) or %u (rectangle/box) numeric coordinates
ErrProcC = 102 // ???
ErrUnknownRtreeIndexDistanceType = 103 //Unknown RTREE index distance type %s
ErrProtocol = 104 // %s
ErrUpsertUniqueSecondaryKey = 105 // Space %s has a unique secondary index and does not support UPSERT
ErrWrongIndexRecord = 106 // Wrong record in _index space: got {%s}, expected {%s}
ErrWrongIndexParts = 107 // Wrong index parts (field %u): %s; expected field1 id (number), field1 type (string), ...
ErrWrongIndexOptions = 108 // Wrong index options (field %u): %s
ErrWrongSchemaVaersion = 109 // Wrong schema version, current: %d, in request: %u
ErrSlabAllocMax = 110 // Failed to allocate %u bytes for tuple in the slab allocator: tuple is too large. Check 'slab_alloc_maximal' configuration option.
errCodeBit = 0x8000
errNoSuchUser = 45 // User '%s' is not found
errPasswordMismatch = 47 // Incorrect password supplied for user '%s'
errUnknownRequestType = 48 // Unknown request type %u
)
8 changes: 4 additions & 4 deletions prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ type Prepared struct {

func fillPrepare(enc *msgpack.Encoder, expr string) error {
enc.EncodeMapLen(1)
enc.EncodeUint(KeySQLText)
enc.EncodeUint(keySQLText)
return enc.EncodeString(expr)
}

func fillUnprepare(enc *msgpack.Encoder, stmt Prepared) error {
enc.EncodeMapLen(1)
enc.EncodeUint(KeyStmtID)
enc.EncodeUint(keyStmtID)
return enc.EncodeUint(uint64(stmt.StatementID))
}

func fillExecutePrepared(enc *msgpack.Encoder, stmt Prepared, args interface{}) error {
enc.EncodeMapLen(2)
enc.EncodeUint(KeyStmtID)
enc.EncodeUint(keyStmtID)
enc.EncodeUint(uint64(stmt.StatementID))
enc.EncodeUint(KeySQLBind)
enc.EncodeUint(keySQLBind)
return encodeSQLBind(enc, args)
}

Expand Down
4 changes: 2 additions & 2 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ type IdRequest struct {
func fillId(enc *msgpack.Encoder, protocolInfo ProtocolInfo) error {
enc.EncodeMapLen(2)

enc.EncodeUint(KeyVersion)
enc.EncodeUint(keyVersion)
if err := enc.Encode(protocolInfo.Version); err != nil {
return err
}

enc.EncodeUint(KeyFeatures)
enc.EncodeUint(keyFeatures)

t := len(protocolInfo.Features)
if err := enc.EncodeArrayLen(t); err != nil {
Expand Down
Loading

0 comments on commit 656a8f4

Please sign in to comment.