Skip to content

schema: move 'concurrent schema update' error to constants #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

- Implemented all box.schema.user operations requests and sugar interface (#426).
- Implemented box.session.su request and sugar interface only for current session granting (#426).
- Defined `ErrConcurrentSchemaUpdate` constant for "concurrent schema update" error.
Now you can check this error with `errors.Is(err, tarantool.ErrConcurrentSchemaUpdate)`.

### Changed

Expand Down
6 changes: 5 additions & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const (
vspaceSpFormatFieldNum = 7
)

var (
ErrConcurrentSchemaUpdate = errors.New("concurrent schema update")
)

func msgpackIsUint(code byte) bool {
return code == msgpcode.Uint8 || code == msgpcode.Uint16 ||
code == msgpcode.Uint32 || code == msgpcode.Uint64 ||
Expand Down Expand Up @@ -415,7 +419,7 @@ func GetSchema(doer Doer) (Schema, error) {
schema.SpacesById[spaceId].IndexesById[index.Id] = index
schema.SpacesById[spaceId].Indexes[index.Name] = index
} else {
return Schema{}, errors.New("concurrent schema update")
return Schema{}, ErrConcurrentSchemaUpdate
}
}

Expand Down
5 changes: 5 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmihailenco/msgpack/v5"

Expand Down Expand Up @@ -160,3 +161,7 @@ func TestResolverNotCalledWithNameSupport(t *testing.T) {
resolver.indexResolverCalls)
}
}

func TestErrConcurrentSchemaUpdate(t *testing.T) {
assert.EqualError(t, tarantool.ErrConcurrentSchemaUpdate, "concurrent schema update")
}
15 changes: 7 additions & 8 deletions tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3999,14 +3999,13 @@ func TestConnect_schema_update(t *testing.T) {
for i := 0; i < 100; i++ {
fut := conn.Do(NewCallRequest("create_spaces"))

if conn, err := Connect(ctx, dialer, opts); err != nil {
if err.Error() != "concurrent schema update" {
t.Errorf("unexpected error: %s", err)
}
} else if conn == nil {
t.Errorf("conn is nil")
} else {
conn.Close()
switch conn, err := Connect(ctx, dialer, opts); {
case err != nil:
assert.ErrorIs(t, err, ErrConcurrentSchemaUpdate)
case conn == nil:
assert.Fail(t, "conn is nil")
default:
_ = conn.Close()
}

if _, err := fut.Get(); err != nil {
Expand Down
Loading