[Tarantool-patches] [PATCH vshard 4/6] config: introduce master 'auto' replicaset option

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Jul 2 01:09:34 MSK 2021


The new option will enable auto-search for master on the marked
replicasets.

Part of #75
---
 test/unit/config.result   | 48 +++++++++++++++++++++++++++++++++++++++
 test/unit/config.test.lua | 21 +++++++++++++++++
 vshard/cfg.lua            | 27 +++++++++++++++++++---
 3 files changed, 93 insertions(+), 3 deletions(-)

diff --git a/test/unit/config.result b/test/unit/config.result
index 9df3bf1..676ee4d 100644
--- a/test/unit/config.result
+++ b/test/unit/config.result
@@ -656,3 +656,51 @@ util.check_error(lcfg.check, cfg)
 cfg.sched_move_quota = nil
 ---
 ...
+--
+-- gh-75: auto master discovery.
+--
+replicaset = {replicas = {uuid = replica}}
+---
+...
+replicaset.master = 'auto'
+---
+...
+cfg.sharding = {rsid = replicaset}
+---
+...
+_ = lcfg.check(cfg)
+---
+...
+replicaset.master = 'non-auto'
+---
+...
+util.check_error(lcfg.check, cfg)
+---
+- Only "auto" master is supported
+...
+replicaset.master = 123
+---
+...
+util.check_error(lcfg.check, cfg)
+---
+- Master search mode must be string
+...
+replica.master = true
+---
+...
+replicaset.master = 'auto'
+---
+...
+util.check_error(lcfg.check, cfg)
+---
+- Can not specify master nodes when master search is enabled, but found master flag
+  in replica uuid uuid
+...
+replica.master = false
+---
+...
+util.check_error(lcfg.check, cfg)
+---
+- Can not specify master nodes when master search is enabled, but found master flag
+  in replica uuid uuid
+...
diff --git a/test/unit/config.test.lua b/test/unit/config.test.lua
index 473e460..4dfbd77 100644
--- a/test/unit/config.test.lua
+++ b/test/unit/config.test.lua
@@ -264,3 +264,24 @@ _ = lcfg.check(cfg)
 cfg.sched_move_quota = -1
 util.check_error(lcfg.check, cfg)
 cfg.sched_move_quota = nil
+
+--
+-- gh-75: auto master discovery.
+--
+replicaset = {replicas = {uuid = replica}}
+replicaset.master = 'auto'
+cfg.sharding = {rsid = replicaset}
+_ = lcfg.check(cfg)
+
+replicaset.master = 'non-auto'
+util.check_error(lcfg.check, cfg)
+
+replicaset.master = 123
+util.check_error(lcfg.check, cfg)
+
+replica.master = true
+replicaset.master = 'auto'
+util.check_error(lcfg.check, cfg)
+
+replica.master = false
+util.check_error(lcfg.check, cfg)
diff --git a/vshard/cfg.lua b/vshard/cfg.lua
index 30f8794..401d969 100644
--- a/vshard/cfg.lua
+++ b/vshard/cfg.lua
@@ -2,6 +2,7 @@
 
 local log = require('log')
 local luri = require('uri')
+local lutil = require('vshard.util')
 local consts = require('vshard.consts')
 
 local function check_uri(uri)
@@ -10,7 +11,7 @@ local function check_uri(uri)
     end
 end
 
-local function check_master(master, ctx)
+local function check_replica_master(master, ctx)
     if master then
         if ctx.master then
             error('Only one master is allowed per replicaset')
@@ -20,6 +21,15 @@ local function check_master(master, ctx)
     end
 end
 
+local function check_replicaset_master(master, ctx)
+    if not lutil.version_is_at_least(1, 10, 0) then
+        error('Only versions >= 1.10 support master discovery')
+    end
+    if master ~= 'auto' then
+        error('Only "auto" master is supported')
+    end
+end
+
 local function is_number(v)
     return type(v) == 'number' and v == v
 end
@@ -111,8 +121,8 @@ local replica_template = {
     name = {type = 'string', name = "Name", is_optional = true},
     zone = {type = {'string', 'number'}, name = "Zone", is_optional = true},
     master = {
-        type = 'boolean', name = "Master", is_optional = true, default = false,
-        check = check_master
+        type = 'boolean', name = "Master", is_optional = true,
+        check = check_replica_master
     },
 }
 
@@ -130,6 +140,10 @@ local replicaset_template = {
         default = 1,
     },
     lock = {type = 'boolean', name = 'Lock', is_optional = true},
+    master = {
+        type = 'string', name = 'Master search mode', is_optional = true,
+        check = check_replicaset_master
+    },
 }
 
 --
@@ -185,6 +199,7 @@ local function check_sharding(sharding)
             error('Replicaset weight can not be Inf')
         end
         validate_config(replicaset, replicaset_template)
+        local is_auto_master = replicaset.master == 'auto'
         for replica_uuid, replica in pairs(replicaset.replicas) do
             if uris[replica.uri] then
                 error(string.format('Duplicate uri %s', replica.uri))
@@ -194,6 +209,12 @@ local function check_sharding(sharding)
                 error(string.format('Duplicate uuid %s', replica_uuid))
             end
             uuids[replica_uuid] = true
+            if is_auto_master and replica.master ~= nil then
+                error(string.format('Can not specify master nodes when '..
+                                    'master search is enabled, but found '..
+                                    'master flag in replica uuid %s',
+                                    replica_uuid))
+            end
             -- Log warning in case replica.name duplicate is
             -- found. Message appears once for each unique
             -- duplicate.
-- 
2.24.3 (Apple Git-128)



More information about the Tarantool-patches mailing list