Skip to content

Commit

Permalink
Use DDL sharding key in replace, insert and upsert
Browse files Browse the repository at this point in the history
Calculate bucket_id for operations replace, insert and upsert
using DDL sharding key.

Part of #166
  • Loading branch information
ligurio committed Jul 15, 2021
1 parent 72b508d commit 1fa83ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crud/common/sharding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ function sharding.tuple_get_bucket_id(tuple, space, specified_bucket_id)
return specified_bucket_id
end

local key = utils.extract_key(tuple, space.index[0].parts)
local primary_index = space.index[0]
local key
local sharding_key = sharding.get_ddl_sharding_key(space.name)
if sharding_key ~= nil then
local space_format = space:format()
local sharding_key_fieldno_map = utils.get_keys_fieldno_map(space_format, sharding_key)
key = utils.extract_sharding_key(tuple, primary_index.parts, sharding_key_fieldno_map)
else
key = utils.extract_key(tuple, primary_index.parts)
end

return sharding.key_get_bucket_id(key)
end

Expand Down
11 changes: 11 additions & 0 deletions crud/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ function utils.unflatten(tuple, space_format)
return object
end

function utils.extract_sharding_key(tuple, key_parts, sharding_fieldno_map)
local key = {}
for i, part in pairs(key_parts) do
local fieldno = part.fieldno
if sharding_fieldno_map[fieldno] ~= nil then
key[i] = tuple[fieldno]
end
end
return key
end

function utils.extract_key(tuple, key_parts)
local key = {}
for i, part in ipairs(key_parts) do
Expand Down

0 comments on commit 1fa83ad

Please sign in to comment.