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

Commit 780c33f

Browse files
authored
Merge pull request #125 from tarantool/gh-111-support-shard-2.0
Support shard-2.1
2 parents acd69af + 5c8298e commit 780c33f

File tree

102 files changed

+1790
-8943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1790
-8943
lines changed

.luacheckrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ std = {
33
'tonumber', 'type', 'assert', 'ipairs', 'math', 'error', 'string',
44
'table', 'pairs', 'os', 'select', 'unpack', 'dofile', 'next',
55
'getmetatable', 'setmetatable', 'rawget', 'print', 'shard_status',
6-
'loadstring',
6+
'loadstring', 'arg',
77
},
88
globals = {'package'}
99
}

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ sudo: true
44

55
dist: trusty
66

7+
env:
8+
- SHARD_VERSION=1.2
9+
- SHARD_VERSION=2.1
10+
711
branches:
812
only:
913
- master
@@ -32,7 +36,7 @@ install:
3236
- cmake .
3337
- sudo make install
3438
- cd ..
35-
- tarantoolctl rocks install shard 1.2
39+
- tarantoolctl rocks install shard "${SHARD_VERSION}"
3640
- tarantoolctl rocks install avro-schema
3741
- cd graphql
3842
- git submodule update --recursive --init

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ default:
1010
lint:
1111
luacheck graphql/*.lua \
1212
test/bench/*.lua \
13-
test/local/*.lua \
13+
test/space/*.lua \
1414
test/testdata/*.lua \
15-
test/common/*.test.lua test/common/lua/*.lua \
16-
test/extra/*.test.lua \
15+
test/common/*.lua \
16+
test/extra/*.lua \
1717
test/*.lua \
1818
--no-redefined --no-unused-args
1919

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

graphql/tarantool_graphql.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,10 @@ local function create_default_accessor(cfg)
13291329
collections = cfg.collections,
13301330
service_fields = cfg.service_fields,
13311331
indexes = cfg.indexes,
1332-
collection_use_tomap = cfg.collection_use_tomap
1332+
collection_use_tomap = cfg.collection_use_tomap,
1333+
resulting_object_cnt_max = cfg.resulting_object_cnt_max,
1334+
fetched_object_cnt_max = cfg.fetched_object_cnt_max,
1335+
timeout_ms = cfg.timeout_ms,
13331336
}, cfg.accessor_funcs)
13341337
end
13351338

@@ -1339,7 +1342,10 @@ local function create_default_accessor(cfg)
13391342
collections = cfg.collections,
13401343
service_fields = cfg.service_fields,
13411344
indexes = cfg.indexes,
1342-
collection_use_tomap = cfg.collection_use_tomap
1345+
collection_use_tomap = cfg.collection_use_tomap,
1346+
resulting_object_cnt_max = cfg.resulting_object_cnt_max,
1347+
fetched_object_cnt_max = cfg.fetched_object_cnt_max,
1348+
timeout_ms = cfg.timeout_ms,
13431349
}, cfg.accessor_funcs);
13441350
end
13451351
end

test/bench/bench.lua

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ local yaml = require('yaml')
1212
local clock = require('clock')
1313
local fiber = require('fiber')
1414
local digest = require('digest')
15-
local multirunner = require('test.common.lua.multirunner')
15+
local multirunner = require('test.common.multirunner')
1616
local graphql = require('graphql')
1717
local utils = require('graphql.utils')
18+
local test_utils = require('test.utils')
1819
local test_run = utils.optional_require('test_run')
1920
test_run = test_run and test_run.new()
2021

@@ -29,29 +30,6 @@ local SCRIPT_DIR = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
2930

3031
local bench = {}
3132

32-
function bench.graphql_from_testdata(testdata, shard)
33-
local accessor_class = shard and graphql.accessor_shard or
34-
graphql.accessor_space
35-
36-
local meta = testdata.get_test_metadata()
37-
38-
local accessor = accessor_class.new({
39-
schemas = meta.schemas,
40-
collections = meta.collections,
41-
service_fields = meta.service_fields,
42-
indexes = meta.indexes,
43-
timeout_ms = graphql.TIMEOUT_INFINITY,
44-
})
45-
46-
local gql_wrapper = graphql.new({
47-
schemas = meta.schemas,
48-
collections = meta.collections,
49-
accessor = accessor,
50-
})
51-
52-
return gql_wrapper
53-
end
54-
5533
local function workload(shard, bench_prepare, bench_iter, opts)
5634
local iterations = opts.iterations
5735
local exp_checksum = opts.checksum
@@ -178,4 +156,14 @@ function bench.run(test_name, opts)
178156
end
179157
end
180158

159+
-- helper for preparing benchmarking environment
160+
function bench.bench_prepare_helper(testdata, shard)
161+
testdata.fill_test_data(shard or box.space)
162+
return test_utils.graphql_from_testdata(testdata, shard, {
163+
graphql_opts = {
164+
timeout_ms = graphql.TIMEOUT_INFINITY,
165+
}
166+
})
167+
end
168+
181169
return bench

test/bench/nesting-1-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_user_id($user_id: String) {
2622
user(user_id: $user_id) {

test/bench/nesting-1-100.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_users {
2622
user {

test/bench/nesting-2-1-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_user_and_passport_id($user_id: String,
2622
$passport_id: String) {

test/bench/nesting-2-100-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_passport_id($passport_id: String) {
2622
user(user_to_passport_c: {passport_id: $passport_id}) {

test/bench/nesting-3-1-1-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_user_and_passport($user_id: String, $number: String) {
2622
user(user_id: $user_id, user_to_passport_c: {

test/bench/nesting-3-100-100-1.test.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ local testdata = require('test.testdata.bench_testdata')
1616
-- ---------
1717

1818
local function bench_prepare(state)
19-
local virtbox = state.shard or box.space
20-
21-
state.gql_wrapper = bench.graphql_from_testdata(testdata, state.shard)
22-
testdata.fill_test_data(virtbox)
23-
19+
state.gql_wrapper = bench.bench_prepare_helper(testdata, state.shard)
2420
local query = [[
2521
query match_by_passport($number: String) {
2622
user(user_to_passport_c: {passport_c: {number: $number}}) {

test/common/avro_refs.test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
77
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path
88

99
local utils = require('test.utils')
10-
local testdata = require('test.common.lua.test_data_avro_refs')
10+
local testdata = require('test.testdata.avro_refs_testdata')
1111

1212
box.cfg({})
1313

test/common/common.test.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env tarantool
2+
3+
local fio = require('fio')
4+
5+
-- require in-repo version of graphql/ sources despite current working directory
6+
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
7+
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path
8+
9+
local utils = require('test.utils')
10+
local testdata = require('test.testdata.common_testdata')
11+
12+
box.cfg({})
13+
14+
utils.run_testdata(testdata)
15+
16+
os.exit()

test/common/compound_index.test.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env tarantool
2+
3+
local fio = require('fio')
4+
5+
-- require in-repo version of graphql/ sources despite current working directory
6+
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
7+
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path
8+
9+
local utils = require('test.utils')
10+
local testdata = require('test.testdata.compound_index_testdata')
11+
12+
box.cfg({})
13+
14+
utils.run_testdata(testdata)
15+
16+
os.exit()

0 commit comments

Comments
 (0)