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: support yield_every in select #350

Merged
merged 1 commit into from
Nov 7, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- Support `crud.schema` request (#336)
- Support `IPROTO_WATCH_ONCE` request type for Tarantool
version >= 3.0.0-alpha1 (#337)
- Support `yield_every` option for crud select requests (#350)

### Changed

Expand Down
1 change: 1 addition & 0 deletions crud/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CountOpts struct {
// load balancing policy.
Balance OptBool
// YieldEvery describes number of tuples processed to yield after.
// Should be positive.
YieldEvery OptUint
// BucketId is a bucket ID.
BucketId OptUint
Expand Down
1 change: 1 addition & 0 deletions crud/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
batchSizeOptName = "batch_size"
fetchLatestMetadataOptName = "fetch_latest_metadata"
noreturnOptName = "noreturn"
yieldEvery = "yield_every"
)

// OptUint is an optional uint.
Expand Down
9 changes: 7 additions & 2 deletions crud/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ type SelectOpts struct {
// the latest migration of the data format. Performance overhead is up to 15%.
// Disabled by default.
FetchLatestMetadata OptBool
// YieldEvery describes number of tuples processed to yield after.
// Should be positive.
YieldEvery OptUint
}

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

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

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand Down
34 changes: 34 additions & 0 deletions crud/tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,40 @@ func TestUnitEmptySchema(t *testing.T) {
require.Equal(t, result.Value, crud.Schema{}, "empty schema expected")
}

var testStorageYieldCases = []struct {
name string
req tarantool.Request
}{
{
"Count",
crud.MakeCountRequest(spaceName).
Opts(crud.CountOpts{
YieldEvery: crud.MakeOptUint(500),
}),
},
{
"Select",
crud.MakeSelectRequest(spaceName).
Opts(crud.SelectOpts{
YieldEvery: crud.MakeOptUint(500),
}),
},
}

func TestYieldEveryOption(t *testing.T) {
conn := connect(t)
defer conn.Close()

for _, testCase := range testStorageYieldCases {
t.Run(testCase.name, func(t *testing.T) {
_, err := conn.Do(testCase.req).Get()
if err != nil {
t.Fatalf("Failed to Do CRUD request: %s", err)
}
})
}
}

// runTestMain is a body of TestMain function
// (see https://pkg.go.dev/testing#hdr-Main).
// Using defer + os.Exit is not works so TestMain body
Expand Down
Loading