-
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.
Preserve stats config and values between reloads
After this patch, statistics module state (enabled/disabled, driver) preserved between package reloads and Tarantool Cartridge role reloads [1]. Since `metrics` package do not fully support preserving registry between role reloads [2] now, this feature doesn't work for `metrics` driver. Corresponding tests are marked with xfail until issue is resolved for metrics. 1. https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_api/modules/cartridge.roles/#reload 2. tarantool/metrics#334 Follows up #224
- Loading branch information
1 parent
9a20223
commit cd3ac0d
Showing
12 changed files
with
292 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
local dev_checks = require('crud.common.dev_checks') | ||
|
||
local stash = {} | ||
|
||
local function get_G_name(name) | ||
return ('__crud_stats_%s'):format(name) | ||
end | ||
|
||
--- Get a stash instance, initialize if needed | ||
-- Stashes are persistent to package reload and cartridge roles reload. | ||
-- | ||
-- @function get | ||
-- | ||
-- @tparam string name | ||
-- Stash identifier. | ||
-- | ||
-- @treturn table A stash instance. | ||
-- | ||
function stash.get(name) | ||
dev_checks('string') | ||
|
||
local _G_name = get_G_name(name) | ||
local instance = rawget(_G, _G_name) or {} | ||
rawset(_G, _G_name, instance) | ||
|
||
local hotreload = package.loaded['cartridge.hotreload'] | ||
if hotreload ~= nil then | ||
hotreload.whitelist_globals({_G_name}) | ||
end | ||
|
||
return instance | ||
end | ||
|
||
--- Reset stash instance | ||
-- Stashes are persistent to package reload and cartridge roles reload. | ||
-- | ||
-- @function get | ||
-- | ||
-- @tparam string name | ||
-- Stash identifier. | ||
-- | ||
-- @treturn table A stash instance. | ||
-- | ||
function stash.reset(name) | ||
dev_checks('string') | ||
|
||
local _G_name = get_G_name(name) | ||
local instance = {} | ||
rawset(_G, _G_name, instance) | ||
|
||
return instance | ||
end | ||
|
||
return stash |
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,64 @@ | ||
#!/usr/bin/env tarantool | ||
|
||
require('strict').on() | ||
_G.is_initialized = function() return false end | ||
|
||
local log = require('log') | ||
local errors = require('errors') | ||
local cartridge = require('cartridge') | ||
|
||
package.preload['customers-storage'] = function() | ||
local engine = os.getenv('ENGINE') or 'memtx' | ||
return { | ||
role_name = 'customers-storage', | ||
init = function() | ||
local customers_space = box.schema.space.create('customers', { | ||
format = { | ||
{name = 'id', type = 'unsigned'}, | ||
{name = 'bucket_id', type = 'unsigned'}, | ||
{name = 'name', type = 'string'}, | ||
{name = 'last_name', type = 'string'}, | ||
{name = 'age', type = 'number'}, | ||
{name = 'city', type = 'string'}, | ||
}, | ||
if_not_exists = true, | ||
engine = engine, | ||
id = 542, | ||
}) | ||
-- primary index | ||
customers_space:create_index('id_index', { | ||
parts = { {field = 'id'} }, | ||
if_not_exists = true, | ||
}) | ||
customers_space:create_index('bucket_id', { | ||
parts = { {field = 'bucket_id'} }, | ||
unique = false, | ||
if_not_exists = true, | ||
}) | ||
customers_space:create_index('age_index', { | ||
parts = { {field = 'age'} }, | ||
unique = false, | ||
if_not_exists = true, | ||
}) | ||
end, | ||
} | ||
end | ||
|
||
local ok, err = errors.pcall('CartridgeCfgError', cartridge.cfg, { | ||
advertise_uri = 'localhost:3301', | ||
http_port = 8081, | ||
bucket_count = 3000, | ||
roles = { | ||
'cartridge.roles.crud-router', | ||
'cartridge.roles.crud-storage', | ||
'customers-storage', | ||
}, | ||
roles_reload_allowed = true, | ||
}) | ||
|
||
if not ok then | ||
log.error('%s', err) | ||
os.exit(1) | ||
end | ||
|
||
_G.is_initialized = cartridge.is_healthy |
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
Oops, something went wrong.