-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide an API to get storages initialization state
There is an issue with using CRUD functionality if not all storages are up. New function is added to get the information about storages state: initialized or not. So, a user can poll state and wait for storages to be initialized before making CRUD calls. Resolves #229
- Loading branch information
Showing
7 changed files
with
233 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
local fio = require('fio') | ||
|
||
local t = require('luatest') | ||
|
||
local helpers = require('test.helper') | ||
|
||
local fiber = require("fiber") | ||
|
||
local pgroup = t.group('replicas_state', { | ||
{engine = 'memtx'} | ||
}) | ||
|
||
local all_storages_initialized = false | ||
|
||
local function wait_storages_init(g) | ||
local storages_initialized = false | ||
local attempts_left = 5 | ||
local wait_for_init_timeout = 1 | ||
while (attempts_left > 0 and not storages_initialized) do | ||
local results, err = g.cluster.main_server.net_box:call("crud.storage_info", {}) | ||
t.assert_equals(err, nil, "Error getting storage status") | ||
storages_initialized = true | ||
for _,v in pairs(results) do | ||
if v.status ~= "running" then | ||
storages_initialized = false | ||
end | ||
end | ||
if not storages_initialized then | ||
fiber.sleep(wait_for_init_timeout) | ||
attempts_left = attempts_left-1 | ||
end | ||
end | ||
return storages_initialized | ||
end | ||
|
||
pgroup.before_all(function(g) | ||
g.cluster = helpers.Cluster:new({ | ||
datadir = fio.tempdir(), | ||
server_command = helpers.entrypoint('srv_select'), | ||
use_vshard = true, | ||
replicasets = helpers.get_test_replicasets(), | ||
env = { | ||
['ENGINE'] = g.params.engine, | ||
}, | ||
}) | ||
g.cluster:start() | ||
|
||
-- wait for storages to initialize | ||
all_storages_initialized = wait_storages_init(g) | ||
end) | ||
|
||
pgroup.after_all(function(g) | ||
helpers.stop_cluster(g.cluster) | ||
fio.rmtree(g.cluster.datadir) | ||
end) | ||
|
||
pgroup.test_crud_storage_status_of_stopped_servers = function(g) | ||
t.assert_equals(all_storages_initialized, true) | ||
|
||
g.cluster:server("s2-replica"):stop() | ||
|
||
local results, err = g.cluster.main_server.net_box:call("crud.storage_info", {}) | ||
t.assert_equals(err, nil, "Error getting storags states") | ||
|
||
local instance = results[helpers.uuid('b', 1)] | ||
t.assert_equals(instance.status, "running") | ||
t.assert_equals(instance.is_master, true) | ||
|
||
local instance = results[helpers.uuid('b', 2)] | ||
t.assert_equals(instance.is_master, false) | ||
|
||
instance = results[helpers.uuid('c', 1)] | ||
t.assert_equals(instance.status, "running") | ||
t.assert_equals(instance.is_master, true) | ||
|
||
instance = results[helpers.uuid('c', 2)] | ||
t.assert_equals(instance.status, "error") -- peer closed | ||
t.assert_equals(instance.is_master, false) | ||
|
||
g.cluster:server("s2-replica"):start() | ||
end | ||
|
||
pgroup.test_disabled_storage_role = function(g) | ||
t.assert_equals(wait_storages_init(g), true) | ||
|
||
-- stop crud storage role on one replica | ||
local server = g.cluster:server("s1-replica") | ||
local results = server.net_box:eval([[ | ||
local serviceregistry = require("cartridge.service-registry") | ||
serviceregistry.get("crud-storage").stop() | ||
return true | ||
]]) | ||
|
||
t.assert_not_equals(results, nil, "Fail to disable storage role") | ||
|
||
local results, err = g.cluster.main_server.net_box:call("crud.storage_info", {}) | ||
t.assert_equals(err, nil, "Error getting storags states") | ||
|
||
local instance = results[helpers.uuid('b', 1)] | ||
t.assert_equals(instance.status, "running") | ||
t.assert_equals(instance.is_master, true) | ||
|
||
instance = results[helpers.uuid('b', 2)] | ||
t.assert_equals(instance.status, "uninitialized") | ||
t.assert_equals(instance.is_master, false) | ||
|
||
instance = results[helpers.uuid('c', 1)] | ||
t.assert_equals(instance.status, "running") | ||
t.assert_equals(instance.is_master, true) | ||
|
||
instance = results[helpers.uuid('c', 2)] | ||
t.assert_equals(instance.status, "running") | ||
t.assert_equals(instance.is_master, false) | ||
end |