-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f2ceed
commit a00dcb5
Showing
27 changed files
with
940 additions
and
237 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
local config = require('sharded_queue.router.config') | ||
local is_metrics_supported = require('sharded_queue.metrics').is_supported | ||
local metrics = require('sharded_queue.router.metrics') | ||
local roles = require('sharded_queue.roles') | ||
local utils = require('sharded_queue.utils') | ||
local queue = require('sharded_queue.router.queue') | ||
|
||
local role_name = "roles.sharded-queue-router" | ||
|
||
local function validate(conf) | ||
conf = conf or {} | ||
if not roles.is_sharding_role_enabled('router') then | ||
error(role_name .. ": instance must be a sharding router to use the role") | ||
end | ||
|
||
local ok, err = utils.validate_tubes(conf.tubes or {}, false) | ||
if not ok then | ||
error(role_name .. ": " .. err) | ||
end | ||
ok, err = utils.validate_cfg(conf.cfg or {}) | ||
if not ok then | ||
error(role_name .. ": " .. err) | ||
end | ||
return true | ||
end | ||
|
||
local function apply(conf) | ||
conf = conf or {} | ||
|
||
queue.export_globals() | ||
|
||
local conf_tubes = conf.tubes or {} | ||
local conf_cfg = conf.cfg or {} | ||
if conf_cfg.metrics ~= nil then | ||
config.metrics = conf_cfg.metrics and true or false | ||
else | ||
config.metrics = is_metrics_supported() | ||
end | ||
|
||
for tube_name, options in pairs(conf_tubes) do | ||
if queue.map()[tube_name] == nil then | ||
queue.add(tube_name, metrics, options) | ||
end | ||
end | ||
|
||
for tube_name, _ in pairs(queue.map()) do | ||
if conf_tubes[tube_name] == nil then | ||
queue.remove(tube_name) | ||
end | ||
end | ||
|
||
if config.metrics then | ||
metrics.enable(queue) | ||
else | ||
metrics.disable() | ||
end | ||
end | ||
|
||
local function stop() | ||
queue.clear_globals() | ||
end | ||
|
||
return { | ||
validate = validate, | ||
apply = apply, | ||
stop = stop, | ||
} |
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,79 @@ | ||
local config = require('sharded_queue.storage.config') | ||
local is_metrics_supported = require('sharded_queue.metrics').is_supported | ||
local methods = require('sharded_queue.storage.methods') | ||
local metrics = require('sharded_queue.storage.metrics') | ||
local roles = require('sharded_queue.roles') | ||
local stats_storage = require('sharded_queue.stats.storage') | ||
local tubes = require('sharded_queue.storage.tubes').new() | ||
local utils = require('sharded_queue.utils') | ||
|
||
local role_name = "roles.sharded-queue-storage" | ||
local watcher = nil | ||
|
||
local function validate(conf) | ||
conf = conf or {} | ||
|
||
if not roles.is_sharding_role_enabled('storage') then | ||
error(role_name .. ": instance must be a sharding storage to use the role") | ||
end | ||
|
||
local ok, err = utils.validate_tubes(conf.tubes or {}, true) | ||
if not ok then | ||
error(role_name .. ": " .. err) | ||
end | ||
ok, err = utils.validate_cfg(conf.cfg or {}) | ||
if not ok then | ||
error(role_name .. ": " .. err) | ||
end | ||
return true | ||
end | ||
|
||
local function apply(conf) | ||
conf = conf or {} | ||
|
||
local conf_tubes = conf.tubes or {} | ||
local conf_cfg = conf.cfg or {} | ||
if conf_cfg.metrics ~= nil then | ||
config.metrics = conf_cfg.metrics and true or false | ||
else | ||
config.metrics = is_metrics_supported() | ||
end | ||
|
||
if watcher ~= nil then | ||
watcher:unregister() | ||
end | ||
watcher = box.watch('box.status', function(_, status) | ||
if status.is_ro == false then | ||
stats_storage.init() | ||
|
||
local new = tubes:update(conf_tubes) | ||
for _, tube in ipairs(new) do | ||
stats_storage.reset(tube) | ||
end | ||
|
||
if config.metrics then | ||
metrics.enable(tubes:map()) | ||
end | ||
methods.init(metrics, tubes) | ||
end | ||
end) | ||
|
||
if config.metrics then | ||
metrics.enable(tubes:map()) | ||
else | ||
metrics.disable() | ||
end | ||
end | ||
|
||
local function stop() | ||
if watcher ~= nil then | ||
watcher:unregister() | ||
watcher = nil | ||
end | ||
end | ||
|
||
return { | ||
validate = validate, | ||
apply = apply, | ||
stop = stop, | ||
} |
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,15 @@ | ||
local config = require('config') | ||
|
||
local function is_sharding_role_enabled(expected) | ||
local sharding_roles = config:get('sharding.roles') | ||
for _, role in ipairs(sharding_roles or {}) do | ||
if role == expected then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
return { | ||
is_sharding_role_enabled = is_sharding_role_enabled, | ||
} |
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
Oops, something went wrong.