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 e744f71
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 24 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ clean:
.PHONY: deps
deps: clean
( cd ./queue/testdata; $(TTCTL) rocks install queue 1.3.0 )
( cd ./crud/testdata; $(TTCTL) rocks install crud 1.1.1 )
( cd ./crud/testdata; $(TTCTL) rocks install crud 1.3.0 )

.PHONY: datetime-timezones
datetime-timezones:
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
54 changes: 44 additions & 10 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,15 +282,20 @@ 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,
skipNullabilityCheckOnFlattenOptName}
fetchLatestMetadataOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
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,
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.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
26 changes: 17 additions & 9 deletions crud/tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,52 @@ 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),
}

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 e744f71

Please sign in to comment.