Skip to content

Commit affaf96

Browse files
crud: change timeout option type
`Timeout` is an option supported for all crud operations using VShard API. In Lua, timeout has `number` type, so float values are allowed. Float timeouts can be useful to set the timeout less than a second. After this patch, `Timeout` will be an optional float64 instead of an optional int. This is a breaking change. CRUD allows to use negative timeouts. This approach does not make any sense for an operation: for example, initial schema fetch will fail. Since the module itself does not check for a negative value argument, we do not forbid it here too. Closes #342
1 parent a664c6b commit affaf96

File tree

8 files changed

+50
-23
lines changed

8 files changed

+50
-23
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
4343
- `iproto.Feature` type now used instead of `ProtocolFeature` (#337)
4444
- `iproto.IPROTO_FEATURE_` constants now used instead of local `Feature`
4545
constants for `protocol` (#337)
46+
- Change `crud` operations `Timeout` option type to `crud.OptFloat64`
47+
instead of `crud.OptUint` (#342)
4648

4749
### Deprecated
4850

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ faster than other packages according to public benchmarks.
3535
* [Call = Call17](#call--call17)
3636
* [IPROTO constants](#iproto-constants)
3737
* [Request interface](#request-interface)
38+
* [CRUD options](#crud-options)
3839
* [Contributing](#contributing)
3940
* [Alternative connectors](#alternative-connectors)
4041

@@ -239,6 +240,11 @@ and user may cancel it in process.
239240
* `iproto.Feature` type used instead of `ProtocolFeature`.
240241
* `iproto.IPROTO_FEATURE_` constants used instead of local ones.
241242

243+
#### CRUD options
244+
245+
* `crud` operations `Timeout` option have `crud.OptFloat64` type
246+
instead of `crud.OptUint`.
247+
242248
## Contributing
243249

244250
See [the contributing guide](CONTRIBUTING.md) for detailed instructions on how

crud/count.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type CountResult = NumberResult
1515
type CountOpts struct {
1616
// Timeout is a `vshard.call` timeout and vshard
1717
// master discovery timeout (in seconds).
18-
Timeout OptUint
18+
Timeout OptFloat64
1919
// VshardRouter is cartridge vshard group name or
2020
// vshard router instance.
2121
VshardRouter OptString

crud/get.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
type GetOpts struct {
1313
// Timeout is a `vshard.call` timeout and vshard
1414
// master discovery timeout (in seconds).
15-
Timeout OptUint
15+
Timeout OptFloat64
1616
// VshardRouter is cartridge vshard group name or
1717
// vshard router instance.
1818
VshardRouter OptString

crud/options.go

+25-6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ func (opt OptInt) Get() (int, bool) {
6363
return opt.value, opt.exist
6464
}
6565

66+
// OptFloat64 is an optional float64.
67+
type OptFloat64 struct {
68+
value float64
69+
exist bool
70+
}
71+
72+
// MakeOptFloat64 creates an optional float64 from value.
73+
func MakeOptFloat64(value float64) OptFloat64 {
74+
return OptFloat64{
75+
value: value,
76+
exist: true,
77+
}
78+
}
79+
80+
// Get returns the float64 value or an error if not present.
81+
func (opt OptFloat64) Get() (float64, bool) {
82+
return opt.value, opt.exist
83+
}
84+
6685
// OptString is an optional string.
6786
type OptString struct {
6887
value string
@@ -120,7 +139,7 @@ func (o *OptTuple) Get() (interface{}, bool) {
120139
type BaseOpts struct {
121140
// Timeout is a `vshard.call` timeout and vshard
122141
// master discovery timeout (in seconds).
123-
Timeout OptUint
142+
Timeout OptFloat64
124143
// VshardRouter is cartridge vshard group name or
125144
// vshard router instance.
126145
VshardRouter OptString
@@ -144,7 +163,7 @@ func (opts BaseOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
144163
type SimpleOperationOpts struct {
145164
// Timeout is a `vshard.call` timeout and vshard
146165
// master discovery timeout (in seconds).
147-
Timeout OptUint
166+
Timeout OptFloat64
148167
// VshardRouter is cartridge vshard group name or
149168
// vshard router instance.
150169
VshardRouter OptString
@@ -186,7 +205,7 @@ func (opts SimpleOperationOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
186205
type SimpleOperationObjectOpts struct {
187206
// Timeout is a `vshard.call` timeout and vshard
188207
// master discovery timeout (in seconds).
189-
Timeout OptUint
208+
Timeout OptFloat64
190209
// VshardRouter is cartridge vshard group name or
191210
// vshard router instance.
192211
VshardRouter OptString
@@ -232,7 +251,7 @@ func (opts SimpleOperationObjectOpts) EncodeMsgpack(enc *msgpack.Encoder) error
232251
type OperationManyOpts struct {
233252
// Timeout is a `vshard.call` timeout and vshard
234253
// master discovery timeout (in seconds).
235-
Timeout OptUint
254+
Timeout OptFloat64
236255
// VshardRouter is cartridge vshard group name or
237256
// vshard router instance.
238257
VshardRouter OptString
@@ -280,7 +299,7 @@ func (opts OperationManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
280299
type OperationObjectManyOpts struct {
281300
// Timeout is a `vshard.call` timeout and vshard
282301
// master discovery timeout (in seconds).
283-
Timeout OptUint
302+
Timeout OptFloat64
284303
// VshardRouter is cartridge vshard group name or
285304
// vshard router instance.
286305
VshardRouter OptString
@@ -332,7 +351,7 @@ func (opts OperationObjectManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
332351
type BorderOpts struct {
333352
// Timeout is a `vshard.call` timeout and vshard
334353
// master discovery timeout (in seconds).
335-
Timeout OptUint
354+
Timeout OptFloat64
336355
// VshardRouter is cartridge vshard group name or
337356
// vshard router instance.
338357
VshardRouter OptString

crud/request_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func BenchmarkLenRequest(b *testing.B) {
137137
buf.Reset()
138138
req := crud.MakeLenRequest(spaceName).
139139
Opts(crud.LenOpts{
140-
Timeout: crud.MakeOptUint(3),
140+
Timeout: crud.MakeOptFloat64(3.5),
141141
})
142142
if err := req.Body(nil, enc); err != nil {
143143
b.Error(err)
@@ -156,7 +156,7 @@ func BenchmarkSelectRequest(b *testing.B) {
156156
buf.Reset()
157157
req := crud.MakeSelectRequest(spaceName).
158158
Opts(crud.SelectOpts{
159-
Timeout: crud.MakeOptUint(3),
159+
Timeout: crud.MakeOptFloat64(3.5),
160160
VshardRouter: crud.MakeOptString("asd"),
161161
Balance: crud.MakeOptBool(true),
162162
})

crud/select.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
type SelectOpts struct {
1313
// Timeout is a `vshard.call` timeout and vshard
1414
// master discovery timeout (in seconds).
15-
Timeout OptUint
15+
Timeout OptFloat64
1616
// VshardRouter is cartridge vshard group name or
1717
// vshard router instance.
1818
VshardRouter OptString

crud/tarantool_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var startOpts test_helpers.StartOpts = test_helpers.StartOpts{
3737
RetryTimeout: 500 * time.Millisecond,
3838
}
3939

40-
var timeout = uint(1)
40+
var timeout = float64(1.1)
4141

4242
var operations = []crud.Operation{
4343
{
@@ -48,43 +48,43 @@ var operations = []crud.Operation{
4848
}
4949

5050
var selectOpts = crud.SelectOpts{
51-
Timeout: crud.MakeOptUint(timeout),
51+
Timeout: crud.MakeOptFloat64(timeout),
5252
}
5353

5454
var countOpts = crud.CountOpts{
55-
Timeout: crud.MakeOptUint(timeout),
55+
Timeout: crud.MakeOptFloat64(timeout),
5656
}
5757

5858
var getOpts = crud.GetOpts{
59-
Timeout: crud.MakeOptUint(timeout),
59+
Timeout: crud.MakeOptFloat64(timeout),
6060
}
6161

6262
var minOpts = crud.MinOpts{
63-
Timeout: crud.MakeOptUint(timeout),
63+
Timeout: crud.MakeOptFloat64(timeout),
6464
}
6565

6666
var maxOpts = crud.MaxOpts{
67-
Timeout: crud.MakeOptUint(timeout),
67+
Timeout: crud.MakeOptFloat64(timeout),
6868
}
6969

7070
var baseOpts = crud.BaseOpts{
71-
Timeout: crud.MakeOptUint(timeout),
71+
Timeout: crud.MakeOptFloat64(timeout),
7272
}
7373

7474
var simpleOperationOpts = crud.SimpleOperationOpts{
75-
Timeout: crud.MakeOptUint(timeout),
75+
Timeout: crud.MakeOptFloat64(timeout),
7676
}
7777

7878
var simpleOperationObjectOpts = crud.SimpleOperationObjectOpts{
79-
Timeout: crud.MakeOptUint(timeout),
79+
Timeout: crud.MakeOptFloat64(timeout),
8080
}
8181

8282
var opManyOpts = crud.OperationManyOpts{
83-
Timeout: crud.MakeOptUint(timeout),
83+
Timeout: crud.MakeOptFloat64(timeout),
8484
}
8585

8686
var opObjManyOpts = crud.OperationObjectManyOpts{
87-
Timeout: crud.MakeOptUint(timeout),
87+
Timeout: crud.MakeOptFloat64(timeout),
8888
}
8989

9090
var conditions = []crud.Condition{
@@ -815,7 +815,7 @@ func TestGetAdditionalOpts(t *testing.T) {
815815
defer conn.Close()
816816

817817
req := crud.MakeGetRequest(spaceName).Key(key).Opts(crud.GetOpts{
818-
Timeout: crud.MakeOptUint(1),
818+
Timeout: crud.MakeOptFloat64(1.1),
819819
Fields: crud.MakeOptTuple([]interface{}{"name"}),
820820
Mode: crud.MakeOptString("read"),
821821
PreferReplica: crud.MakeOptBool(true),

0 commit comments

Comments
 (0)