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 BED6125A20 for ; Thu, 7 Jun 2018 07:51:00 -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 CFX6CKovJkHL for ; Thu, 7 Jun 2018 07:51:00 -0400 (EDT) Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 223FA25A06 for ; Thu, 7 Jun 2018 07:51:00 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH][vshard] Log warning on duplicate replica.name Date: Thu, 7 Jun 2018 14:50:43 +0300 Message-Id: <20180607115043.3851-1-avkhatskevich@tarantool.org> 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: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org 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