Skip to content

Commit

Permalink
crud: support fetch_latest_metadata option
Browse files Browse the repository at this point in the history
`fetch_latest_metadata` option was introduced in crud 1.2.0 [1].

1. tarantool/crud@2675925
  • Loading branch information
DifferentialOrange committed Oct 5, 2023
1 parent ce1be6a commit 27d1cb6
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- Meaningful description for read/write socket errors (#129)
- Support password and password file to decrypt private SSL key file (#319)
- Support `operation_data` in `crud.Error` (#330)
- Support `fetch_latest_metadata` option for crud requests with metadata (#335)

### Changed

Expand Down
10 changes: 8 additions & 2 deletions crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ type GetOpts struct {
// Balance is a parameter to use replica according to vshard
// load balancing policy.
Balance OptBool
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
}

// EncodeMsgpack provides custom msgpack encoder.
func (opts GetOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
const optsCnt = 7
const optsCnt = 8

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, bucketIdOptName, modeOptName,
preferReplicaOptName, balanceOptName}
preferReplicaOptName, balanceOptName, fetchLatestMetadataOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
Expand All @@ -47,6 +52,7 @@ func (opts GetOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
values[4], exists[4] = opts.Mode.Get()
values[5], exists[5] = opts.PreferReplica.Get()
values[6], exists[6] = opts.Balance.Get()
values[7], exists[7] = opts.FetchLatestMetadata.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand Down
52 changes: 43 additions & 9 deletions crud/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
firstOptName = "first"
afterOptName = "after"
batchSizeOptName = "batch_size"
fetchLatestMetadataOptName = "fetch_latest_metadata"
)

// OptUint is an optional uint.
Expand Down Expand Up @@ -150,20 +151,26 @@ type SimpleOperationOpts struct {
Fields OptTuple
// BucketId is a bucket ID.
BucketId OptUint
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
}

// EncodeMsgpack provides custom msgpack encoder.
func (opts SimpleOperationOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
const optsCnt = 4
const optsCnt = 5

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, bucketIdOptName}
fieldsOptName, bucketIdOptName, fetchLatestMetadataOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
values[1], exists[1] = opts.VshardRouter.Get()
values[2], exists[2] = opts.Fields.Get()
values[3], exists[3] = opts.BucketId.Get()
values[4], exists[4] = opts.FetchLatestMetadata.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand All @@ -184,21 +191,28 @@ type SimpleOperationObjectOpts struct {
// SkipNullabilityCheckOnFlatten is a parameter to allow
// setting null values to non-nullable fields.
SkipNullabilityCheckOnFlatten OptBool
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
}

// EncodeMsgpack provides custom msgpack encoder.
func (opts SimpleOperationObjectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
const optsCnt = 5
const optsCnt = 6

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, bucketIdOptName, skipNullabilityCheckOnFlattenOptName}
fieldsOptName, bucketIdOptName, skipNullabilityCheckOnFlattenOptName,
fetchLatestMetadataOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
values[1], exists[1] = opts.VshardRouter.Get()
values[2], exists[2] = opts.Fields.Get()
values[3], exists[3] = opts.BucketId.Get()
values[4], exists[4] = opts.SkipNullabilityCheckOnFlatten.Get()
values[5], exists[5] = opts.FetchLatestMetadata.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand All @@ -221,21 +235,28 @@ type OperationManyOpts struct {
// RollbackOnError is a parameter because of what any failed operation
// will lead to rollback on a storage, where the operation is failed.
RollbackOnError OptBool
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
}

// EncodeMsgpack provides custom msgpack encoder.
func (opts OperationManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
const optsCnt = 5
const optsCnt = 6

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName}
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName,
fetchLatestMetadataOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
values[1], exists[1] = opts.VshardRouter.Get()
values[2], exists[2] = opts.Fields.Get()
values[3], exists[3] = opts.StopOnError.Get()
values[4], exists[4] = opts.RollbackOnError.Get()
values[5], exists[5] = opts.FetchLatestMetadata.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand All @@ -261,11 +282,16 @@ type OperationObjectManyOpts struct {
// SkipNullabilityCheckOnFlatten is a parameter to allow
// setting null values to non-nullable fields.
SkipNullabilityCheckOnFlatten OptBool
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
}

// EncodeMsgpack provides custom msgpack encoder.
func (opts OperationObjectManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
const optsCnt = 6
const optsCnt = 7

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName,
Expand All @@ -278,6 +304,7 @@ func (opts OperationObjectManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
values[3], exists[3] = opts.StopOnError.Get()
values[4], exists[4] = opts.RollbackOnError.Get()
values[5], exists[5] = opts.SkipNullabilityCheckOnFlatten.Get()
values[6], exists[6] = opts.FetchLatestMetadata.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand All @@ -292,18 +319,25 @@ type BorderOpts struct {
VshardRouter OptString
// Fields is field names for getting only a subset of fields.
Fields OptTuple
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
}

// EncodeMsgpack provides custom msgpack encoder.
func (opts BorderOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
const optsCnt = 3
const optsCnt = 4

names := [optsCnt]string{timeoutOptName, vshardRouterOptName, fieldsOptName}
names := [optsCnt]string{timeoutOptName, vshardRouterOptName, fieldsOptName,
skipNullabilityCheckOnFlattenOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
values[1], exists[1] = opts.VshardRouter.Get()
values[2], exists[2] = opts.Fields.Get()
values[3], exists[3] = opts.FetchLatestMetadata.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand Down
10 changes: 8 additions & 2 deletions crud/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ type SelectOpts struct {
// Fullscan describes if a critical log entry will be skipped on
// potentially long select.
Fullscan OptBool
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
// in first return value, otherwise it may not take into account
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
}

// EncodeMsgpack provides custom msgpack encoder.
func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
const optsCnt = 12
const optsCnt = 13

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, bucketIdOptName,
modeOptName, preferReplicaOptName, balanceOptName,
firstOptName, afterOptName, batchSizeOptName,
forceMapCallOptName, fullscanOptName}
forceMapCallOptName, fullscanOptName, fetchLatestMetadataOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
Expand All @@ -66,6 +71,7 @@ func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
values[9], exists[9] = opts.BatchSize.Get()
values[10], exists[10] = opts.ForceMapCall.Get()
values[11], exists[11] = opts.Fullscan.Get()
values[12], exists[12] = opts.FetchLatestMetadata.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand Down
29 changes: 19 additions & 10 deletions crud/tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,53 @@ var operations = []crud.Operation{
}

var selectOpts = crud.SelectOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),
}

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

var getOpts = crud.GetOpts{
Timeout: crud.MakeOptUint(timeout),
Mode: crud.MakeOptString("read"),
Timeout: crud.MakeOptUint(timeout),
Mode: crud.MakeOptString("read"),
FetchLatestMetadata: crud.MakeOptBool(true),
}

var minOpts = crud.MinOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),
}

var maxOpts = crud.MaxOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),
}

var baseOpts = crud.BaseOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ee (bundle-1.10.11-0-gf0b0e7ecf-r470, false, false, false)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unknown field FetchLatestMetadata in struct literal of type crud.BaseOpts (typecheck)

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ee (bundle-2.10.0-1-gfa775b383-r486-linux-x86_64, false, true)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ce (1.13, 1.10, false, false)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ee (sdk-gc64-2.11.0-0-r577.linux.x86_64, true, true, release/linux/x86_64/2.11/)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ce (1.13, 2.8, false, false)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ce (1.13, 2.10, false, false)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ce (1.13, 2.x-latest, false, false)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ce (2.x-latest, true, 1.13)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts

Check failure on line 77 in crud/tarantool_test.go

View workflow job for this annotation

GitHub Actions / run-tests-ce (2.x-latest, true, 1.18, false)

unknown field 'FetchLatestMetadata' in struct literal of type crud.BaseOpts
}

var simpleOperationOpts = crud.SimpleOperationOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),
}

var simpleOperationObjectOpts = crud.SimpleOperationObjectOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),
}

var opManyOpts = crud.OperationManyOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),
}

var opObjManyOpts = crud.OperationObjectManyOpts{
Timeout: crud.MakeOptUint(timeout),
Timeout: crud.MakeOptUint(timeout),
FetchLatestMetadata: crud.MakeOptBool(true),
}

var conditions = []crud.Condition{
Expand Down

0 comments on commit 27d1cb6

Please sign in to comment.