From: Alex Khatskevich <avkhatskevich@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, tarantool-patches@freelists.org Subject: [tarantool-patches] Re: [PATCH][vshard] Log warning on duplicate replica.name Date: Thu, 7 Jun 2018 19:44:38 +0300 [thread overview] Message-ID: <26948b8a-a552-d558-df71-490c81916d7f@tarantool.org> (raw) In-Reply-To: <b1d85339-1a28-0d4b-3472-3055541b8a35@tarantool.org> > Please, print the warning on each duplicate only once. Now if I use > the same name > N >= 2 times, the warning for the name is printed N - 1 times. > > Example: > > name1, name1, name1, name1 > > In the log I see: > > Duplicate replica.name found: name1 > Duplicate replica.name found: name1 > Duplicate replica.name found: name1 > > Must be: > > Duplicate replica.name found: name1 > > For example, you can store in 'names' not booleans, but count of name > duplicates. And print the warning only when the count is 2. Fixed New diff: commit c1d573d035994723c11b2c0e7151f52f67dd5d55 Author: AKhatskevich <avkhatskevich@tarantool.org> Date: Thu Jun 7 14:43:16 2018 +0300 Log warning on duplicate replica.name In case duplicate replica.name found, log warning. Message appears once for each unique duplicate. Closes #101 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..7a25cc9 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,18 @@ 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. + -- Message appears once for each unique duplicate. + local name = replica.name + if name then + if names[name] == nil then + names[name] = 1 + elseif names[name] == 1 then + log.warn('Duplicate replica.name found: %s', name) + -- Next duplicates should not be reported. + names[name] = 2 + end + end end end end
next prev parent reply other threads:[~2018-06-07 16:44 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-07 11:50 [tarantool-patches] " AKhatskevich 2018-06-07 14:49 ` [tarantool-patches] " Vladislav Shpilevoy 2018-06-07 16:44 ` Alex Khatskevich [this message] 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=26948b8a-a552-d558-df71-490c81916d7f@tarantool.org \ --to=avkhatskevich@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='[tarantool-patches] Re: [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