From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 8E76C25C26 for ; Thu, 7 Jun 2018 12:44:40 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id e3wkDwa3v-fu for ; Thu, 7 Jun 2018 12:44:40 -0400 (EDT) Received: from smtp62.i.mail.ru (smtp62.i.mail.ru [217.69.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 4D0EF25B94 for ; Thu, 7 Jun 2018 12:44:40 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH][vshard] Log warning on duplicate replica.name References: <20180607115043.3851-1-avkhatskevich@tarantool.org> From: Alex Khatskevich Message-ID: <26948b8a-a552-d558-df71-490c81916d7f@tarantool.org> Date: Thu, 7 Jun 2018 19:44:38 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: Vladislav Shpilevoy , tarantool-patches@freelists.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 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