[Tarantool-patches] [PATCH v2 vshard 2/2] storage: introduce vshard.storage._call()
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Wed Mar 25 02:44:47 MSK 2020
It is a new internal function which is supposed to absorb all the
other internal functions to make it easier to change them, to
simplify adding new and drop old functions.
This also hides them from vshard.storage.* namespace so users
can't try to use them not knowing they are private.
Additionally, _call() allows to change internal function set even
on read-only instances, because it has nothing to do with the
schema. Internal function set can be updated by reload.
Closes #227
Part of #210
---
test/unit/upgrade.result | 1 +
test/upgrade/upgrade.result | 22 ++++++++++++++++++
test/upgrade/upgrade.test.lua | 4 ++++
vshard/storage/init.lua | 42 +++++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+)
diff --git a/test/unit/upgrade.result b/test/unit/upgrade.result
index a801862..c82208e 100644
--- a/test/unit/upgrade.result
+++ b/test/unit/upgrade.result
@@ -204,6 +204,7 @@ upgrade_trace
| - No errinj
| - - true
| - diff:
+ | func_count: 1
| new_version: '{0.1.16.0}'
| old_version: '{0.1.15.0}'
| ...
diff --git a/test/upgrade/upgrade.result b/test/upgrade/upgrade.result
index 4157b08..c2d54a3 100644
--- a/test/upgrade/upgrade.result
+++ b/test/upgrade/upgrade.result
@@ -92,6 +92,10 @@ vshard.storage.internal.schema_latest_version
| ---
| - null
| ...
+vshard.storage._call == nil
+ | ---
+ | - true
+ | ...
bucket_count = vshard.consts.DEFAULT_BUCKET_COUNT / 2
| ---
| ...
@@ -151,6 +155,20 @@ vshard.storage.internal.schema_latest_version
| ---
| - '{0.1.16.0}'
| ...
+vshard.storage._call ~= nil
+ | ---
+ | - true
+ | ...
+vshard.storage._call('test_api', 1, 2, 3)
+ | ---
+ | - bucket_recv: true
+ | rebalancer_apply_routes: true
+ | test_api: true
+ | rebalancer_request_state: true
+ | - 1
+ | - 2
+ | - 3
+ | ...
test_run:switch('storage_1_b')
| ---
@@ -168,6 +186,10 @@ vshard.storage.internal.schema_latest_version
| ---
| - '{0.1.16.0}'
| ...
+vshard.storage._call ~= nil
+ | ---
+ | - true
+ | ...
test_run:switch('default')
| ---
diff --git a/test/upgrade/upgrade.test.lua b/test/upgrade/upgrade.test.lua
index 3a4d113..aea0da8 100644
--- a/test/upgrade/upgrade.test.lua
+++ b/test/upgrade/upgrade.test.lua
@@ -31,6 +31,7 @@ test_run:switch('storage_2_a')
box.space._schema:get({'oncevshard:storage:1'}) or box.space._schema:select()
vshard.storage.internal.schema_current_version
vshard.storage.internal.schema_latest_version
+vshard.storage._call == nil
bucket_count = vshard.consts.DEFAULT_BUCKET_COUNT / 2
first_bucket = vshard.consts.DEFAULT_BUCKET_COUNT / 2 + 1
vshard.storage.bucket_force_create(first_bucket, bucket_count)
@@ -51,11 +52,14 @@ test_run:switch('storage_1_a')
box.space._schema:get({'vshard_version'})
vshard.storage.internal.schema_current_version()
vshard.storage.internal.schema_latest_version
+vshard.storage._call ~= nil
+vshard.storage._call('test_api', 1, 2, 3)
test_run:switch('storage_1_b')
box.space._schema:get({'vshard_version'})
vshard.storage.internal.schema_current_version()
vshard.storage.internal.schema_latest_version
+vshard.storage._call ~= nil
test_run:switch('default')
-- Main purpose of the test - ensure that data can be safely moved
diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua
index ebc6af1..801c1f2 100644
--- a/vshard/storage/init.lua
+++ b/vshard/storage/init.lua
@@ -344,12 +344,30 @@ local function schema_upgrade_to_0_1_16_0(username)
log.info("Insert 'vshard_version' into _schema")
box.space._schema:replace({'vshard_version', 0, 1, 16, 0})
box.space._schema:delete({'oncevshard:storage:1'})
+
+ -- vshard.storage._call() is supposed to replace some internal
+ -- functions exposed in _func; to allow introduction of new
+ -- functions on replicas; to allow change of internal
+ -- functions without touching the schema.
+ local func = 'vshard.storage._call'
+ log.info('Create function %s()', func)
+ box.schema.func.create(func, {setuid = true})
+ box.schema.user.grant(username, 'execute', 'function', func)
+ -- Don't drop old functions in the same version. Removal can
+ -- happen only after 0.1.16. Or there should appear support of
+ -- rebalancing from too old versions. Drop of these functions
+ -- now would immediately make it impossible to rebalance from
+ -- old instances.
end
local function schema_downgrade_from_0_1_16_0()
log.info("Remove 'vshard_version' from _schema")
box.space._schema:replace({'oncevshard:storage:1'})
box.space._schema:delete({'vshard_version'})
+
+ local func = 'vshard.storage._call'
+ log.info('Remove function %s()', func)
+ box.schema.func.drop(func, {if_exists = true})
end
local function schema_current_version()
@@ -2218,6 +2236,29 @@ local function storage_call(bucket_id, mode, name, args)
return ok, ret1, ret2, ret3
end
+local service_call_api
+
+local function service_call_test_api(...)
+ return service_call_api, ...
+end
+
+service_call_api = setmetatable({
+ bucket_recv = bucket_recv,
+ rebalancer_apply_routes = rebalancer_apply_routes,
+ rebalancer_request_state = rebalancer_request_state,
+ test_api = service_call_test_api,
+}, {__serialize = function(api)
+ local res = {}
+ for k, _ in pairs(api) do
+ res[k] = true
+ end
+ return res
+end})
+
+local function service_call(service_name, ...)
+ return service_call_api[service_name](...)
+end
+
--------------------------------------------------------------------------------
-- Configuration
--------------------------------------------------------------------------------
@@ -2673,6 +2714,7 @@ return {
rebalancing_is_in_progress = rebalancing_is_in_progress,
recovery_wakeup = recovery_wakeup,
call = storage_call,
+ _call = service_call,
cfg = function(cfg, uuid) return storage_cfg(cfg, uuid, false) end,
info = storage_info,
buckets_info = storage_buckets_info,
--
2.21.1 (Apple Git-122.3)
More information about the Tarantool-patches
mailing list