From: AKhatskevich <avkhatskevich@tarantool.org> To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH][vshard] Log warning on duplicate replica.name Date: Thu, 7 Jun 2018 14:50:43 +0300 [thread overview] Message-ID: <20180607115043.3851-1-avkhatskevich@tarantool.org> (raw) In case duplicate replica.name found, log warning. Closes #101 --- Branch: https://github.com/tarantool/vshard/tree/kh/gh-101-duplicate_name_warning Issue: https://github.com/tarantool/vshard/issues/101 test/unit/config.result | 62 +++++++++++++++++++++++++++++++++++++++++++++-- test/unit/config.test.lua | 29 ++++++++++++++++++++-- vshard/cfg.lua | 8 ++++++ 3 files changed, 95 insertions(+), 4 deletions(-) diff --git a/test/unit/config.result b/test/unit/config.result index 8449ec3..b82303b 100644 --- a/test/unit/config.result +++ b/test/unit/config.result @@ -120,13 +120,13 @@ cfg.sharding['rsid2'] = nil --- ... -- UUID duplicate in different replicasets. -replicaset2 = {replicas = {['id3'] = {uri = 'uri:uri@uri2', name = 'storage', master = true}}} +replicaset2 = {replicas = {['id3'] = {uri = 'uri:uri@uri2', name = 'storage2', master = true}}} --- ... cfg.sharding['rsid2'] = replicaset2 --- ... -replicaset3 = {replicas = {['id3'] = {uri = 'uri:uri@uri3', name = 'storage', master = true}}} +replicaset3 = {replicas = {['id3'] = {uri = 'uri:uri@uri3', name = 'storage3', master = false}}} --- ... cfg.sharding['rsid3'] = replicaset3 @@ -136,6 +136,64 @@ check(cfg) --- - Duplicate uuid id3 ... +cfg.sharding['rsid3'] = nil +--- +... +cfg.sharding['rsid2'] = nil +--- +... +-- +-- gh-101: Log warning in case replica.name duplicate found. +-- +-- name duplicate in one replicaset. +replica2_1 = {uri = 'uri:uri@uri2_1', name = 'dup_name1', master = true} +--- +... +replica2_2 = {uri = 'uri:uri@uri2_2', name = 'dup_name1', master = false} +--- +... +replicaset2 = {replicas = {['id2'] = replica2_1, ['id3'] = replica2_2}} +--- +... +cfg.sharding['rsid2'] = replicaset2 +--- +... +_ = check(cfg) +--- +... +test_run:grep_log('default', 'Duplicate replica.name found: dup_name1') +--- +- 'Duplicate replica.name found: dup_name1' +... +cfg.sharding['rsid2'] = nil +--- +... +-- name duplicate in different replicasets. +replica2 = {uri = 'uri:uri@uri2', name = 'dup_name2', master = true} +--- +... +replica3 = {uri = 'uri:uri@uri3', name = 'dup_name2', master = true} +--- +... +replicaset2 = {replicas = {['id2'] = replica2}} +--- +... +replicaset3 = {replicas = {['id3'] = replica3}} +--- +... +cfg.sharding['rsid2'] = replicaset2 +--- +... +cfg.sharding['rsid3'] = replicaset3 +--- +... +_ = check(cfg) +--- +... +test_run:grep_log('default', 'Duplicate replica.name found: dup_name2') +--- +- 'Duplicate replica.name found: dup_name2' +... cfg.sharding['rsid2'] = nil --- ... diff --git a/test/unit/config.test.lua b/test/unit/config.test.lua index 0b01b3e..9b2b7be 100644 --- a/test/unit/config.test.lua +++ b/test/unit/config.test.lua @@ -57,11 +57,36 @@ check(cfg) cfg.sharding['rsid2'] = nil -- UUID duplicate in different replicasets. -replicaset2 = {replicas = {['id3'] = {uri = 'uri:uri@uri2', name = 'storage', master = true}}} +replicaset2 = {replicas = {['id3'] = {uri = 'uri:uri@uri2', name = 'storage2', master = true}}} cfg.sharding['rsid2'] = replicaset2 -replicaset3 = {replicas = {['id3'] = {uri = 'uri:uri@uri3', name = 'storage', master = true}}} +replicaset3 = {replicas = {['id3'] = {uri = 'uri:uri@uri3', name = 'storage3', master = false}}} cfg.sharding['rsid3'] = replicaset3 check(cfg) +cfg.sharding['rsid3'] = nil +cfg.sharding['rsid2'] = nil + +-- +-- gh-101: Log warning in case replica.name duplicate found. +-- + +-- name duplicate in one replicaset. +replica2_1 = {uri = 'uri:uri@uri2_1', name = 'dup_name1', master = true} +replica2_2 = {uri = 'uri:uri@uri2_2', name = 'dup_name1', master = false} +replicaset2 = {replicas = {['id2'] = replica2_1, ['id3'] = replica2_2}} +cfg.sharding['rsid2'] = replicaset2 +_ = check(cfg) +test_run:grep_log('default', 'Duplicate replica.name found: dup_name1') +cfg.sharding['rsid2'] = nil + +-- name duplicate in different replicasets. +replica2 = {uri = 'uri:uri@uri2', name = 'dup_name2', master = true} +replica3 = {uri = 'uri:uri@uri3', name = 'dup_name2', master = true} +replicaset2 = {replicas = {['id2'] = replica2}} +replicaset3 = {replicas = {['id3'] = replica3}} +cfg.sharding['rsid2'] = replicaset2 +cfg.sharding['rsid3'] = replicaset3 +_ = check(cfg) +test_run:grep_log('default', 'Duplicate replica.name found: dup_name2') cfg.sharding['rsid2'] = nil cfg.sharding['rsid3'] = nil diff --git a/vshard/cfg.lua b/vshard/cfg.lua index a389eea..c3cf5d7 100644 --- a/vshard/cfg.lua +++ b/vshard/cfg.lua @@ -141,6 +141,7 @@ end local function check_sharding(sharding) local uuids = {} local uris = {} + local names = {} for replicaset_uuid, replicaset in pairs(sharding) do if uuids[replicaset_uuid] then error(string.format('Duplicate uuid %s', replicaset_uuid)) @@ -159,6 +160,13 @@ local function check_sharding(sharding) error(string.format('Duplicate uuid %s', replica_uuid)) end uuids[replica_uuid] = true + -- log warning in case replica.name duplicate found + if replica.name then + if names[replica.name] then + log.warn('Duplicate replica.name found: %s', replica.name) + end + names[replica.name] = true + end end end end -- 2.14.1
next reply other threads:[~2018-06-07 11:51 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-07 11:50 AKhatskevich [this message] 2018-06-07 14:49 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-07 16:44 ` Alex Khatskevich 2018-06-07 19:05 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180607115043.3851-1-avkhatskevich@tarantool.org \ --to=avkhatskevich@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH][vshard] Log warning on duplicate replica.name' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox