Skip to content

Commit 4116f2c

Browse files
crud: support yield_every in select
`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
1 parent c564e6d commit 4116f2c

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2222
- Support `crud.schema` request (#336)
2323
- Support `IPROTO_WATCH_ONCE` request type for Tarantool
2424
version >= 3.0.0-alpha1 (#337)
25+
- Support `yield_every` option for crud select requests (#350)
2526

2627
### Changed
2728

crud/count.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type CountOpts struct {
2929
// load balancing policy.
3030
Balance OptBool
3131
// YieldEvery describes number of tuples processed to yield after.
32+
// Should be positive.
3233
YieldEvery OptUint
3334
// BucketId is a bucket ID.
3435
BucketId OptUint

crud/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
batchSizeOptName = "batch_size"
2424
fetchLatestMetadataOptName = "fetch_latest_metadata"
2525
noreturnOptName = "noreturn"
26+
yieldEvery = "yield_every"
2627
)
2728

2829
// OptUint is an optional uint.

crud/select.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@ type SelectOpts struct {
4646
// the latest migration of the data format. Performance overhead is up to 15%.
4747
// Disabled by default.
4848
FetchLatestMetadata OptBool
49+
// YieldEvery describes number of tuples processed to yield after.
50+
// Should be positive.
51+
YieldEvery OptUint
4952
}
5053

5154
// EncodeMsgpack provides custom msgpack encoder.
5255
func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
53-
const optsCnt = 13
56+
const optsCnt = 14
5457

5558
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
5659
fieldsOptName, bucketIdOptName,
5760
modeOptName, preferReplicaOptName, balanceOptName,
5861
firstOptName, afterOptName, batchSizeOptName,
59-
forceMapCallOptName, fullscanOptName, fetchLatestMetadataOptName}
62+
forceMapCallOptName, fullscanOptName, fetchLatestMetadataOptName,
63+
yieldEveryOptName}
6064
values := [optsCnt]interface{}{}
6165
exists := [optsCnt]bool{}
6266
values[0], exists[0] = opts.Timeout.Get()
@@ -72,6 +76,7 @@ func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
7276
values[10], exists[10] = opts.ForceMapCall.Get()
7377
values[11], exists[11] = opts.Fullscan.Get()
7478
values[12], exists[12] = opts.FetchLatestMetadata.Get()
79+
values[13], exists[13] = opts.YieldEvery.Get()
7580

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

crud/tarantool_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,40 @@ func TestUnitEmptySchema(t *testing.T) {
13331333
require.Equal(t, result.Value, crud.Schema{}, "empty schema expected")
13341334
}
13351335

1336+
var testStorageYieldCases = []struct {
1337+
name string
1338+
req tarantool.Request
1339+
}{
1340+
{
1341+
"Count",
1342+
crud.MakeCountRequest(spaceName).
1343+
Opts(crud.CountOpts{
1344+
YieldEvery: crud.MakeOptUint(500),
1345+
}),
1346+
},
1347+
{
1348+
"Select",
1349+
crud.MakeSelectRequest(spaceName).
1350+
Opts(crud.SelectOpts{
1351+
YieldEvery: crud.MakeOptUint(500),
1352+
}),
1353+
},
1354+
}
1355+
1356+
func TestYieldEveryOption(t *testing.T) {
1357+
conn := connect(t)
1358+
defer conn.Close()
1359+
1360+
for _, testCase := range testStorageYieldCases {
1361+
t.Run(testCase.name, func(t *testing.T) {
1362+
_, err := conn.Do(testCase.req).Get()
1363+
if err != nil {
1364+
t.Fatalf("Failed to Do CRUD request: %s", err)
1365+
}
1366+
})
1367+
}
1368+
}
1369+
13361370
// runTestMain is a body of TestMain function
13371371
// (see https://pkg.go.dev/testing#hdr-Main).
13381372
// Using defer + os.Exit is not works so TestMain body

0 commit comments

Comments
 (0)