Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 8ca29dc

Browse files
committed
Add check for resharding state for mutations
Thanks to Pavel Yudin (@Kasen) for pointing me the way to do so.
1 parent 1a131ee commit 8ca29dc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

graphql/accessor_shard.lua

+30
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ local function shard_check_error(func_name, result, err)
2323
error(('%s: %s'):format(func_name, json.encode(err)))
2424
end
2525

26+
-- Should work for shard-1.2 and shard-2.1 both.
27+
local function shard_check_status(func_name)
28+
if box.space._shard == nil then return end
29+
30+
local mode = box.space._shard:get({'RESHARDING_STATE'})
31+
local resharding_is_in_progress = mode ~= nil and #mode >= 2 and
32+
type(mode[2]) == 'number' and mode[2] > 0
33+
if resharding_is_in_progress then
34+
error(('%s: shard cluster is in the resharding state, ' ..
35+
'modification requests are temporary forbidden'):format(
36+
func_name))
37+
end
38+
end
39+
2640
--- Determines whether certain fields of two tables are the same.
2741
---
2842
--- Table fields of t1 and t2 are compared recursively by all its fields.
@@ -283,6 +297,9 @@ end
283297
--- @treturn cdata/table `tuple`
284298
local function insert_tuple(collection_name, tuple)
285299
local func_name = 'accessor_shard.insert_tuple'
300+
301+
shard_check_status(func_name)
302+
286303
local result, err = shard:insert(collection_name, tuple)
287304
shard_check_error(func_name, result, err)
288305

@@ -337,6 +354,7 @@ local function space_operation(collection_name, nodes, operation, ...)
337354
end
338355

339356
--- Delete tuple by a primary key.
357+
---
340358
--- @tparam string collection_name
341359
---
342360
--- @param key primary key
@@ -347,6 +365,14 @@ end
347365
---
348366
--- @treturn cdata tuple
349367
local function delete_tuple(collection_name, key, opts)
368+
local func_name = 'accessor_shard.delete_tuple'
369+
370+
local opts = opts or {}
371+
check(opts, 'opts', 'table')
372+
check(opts.tuple, 'opts.tuple', 'nil', 'cdata', 'table')
373+
374+
shard_check_status(func_name)
375+
350376
local tuple = opts.tuple or get_tuple(collection_name, key)
351377
local nodes = shard.shard(tuple[SHARD_KEY_FIELD_NO])
352378
local tuple = space_operation(collection_name, nodes, 'delete', key)
@@ -372,10 +398,14 @@ end
372398
---
373399
--- @treturn cdata/table `tuple`
374400
local function update_tuple(collection_name, key, statements, opts)
401+
local func_name = 'accessor_shard.update_tuple'
402+
375403
local opts = opts or {}
376404
check(opts, 'opts', 'table')
377405
check(opts.tuple, 'opts.tuple', 'nil', 'cdata', 'table')
378406

407+
shard_check_status(func_name)
408+
379409
local is_shard_key_to_be_updated = false
380410
for _, statement in ipairs(statements) do
381411
-- statement is {operator, field_no, value}

0 commit comments

Comments
 (0)