Skip to content

Commit

Permalink
internal: move statistics.lua to stats/storage.lua
Browse files Browse the repository at this point in the history
The commit moves storage-specific statistics into a file with another
name to make clear its purpose.

Part of #69
  • Loading branch information
oleg-jukovec committed Mar 19, 2024
1 parent b4a3bff commit 5e5fd9f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sharded-queue-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
Expand Down
4 changes: 2 additions & 2 deletions sharded_queue/drivers/fifo.lua
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down
4 changes: 2 additions & 2 deletions sharded_queue/drivers/fifottl.lua
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---- Module used to store storage-specific statistics.

local state = require('sharded_queue.state')

local statistics = {}
Expand All @@ -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' },
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions sharded_queue/storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 {}

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5e5fd9f

Please sign in to comment.