2
2
--- (@{accessor_general}) behaves as shard accessor and provides the
3
3
--- `accessor_shard.new` function to create a new shard data accessor instance.
4
4
5
+ local json = require (' json' )
5
6
local shard = require (' shard' )
6
7
local accessor_general = require (' graphql.accessor_general' )
7
8
8
9
local accessor_shard = {}
9
10
10
11
local LIMIT = 100000 -- XXX: we need to raise an error when a limit reached
11
12
13
+ local function shard_check_error (func_name , result , err )
14
+ if result ~= nil then return end
15
+ error ((' %s: %s' ):format (func_name , json .encode (err )))
16
+ end
17
+
12
18
-- Check whether a collection (it is sharded space for that accessor) exists.
13
19
local function is_collection_exists (collection_name )
20
+ local func_name = ' accessor_shard.is_collection_exists'
14
21
local exists
15
22
for _ , zone in ipairs (shard .shards ) do
16
23
for _ , node in ipairs (zone ) do
17
- local cur = shard :space_call (collection_name , node ,
24
+ local cur , err = shard :space_call (collection_name , node ,
18
25
function (space_obj )
19
26
return space_obj ~= nil
20
27
end )
28
+ shard_check_error (func_name , cur , err )
21
29
assert (exists == nil or cur == exists ,
22
30
(' space "%s" exists on some shards, ' ..
23
31
' but does not on others' ):format (collection_name ))
31
39
--- determining whether the index exists within a shard cluster is
32
40
--- not-so-trivial as for local spaces.
33
41
local function is_index_exists (collection_name , index_name )
42
+ local func_name = ' accessor_shard.is_index_exists'
34
43
local exists
35
44
for _ , zone in ipairs (shard .shards ) do
36
45
for _ , node in ipairs (zone ) do
37
- local cur = shard :space_call (collection_name , node ,
46
+ local cur , err = shard :space_call (collection_name , node ,
38
47
function (space_obj )
39
48
return space_obj .index [index_name ] ~= nil
40
49
end )
50
+ shard_check_error (func_name , cur , err )
41
51
assert (exists == nil or cur == exists ,
42
52
(' index "%s" of space "%s" exists on some shards, ' ..
43
53
' but does not on others' ):format (index_name , collection_name ))
@@ -57,10 +67,12 @@ local function get_index(collection_name, index_name)
57
67
local index = setmetatable ({}, {
58
68
__index = {
59
69
pairs = function (self , value , opts )
70
+ local func_name = ' accessor_shard.get_index.<index>.pairs'
60
71
local opts = opts or {}
61
72
opts .limit = opts .limit or LIMIT
62
- local tuples = shard :secondary_select (collection_name ,
73
+ local tuples , err = shard :secondary_select (collection_name ,
63
74
index_name , opts , value , 0 )
75
+ shard_check_error (func_name , tuples , err )
64
76
local cur = 1
65
77
local function gen ()
66
78
if cur > # tuples then return nil end
0 commit comments