Skip to content

Commit acedf56

Browse files
committed
api: add separate types for constants
Closes #158
1 parent 5ce7209 commit acedf56

11 files changed

+90
-54
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1111
### Added
1212

1313
- Type() method to the Request interface (#158)
14+
- Enumeration types for RLimitAction/iterators (#158)
1415

1516
### Changed
1617

connection.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,19 @@ type connShard struct {
236236
enc *msgpack.Encoder
237237
}
238238

239+
// RLimitActions is an enumeration type for an action to do when a rate limit
240+
// is reached.
241+
type RLimitAction int
242+
243+
const (
244+
// RLimitDrop immediately aborts the request.
245+
RLimitDrop RLimitAction = iota
246+
// RLimitWait waits during timeout period for some request to be answered.
247+
// If no request answered during timeout period, this request is aborted.
248+
// If no timeout period is set, it will wait forever.
249+
RLimitWait
250+
)
251+
239252
// Opts is a way to configure Connection
240253
type Opts struct {
241254
// Auth is an authentication method.
@@ -274,14 +287,9 @@ type Opts struct {
274287
// It is disabled by default.
275288
// See RLimitAction for possible actions when RateLimit.reached.
276289
RateLimit uint
277-
// RLimitAction tells what to do when RateLimit reached:
278-
// RLimitDrop - immediately abort request,
279-
// RLimitWait - wait during timeout period for some request to be answered.
280-
// If no request answered during timeout period, this request
281-
// is aborted.
282-
// If no timeout period is set, it will wait forever.
290+
// RLimitAction tells what to do when RateLimit is reached.
283291
// It is required if RateLimit is specified.
284-
RLimitAction uint
292+
RLimitAction RLimitAction
285293
// Concurrency is amount of separate mutexes for request
286294
// queues and buffers inside of connection.
287295
// It is rounded up to nearest power of 2.

connector.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Connector interface {
88
Ping() (resp *Response, err error)
99
ConfiguredTimeout() time.Duration
1010

11-
Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (resp *Response, err error)
11+
Select(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) (resp *Response, err error)
1212
Insert(space interface{}, tuple interface{}) (resp *Response, err error)
1313
Replace(space interface{}, tuple interface{}) (resp *Response, err error)
1414
Delete(space, index interface{}, key interface{}) (resp *Response, err error)
@@ -21,7 +21,7 @@ type Connector interface {
2121
Execute(expr string, args interface{}) (resp *Response, err error)
2222

2323
GetTyped(space, index interface{}, key interface{}, result interface{}) (err error)
24-
SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}) (err error)
24+
SelectTyped(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}, result interface{}) (err error)
2525
InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error)
2626
ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error)
2727
DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
@@ -32,7 +32,7 @@ type Connector interface {
3232
EvalTyped(expr string, args interface{}, result interface{}) (err error)
3333
ExecuteTyped(expr string, args interface{}, result interface{}) (SQLInfo, []ColumnMetaData, error)
3434

35-
SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future
35+
SelectAsync(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) *Future
3636
InsertAsync(space interface{}, tuple interface{}) *Future
3737
ReplaceAsync(space interface{}, tuple interface{}) *Future
3838
DeleteAsync(space, index interface{}, key interface{}) *Future

const.go

-16
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@ const (
99
)
1010

1111
const (
12-
IterEq = uint32(0) // key == x ASC order
13-
IterReq = uint32(1) // key == x DESC order
14-
IterAll = uint32(2) // all tuples
15-
IterLt = uint32(3) // key < x
16-
IterLe = uint32(4) // key <= x
17-
IterGe = uint32(5) // key >= x
18-
IterGt = uint32(6) // key > x
19-
IterBitsAllSet = uint32(7) // all bits from x are set in key
20-
IterBitsAnySet = uint32(8) // at least one x's bit is set
21-
IterBitsAllNotSet = uint32(9) // all bits are not set
22-
IterOverlaps = uint32(10) // key overlaps x
23-
IterNeighbor = uint32(11) // tuples in distance ascending order from specified point
24-
25-
RLimitDrop = 1
26-
RLimitWait = 2
27-
2812
OkCode = uint32(iproto.IPROTO_OK)
2913
PushCode = uint32(iproto.IPROTO_CHUNK)
3014
)

export_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func RefImplPingBody(enc *msgpack.Encoder) error {
2424

2525
// RefImplSelectBody is reference implementation for filling of a select
2626
// request's body.
27-
func RefImplSelectBody(enc *msgpack.Encoder, space, index, offset, limit, iterator uint32,
27+
func RefImplSelectBody(enc *msgpack.Encoder, space, index, offset, limit uint32, iterator Iter,
2828
key, after interface{}, fetchPos bool) error {
2929
return fillSelect(enc, space, index, offset, limit, iterator, key, after, fetchPos)
3030
}

iterator.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package tarantool
2+
3+
import (
4+
"github.com/tarantool/go-iproto"
5+
)
6+
7+
// Iter is an enumeration type of a select iterator.
8+
type Iter uint32
9+
10+
const (
11+
// Key == x ASC order.
12+
IterEq Iter = Iter(iproto.ITER_EQ)
13+
// Key == x DESC order.
14+
IterReq Iter = Iter(iproto.ITER_REQ)
15+
// All tuples.
16+
IterAll Iter = Iter(iproto.ITER_ALL)
17+
// Key < x.
18+
IterLt Iter = Iter(iproto.ITER_LT)
19+
// Key <= x.
20+
IterLe Iter = Iter(iproto.ITER_LE)
21+
// Key >= x.
22+
IterGe Iter = Iter(iproto.ITER_GE)
23+
// Key > x.
24+
IterGt Iter = Iter(iproto.ITER_GT)
25+
// All bits from x are set in key.
26+
IterBitsAllSet Iter = Iter(iproto.ITER_BITS_ALL_SET)
27+
// All bits are not set.
28+
IterBitsAnySet Iter = Iter(iproto.ITER_BITS_ANY_SET)
29+
// All bits are not set.
30+
IterBitsAllNotSet Iter = Iter(iproto.ITER_BITS_ALL_NOT_SET)
31+
// Key overlaps x.
32+
IterOverlaps Iter = Iter(iproto.ITER_OVERLAPS)
33+
// Tuples in distance ascending order from specified point.
34+
IterNeighbor Iter = Iter(iproto.ITER_NEIGHBOR)
35+
)

pool/connection_pool.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ func (connPool *ConnectionPool) Ping(userMode Mode) (*tarantool.Response, error)
373373
}
374374

375375
// Select performs select to box space.
376-
func (connPool *ConnectionPool) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}, userMode ...Mode) (resp *tarantool.Response, err error) {
376+
func (connPool *ConnectionPool) Select(space, index interface{},
377+
offset, limit uint32,
378+
iterator tarantool.Iter, key interface{}, userMode ...Mode) (resp *tarantool.Response, err error) {
377379
conn, err := connPool.getConnByMode(ANY, userMode)
378380
if err != nil {
379381
return nil, err
@@ -503,7 +505,9 @@ func (connPool *ConnectionPool) GetTyped(space, index interface{}, key interface
503505
}
504506

505507
// SelectTyped performs select to box space and fills typed result.
506-
func (connPool *ConnectionPool) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}, userMode ...Mode) (err error) {
508+
func (connPool *ConnectionPool) SelectTyped(space, index interface{},
509+
offset, limit uint32,
510+
iterator tarantool.Iter, key interface{}, result interface{}, userMode ...Mode) (err error) {
507511
conn, err := connPool.getConnByMode(ANY, userMode)
508512
if err != nil {
509513
return err
@@ -609,7 +613,9 @@ func (connPool *ConnectionPool) ExecuteTyped(expr string, args interface{}, resu
609613
}
610614

611615
// SelectAsync sends select request to Tarantool and returns Future.
612-
func (connPool *ConnectionPool) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}, userMode ...Mode) *tarantool.Future {
616+
func (connPool *ConnectionPool) SelectAsync(space, index interface{},
617+
offset, limit uint32,
618+
iterator tarantool.Iter, key interface{}, userMode ...Mode) *tarantool.Future {
613619
conn, err := connPool.getConnByMode(ANY, userMode)
614620
if err != nil {
615621
return newErrorFuture(err)

pool/connector.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *ConnectorAdapter) ConfiguredTimeout() time.Duration {
6363

6464
// Select performs select to box space.
6565
func (c *ConnectorAdapter) Select(space, index interface{},
66-
offset, limit, iterator uint32,
66+
offset, limit uint32, iterator tarantool.Iter,
6767
key interface{}) (*tarantool.Response, error) {
6868
return c.pool.Select(space, index, offset, limit, iterator, key, c.mode)
6969
}
@@ -141,7 +141,7 @@ func (c *ConnectorAdapter) GetTyped(space, index interface{},
141141

142142
// SelectTyped performs select to box space and fills typed result.
143143
func (c *ConnectorAdapter) SelectTyped(space, index interface{},
144-
offset, limit, iterator uint32,
144+
offset, limit uint32, iterator tarantool.Iter,
145145
key interface{}, result interface{}) error {
146146
return c.pool.SelectTyped(space, index, offset, limit, iterator, key, result, c.mode)
147147
}
@@ -206,7 +206,7 @@ func (c *ConnectorAdapter) ExecuteTyped(expr string, args interface{},
206206

207207
// SelectAsync sends select request to Tarantool and returns Future.
208208
func (c *ConnectorAdapter) SelectAsync(space, index interface{},
209-
offset, limit, iterator uint32, key interface{}) *tarantool.Future {
209+
offset, limit uint32, iterator tarantool.Iter, key interface{}) *tarantool.Future {
210210
return c.pool.SelectAsync(space, index, offset, limit, iterator, key, c.mode)
211211
}
212212

pool/connector_test.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ func TestConnectorConfiguredTimeoutWithError(t *testing.T) {
125125

126126
type baseRequestMock struct {
127127
Pooler
128-
called int
129-
functionName string
130-
offset, limit, iterator uint32
131-
space, index interface{}
132-
args, tuple, key, ops interface{}
133-
result interface{}
134-
mode Mode
128+
called int
129+
functionName string
130+
offset, limit uint32
131+
iterator tarantool.Iter
132+
space, index interface{}
133+
args, tuple, key, ops interface{}
134+
result interface{}
135+
mode Mode
135136
}
136137

137138
var reqResp *tarantool.Response = &tarantool.Response{}
@@ -141,7 +142,7 @@ var reqFuture *tarantool.Future = &tarantool.Future{}
141142
var reqFunctionName string = "any_name"
142143
var reqOffset uint32 = 1
143144
var reqLimit uint32 = 2
144-
var reqIterator uint32 = 3
145+
var reqIterator tarantool.Iter = tarantool.IterLt
145146
var reqSpace interface{} = []interface{}{1}
146147
var reqIndex interface{} = []interface{}{2}
147148
var reqArgs interface{} = []interface{}{3}
@@ -188,7 +189,7 @@ type selectMock struct {
188189
}
189190

190191
func (m *selectMock) Select(space, index interface{},
191-
offset, limit, iterator uint32, key interface{},
192+
offset, limit uint32, iterator tarantool.Iter, key interface{},
192193
mode ...Mode) (*tarantool.Response, error) {
193194
m.called++
194195
m.space = space
@@ -224,7 +225,7 @@ type selectTypedMock struct {
224225
}
225226

226227
func (m *selectTypedMock) SelectTyped(space, index interface{},
227-
offset, limit, iterator uint32, key interface{},
228+
offset, limit uint32, iterator tarantool.Iter, key interface{},
228229
result interface{}, mode ...Mode) error {
229230
m.called++
230231
m.space = space
@@ -262,7 +263,7 @@ type selectAsyncMock struct {
262263
}
263264

264265
func (m *selectAsyncMock) SelectAsync(space, index interface{},
265-
offset, limit, iterator uint32, key interface{},
266+
offset, limit uint32, iterator tarantool.Iter, key interface{},
266267
mode ...Mode) *tarantool.Future {
267268
m.called++
268269
m.space = space

pool/pooler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Pooler interface {
1313
Ping(mode Mode) (*tarantool.Response, error)
1414
ConfiguredTimeout(mode Mode) (time.Duration, error)
1515

16-
Select(space, index interface{}, offset, limit, iterator uint32,
16+
Select(space, index interface{}, offset, limit uint32, iterator tarantool.Iter,
1717
key interface{}, mode ...Mode) (*tarantool.Response, error)
1818
Insert(space interface{}, tuple interface{},
1919
mode ...Mode) (*tarantool.Response, error)
@@ -38,7 +38,7 @@ type Pooler interface {
3838

3939
GetTyped(space, index interface{}, key interface{}, result interface{},
4040
mode ...Mode) error
41-
SelectTyped(space, index interface{}, offset, limit, iterator uint32,
41+
SelectTyped(space, index interface{}, offset, limit uint32, iterator tarantool.Iter,
4242
key interface{}, result interface{}, mode ...Mode) error
4343
InsertTyped(space interface{}, tuple interface{}, result interface{},
4444
mode ...Mode) error
@@ -59,7 +59,7 @@ type Pooler interface {
5959
ExecuteTyped(expr string, args interface{}, result interface{},
6060
mode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error)
6161

62-
SelectAsync(space, index interface{}, offset, limit, iterator uint32,
62+
SelectAsync(space, index interface{}, offset, limit uint32, iterator tarantool.Iter,
6363
key interface{}, mode ...Mode) *tarantool.Future
6464
InsertAsync(space interface{}, tuple interface{},
6565
mode ...Mode) *tarantool.Future

request.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{})
3131
return enc.Encode(key)
3232
}
3333

34-
func fillIterator(enc *msgpack.Encoder, offset, limit, iterator uint32) error {
34+
func fillIterator(enc *msgpack.Encoder, offset, limit uint32, iterator Iter) error {
3535
if err := enc.EncodeUint(uint64(iproto.IPROTO_ITERATOR)); err != nil {
3636
return err
3737
}
@@ -66,7 +66,7 @@ func fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) error {
6666
return enc.Encode(tuple)
6767
}
6868

69-
func fillSelect(enc *msgpack.Encoder, spaceNo, indexNo, offset, limit, iterator uint32,
69+
func fillSelect(enc *msgpack.Encoder, spaceNo, indexNo, offset, limit uint32, iterator Iter,
7070
key, after interface{}, fetchPos bool) error {
7171
mapLen := 6
7272
if fetchPos {
@@ -174,7 +174,7 @@ func (conn *Connection) Ping() (resp *Response, err error) {
174174
// Select performs select to box space.
175175
//
176176
// It is equal to conn.SelectAsync(...).Get().
177-
func (conn *Connection) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (resp *Response, err error) {
177+
func (conn *Connection) Select(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) (resp *Response, err error) {
178178
return conn.SelectAsync(space, index, offset, limit, iterator, key).Get()
179179
}
180180

@@ -292,7 +292,7 @@ func (conn *Connection) GetTyped(space, index interface{}, key interface{}, resu
292292
// SelectTyped performs select to box space and fills typed result.
293293
//
294294
// It is equal to conn.SelectAsync(space, index, offset, limit, iterator, key).GetTyped(&result)
295-
func (conn *Connection) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}) (err error) {
295+
func (conn *Connection) SelectTyped(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}, result interface{}) (err error) {
296296
return conn.SelectAsync(space, index, offset, limit, iterator, key).GetTyped(result)
297297
}
298298

@@ -369,7 +369,7 @@ func (conn *Connection) ExecuteTyped(expr string, args interface{}, result inter
369369
}
370370

371371
// SelectAsync sends select request to Tarantool and returns Future.
372-
func (conn *Connection) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future {
372+
func (conn *Connection) SelectAsync(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) *Future {
373373
req := NewSelectRequest(space).
374374
Index(index).
375375
Offset(offset).
@@ -740,7 +740,8 @@ func (req *PingRequest) Context(ctx context.Context) *PingRequest {
740740
type SelectRequest struct {
741741
spaceIndexRequest
742742
isIteratorSet, fetchPos bool
743-
offset, limit, iterator uint32
743+
offset, limit uint32
744+
iterator Iter
744745
key, after interface{}
745746
}
746747

@@ -781,7 +782,7 @@ func (req *SelectRequest) Limit(limit uint32) *SelectRequest {
781782

782783
// Iterator set the iterator for the select request.
783784
// Note: default value is IterAll if key is not set or IterEq otherwise.
784-
func (req *SelectRequest) Iterator(iterator uint32) *SelectRequest {
785+
func (req *SelectRequest) Iterator(iterator Iter) *SelectRequest {
785786
req.iterator = iterator
786787
req.isIteratorSet = true
787788
return req

0 commit comments

Comments
 (0)