Skip to content

Commit b87066f

Browse files
committed
Use DDL sharding key in replace, insert and upsert
Calculate bucket_id for operations replace, insert and upsert using DDL sharding key. Part of #166
1 parent be9003e commit b87066f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crud/common/sharding.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ function sharding.tuple_get_bucket_id(tuple, space, specified_bucket_id)
2222
return specified_bucket_id
2323
end
2424

25-
local key = utils.extract_key(tuple, space.index[0].parts)
25+
local primary_index = space.index[0]
26+
local key
27+
local sharding_key = sharding.get_ddl_sharding_key(space.name)
28+
if sharding_key ~= nil then
29+
local space_format = space:format()
30+
local sharding_key_fieldno_map = utils.get_keys_fieldno_map(space_format, sharding_key)
31+
key = utils.extract_sharding_key(tuple, primary_index.parts, sharding_key_fieldno_map)
32+
else
33+
key = utils.extract_key(tuple, primary_index.parts)
34+
end
35+
2636
return sharding.key_get_bucket_id(key)
2737
end
2838

crud/common/utils.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ function utils.unflatten(tuple, space_format)
140140
return object
141141
end
142142

143+
function utils.extract_sharding_key(tuple, key_parts, sharding_fieldno_map)
144+
local key = {}
145+
for i, part in pairs(key_parts) do
146+
local fieldno = part.fieldno
147+
if sharding_fieldno_map[fieldno] ~= nil then
148+
key[i] = tuple[fieldno]
149+
end
150+
end
151+
return key
152+
end
153+
143154
function utils.extract_key(tuple, key_parts)
144155
local key = {}
145156
for i, part in ipairs(key_parts) do

0 commit comments

Comments
 (0)