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 API improvements #335

Merged
merged 6 commits into from
Oct 9, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ 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)
- Support `noreturn` option for data change crud requests (#335)

### Changed

Expand Down Expand Up @@ -55,6 +57,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- Incorrect decoding of an MP_DECIMAL when the `scale` value is negative (#314)
- Incorrect options (`after`, `batch_size` and `force_map_call`) setup for
crud.SelectRequest (#320)
- Incorrect options (`vshard_router`, `fields`, `bucket_id`, `mode`,
`prefer_replica`, `balance`) setup for crud.GetRequest (#335)

## [1.12.0] - 2023-06-07

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
27 changes: 27 additions & 0 deletions crud/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,33 @@ func ExampleResult_many() {
// [[2010 45 bla] [2011 4 bla]]
}

// ExampleResult_noreturn demonstrates noreturn request: a data change
// request where you don't need to retrieve the result, just want to know
// whether it was successful or not.
func ExampleResult_noreturn() {
conn := exampleConnect()
req := crud.MakeReplaceManyRequest(exampleSpace).
Tuples([]crud.Tuple{
[]interface{}{uint(2010), nil, "bla"},
[]interface{}{uint(2011), nil, "bla"},
}).
Opts(crud.ReplaceManyOpts{
Noreturn: crud.MakeOptBool(true),
})

ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
fmt.Printf("Failed to execute request: %s", err)
return
}

fmt.Println(ret.Metadata)
fmt.Println(ret.Rows)
// Output:
// []
// <nil>
}

// ExampleResult_error demonstrates how to use a helper type Result
// to handle a crud error.
func ExampleResult_error() {
Expand Down
19 changes: 13 additions & 6 deletions crud/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@ 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()
values[1], exists[1] = opts.VshardRouter.Get()
values[1], exists[1] = opts.BucketId.Get()
values[2], exists[2] = opts.Mode.Get()
values[3], exists[3] = opts.PreferReplica.Get()
values[4], exists[4] = opts.Balance.Get()
values[2], exists[2] = opts.Fields.Get()
values[3], exists[3] = opts.BucketId.Get()
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
79 changes: 67 additions & 12 deletions crud/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
firstOptName = "first"
afterOptName = "after"
batchSizeOptName = "batch_size"
fetchLatestMetadataOptName = "fetch_latest_metadata"
noreturnOptName = "noreturn"
)

// OptUint is an optional uint.
Expand Down Expand Up @@ -138,6 +140,7 @@ func (opts BaseOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
}

// SimpleOperationOpts describes options for simple CRUD operations.
// It also covers `upsert_object` options.
type SimpleOperationOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Expand All @@ -149,26 +152,37 @@ 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
// Noreturn suppresses successfully processed data (first return value is `nil`).
// Disabled by default.
Noreturn OptBool
}

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

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, bucketIdOptName}
fieldsOptName, bucketIdOptName, fetchLatestMetadataOptName,
noreturnOptName}
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()
values[5], exists[5] = opts.Noreturn.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}

// SimpleOperationObjectOpts describes options for simple CRUD
// operations with objects.
// operations with objects. It doesn't cover `upsert_object` options.
type SimpleOperationObjectOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Expand All @@ -183,26 +197,38 @@ 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
// Noreturn suppresses successfully processed data (first return value is `nil`).
// Disabled by default.
Noreturn OptBool
}

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

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, bucketIdOptName, skipNullabilityCheckOnFlattenOptName}
fieldsOptName, bucketIdOptName, skipNullabilityCheckOnFlattenOptName,
fetchLatestMetadataOptName, noreturnOptName}
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()
values[6], exists[6] = opts.Noreturn.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}

// OperationManyOpts describes options for CRUD operations with many tuples.
// It also covers `upsert_object_many` options.
type OperationManyOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Expand All @@ -219,27 +245,38 @@ 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
// Noreturn suppresses successfully processed data (first return value is `nil`).
// Disabled by default.
Noreturn OptBool
}

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

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName}
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName,
fetchLatestMetadataOptName, noreturnOptName}
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()
values[6], exists[6] = opts.Noreturn.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}

// OperationObjectManyOpts describes options for CRUD operations
// with many objects.
// with many objects. It doesn't cover `upsert_object_many` options.
type OperationObjectManyOpts struct {
// Timeout is a `vshard.call` timeout and vshard
// master discovery timeout (in seconds).
Expand All @@ -259,15 +296,24 @@ 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
// Noreturn suppresses successfully processed data (first return value is `nil`).
// Disabled by default.
Noreturn OptBool
}

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

names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName,
skipNullabilityCheckOnFlattenOptName}
skipNullabilityCheckOnFlattenOptName, fetchLatestMetadataOptName,
noreturnOptName}
values := [optsCnt]interface{}{}
exists := [optsCnt]bool{}
values[0], exists[0] = opts.Timeout.Get()
Expand All @@ -276,6 +322,8 @@ 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()
values[7], exists[7] = opts.Noreturn.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand All @@ -290,18 +338,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
Loading