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 1, 2023
1 parent a664c6b commit 4837a79
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 134 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
23 changes: 16 additions & 7 deletions crud/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,34 @@ 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 spaceNo, indexNo, nil
return indexNo, nil
}

func (*ValidSchemeResolver) NamesUseSupported() bool {
return false
}

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
20 changes: 12 additions & 8 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"time"

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

Expand All @@ -25,39 +26,42 @@ 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 {
return fillSelect(enc, space, index, offset, limit, iterator, key, after,
fetchPos, iproto.IPROTO_SPACE_ID, iproto.IPROTO_INDEX_ID)
}

// 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)
return fillInsert(enc, space, tuple, iproto.IPROTO_SPACE_ID)
}

// 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)
return fillInsert(enc, space, tuple, iproto.IPROTO_SPACE_ID)
}

// 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)
return fillDelete(enc, space, index, key,
iproto.IPROTO_SPACE_ID, iproto.IPROTO_INDEX_ID)
}

// 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)
return fillUpdate(enc, space, index, key, ops,
iproto.IPROTO_SPACE_ID, iproto.IPROTO_INDEX_ID)
}

// 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)
return fillUpsert(enc, space, tuple, ops, iproto.IPROTO_SPACE_ID)
}

// 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 4837a79

Please sign in to comment.