Skip to content

Commit

Permalink
api: support IPROTO_FEATURE_SPACE_AND_INDEX_NAMES
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DerekBum committed Nov 2, 2023
1 parent a664c6b commit 580d3be
Show file tree
Hide file tree
Showing 12 changed files with 545 additions and 139 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ 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 `IPROTO_FEATURE_SPACE_AND_INDEX_NAMES` for Tarantool
version >= 3.0.0-alpha1 (#338). It allows to use space and index names instead
of their IDs

### Changed

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ and user may cancel it in process.
* `iproto.Feature` type used instead of `ProtocolFeature`.
* `iproto.IPROTO_FEATURE_` constants used instead of local ones.

#### Schema changes

`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.

## Contributing

See [the contributing guide](CONTRIBUTING.md) for detailed instructions on how
Expand Down
28 changes: 21 additions & 7 deletions crud/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/tarantool/go-tarantool/v2"
"github.com/tarantool/go-tarantool/v2/crud"
"github.com/tarantool/go-tarantool/v2/test_helpers"
)

const invalidSpaceMsg = "invalid space"
Expand Down Expand Up @@ -72,25 +73,38 @@ var expectedOpts = map[string]interface{}{
type ValidSchemeResolver struct {
}

func (*ValidSchemeResolver) ResolveSpaceIndex(s, i interface{}) (uint32, uint32, error) {
var spaceNo, indexNo uint32
func (*ValidSchemeResolver) ResolveSpace(s interface{}) (uint32, error) {
var spaceNo uint32
if s != nil {
spaceNo = uint32(s.(int))
} else {
spaceNo = defaultSpace
}
if spaceNo == invalidSpace {
return 0, errors.New(invalidSpaceMsg)
}
return spaceNo, nil
}

func (*ValidSchemeResolver) ResolveIndex(i interface{}, spaceNo uint32) (uint32, error) {
var indexNo uint32
if i != nil {
indexNo = uint32(i.(int))
} else {
indexNo = defaultIndex
}
if spaceNo == invalidSpace {
return 0, 0, errors.New(invalidSpaceMsg)
}
if indexNo == invalidIndex {
return 0, 0, errors.New(invalidIndexMsg)
return 0, errors.New(invalidIndexMsg)
}
return indexNo, nil
}

func (*ValidSchemeResolver) NamesUseSupported() bool {
isLess, err := test_helpers.IsTarantoolVersionLess(3, 0, 0)
if err != nil {
return false
}
return spaceNo, indexNo, nil
return !isLess
}

var resolver ValidSchemeResolver
Expand Down
1 change: 1 addition & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func ExampleProtocolVersion() {
// Connector client protocol feature: IPROTO_FEATURE_ERROR_EXTENSION
// Connector client protocol feature: IPROTO_FEATURE_WATCHERS
// Connector client protocol feature: IPROTO_FEATURE_PAGINATION
// Connector client protocol feature: IPROTO_FEATURE_SPACE_AND_INDEX_NAMES
// Connector client protocol feature: IPROTO_FEATURE_WATCH_ONCE
}

Expand Down
51 changes: 38 additions & 13 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@ import (
"net"
"time"

"github.com/tarantool/go-iproto"
"github.com/vmihailenco/msgpack/v5"
)

func getSpaceKey(space interface{}) iproto.Key {
if _, ok := space.(string); ok {
return iproto.IPROTO_SPACE_NAME
}
return iproto.IPROTO_SPACE_ID
}

func getIndexKey(index interface{}) iproto.Key {
if _, ok := index.(string); ok {
return iproto.IPROTO_INDEX_NAME
}
return iproto.IPROTO_INDEX_ID
}

func SslDialContext(ctx context.Context, network, address string,
opts SslOpts) (connection net.Conn, err error) {
return sslDialContext(ctx, network, address, opts)
Expand All @@ -25,39 +40,49 @@ func RefImplPingBody(enc *msgpack.Encoder) error {

// RefImplSelectBody is reference implementation for filling of a select
// request's body.
func RefImplSelectBody(enc *msgpack.Encoder, space, index, offset, limit uint32, iterator Iter,
key, after interface{}, fetchPos bool) error {
return fillSelect(enc, space, index, offset, limit, iterator, key, after, fetchPos)
func RefImplSelectBody(enc *msgpack.Encoder, space, index interface{},
offset, limit uint32, iterator Iter, key, after interface{}, fetchPos bool) error {
iprotoSpaceKey := getSpaceKey(space)
iprotoIndexKey := getIndexKey(index)
return fillSelect(enc, space, index, offset, limit, iterator, key, after,
fetchPos, iprotoSpaceKey, iprotoIndexKey)
}

// RefImplInsertBody is reference implementation for filling of an insert
// request's body.
func RefImplInsertBody(enc *msgpack.Encoder, space uint32, tuple interface{}) error {
return fillInsert(enc, space, tuple)
func RefImplInsertBody(enc *msgpack.Encoder, space, tuple interface{}) error {
iprotoSpaceKey := getSpaceKey(space)
return fillInsert(enc, space, tuple, iprotoSpaceKey)
}

// RefImplReplaceBody is reference implementation for filling of a replace
// request's body.
func RefImplReplaceBody(enc *msgpack.Encoder, space uint32, tuple interface{}) error {
return fillInsert(enc, space, tuple)
func RefImplReplaceBody(enc *msgpack.Encoder, space, tuple interface{}) error {
iprotoSpaceKey := getSpaceKey(space)
return fillInsert(enc, space, tuple, iprotoSpaceKey)
}

// RefImplDeleteBody is reference implementation for filling of a delete
// request's body.
func RefImplDeleteBody(enc *msgpack.Encoder, space, index uint32, key interface{}) error {
return fillDelete(enc, space, index, key)
func RefImplDeleteBody(enc *msgpack.Encoder, space, index, key interface{}) error {
iprotoSpaceKey := getSpaceKey(space)
iprotoIndexKey := getIndexKey(index)
return fillDelete(enc, space, index, key, iprotoSpaceKey, iprotoIndexKey)
}

// RefImplUpdateBody is reference implementation for filling of an update
// request's body.
func RefImplUpdateBody(enc *msgpack.Encoder, space, index uint32, key, ops interface{}) error {
return fillUpdate(enc, space, index, key, ops)
func RefImplUpdateBody(enc *msgpack.Encoder, space, index, key, ops interface{}) error {
iprotoSpaceKey := getSpaceKey(space)
iprotoIndexKey := getIndexKey(index)
return fillUpdate(enc, space, index, key, ops, iprotoSpaceKey, iprotoIndexKey)
}

// RefImplUpsertBody is reference implementation for filling of an upsert
// request's body.
func RefImplUpsertBody(enc *msgpack.Encoder, space uint32, tuple, ops interface{}) error {
return fillUpsert(enc, space, tuple, ops)
func RefImplUpsertBody(enc *msgpack.Encoder, space, tuple, ops interface{}) error {
iprotoSpaceKey := getSpaceKey(space)
return fillUpsert(enc, space, tuple, ops, iprotoSpaceKey)
}

// RefImplCallBody is reference implementation for filling of a call or call17
Expand Down
1 change: 1 addition & 0 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var clientProtocolInfo ProtocolInfo = ProtocolInfo{
iproto.IPROTO_FEATURE_ERROR_EXTENSION,
iproto.IPROTO_FEATURE_WATCHERS,
iproto.IPROTO_FEATURE_PAGINATION,
iproto.IPROTO_FEATURE_SPACE_AND_INDEX_NAMES,
iproto.IPROTO_FEATURE_WATCH_ONCE,
},
}
Expand Down
Loading

0 comments on commit 580d3be

Please sign in to comment.