Skip to content

Commit 2519df9

Browse files
internal: use vshard router object
This patch is the groundwork for vshard groups and custom routers support. Test runs have shown that this patch do not affects the performance of crud requests. Part of #44
1 parent 1920cca commit 2519df9

File tree

21 files changed

+54
-29
lines changed

21 files changed

+54
-29
lines changed

crud/borders.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ local function call_get_border_on_router(border_name, space_name, index_name, op
7575

7676
opts = opts or {}
7777

78-
local space = utils.get_space(space_name, vshard.router.routeall())
78+
local vshard_router = vshard.router.static
79+
local replicasets = vshard_router:routeall()
80+
local space = utils.get_space(space_name, replicasets)
7981
if space == nil then
8082
return nil, BorderError:new("Space %q doesn't exist", space_name), const.NEED_SCHEMA_RELOAD
8183
end
@@ -98,7 +100,6 @@ local function call_get_border_on_router(border_name, space_name, index_name, op
98100
local cmp_key_parts = utils.merge_primary_key_parts(index.parts, primary_index.parts)
99101
local field_names = utils.enrich_field_names_with_cmp_key(opts.fields, cmp_key_parts, space:format())
100102

101-
local replicasets = vshard.router.routeall()
102103
local call_opts = {
103104
mode = 'read',
104105
replicasets = replicasets,

crud/common/call.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ local function wrap_vshard_err(err, func_name, replicaset_uuid, bucket_id)
4848
end
4949

5050
if replicaset_uuid == nil then
51-
local replicaset, _ = vshard.router.route(bucket_id)
51+
local vshard_router = vshard.router.static
52+
local replicaset, _ = vshard_router:route(bucket_id)
5253
if replicaset == nil then
5354
return CallError:new(
5455
"Function returned an error, but we couldn't figure out the replicaset: %s", err
@@ -150,7 +151,8 @@ function call.single(bucket_id, func_name, func_args, opts)
150151

151152
local timeout = opts.timeout or const.DEFAULT_VSHARD_CALL_TIMEOUT
152153

153-
local res, err = vshard.router[vshard_call_name](bucket_id, func_name, func_args, {
154+
local vshard_router = vshard.router.static
155+
local res, err = vshard_router[vshard_call_name](vshard_router, bucket_id, func_name, func_args, {
154156
timeout = timeout,
155157
})
156158

@@ -172,7 +174,8 @@ function call.any(func_name, func_args, opts)
172174

173175
local timeout = opts.timeout or const.DEFAULT_VSHARD_CALL_TIMEOUT
174176

175-
local replicasets, err = vshard.router.routeall()
177+
local vshard_router = vshard.router.static
178+
local replicasets, err = vshard_router:routeall()
176179
if replicasets == nil then
177180
return nil, CallError:new("Failed to get all replicasets: %s", err.err)
178181
end

crud/common/map_call_cases/base_iter.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ function BaseIterator:new(opts)
3030
if opts.replicasets ~= nil then
3131
replicasets = opts.replicasets
3232
else
33-
replicasets, err = vshard.router.routeall()
34-
if replicasets == nil then
33+
local vshard_router = vshard.router.static
34+
replicasets, err = vshard_router:routeall()
35+
if err ~= nil then
3536
return nil, GetReplicasetsError:new("Failed to get all replicasets: %s", err.err)
3637
end
3738
end

crud/common/schema.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ function schema.wrap_func_reload(func, ...)
9191
break
9292
end
9393

94-
local ok, reload_schema_err = reload_schema(vshard.router.routeall())
94+
local vshard_router = vshard.router.static
95+
local ok, reload_schema_err = reload_schema(vshard_router:routeall())
9596
if not ok then
9697
log.warn("Failed to reload schema: %s", reload_schema_err)
9798
break

crud/common/sharding/init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ local sharding_utils = require('crud.common.sharding.utils')
1414
local sharding = {}
1515

1616
function sharding.get_replicasets_by_bucket_id(bucket_id)
17-
local replicaset, err = vshard.router.route(bucket_id)
17+
local vshard_router = vshard.router.static
18+
local replicaset, err = vshard_router:route(bucket_id)
1819
if replicaset == nil then
1920
return nil, GetReplicasetsError:new("Failed to get replicaset for bucket_id %s: %s", bucket_id, err.err)
2021
end
@@ -43,7 +44,7 @@ function sharding.key_get_bucket_id(space_name, key, specified_bucket_id)
4344
}
4445
end
4546

46-
return { bucket_id = vshard.router.bucket_id_strcrc32(key) }
47+
return { bucket_id = vshard_router:bucket_id_strcrc32(key) }
4748
end
4849

4950
function sharding.tuple_get_bucket_id(tuple, space, specified_bucket_id)
@@ -241,7 +242,8 @@ function sharding.split_tuples_by_replicaset(tuples, space, opts)
241242
skip_sharding_hash_check = false
242243
end
243244

244-
local replicaset, err = vshard.router.route(sharding_data.bucket_id)
245+
local vshard_router = vshard.router.static
246+
local replicaset, err = vshard_router:route(sharding_data.bucket_id)
245247
if replicaset == nil then
246248
return nil, GetReplicasetsError:new(
247249
"Failed to get replicaset for bucket_id %s: %s",

crud/common/utils.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,8 @@ function utils.cut_rows(rows, metadata, field_names)
634634
end
635635

636636
local function flatten_obj(space_name, obj)
637-
local space_format, err = utils.get_space_format(space_name, vshard.router.routeall())
637+
local vshard_router = vshard.router.static
638+
local space_format, err = utils.get_space_format(space_name, vshard_router:routeall())
638639
if err ~= nil then
639640
return nil, FlattenError:new("Failed to get space format: %s", err), const.NEED_SCHEMA_RELOAD
640641
end
@@ -760,7 +761,8 @@ end
760761
--
761762
-- @return a table of storage states by replica uuid.
762763
function utils.storage_info(opts)
763-
local replicasets, err = vshard.router.routeall()
764+
local vshard_router = vshard.router.static
765+
local replicasets, err = vshard_router:routeall()
764766
if replicasets == nil then
765767
return nil, StorageInfoError:new("Failed to get all replicasets: %s", err.err)
766768
end

crud/count.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ local function call_count_on_router(space_name, user_conditions, opts)
134134
return nil, CountError:new("Failed to parse conditions: %s", err)
135135
end
136136

137-
local replicasets, err = vshard.router.routeall()
137+
local vshard_router = vshard.router.static
138+
local replicasets, err = vshard_router:routeall()
138139
if err ~= nil then
139140
return nil, CountError:new("Failed to get all replicasets: %s", err)
140141
end

crud/delete.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ local function call_delete_on_router(space_name, key, opts)
6464

6565
opts = opts or {}
6666

67-
local space = utils.get_space(space_name, vshard.router.routeall())
67+
local vshard_router = vshard.router.static
68+
local space = utils.get_space(space_name, vshard_router:routeall())
6869
if space == nil then
6970
return nil, DeleteError:new("Space %q doesn't exist", space_name), const.NEED_SCHEMA_RELOAD
7071
end

crud/get.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ local function call_get_on_router(space_name, key, opts)
6767

6868
opts = opts or {}
6969

70-
local space = utils.get_space(space_name, vshard.router.routeall())
70+
local vshard_router = vshard.router.static
71+
local space = utils.get_space(space_name, vshard_router:routeall())
7172
if space == nil then
7273
return nil, GetError:new("Space %q doesn't exist", space_name), const.NEED_SCHEMA_RELOAD
7374
end

crud/insert.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ local function call_insert_on_router(space_name, original_tuple, opts)
6666

6767
opts = opts or {}
6868

69-
local space = utils.get_space(space_name, vshard.router.routeall())
69+
local vshard_router = vshard.router.static
70+
local space = utils.get_space(space_name, vshard_router:routeall())
7071
if space == nil then
7172
return nil, InsertError:new("Space %q doesn't exist", space_name), const.NEED_SCHEMA_RELOAD
7273
end

0 commit comments

Comments
 (0)