Skip to content

Commit 580d3be

Browse files
committed
api: support IPROTO_FEATURE_SPACE_AND_INDEX_NAMES
Support `IPROTO_FEATURE_SPACE_AND_INDEX_NAMES` for Tarantool version >= 3.0.0-alpha. It allows to use space and index names instead of their IDs. `ResolveSpaceIndex` function for `SchemaResolver` interface split into two: `ResolveSpace` and `ResolveIndex`. `NamesUseSupported` function added into the interface to get information if usage of space and index names is supported. Closes #338
1 parent a664c6b commit 580d3be

12 files changed

+545
-139
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ 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 `IPROTO_FEATURE_SPACE_AND_INDEX_NAMES` for Tarantool
26+
version >= 3.0.0-alpha1 (#338). It allows to use space and index names instead
27+
of their IDs
2528

2629
### Changed
2730

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ and user may cancel it in process.
239239
* `iproto.Feature` type used instead of `ProtocolFeature`.
240240
* `iproto.IPROTO_FEATURE_` constants used instead of local ones.
241241

242+
#### Schema changes
243+
244+
`ResolveSpaceIndex` function for `SchemaResolver` interface split into two:
245+
`ResolveSpace` and `ResolveIndex`. `NamesUseSupported` function added into the
246+
interface to get information if usage of space and index names is supported.
247+
242248
## Contributing
243249

244250
See [the contributing guide](CONTRIBUTING.md) for detailed instructions on how

crud/request_test.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/tarantool/go-tarantool/v2"
1414
"github.com/tarantool/go-tarantool/v2/crud"
15+
"github.com/tarantool/go-tarantool/v2/test_helpers"
1516
)
1617

1718
const invalidSpaceMsg = "invalid space"
@@ -72,25 +73,38 @@ var expectedOpts = map[string]interface{}{
7273
type ValidSchemeResolver struct {
7374
}
7475

75-
func (*ValidSchemeResolver) ResolveSpaceIndex(s, i interface{}) (uint32, uint32, error) {
76-
var spaceNo, indexNo uint32
76+
func (*ValidSchemeResolver) ResolveSpace(s interface{}) (uint32, error) {
77+
var spaceNo uint32
7778
if s != nil {
7879
spaceNo = uint32(s.(int))
7980
} else {
8081
spaceNo = defaultSpace
8182
}
83+
if spaceNo == invalidSpace {
84+
return 0, errors.New(invalidSpaceMsg)
85+
}
86+
return spaceNo, nil
87+
}
88+
89+
func (*ValidSchemeResolver) ResolveIndex(i interface{}, spaceNo uint32) (uint32, error) {
90+
var indexNo uint32
8291
if i != nil {
8392
indexNo = uint32(i.(int))
8493
} else {
8594
indexNo = defaultIndex
8695
}
87-
if spaceNo == invalidSpace {
88-
return 0, 0, errors.New(invalidSpaceMsg)
89-
}
9096
if indexNo == invalidIndex {
91-
return 0, 0, errors.New(invalidIndexMsg)
97+
return 0, errors.New(invalidIndexMsg)
98+
}
99+
return indexNo, nil
100+
}
101+
102+
func (*ValidSchemeResolver) NamesUseSupported() bool {
103+
isLess, err := test_helpers.IsTarantoolVersionLess(3, 0, 0)
104+
if err != nil {
105+
return false
92106
}
93-
return spaceNo, indexNo, nil
107+
return !isLess
94108
}
95109

96110
var resolver ValidSchemeResolver

example_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ func ExampleProtocolVersion() {
634634
// Connector client protocol feature: IPROTO_FEATURE_ERROR_EXTENSION
635635
// Connector client protocol feature: IPROTO_FEATURE_WATCHERS
636636
// Connector client protocol feature: IPROTO_FEATURE_PAGINATION
637+
// Connector client protocol feature: IPROTO_FEATURE_SPACE_AND_INDEX_NAMES
637638
// Connector client protocol feature: IPROTO_FEATURE_WATCH_ONCE
638639
}
639640

export_test.go

+38-13
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ import (
55
"net"
66
"time"
77

8+
"github.com/tarantool/go-iproto"
89
"github.com/vmihailenco/msgpack/v5"
910
)
1011

12+
func getSpaceKey(space interface{}) iproto.Key {
13+
if _, ok := space.(string); ok {
14+
return iproto.IPROTO_SPACE_NAME
15+
}
16+
return iproto.IPROTO_SPACE_ID
17+
}
18+
19+
func getIndexKey(index interface{}) iproto.Key {
20+
if _, ok := index.(string); ok {
21+
return iproto.IPROTO_INDEX_NAME
22+
}
23+
return iproto.IPROTO_INDEX_ID
24+
}
25+
1126
func SslDialContext(ctx context.Context, network, address string,
1227
opts SslOpts) (connection net.Conn, err error) {
1328
return sslDialContext(ctx, network, address, opts)
@@ -25,39 +40,49 @@ func RefImplPingBody(enc *msgpack.Encoder) error {
2540

2641
// RefImplSelectBody is reference implementation for filling of a select
2742
// request's body.
28-
func RefImplSelectBody(enc *msgpack.Encoder, space, index, offset, limit uint32, iterator Iter,
29-
key, after interface{}, fetchPos bool) error {
30-
return fillSelect(enc, space, index, offset, limit, iterator, key, after, fetchPos)
43+
func RefImplSelectBody(enc *msgpack.Encoder, space, index interface{},
44+
offset, limit uint32, iterator Iter, key, after interface{}, fetchPos bool) error {
45+
iprotoSpaceKey := getSpaceKey(space)
46+
iprotoIndexKey := getIndexKey(index)
47+
return fillSelect(enc, space, index, offset, limit, iterator, key, after,
48+
fetchPos, iprotoSpaceKey, iprotoIndexKey)
3149
}
3250

3351
// RefImplInsertBody is reference implementation for filling of an insert
3452
// request's body.
35-
func RefImplInsertBody(enc *msgpack.Encoder, space uint32, tuple interface{}) error {
36-
return fillInsert(enc, space, tuple)
53+
func RefImplInsertBody(enc *msgpack.Encoder, space, tuple interface{}) error {
54+
iprotoSpaceKey := getSpaceKey(space)
55+
return fillInsert(enc, space, tuple, iprotoSpaceKey)
3756
}
3857

3958
// RefImplReplaceBody is reference implementation for filling of a replace
4059
// request's body.
41-
func RefImplReplaceBody(enc *msgpack.Encoder, space uint32, tuple interface{}) error {
42-
return fillInsert(enc, space, tuple)
60+
func RefImplReplaceBody(enc *msgpack.Encoder, space, tuple interface{}) error {
61+
iprotoSpaceKey := getSpaceKey(space)
62+
return fillInsert(enc, space, tuple, iprotoSpaceKey)
4363
}
4464

4565
// RefImplDeleteBody is reference implementation for filling of a delete
4666
// request's body.
47-
func RefImplDeleteBody(enc *msgpack.Encoder, space, index uint32, key interface{}) error {
48-
return fillDelete(enc, space, index, key)
67+
func RefImplDeleteBody(enc *msgpack.Encoder, space, index, key interface{}) error {
68+
iprotoSpaceKey := getSpaceKey(space)
69+
iprotoIndexKey := getIndexKey(index)
70+
return fillDelete(enc, space, index, key, iprotoSpaceKey, iprotoIndexKey)
4971
}
5072

5173
// RefImplUpdateBody is reference implementation for filling of an update
5274
// request's body.
53-
func RefImplUpdateBody(enc *msgpack.Encoder, space, index uint32, key, ops interface{}) error {
54-
return fillUpdate(enc, space, index, key, ops)
75+
func RefImplUpdateBody(enc *msgpack.Encoder, space, index, key, ops interface{}) error {
76+
iprotoSpaceKey := getSpaceKey(space)
77+
iprotoIndexKey := getIndexKey(index)
78+
return fillUpdate(enc, space, index, key, ops, iprotoSpaceKey, iprotoIndexKey)
5579
}
5680

5781
// RefImplUpsertBody is reference implementation for filling of an upsert
5882
// request's body.
59-
func RefImplUpsertBody(enc *msgpack.Encoder, space uint32, tuple, ops interface{}) error {
60-
return fillUpsert(enc, space, tuple, ops)
83+
func RefImplUpsertBody(enc *msgpack.Encoder, space, tuple, ops interface{}) error {
84+
iprotoSpaceKey := getSpaceKey(space)
85+
return fillUpsert(enc, space, tuple, ops, iprotoSpaceKey)
6186
}
6287

6388
// RefImplCallBody is reference implementation for filling of a call or call17

protocol.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var clientProtocolInfo ProtocolInfo = ProtocolInfo{
5656
iproto.IPROTO_FEATURE_ERROR_EXTENSION,
5757
iproto.IPROTO_FEATURE_WATCHERS,
5858
iproto.IPROTO_FEATURE_PAGINATION,
59+
iproto.IPROTO_FEATURE_SPACE_AND_INDEX_NAMES,
5960
iproto.IPROTO_FEATURE_WATCH_ONCE,
6061
},
6162
}

0 commit comments

Comments
 (0)