Skip to content

Commit

Permalink
test: change space id range
Browse files Browse the repository at this point in the history
In Tarantool, user space ids starts from 512. You can set arbitrary id
or use autoincrement (sequence also starts from 512). Unfortunately,
mixing spaces with autoincremented ids and spaces with explicit ids may
cause id conflict [1]. Since there are cases when we cannot explicitly
set space id (creating a space with SQL), a short range of free ids
(from 512 to 515) causes problems. This patch increases range of free
ids (now it's from 512 to 615) so it should be ok until [1] is resolved.

1. tarantool/tarantool#8036

Part of #215
  • Loading branch information
DifferentialOrange committed Dec 12, 2022
1 parent 265f96c commit 9648c4f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
14 changes: 7 additions & 7 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ box.cfg{

box.once("init", function()
local st = box.schema.space.create('schematest', {
id = 516,
id = 616,
temporary = true,
if_not_exists = true,
field_count = 7,
Expand Down Expand Up @@ -36,7 +36,7 @@ box.once("init", function()
st:truncate()

local s = box.schema.space.create('test', {
id = 517,
id = 617,
if_not_exists = true,
})
s:create_index('primary', {
Expand All @@ -46,7 +46,7 @@ box.once("init", function()
})

local s = box.schema.space.create('teststring', {
id = 518,
id = 618,
if_not_exists = true,
})
s:create_index('primary', {
Expand All @@ -56,7 +56,7 @@ box.once("init", function()
})

local s = box.schema.space.create('testintint', {
id = 519,
id = 619,
if_not_exists = true,
})
s:create_index('primary', {
Expand All @@ -66,7 +66,7 @@ box.once("init", function()
})

local s = box.schema.space.create('SQL_TEST', {
id = 520,
id = 620,
if_not_exists = true,
format = {
{name = "NAME0", type = "unsigned"},
Expand All @@ -82,7 +82,7 @@ box.once("init", function()
s:insert{1, "test", "test"}

local s = box.schema.space.create('test_perf', {
id = 521,
id = 621,
temporary = true,
if_not_exists = true,
field_count = 3,
Expand Down Expand Up @@ -117,7 +117,7 @@ box.once("init", function()
end

local s = box.schema.space.create('test_error_type', {
id = 522,
id = 622,
temporary = true,
if_not_exists = true,
field_count = 2,
Expand Down
2 changes: 1 addition & 1 deletion example_custom_unpacking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Example_customUnpacking() {
log.Fatalf("Failed to connect: %s", err.Error())
}

spaceNo := uint32(517)
spaceNo := uint32(617)
indexNo := uint32(0)

tuple := Tuple2{Cid: 777, Orig: "orig", Members: []Member{{"lol", "", 1}, {"wut", "", 3}}}
Expand Down
24 changes: 12 additions & 12 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ExampleConnection_Select() {
conn.Replace(spaceNo, []interface{}{uint(1111), "hello", "world"})
conn.Replace(spaceNo, []interface{}{uint(1112), "hallo", "werld"})

resp, err := conn.Select(517, 0, 0, 100, tarantool.IterEq, []interface{}{uint(1111)})
resp, err := conn.Select(617, 0, 0, 100, tarantool.IterEq, []interface{}{uint(1111)})

if err != nil {
fmt.Printf("error in select is %v", err)
Expand All @@ -75,7 +75,7 @@ func ExampleConnection_SelectTyped() {
defer conn.Close()
var res []Tuple

err := conn.SelectTyped(517, 0, 0, 100, tarantool.IterEq, tarantool.IntKey{1111}, &res)
err := conn.SelectTyped(617, 0, 0, 100, tarantool.IterEq, tarantool.IntKey{1111}, &res)

if err != nil {
fmt.Printf("error in select is %v", err)
Expand All @@ -96,7 +96,7 @@ func ExampleConnection_SelectTyped() {
func ExampleConnection_SelectAsync() {
conn := example_connect(opts)
defer conn.Close()
spaceNo := uint32(517)
spaceNo := uint32(617)

conn.Insert(spaceNo, []interface{}{uint(16), "test", "one"})
conn.Insert(spaceNo, []interface{}{uint(17), "test", "one"})
Expand Down Expand Up @@ -223,7 +223,7 @@ func ExampleSelectRequest() {
conn := example_connect(opts)
defer conn.Close()

req := tarantool.NewSelectRequest(517).
req := tarantool.NewSelectRequest(617).
Limit(100).
Key(tarantool.IntKey{1111})
resp, err := conn.Do(req).Get()
Expand Down Expand Up @@ -253,7 +253,7 @@ func ExampleUpdateRequest() {
conn := example_connect(opts)
defer conn.Close()

req := tarantool.NewUpdateRequest(517).
req := tarantool.NewUpdateRequest(617).
Key(tarantool.IntKey{1111}).
Operations(tarantool.NewOperations().Assign(1, "bye"))
resp, err := conn.Do(req).Get()
Expand Down Expand Up @@ -284,7 +284,7 @@ func ExampleUpsertRequest() {
defer conn.Close()

var req tarantool.Request
req = tarantool.NewUpsertRequest(517).
req = tarantool.NewUpsertRequest(617).
Tuple([]interface{}{uint(1113), "first", "first"}).
Operations(tarantool.NewOperations().Assign(1, "updated"))
resp, err := conn.Do(req).Get()
Expand All @@ -305,7 +305,7 @@ func ExampleUpsertRequest() {
}
fmt.Printf("response is %#v\n", resp.Data)

req = tarantool.NewSelectRequest(517).
req = tarantool.NewSelectRequest(617).
Limit(100).
Key(tarantool.IntKey{1113})
resp, err = conn.Do(req).Get()
Expand Down Expand Up @@ -830,12 +830,12 @@ func ExampleSchema() {
}

space1 := schema.Spaces["test"]
space2 := schema.SpacesById[516]
space2 := schema.SpacesById[616]
fmt.Printf("Space 1 ID %d %s\n", space1.Id, space1.Name)
fmt.Printf("Space 2 ID %d %s\n", space2.Id, space2.Name)
// Output:
// Space 1 ID 517 test
// Space 2 ID 516 schematest
// Space 1 ID 617 test
// Space 2 ID 616 schematest
}

// Example demonstrates how to retrieve information with space schema.
Expand All @@ -854,7 +854,7 @@ func ExampleSpace() {

// Access Space objects by name or ID.
space1 := schema.Spaces["test"]
space2 := schema.SpacesById[516] // It's a map.
space2 := schema.SpacesById[616] // It's a map.
fmt.Printf("Space 1 ID %d %s %s\n", space1.Id, space1.Name, space1.Engine)
fmt.Printf("Space 1 ID %d %t\n", space1.FieldsCount, space1.Temporary)

Expand All @@ -875,7 +875,7 @@ func ExampleSpace() {
fmt.Printf("SpaceField 2 %s %s\n", spaceField2.Name, spaceField2.Type)

// Output:
// Space 1 ID 517 test memtx
// Space 1 ID 617 test memtx
// Space 1 ID 0 false
// Index 0 primary
// &{0 unsigned} &{2 string}
Expand Down
4 changes: 2 additions & 2 deletions multi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rawset(_G, 'get_cluster_nodes', get_cluster_nodes)

box.once("init", function()
local s = box.schema.space.create('test', {
id = 517,
id = 617,
if_not_exists = true,
})
s:create_index('primary', {type = 'tree', parts = {1, 'string'}, if_not_exists = true})
Expand All @@ -22,7 +22,7 @@ box.once("init", function()
box.schema.user.grant('test', 'read,write,execute', 'universe')

local sp = box.schema.space.create('SQL_TEST', {
id = 521,
id = 621,
if_not_exists = true,
format = {
{name = "NAME0", type = "unsigned"},
Expand Down
2 changes: 1 addition & 1 deletion multi/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var server1 = "127.0.0.1:3013"
var server2 = "127.0.0.1:3014"
var spaceNo = uint32(517)
var spaceNo = uint32(617)
var spaceName = "test"
var indexNo = uint32(0)
var connOpts = tarantool.Opts{
Expand Down
32 changes: 16 additions & 16 deletions tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func convertUint64(v interface{}) (result uint64, err error) {
}

var server = "127.0.0.1:3013"
var spaceNo = uint32(517)
var spaceNo = uint32(617)
var spaceName = "test"
var indexNo = uint32(0)
var indexName = "primary"
Expand Down Expand Up @@ -1776,29 +1776,29 @@ func TestSchema(t *testing.T) {
}
var space, space2 *Space
var ok bool
if space, ok = schema.SpacesById[516]; !ok {
t.Errorf("space with id = 516 was not found in schema.SpacesById")
if space, ok = schema.SpacesById[616]; !ok {
t.Errorf("space with id = 616 was not found in schema.SpacesById")
}
if space2, ok = schema.Spaces["schematest"]; !ok {
t.Errorf("space with name 'schematest' was not found in schema.SpacesById")
}
if space != space2 {
t.Errorf("space with id = 516 and space with name schematest are different")
t.Errorf("space with id = 616 and space with name schematest are different")
}
if space.Id != 516 {
t.Errorf("space 516 has incorrect Id")
if space.Id != 616 {
t.Errorf("space 616 has incorrect Id")
}
if space.Name != "schematest" {
t.Errorf("space 516 has incorrect Name")
t.Errorf("space 616 has incorrect Name")
}
if !space.Temporary {
t.Errorf("space 516 should be temporary")
t.Errorf("space 616 should be temporary")
}
if space.Engine != "memtx" {
t.Errorf("space 516 engine should be memtx")
t.Errorf("space 616 engine should be memtx")
}
if space.FieldsCount != 7 {
t.Errorf("space 516 has incorrect fields count")
t.Errorf("space 616 has incorrect fields count")
}

if space.FieldsById == nil {
Expand Down Expand Up @@ -1908,20 +1908,20 @@ func TestSchema(t *testing.T) {
}

var rSpaceNo, rIndexNo uint32
rSpaceNo, rIndexNo, err = schema.ResolveSpaceIndex(516, 3)
if err != nil || rSpaceNo != 516 || rIndexNo != 3 {
rSpaceNo, rIndexNo, err = schema.ResolveSpaceIndex(616, 3)
if err != nil || rSpaceNo != 616 || rIndexNo != 3 {
t.Errorf("numeric space and index params not resolved as-is")
}
rSpaceNo, _, err = schema.ResolveSpaceIndex(516, nil)
if err != nil || rSpaceNo != 516 {
rSpaceNo, _, err = schema.ResolveSpaceIndex(616, nil)
if err != nil || rSpaceNo != 616 {
t.Errorf("numeric space param not resolved as-is")
}
rSpaceNo, rIndexNo, err = schema.ResolveSpaceIndex("schematest", "secondary")
if err != nil || rSpaceNo != 516 || rIndexNo != 3 {
if err != nil || rSpaceNo != 616 || rIndexNo != 3 {
t.Errorf("symbolic space and index params not resolved")
}
rSpaceNo, _, err = schema.ResolveSpaceIndex("schematest", nil)
if err != nil || rSpaceNo != 516 {
if err != nil || rSpaceNo != 616 {
t.Errorf("symbolic space param not resolved")
}
_, _, err = schema.ResolveSpaceIndex("schematest22", "secondary")
Expand Down

0 comments on commit 9648c4f

Please sign in to comment.