Skip to content

Commit e744f71

Browse files
crud: support fetch_latest_metadata option
`fetch_latest_metadata` option was introduced in crud 1.2.0 [1]. 1. tarantool/crud@2675925
1 parent ce1be6a commit e744f71

File tree

6 files changed

+79
-24
lines changed

6 files changed

+79
-24
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1717
- Meaningful description for read/write socket errors (#129)
1818
- Support password and password file to decrypt private SSL key file (#319)
1919
- Support `operation_data` in `crud.Error` (#330)
20+
- Support `fetch_latest_metadata` option for crud requests with metadata (#335)
2021

2122
### Changed
2223

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ clean:
2727
.PHONY: deps
2828
deps: clean
2929
( cd ./queue/testdata; $(TTCTL) rocks install queue 1.3.0 )
30-
( cd ./crud/testdata; $(TTCTL) rocks install crud 1.1.1 )
30+
( cd ./crud/testdata; $(TTCTL) rocks install crud 1.3.0 )
3131

3232
.PHONY: datetime-timezones
3333
datetime-timezones:

crud/get.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ type GetOpts struct {
2929
// Balance is a parameter to use replica according to vshard
3030
// load balancing policy.
3131
Balance OptBool
32+
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
33+
// in first return value, otherwise it may not take into account
34+
// the latest migration of the data format. Performance overhead is up to 15%.
35+
// Disabled by default.
36+
FetchLatestMetadata OptBool
3237
}
3338

3439
// EncodeMsgpack provides custom msgpack encoder.
3540
func (opts GetOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
36-
const optsCnt = 7
41+
const optsCnt = 8
3742

3843
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
3944
fieldsOptName, bucketIdOptName, modeOptName,
40-
preferReplicaOptName, balanceOptName}
45+
preferReplicaOptName, balanceOptName, fetchLatestMetadataOptName}
4146
values := [optsCnt]interface{}{}
4247
exists := [optsCnt]bool{}
4348
values[0], exists[0] = opts.Timeout.Get()
@@ -47,6 +52,7 @@ func (opts GetOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
4752
values[4], exists[4] = opts.Mode.Get()
4853
values[5], exists[5] = opts.PreferReplica.Get()
4954
values[6], exists[6] = opts.Balance.Get()
55+
values[7], exists[7] = opts.FetchLatestMetadata.Get()
5056

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

crud/options.go

+44-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
firstOptName = "first"
2222
afterOptName = "after"
2323
batchSizeOptName = "batch_size"
24+
fetchLatestMetadataOptName = "fetch_latest_metadata"
2425
)
2526

2627
// OptUint is an optional uint.
@@ -150,20 +151,26 @@ type SimpleOperationOpts struct {
150151
Fields OptTuple
151152
// BucketId is a bucket ID.
152153
BucketId OptUint
154+
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
155+
// in first return value, otherwise it may not take into account
156+
// the latest migration of the data format. Performance overhead is up to 15%.
157+
// Disabled by default.
158+
FetchLatestMetadata OptBool
153159
}
154160

155161
// EncodeMsgpack provides custom msgpack encoder.
156162
func (opts SimpleOperationOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
157-
const optsCnt = 4
163+
const optsCnt = 5
158164

159165
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
160-
fieldsOptName, bucketIdOptName}
166+
fieldsOptName, bucketIdOptName, fetchLatestMetadataOptName}
161167
values := [optsCnt]interface{}{}
162168
exists := [optsCnt]bool{}
163169
values[0], exists[0] = opts.Timeout.Get()
164170
values[1], exists[1] = opts.VshardRouter.Get()
165171
values[2], exists[2] = opts.Fields.Get()
166172
values[3], exists[3] = opts.BucketId.Get()
173+
values[4], exists[4] = opts.FetchLatestMetadata.Get()
167174

168175
return encodeOptions(enc, names[:], values[:], exists[:])
169176
}
@@ -184,21 +191,28 @@ type SimpleOperationObjectOpts struct {
184191
// SkipNullabilityCheckOnFlatten is a parameter to allow
185192
// setting null values to non-nullable fields.
186193
SkipNullabilityCheckOnFlatten OptBool
194+
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
195+
// in first return value, otherwise it may not take into account
196+
// the latest migration of the data format. Performance overhead is up to 15%.
197+
// Disabled by default.
198+
FetchLatestMetadata OptBool
187199
}
188200

189201
// EncodeMsgpack provides custom msgpack encoder.
190202
func (opts SimpleOperationObjectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
191-
const optsCnt = 5
203+
const optsCnt = 6
192204

193205
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
194-
fieldsOptName, bucketIdOptName, skipNullabilityCheckOnFlattenOptName}
206+
fieldsOptName, bucketIdOptName, skipNullabilityCheckOnFlattenOptName,
207+
fetchLatestMetadataOptName}
195208
values := [optsCnt]interface{}{}
196209
exists := [optsCnt]bool{}
197210
values[0], exists[0] = opts.Timeout.Get()
198211
values[1], exists[1] = opts.VshardRouter.Get()
199212
values[2], exists[2] = opts.Fields.Get()
200213
values[3], exists[3] = opts.BucketId.Get()
201214
values[4], exists[4] = opts.SkipNullabilityCheckOnFlatten.Get()
215+
values[5], exists[5] = opts.FetchLatestMetadata.Get()
202216

203217
return encodeOptions(enc, names[:], values[:], exists[:])
204218
}
@@ -221,21 +235,28 @@ type OperationManyOpts struct {
221235
// RollbackOnError is a parameter because of what any failed operation
222236
// will lead to rollback on a storage, where the operation is failed.
223237
RollbackOnError OptBool
238+
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
239+
// in first return value, otherwise it may not take into account
240+
// the latest migration of the data format. Performance overhead is up to 15%.
241+
// Disabled by default.
242+
FetchLatestMetadata OptBool
224243
}
225244

226245
// EncodeMsgpack provides custom msgpack encoder.
227246
func (opts OperationManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
228-
const optsCnt = 5
247+
const optsCnt = 6
229248

230249
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
231-
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName}
250+
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName,
251+
fetchLatestMetadataOptName}
232252
values := [optsCnt]interface{}{}
233253
exists := [optsCnt]bool{}
234254
values[0], exists[0] = opts.Timeout.Get()
235255
values[1], exists[1] = opts.VshardRouter.Get()
236256
values[2], exists[2] = opts.Fields.Get()
237257
values[3], exists[3] = opts.StopOnError.Get()
238258
values[4], exists[4] = opts.RollbackOnError.Get()
259+
values[5], exists[5] = opts.FetchLatestMetadata.Get()
239260

240261
return encodeOptions(enc, names[:], values[:], exists[:])
241262
}
@@ -261,15 +282,20 @@ type OperationObjectManyOpts struct {
261282
// SkipNullabilityCheckOnFlatten is a parameter to allow
262283
// setting null values to non-nullable fields.
263284
SkipNullabilityCheckOnFlatten OptBool
285+
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
286+
// in first return value, otherwise it may not take into account
287+
// the latest migration of the data format. Performance overhead is up to 15%.
288+
// Disabled by default.
289+
FetchLatestMetadata OptBool
264290
}
265291

266292
// EncodeMsgpack provides custom msgpack encoder.
267293
func (opts OperationObjectManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
268-
const optsCnt = 6
294+
const optsCnt = 7
269295

270296
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
271297
fieldsOptName, stopOnErrorOptName, rollbackOnErrorOptName,
272-
skipNullabilityCheckOnFlattenOptName}
298+
fetchLatestMetadataOptName}
273299
values := [optsCnt]interface{}{}
274300
exists := [optsCnt]bool{}
275301
values[0], exists[0] = opts.Timeout.Get()
@@ -278,6 +304,7 @@ func (opts OperationObjectManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
278304
values[3], exists[3] = opts.StopOnError.Get()
279305
values[4], exists[4] = opts.RollbackOnError.Get()
280306
values[5], exists[5] = opts.SkipNullabilityCheckOnFlatten.Get()
307+
values[6], exists[6] = opts.FetchLatestMetadata.Get()
281308

282309
return encodeOptions(enc, names[:], values[:], exists[:])
283310
}
@@ -292,18 +319,25 @@ type BorderOpts struct {
292319
VshardRouter OptString
293320
// Fields is field names for getting only a subset of fields.
294321
Fields OptTuple
322+
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
323+
// in first return value, otherwise it may not take into account
324+
// the latest migration of the data format. Performance overhead is up to 15%.
325+
// Disabled by default.
326+
FetchLatestMetadata OptBool
295327
}
296328

297329
// EncodeMsgpack provides custom msgpack encoder.
298330
func (opts BorderOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
299-
const optsCnt = 3
331+
const optsCnt = 4
300332

301-
names := [optsCnt]string{timeoutOptName, vshardRouterOptName, fieldsOptName}
333+
names := [optsCnt]string{timeoutOptName, vshardRouterOptName, fieldsOptName,
334+
fetchLatestMetadataOptName}
302335
values := [optsCnt]interface{}{}
303336
exists := [optsCnt]bool{}
304337
values[0], exists[0] = opts.Timeout.Get()
305338
values[1], exists[1] = opts.VshardRouter.Get()
306339
values[2], exists[2] = opts.Fields.Get()
340+
values[3], exists[3] = opts.FetchLatestMetadata.Get()
307341

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

crud/select.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,22 @@ type SelectOpts struct {
4141
// Fullscan describes if a critical log entry will be skipped on
4242
// potentially long select.
4343
Fullscan OptBool
44+
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
45+
// in first return value, otherwise it may not take into account
46+
// the latest migration of the data format. Performance overhead is up to 15%.
47+
// Disabled by default.
48+
FetchLatestMetadata OptBool
4449
}
4550

4651
// EncodeMsgpack provides custom msgpack encoder.
4752
func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
48-
const optsCnt = 12
53+
const optsCnt = 13
4954

5055
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
5156
fieldsOptName, bucketIdOptName,
5257
modeOptName, preferReplicaOptName, balanceOptName,
5358
firstOptName, afterOptName, batchSizeOptName,
54-
forceMapCallOptName, fullscanOptName}
59+
forceMapCallOptName, fullscanOptName, fetchLatestMetadataOptName}
5560
values := [optsCnt]interface{}{}
5661
exists := [optsCnt]bool{}
5762
values[0], exists[0] = opts.Timeout.Get()
@@ -66,6 +71,7 @@ func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
6671
values[9], exists[9] = opts.BatchSize.Get()
6772
values[10], exists[10] = opts.ForceMapCall.Get()
6873
values[11], exists[11] = opts.Fullscan.Get()
74+
values[12], exists[12] = opts.FetchLatestMetadata.Get()
6975

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

crud/tarantool_test.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,52 @@ var operations = []crud.Operation{
4848
}
4949

5050
var selectOpts = crud.SelectOpts{
51-
Timeout: crud.MakeOptUint(timeout),
51+
Timeout: crud.MakeOptUint(timeout),
52+
FetchLatestMetadata: crud.MakeOptBool(true),
5253
}
5354

5455
var countOpts = crud.CountOpts{
5556
Timeout: crud.MakeOptUint(timeout),
5657
}
5758

5859
var getOpts = crud.GetOpts{
59-
Timeout: crud.MakeOptUint(timeout),
60-
Mode: crud.MakeOptString("read"),
60+
Timeout: crud.MakeOptUint(timeout),
61+
Mode: crud.MakeOptString("read"),
62+
FetchLatestMetadata: crud.MakeOptBool(true),
6163
}
6264

6365
var minOpts = crud.MinOpts{
64-
Timeout: crud.MakeOptUint(timeout),
66+
Timeout: crud.MakeOptUint(timeout),
67+
FetchLatestMetadata: crud.MakeOptBool(true),
6568
}
6669

6770
var maxOpts = crud.MaxOpts{
68-
Timeout: crud.MakeOptUint(timeout),
71+
Timeout: crud.MakeOptUint(timeout),
72+
FetchLatestMetadata: crud.MakeOptBool(true),
6973
}
7074

7175
var baseOpts = crud.BaseOpts{
7276
Timeout: crud.MakeOptUint(timeout),
7377
}
7478

7579
var simpleOperationOpts = crud.SimpleOperationOpts{
76-
Timeout: crud.MakeOptUint(timeout),
80+
Timeout: crud.MakeOptUint(timeout),
81+
FetchLatestMetadata: crud.MakeOptBool(true),
7782
}
7883

7984
var simpleOperationObjectOpts = crud.SimpleOperationObjectOpts{
80-
Timeout: crud.MakeOptUint(timeout),
85+
Timeout: crud.MakeOptUint(timeout),
86+
FetchLatestMetadata: crud.MakeOptBool(true),
8187
}
8288

8389
var opManyOpts = crud.OperationManyOpts{
84-
Timeout: crud.MakeOptUint(timeout),
90+
Timeout: crud.MakeOptUint(timeout),
91+
FetchLatestMetadata: crud.MakeOptBool(true),
8592
}
8693

8794
var opObjManyOpts = crud.OperationObjectManyOpts{
88-
Timeout: crud.MakeOptUint(timeout),
95+
Timeout: crud.MakeOptUint(timeout),
96+
FetchLatestMetadata: crud.MakeOptBool(true),
8997
}
9098

9199
var conditions = []crud.Condition{

0 commit comments

Comments
 (0)