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

Commit cca757a

Browse files
committed
Support shard-2.1
Part of #111.
1 parent dd27668 commit cca757a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ make test
101101
* tarantool,
102102
* lulpeg,
103103
* >=tarantool/avro-schema-2.0-71-gfea0ead,
104-
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) (optional),
104+
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) or
105+
>=tarantool/shard-2.1-0-g0a7d98f (optional),
105106
* lrexlib-pcre2 or lrexlib-pcre (optional).
106107
* For test (additionally to 'for use'):
107108
* python 2.7,
108109
* virtualenv,
109110
* luacheck,
110-
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0),
111+
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0) or
112+
>=tarantool/shard-2.1-0-g0a7d98f.
111113
* >=tarantool/avro-schema-2.2.2-4-g1145e3e.
112114
* For building apidoc (additionally to 'for use'):
113115
* ldoc.

graphql/accessor_shard.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22
--- (@{accessor_general}) behaves as shard accessor and provides the
33
--- `accessor_shard.new` function to create a new shard data accessor instance.
44

5+
local json = require('json')
56
local shard = require('shard')
67
local accessor_general = require('graphql.accessor_general')
78

89
local accessor_shard = {}
910

1011
local LIMIT = 100000 -- XXX: we need to raise an error when a limit reached
1112

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+
1218
-- Check whether a collection (it is sharded space for that accessor) exists.
1319
local function is_collection_exists(collection_name)
20+
local func_name = 'accessor_shard.is_collection_exists'
1421
local exists
1522
for _, zone in ipairs(shard.shards) do
1623
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,
1825
function(space_obj)
1926
return space_obj ~= nil
2027
end)
28+
shard_check_error(func_name, cur, err)
2129
assert(exists == nil or cur == exists,
2230
('space "%s" exists on some shards, ' ..
2331
'but does not on others'):format(collection_name))
@@ -31,13 +39,15 @@ end
3139
--- determining whether the index exists within a shard cluster is
3240
--- not-so-trivial as for local spaces.
3341
local function is_index_exists(collection_name, index_name)
42+
local func_name = 'accessor_shard.is_index_exists'
3443
local exists
3544
for _, zone in ipairs(shard.shards) do
3645
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,
3847
function(space_obj)
3948
return space_obj.index[index_name] ~= nil
4049
end)
50+
shard_check_error(func_name, cur, err)
4151
assert(exists == nil or cur == exists,
4252
('index "%s" of space "%s" exists on some shards, ' ..
4353
'but does not on others'):format(index_name, collection_name))
@@ -57,10 +67,12 @@ local function get_index(collection_name, index_name)
5767
local index = setmetatable({}, {
5868
__index = {
5969
pairs = function(self, value, opts)
70+
local func_name = 'accessor_shard.get_index.<index>.pairs'
6071
local opts = opts or {}
6172
opts.limit = opts.limit or LIMIT
62-
local tuples = shard:secondary_select(collection_name,
73+
local tuples, err = shard:secondary_select(collection_name,
6374
index_name, opts, value, 0)
75+
shard_check_error(func_name, tuples, err)
6476
local cur = 1
6577
local function gen()
6678
if cur > #tuples then return nil end

0 commit comments

Comments
 (0)