Skip to content

Commit dc1d5cb

Browse files
Vladimir Rogachsharonovd
authored andcommitted
Display a warning when register_sharding_key() is called with a bucket_id key
1 parent fc6b3c3 commit dc1d5cb

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ Every migration (e. g. `0001_create_my_sharded_space_DATETIME.lua`) should expos
142142
return true
143143
end
144144
```
145-
145+
Warning! It's not correct to specify 'bucket_id' as a 'key' parameter for register_sharding_key().
146+
The 'bucket_id' field is a place where the output of sharding function is saved to.
146147

147148

148149
## Limitations

migrator/utils.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local log = require('log')
12

23
local function value_in(val, arr)
34
for i, elem in ipairs(arr) do
@@ -16,8 +17,21 @@ local function compare(a, b)
1617
return true
1718
end
1819

20+
1921
-- TODO: remove this ugly hack
22+
---
23+
--- Set fields that are used for sharding key calculation for a specified space.
24+
---
25+
--- @param space_name string name of sharded space
26+
--- @param key table array of field names that will be used as input of sharding function
27+
---
2028
local function register_sharding_key(space_name, key)
29+
30+
if value_in('bucket_id', key) then
31+
log.error("Wrong sharding key: 'bucket_id' is used as input of sharding function for space '"
32+
.. space_name .. "'")
33+
end
34+
2135
if box.space._ddl_sharding_key == nil then
2236
local sharding_space = box.schema.space.create('_ddl_sharding_key', {
2337
format = {

test/integration/basic_test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ for k, configure_func in pairs(cases) do
153153
},
154154
},
155155
is_local = false,
156-
sharding_key = { "bucket_id" },
156+
sharding_key = { "key" },
157157
temporary = false,
158158
},
159159

test/integration/migrations/03_sharded.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ return {
1919
if_not_exists = true,
2020
unique = false
2121
})
22-
utils.register_sharding_key('sharded', {'bucket_id'})
22+
utils.register_sharding_key('sharded', {'key'})
2323
return nil
2424
end
2525
}

0 commit comments

Comments
 (0)