@@ -23,6 +23,20 @@ local function shard_check_error(func_name, result, err)
23
23
error ((' %s: %s' ):format (func_name , json .encode (err )))
24
24
end
25
25
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
+
26
40
--- Determines whether certain fields of two tables are the same.
27
41
---
28
42
--- Table fields of t1 and t2 are compared recursively by all its fields.
283
297
--- @treturn cdata/table `tuple`
284
298
local function insert_tuple (collection_name , tuple )
285
299
local func_name = ' accessor_shard.insert_tuple'
300
+
301
+ shard_check_status (func_name )
302
+
286
303
local result , err = shard :insert (collection_name , tuple )
287
304
shard_check_error (func_name , result , err )
288
305
@@ -337,6 +354,7 @@ local function space_operation(collection_name, nodes, operation, ...)
337
354
end
338
355
339
356
--- Delete tuple by a primary key.
357
+ ---
340
358
--- @tparam string collection_name
341
359
---
342
360
--- @param key primary key
347
365
---
348
366
--- @treturn cdata tuple
349
367
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
+
350
376
local tuple = opts .tuple or get_tuple (collection_name , key )
351
377
local nodes = shard .shard (tuple [SHARD_KEY_FIELD_NO ])
352
378
local tuple = space_operation (collection_name , nodes , ' delete' , key )
@@ -372,10 +398,14 @@ end
372
398
---
373
399
--- @treturn cdata/table `tuple`
374
400
local function update_tuple (collection_name , key , statements , opts )
401
+ local func_name = ' accessor_shard.update_tuple'
402
+
375
403
local opts = opts or {}
376
404
check (opts , ' opts' , ' table' )
377
405
check (opts .tuple , ' opts.tuple' , ' nil' , ' cdata' , ' table' )
378
406
407
+ shard_check_status (func_name )
408
+
379
409
local is_shard_key_to_be_updated = false
380
410
for _ , statement in ipairs (statements ) do
381
411
-- statement is {operator, field_no, value}
0 commit comments