[patches] [PATCH vshard 4/4] storage: refactor garbage collection variable names

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Mon Feb 26 13:08:56 MSK 2018


After #77 there are two garbage collection options: for lua and
for buckets. Unify names of the attributes of these two GC types
to the format "collect_<lua/bucket>_garbage_<fiber/interval>".

Follow up #77

Signed-off-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
---
 test/storage/garbage_collector.result   |  2 +-
 test/storage/garbage_collector.test.lua |  2 +-
 test/unit/config.result                 |  8 ++--
 test/unit/config.test.lua               |  8 ++--
 test/unit/garbage.result                |  2 +-
 test/unit/garbage.test.lua              |  2 +-
 vshard/cfg.lua                          |  6 +--
 vshard/consts.lua                       |  2 +-
 vshard/storage/init.lua                 | 80 ++++++++++++++++++---------------
 9 files changed, 60 insertions(+), 52 deletions(-)

diff --git a/test/storage/garbage_collector.result b/test/storage/garbage_collector.result
index 81c4ac1..3588fb4 100644
--- a/test/storage/garbage_collector.result
+++ b/test/storage/garbage_collector.result
@@ -137,7 +137,7 @@ a = setmetatable({}, {__mode = 'v'})
 a.k = {b = 100}
 ---
 ...
-iters = vshard.consts.COLLECT_LUA_GARBAGE_INTERVAL / vshard.consts.DEFAULT_GARBAGE_COLLECT_INTERVAL
+iters = vshard.consts.COLLECT_LUA_GARBAGE_INTERVAL / vshard.consts.DEFAULT_COLLECT_BUCKET_GARBAGE_INTERVAL
 ---
 ...
 -- Wait until Lua GC deletes a.k.
diff --git a/test/storage/garbage_collector.test.lua b/test/storage/garbage_collector.test.lua
index 4b46f79..79e76d8 100644
--- a/test/storage/garbage_collector.test.lua
+++ b/test/storage/garbage_collector.test.lua
@@ -53,7 +53,7 @@ vshard.storage.cfg(cfg, names.storage_1_a)
 -- deleted on the next GC.
 a = setmetatable({}, {__mode = 'v'})
 a.k = {b = 100}
-iters = vshard.consts.COLLECT_LUA_GARBAGE_INTERVAL / vshard.consts.DEFAULT_GARBAGE_COLLECT_INTERVAL
+iters = vshard.consts.COLLECT_LUA_GARBAGE_INTERVAL / vshard.consts.DEFAULT_COLLECT_BUCKET_GARBAGE_INTERVAL
 -- Wait until Lua GC deletes a.k.
 for i = 1, iters + 1 do vshard.storage.garbage_collector_wakeup() fiber.sleep(0.01) end
 a.k
diff --git a/test/unit/config.result b/test/unit/config.result
index 33b1094..99a77b6 100644
--- a/test/unit/config.result
+++ b/test/unit/config.result
@@ -373,28 +373,28 @@ lcfg.check(cfg)
 --
 -- gh-77: garbage collection options.
 --
-cfg.garbage_collect_interval = 'str'
+cfg.collect_bucket_garbage_interval = 'str'
 ---
 ...
 check(cfg)
 ---
 - Garbage collect interval must be positive number
 ...
-cfg.garbage_collect_interval = 0
+cfg.collect_bucket_garbage_interval = 0
 ---
 ...
 check(cfg)
 ---
 - Garbage collect interval must be positive number
 ...
-cfg.garbage_collect_interval = -1
+cfg.collect_bucket_garbage_interval = -1
 ---
 ...
 check(cfg)
 ---
 - Garbage collect interval must be positive number
 ...
-cfg.garbage_collect_interval = 100.5
+cfg.collect_bucket_garbage_interval = 100.5
 ---
 ...
 lcfg.check(cfg)
diff --git a/test/unit/config.test.lua b/test/unit/config.test.lua
index 333d165..7cb93d5 100644
--- a/test/unit/config.test.lua
+++ b/test/unit/config.test.lua
@@ -151,13 +151,13 @@ lcfg.check(cfg)
 --
 -- gh-77: garbage collection options.
 --
-cfg.garbage_collect_interval = 'str'
+cfg.collect_bucket_garbage_interval = 'str'
 check(cfg)
-cfg.garbage_collect_interval = 0
+cfg.collect_bucket_garbage_interval = 0
 check(cfg)
-cfg.garbage_collect_interval = -1
+cfg.collect_bucket_garbage_interval = -1
 check(cfg)
-cfg.garbage_collect_interval = 100.5
+cfg.collect_bucket_garbage_interval = 100.5
 lcfg.check(cfg)
 
 cfg.collect_lua_garbage = 100
diff --git a/test/unit/garbage.result b/test/unit/garbage.result
index 83d7b9f..f7e7204 100644
--- a/test/unit/garbage.result
+++ b/test/unit/garbage.result
@@ -27,7 +27,7 @@ test_run:cmd("setopt delimiter ''");
 vshard.storage.internal.shard_index = 'bucket_id'
 ---
 ...
-vshard.storage.internal.garbage_collect_interval = vshard.consts.DEFAULT_GARBAGE_COLLECT_INTERVAL
+vshard.storage.internal.collect_bucket_garbage_interval = vshard.consts.DEFAULT_COLLECT_BUCKET_GARBAGE_INTERVAL
 ---
 ...
 --
diff --git a/test/unit/garbage.test.lua b/test/unit/garbage.test.lua
index 0a5aca9..9f2a9d3 100644
--- a/test/unit/garbage.test.lua
+++ b/test/unit/garbage.test.lua
@@ -13,7 +13,7 @@ end;
 test_run:cmd("setopt delimiter ''");
 
 vshard.storage.internal.shard_index = 'bucket_id'
-vshard.storage.internal.garbage_collect_interval = vshard.consts.DEFAULT_GARBAGE_COLLECT_INTERVAL
+vshard.storage.internal.collect_bucket_garbage_interval = vshard.consts.DEFAULT_COLLECT_BUCKET_GARBAGE_INTERVAL
 
 --
 -- Find nothing if no bucket_id anywhere, or there is no index
diff --git a/vshard/cfg.lua b/vshard/cfg.lua
index 7df68fc..a8656a0 100644
--- a/vshard/cfg.lua
+++ b/vshard/cfg.lua
@@ -124,8 +124,8 @@ local function cfg_check(shard_cfg)
                   'positive integer')
         end
     end
-    if shard_cfg.garbage_collect_interval ~= nil then
-        local t = shard_cfg.garbage_collect_interval
+    if shard_cfg.collect_bucket_garbage_interval ~= nil then
+        local t = shard_cfg.collect_bucket_garbage_interval
         if type(t) ~= 'number' or t <= 0 then
             error('Garbage collect interval must be positive number')
         end
@@ -166,7 +166,7 @@ local function prepare_for_box_cfg(cfg)
     cfg.rebalancer_disbalance_threshold = nil
     cfg.rebalancer_max_receiving = nil
     cfg.shard_index = nil
-    cfg.garbage_collect_interval = nil
+    cfg.collect_bucket_garbage_interval = nil
     cfg.collect_lua_garbage = nil
 end
 
diff --git a/vshard/consts.lua b/vshard/consts.lua
index ff6f6b0..47651d7 100644
--- a/vshard/consts.lua
+++ b/vshard/consts.lua
@@ -32,7 +32,7 @@ return {
     FAILOVER_DOWN_TIMEOUT = 1;
     SYNC_TIMEOUT = 1;
     RECONNECT_TIMEOUT = 0.5;
-    DEFAULT_GARBAGE_COLLECT_INTERVAL = 0.5;
+    DEFAULT_COLLECT_BUCKET_GARBAGE_INTERVAL = 0.5;
     RECOVERY_INTERVAL = 5;
     COLLECT_LUA_GARBAGE_INTERVAL = 100;
     DISCOVERY_INTERVAL = 10;
diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua
index 499523a..a449aec 100644
--- a/vshard/storage/init.lua
+++ b/vshard/storage/init.lua
@@ -15,19 +15,49 @@ if not M then
     -- The module is loaded for the first time.
     --
     M = {
+        ---------------- Common module attributes ----------------
         --
         -- All known replicasets used for bucket re-balancing.
         -- See format in replicaset.lua.
         --
         replicasets = nil,
+        -- Triggers on master switch event. They are called right
+        -- before the event occurs.
+        _on_master_enable = trigger.new('_on_master_enable'),
+        _on_master_disable = trigger.new('_on_master_disable'),
+        -- Index which is a trigger to shard its space by numbers in
+        -- this index. It must have at first part either unsigned,
+        -- or integer or number type and be not nullable. Values in
+        -- this part are considered as bucket identifiers.
+        shard_index = nil,
+        -- Bucket count stored on all replicasets.
+        total_bucket_count = 0,
+        errinj = {
+            ERRINJ_BUCKET_FIND_GARBAGE_DELAY = false,
+            ERRINJ_RELOAD = false,
+        },
+        -- This counter is used to restart background fibers with
+        -- new reloaded code.
+        module_version = 0,
+
+        ------------------- Garbage collection -------------------
         -- Fiber to remove garbage buckets data.
-        garbage_collect_fiber = nil,
+        collect_bucket_garbage_fiber = nil,
+        -- Do buckets garbage collection once per this time.
+        collect_bucket_garbage_interval = nil,
+        -- If true, then bucket garbage collection fiber starts to
+        -- call collectgarbage() periodically.
+        collect_lua_garbage = nil,
+
+        -------------------- Bucket recovery ---------------------
         -- Bucket identifiers which are not active and are not being
         -- sent - their status is unknown. Their state must be checked
         -- periodically in recovery fiber.
         buckets_to_recovery = {},
         buckets_to_recovery_count = 0,
         recovery_fiber = nil,
+
+        ----------------------- Rebalancer -----------------------
         -- Fiber to rebalance a cluster.
         rebalancer_fiber = nil,
         -- Fiber which applies routes one by one. Its presense and
@@ -37,35 +67,12 @@ if not M then
         -- Internal flag to activate and deactivate rebalancer. Mostly
         -- for tests.
         is_rebalancer_active = true,
-        -- Triggers on master switch event. They are called right
-        -- before the event occurs.
-        _on_master_enable = trigger.new('_on_master_enable'),
-        _on_master_disable = trigger.new('_on_master_disable'),
-        -- Index which is a trigger to shard its space by numbers in
-        -- this index. It must have at first part either unsigned,
-        -- or integer or number type and be not nullable. Values in
-        -- this part are considered as bucket identifiers.
-        shard_index = nil,
-        -- Bucket count stored on all replicasets.
-        total_bucket_count = 0,
-        -- If true, then bucket garbage collection fiber starts to
-        -- call collectgarbage() periodically.
-        collect_lua_garbage = nil,
         -- Maximal allowed percent deviation of bucket count on a
         -- replicaset from ethalon bucket count.
         rebalancer_disbalance_threshold = 0,
         -- Maximal bucket count that can be received by a single
         -- replicaset simultaneously.
         rebalancer_max_receiving = 0,
-        -- Do buckets garbage collection once per this time.
-        garbage_collect_interval = nil,
-        errinj = {
-            ERRINJ_BUCKET_FIND_GARBAGE_DELAY = false,
-            ERRINJ_RELOAD = false,
-        },
-        -- This counter is used to restart background fibers with
-        -- new reloaded code.
-        module_version = 0,
     }
 end
 
@@ -541,9 +548,9 @@ local function local_on_master_disable()
     box.cfg({read_only = true})
     log.verbose("Resigning from the replicaset master role...")
     -- Stop garbage collecting
-    if M.garbage_collect_fiber ~= nil then
-        M.garbage_collect_fiber:cancel()
-        M.garbage_collect_fiber = nil
+    if M.collect_bucket_garbage_fiber ~= nil then
+        M.collect_bucket_garbage_fiber:cancel()
+        M.collect_bucket_garbage_fiber = nil
         log.info("GC stopped")
     end
     if M.recovery_fiber ~= nil then
@@ -568,7 +575,7 @@ local function local_on_master_enable()
     log.verbose("Taking on replicaset master role...")
     recovery_garbage_receiving_buckets()
     -- Start background process to collect garbage.
-    M.garbage_collect_fiber =
+    M.collect_bucket_garbage_fiber =
         lfiber.create(util.reloadable_fiber_f, M, 'collect_garbage_f',
                       'Garbage collector')
     log.info("GC is started")
@@ -843,7 +850,7 @@ function collect_garbage_f(module_version)
     -- for next deletion.
     local empty_sent_buckets = {}
     local iterations_until_lua_gc =
-        consts.COLLECT_LUA_GARBAGE_INTERVAL / M.garbage_collect_interval
+        consts.COLLECT_LUA_GARBAGE_INTERVAL / M.collect_bucket_garbage_interval
 
     while M.module_version == module_version do
         -- Check if no changes in buckets configuration.
@@ -886,11 +893,11 @@ function collect_garbage_f(module_version)
 ::continue::
         iterations_until_lua_gc = iterations_until_lua_gc - 1
         if iterations_until_lua_gc == 0 and M.collect_lua_garbage then
-            iterations_until_lua_gc =
-                consts.COLLECT_LUA_GARBAGE_INTERVAL / M.garbage_collect_interval
+            iterations_until_lua_gc = consts.COLLECT_LUA_GARBAGE_INTERVAL /
+                                      M.collect_bucket_garbage_interval
             collectgarbage()
         end
-        lfiber.sleep(M.garbage_collect_interval)
+        lfiber.sleep(M.collect_bucket_garbage_interval)
     end
 end
 
@@ -898,8 +905,8 @@ end
 -- Immediately wakeup bucket garbage collector.
 --
 local function garbage_collector_wakeup()
-    if M.garbage_collect_fiber then
-        M.garbage_collect_fiber:wakeup()
+    if M.collect_bucket_garbage_fiber then
+        M.collect_bucket_garbage_fiber:wakeup()
     end
 end
 
@@ -1343,8 +1350,9 @@ local function storage_cfg(cfg, this_replica_uuid)
     M.rebalancer_max_receiving = cfg.rebalancer_max_receiving or
                                     consts.DEFAULT_REBALANCER_MAX_RECEIVING
     M.shard_index = cfg.shard_index or 'bucket_id'
-    M.garbage_collect_interval = cfg.garbage_collect_interval or
-                                 consts.DEFAULT_GARBAGE_COLLECT_INTERVAL
+    M.collect_bucket_garbage_interval =
+        cfg.collect_bucket_garbage_interval or
+        consts.DEFAULT_COLLECT_BUCKET_GARBAGE_INTERVAL
     M.collect_lua_garbage = cfg.collect_lua_garbage
     lcfg.prepare_for_box_cfg(cfg)
 
-- 
2.14.3 (Apple Git-98)




More information about the Tarantool-patches mailing list