Skip to content

Commit

Permalink
crud: support yield_every in select
Browse files Browse the repository at this point in the history
`yield_every` was introduced to crud.count and crud.select
in crud 1.1.1 [1]. The option is already supported for count requests,
but select request misses it. This patch adds the option.

1. https://github.com/tarantool/crud/releases/tag/1.1.1
  • Loading branch information
DifferentialOrange committed Nov 7, 2023
1 parent c564e6d commit 4116f2c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
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

0 comments on commit 4116f2c

Please sign in to comment.