Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crud: change timeout option type #343

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- `iproto.Feature` type now used instead of `ProtocolFeature` (#337)
- `iproto.IPROTO_FEATURE_` constants now used instead of local `Feature`
constants for `protocol` (#337)
- Change `crud` operations `Timeout` option type to `crud.OptFloat64`
instead of `crud.OptUint` (#342)

### Deprecated

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ faster than other packages according to public benchmarks.
* [decimal package](#decimal-package)
* [multi package](#multi-package)
* [pool package](#pool-package)
* [crud package](#crud-package)
* [msgpack.v5](#msgpackv5)
* [Call = Call17](#call--call17)
* [IPROTO constants](#iproto-constants)
Expand Down Expand Up @@ -187,6 +188,11 @@ The subpackage has been deleted. You could use `pool` instead.
* `pool.Add` now accepts context as first argument, which user may cancel in
process.

#### crud package

* `crud` operations `Timeout` option has `crud.OptFloat64` type
instead of `crud.OptUint`.

#### msgpack.v5

Most function names and argument types in `msgpack.v5` and `msgpack.v2`
Expand Down
2 changes: 1 addition & 1 deletion crud/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CountResult = NumberResult
type CountOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down
2 changes: 1 addition & 1 deletion crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type GetOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down
31 changes: 25 additions & 6 deletions crud/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ func (opt OptInt) Get() (int, bool) {
return opt.value, opt.exist
}

// OptFloat64 is an optional float64.
type OptFloat64 struct {
value float64
exist bool
}

// MakeOptFloat64 creates an optional float64 from value.
func MakeOptFloat64(value float64) OptFloat64 {
return OptFloat64{
value: value,
exist: true,
}
}

// Get returns the float64 value or an error if not present.
func (opt OptFloat64) Get() (float64, bool) {
return opt.value, opt.exist
}

// OptString is an optional string.
type OptString struct {
value string
Expand Down Expand Up @@ -120,7 +139,7 @@ func (o *OptTuple) Get() (interface{}, bool) {
type BaseOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand All @@ -144,7 +163,7 @@ func (opts BaseOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
type SimpleOperationOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down Expand Up @@ -186,7 +205,7 @@ func (opts SimpleOperationOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
type SimpleOperationObjectOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down Expand Up @@ -232,7 +251,7 @@ func (opts SimpleOperationObjectOpts) EncodeMsgpack(enc *msgpack.Encoder) error
type OperationManyOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down Expand Up @@ -280,7 +299,7 @@ func (opts OperationManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
type OperationObjectManyOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down Expand Up @@ -332,7 +351,7 @@ func (opts OperationObjectManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
type BorderOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down
4 changes: 2 additions & 2 deletions crud/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func BenchmarkLenRequest(b *testing.B) {
buf.Reset()
req := crud.MakeLenRequest(spaceName).
Opts(crud.LenOpts{
Timeout: crud.MakeOptUint(3),
Timeout: crud.MakeOptFloat64(3.5),
})
if err := req.Body(nil, enc); err != nil {
b.Error(err)
Expand All @@ -156,7 +156,7 @@ func BenchmarkSelectRequest(b *testing.B) {
buf.Reset()
req := crud.MakeSelectRequest(spaceName).
Opts(crud.SelectOpts{
Timeout: crud.MakeOptUint(3),
Timeout: crud.MakeOptFloat64(3.5),
VshardRouter: crud.MakeOptString("asd"),
Balance: crud.MakeOptBool(true),
})
Expand Down
2 changes: 1 addition & 1 deletion crud/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type SelectOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Timeout OptUint
Timeout OptFloat64
// VshardRouter is cartridge vshard group name or
// vshard router instance.
VshardRouter OptString
Expand Down
24 changes: 12 additions & 12 deletions crud/tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var startOpts test_helpers.StartOpts = test_helpers.StartOpts{
RetryTimeout: 500 * time.Millisecond,
}

var timeout = uint(1)
var timeout = float64(1.1)

var operations = []crud.Operation{
{
Expand All @@ -48,43 +48,43 @@ var operations = []crud.Operation{
}

var selectOpts = crud.SelectOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var countOpts = crud.CountOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var getOpts = crud.GetOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var minOpts = crud.MinOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var maxOpts = crud.MaxOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var baseOpts = crud.BaseOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var simpleOperationOpts = crud.SimpleOperationOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var simpleOperationObjectOpts = crud.SimpleOperationObjectOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var opManyOpts = crud.OperationManyOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

var opObjManyOpts = crud.OperationObjectManyOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptFloat64(timeout),
}

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

req := crud.MakeGetRequest(spaceName).Key(key).Opts(crud.GetOpts{
Timeout: crud.MakeOptUint(1),
Timeout: crud.MakeOptFloat64(1.1),
Fields: crud.MakeOptTuple([]interface{}{"name"}),
Mode: crud.MakeOptString("read"),
PreferReplica: crud.MakeOptBool(true),
Expand Down