Skip to content

Warn when register_sharding_key() is called with 'bucket_id' key #49

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 21, 2021
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ Every migration (e. g. `0001_create_my_sharded_space_DATETIME.lua`) should expos
return true
end
```

Warning! It's not correct to specify 'bucket_id' as a 'key' parameter for register_sharding_key().
The 'bucket_id' field is a place where the output of sharding function is saved to.


## Limitations
Expand Down
14 changes: 14 additions & 0 deletions migrator/utils.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local log = require('log')

local function value_in(val, arr)
for i, elem in ipairs(arr) do
Expand All @@ -16,8 +17,21 @@ local function compare(a, b)
return true
end


-- TODO: remove this ugly hack
---
--- Set fields that are used for sharding key calculation for a specified space.
---
--- @param space_name string name of sharded space
--- @param key table array of field names that will be used as input of sharding function
---
local function register_sharding_key(space_name, key)

if value_in('bucket_id', key) then
log.error("Wrong sharding key: 'bucket_id' is used as input of sharding function for space '"
.. space_name .. "'")
end

if box.space._ddl_sharding_key == nil then
local sharding_space = box.schema.space.create('_ddl_sharding_key', {
format = {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/basic_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ for k, configure_func in pairs(cases) do
},
},
is_local = false,
sharding_key = { "bucket_id" },
sharding_key = { "key" },
temporary = false,
},

Expand Down
2 changes: 1 addition & 1 deletion test/integration/migrations/03_sharded.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return {
if_not_exists = true,
unique = false
})
utils.register_sharding_key('sharded', {'bucket_id'})
utils.register_sharding_key('sharded', {'key'})
return nil
end
}