Skip to content

Commit 7d8f33c

Browse files
committed
api: remove unnecessary IPROTO constants
We will have a separate package for it [1]. 1. #267 Part of #158
1 parent 512fe6a commit 7d8f33c

12 files changed

+139
-236
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2929
- pool/RoundRobinStrategy (#158)
3030
- DeadlineIO (#158)
3131
- UUID_extId (#158)
32+
- IPROTO constants (#158)
3233

3334
### Fixed
3435

connection.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ type Connection struct {
162162
opts Opts
163163
state uint32
164164
dec *msgpack.Decoder
165-
lenbuf [PacketLengthBytes]byte
165+
lenbuf [packetLengthBytes]byte
166166

167167
lastStreamId uint64
168168

@@ -405,8 +405,8 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
405405
ter, ok := err.(Error)
406406
if conn.opts.Reconnect <= 0 {
407407
return nil, err
408-
} else if ok && (ter.Code == ErrNoSuchUser ||
409-
ter.Code == ErrPasswordMismatch) {
408+
} else if ok && (ter.Code == errNoSuchUser ||
409+
ter.Code == errPasswordMismatch) {
410410
// Reported auth errors immediately.
411411
return nil, err
412412
} else {
@@ -583,7 +583,7 @@ func pack(h *smallWBuf, enc *msgpack.Encoder, reqid uint32,
583583
hMapLen := byte(0x82) // 2 element map.
584584
if streamId != ignoreStreamId {
585585
hMapLen = byte(0x83) // 3 element map.
586-
streamBytes[0] = KeyStreamId
586+
streamBytes[0] = keyStreamId
587587
if streamId > math.MaxUint32 {
588588
streamBytesLen = streamBytesLenUint64
589589
streamBytes[1] = uint64Code
@@ -598,8 +598,8 @@ func pack(h *smallWBuf, enc *msgpack.Encoder, reqid uint32,
598598
hBytes := append([]byte{
599599
uint32Code, 0, 0, 0, 0, // Length.
600600
hMapLen,
601-
KeyCode, byte(req.Code()), // Request code.
602-
KeySync, uint32Code,
601+
keyCode, byte(req.Code()), // Request code.
602+
keySync, uint32Code,
603603
byte(reqid >> 24), byte(reqid >> 16),
604604
byte(reqid >> 8), byte(reqid),
605605
}, streamBytes[:streamBytesLen]...)
@@ -802,12 +802,12 @@ func readWatchEvent(reader io.Reader) (connWatchEvent, error) {
802802
}
803803

804804
switch cd {
805-
case KeyEvent:
805+
case keyEvent:
806806
if event.key, err = d.DecodeString(); err != nil {
807807
return event, err
808808
}
809809
keyExist = true
810-
case KeyEventData:
810+
case keyEventData:
811811
if event.value, err = d.DecodeInterface(); err != nil {
812812
return event, err
813813
}

const.go

+44-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
package tarantool
22

3+
const (
4+
packetLengthBytes = 5
5+
)
6+
7+
const (
8+
keyCode = 0x00
9+
keySync = 0x01
10+
keyStreamId = 0x0a
11+
keySpaceNo = 0x10
12+
keyIndexNo = 0x11
13+
keyLimit = 0x12
14+
keyOffset = 0x13
15+
keyIterator = 0x14
16+
keyFetchPos = 0x1f
17+
keyKey = 0x20
18+
keyTuple = 0x21
19+
keyFunctionName = 0x22
20+
keyUserName = 0x23
21+
keyExpression = 0x27
22+
keyAfterPos = 0x2e
23+
keyAfterTuple = 0x2f
24+
keyDefTuple = 0x28
25+
keyData = 0x30
26+
keyError24 = 0x31 /* Error in pre-2.4 format. */
27+
keyMetaData = 0x32
28+
keyBindCount = 0x34
29+
keyPos = 0x35
30+
keySQLText = 0x40
31+
keySQLBind = 0x41
32+
keySQLInfo = 0x42
33+
keyStmtID = 0x43
34+
keyError = 0x52 /* Extended error in >= 2.4 format. */
35+
keyVersion = 0x54
36+
keyFeatures = 0x55
37+
keyTimeout = 0x56
38+
keyEvent = 0x57
39+
keyEventData = 0x58
40+
keyTxnIsolation = 0x59
41+
keyAuthType = 0x5b
42+
)
43+
344
const (
445
SelectRequestCode = 1
546
InsertRequestCode = 2
@@ -23,50 +64,6 @@ const (
2364
UnwatchRequestCode = 75
2465
CallRequestCode = Call17RequestCode
2566

26-
KeyCode = 0x00
27-
KeySync = 0x01
28-
KeyStreamId = 0x0a
29-
KeySpaceNo = 0x10
30-
KeyIndexNo = 0x11
31-
KeyLimit = 0x12
32-
KeyOffset = 0x13
33-
KeyIterator = 0x14
34-
KeyFetchPos = 0x1f
35-
KeyKey = 0x20
36-
KeyTuple = 0x21
37-
KeyFunctionName = 0x22
38-
KeyUserName = 0x23
39-
KeyExpression = 0x27
40-
KeyAfterPos = 0x2e
41-
KeyAfterTuple = 0x2f
42-
KeyDefTuple = 0x28
43-
KeyData = 0x30
44-
KeyError24 = 0x31 /* Error in pre-2.4 format. */
45-
KeyMetaData = 0x32
46-
KeyBindCount = 0x34
47-
KeyPos = 0x35
48-
KeySQLText = 0x40
49-
KeySQLBind = 0x41
50-
KeySQLInfo = 0x42
51-
KeyStmtID = 0x43
52-
KeyError = 0x52 /* Extended error in >= 2.4 format. */
53-
KeyVersion = 0x54
54-
KeyFeatures = 0x55
55-
KeyTimeout = 0x56
56-
KeyEvent = 0x57
57-
KeyEventData = 0x58
58-
KeyTxnIsolation = 0x59
59-
KeyAuthType = 0x5b
60-
61-
KeyFieldName = 0x00
62-
KeyFieldType = 0x01
63-
KeyFieldColl = 0x02
64-
KeyFieldIsNullable = 0x03
65-
KeyIsAutoincrement = 0x04
66-
KeyFieldSpan = 0x05
67-
KeySQLInfoRowCount = 0x00
68-
KeySQLInfoAutoincrementIds = 0x01
69-
7067
// https://github.com/fl00r/go-tarantool-1.6/issues/2
7168

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

86-
OkCode = uint32(0)
87-
EventCode = uint32(0x4c)
88-
PushCode = uint32(0x80)
89-
ErrorCodeBit = 0x8000
90-
PacketLengthBytes = 5
91-
ErSpaceExistsCode = 0xa
92-
IteratorCode = 0x14
83+
OkCode = uint32(0)
84+
EventCode = uint32(0x4c)
85+
PushCode = uint32(0x80)
9386
)

dial.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func identify(w writeFlusher, r io.Reader) (ProtocolInfo, error) {
261261

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

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

373373
respBytes, err := read(r, lenbuf[:])
374374
if err != nil {

errors.go

+4-111
Original file line numberDiff line numberDiff line change
@@ -60,115 +60,8 @@ const (
6060

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

prepared.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ type Prepared struct {
2222

2323
func fillPrepare(enc *msgpack.Encoder, expr string) error {
2424
enc.EncodeMapLen(1)
25-
enc.EncodeUint(KeySQLText)
25+
enc.EncodeUint(keySQLText)
2626
return enc.EncodeString(expr)
2727
}
2828

2929
func fillUnprepare(enc *msgpack.Encoder, stmt Prepared) error {
3030
enc.EncodeMapLen(1)
31-
enc.EncodeUint(KeyStmtID)
31+
enc.EncodeUint(keyStmtID)
3232
return enc.EncodeUint(uint64(stmt.StatementID))
3333
}
3434

3535
func fillExecutePrepared(enc *msgpack.Encoder, stmt Prepared, args interface{}) error {
3636
enc.EncodeMapLen(2)
37-
enc.EncodeUint(KeyStmtID)
37+
enc.EncodeUint(keyStmtID)
3838
enc.EncodeUint(uint64(stmt.StatementID))
39-
enc.EncodeUint(KeySQLBind)
39+
enc.EncodeUint(keySQLBind)
4040
return encodeSQLBind(enc, args)
4141
}
4242

protocol.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ type IdRequest struct {
106106
func fillId(enc *msgpack.Encoder, protocolInfo ProtocolInfo) error {
107107
enc.EncodeMapLen(2)
108108

109-
enc.EncodeUint(KeyVersion)
109+
enc.EncodeUint(keyVersion)
110110
if err := enc.Encode(protocolInfo.Version); err != nil {
111111
return err
112112
}
113113

114-
enc.EncodeUint(KeyFeatures)
114+
enc.EncodeUint(keyFeatures)
115115

116116
t := len(protocolInfo.Features)
117117
if err := enc.EncodeArrayLen(t); err != nil {

0 commit comments

Comments
 (0)