From 5e5fd9f565c83cb356d5dc56c76868d05a890e4b Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Tue, 19 Mar 2024 15:48:39 +0300 Subject: [PATCH] internal: move statistics.lua to stats/storage.lua The commit moves storage-specific statistics into a file with another name to make clear its purpose. Part of #69 --- sharded-queue-scm-1.rockspec | 2 +- sharded_queue/drivers/fifo.lua | 4 ++-- sharded_queue/drivers/fifottl.lua | 4 ++-- sharded_queue/{statistics.lua => stats/storage.lua} | 9 +++++++-- sharded_queue/storage.lua | 8 ++++---- 5 files changed, 16 insertions(+), 11 deletions(-) rename sharded_queue/{statistics.lua => stats/storage.lua} (91%) diff --git a/sharded-queue-scm-1.rockspec b/sharded-queue-scm-1.rockspec index 8019077..be11c3d 100755 --- a/sharded-queue-scm-1.rockspec +++ b/sharded-queue-scm-1.rockspec @@ -28,7 +28,7 @@ build = { ['sharded_queue.utils'] = 'sharded_queue/utils.lua', ['sharded_queue.stash'] = 'sharded_queue/stash.lua', ['sharded_queue.state'] = 'sharded_queue/state.lua', - ['sharded_queue.statistics'] = 'sharded_queue/statistics.lua', + ['sharded_queue.stats.storage'] = 'sharded_queue/stats/storage.lua', ['sharded_queue.version'] = 'sharded_queue/version.lua', }, }, diff --git a/sharded_queue/drivers/fifo.lua b/sharded_queue/drivers/fifo.lua index 474feaa..edb2ff7 100644 --- a/sharded_queue/drivers/fifo.lua +++ b/sharded_queue/drivers/fifo.lua @@ -1,10 +1,10 @@ local state = require('sharded_queue.state') local utils = require('sharded_queue.utils') local log = require('log') -- luacheck: ignore -local statistics = require('sharded_queue.statistics') +local stats = require('sharded_queue.stats.storage') local function update_stat(tube_name, name) - statistics.update(tube_name, name, '+', 1) + stats.update(tube_name, name, '+', 1) end local method = {} diff --git a/sharded_queue/drivers/fifottl.lua b/sharded_queue/drivers/fifottl.lua index cdc7195..e6afca2 100644 --- a/sharded_queue/drivers/fifottl.lua +++ b/sharded_queue/drivers/fifottl.lua @@ -1,7 +1,7 @@ local fiber = require('fiber') local state = require('sharded_queue.state') local utils = require('sharded_queue.utils') -local statistics = require('sharded_queue.statistics') +local stats = require('sharded_queue.stats.storage') local time = require('sharded_queue.time') local log = require('log') -- luacheck: ignore @@ -19,7 +19,7 @@ local index = { } local function update_stat(tube_name, name) - statistics.update(tube_name, name, '+', 1) + stats.update(tube_name, name, '+', 1) end local function is_expired(task) diff --git a/sharded_queue/statistics.lua b/sharded_queue/stats/storage.lua similarity index 91% rename from sharded_queue/statistics.lua rename to sharded_queue/stats/storage.lua index 808616d..d2184e8 100644 --- a/sharded_queue/statistics.lua +++ b/sharded_queue/stats/storage.lua @@ -1,3 +1,5 @@ +---- Module used to store storage-specific statistics. + local state = require('sharded_queue.state') local statistics = {} @@ -15,7 +17,8 @@ local actions = { } function statistics.init() - local space_stat = box.schema.space.create('_queue_statistics', { if_not_exists = true }) + local space_stat = box.schema.space.create('_queue_statistics', + { if_not_exists = true }) space_stat:format({ { 'tube_name', 'string' }, { 'done', 'unsigned' }, @@ -40,7 +43,9 @@ end function statistics.update(tube_name, stat_name, operation, value) if actions[stat_name] == nil then return end - box.space._queue_statistics:update(tube_name, { { operation, actions[stat_name], value } }) + + box.space._queue_statistics:update(tube_name, + { { operation, actions[stat_name], value } }) end function statistics.reset(tube_name) diff --git a/sharded_queue/storage.lua b/sharded_queue/storage.lua index d09c4f7..84381cb 100644 --- a/sharded_queue/storage.lua +++ b/sharded_queue/storage.lua @@ -4,7 +4,7 @@ local json = require('json') local cartridge = require('cartridge') local state = require('sharded_queue.state') -local statistics = require('sharded_queue.statistics') +local stats_storage = require('sharded_queue.stats.storage') local DEFAULT_DRIVER = 'sharded_queue.drivers.fifottl' @@ -61,7 +61,7 @@ local methods = { local function apply_config(cfg, opts) if opts.is_master then - statistics.init() + stats_storage.init() local cfg_tubes = cfg.tubes or {} @@ -76,7 +76,7 @@ local function apply_config(cfg, opts) name = tube_name, options = cfg_tubes[tube_name] }) - statistics.reset(tube_name) + stats_storage.reset(tube_name) end end @@ -104,7 +104,7 @@ local function apply_config(cfg, opts) end local tube_statistic_func = function(args) - return statistics.get(args.tube_name) + return stats_storage.get(args.tube_name) end rawset(_G, 'tube_statistic', tube_statistic_func)