From 5da1477e076a5250d01892659b6f378426f4d231 Mon Sep 17 00:00:00 2001 From: Nikita Zheleztsov Date: Wed, 13 Dec 2023 02:01:02 +0300 Subject: [PATCH] error: more generic argument names In the following commits it'll be allowed to use names instead of UUIDs. This patch refactors error module, changing the name of arguments, accepted by errors: from now on it may be either UUID or persistent name, so we cannot say, that this is always UUID, as it's done now. The alternative would be to rename arguments according to the configuration used on the fly. It's not selected, as it complicates expluatation. Note, that this is breaking change, if user's code relies on UUID arguments of returned errors! Part of #426 NO_DOC=refactoring --- test/misc/check_uuid_on_connect.result | 6 +++--- test/router/master_discovery.result | 18 +++++++++--------- test/router/router.result | 22 +++++++++++----------- test/storage/storage.result | 14 +++++++------- test/unit/error.result | 4 ++-- vshard/error.lua | 18 +++++++++--------- vshard/router/init.lua | 3 +-- vshard/storage/init.lua | 3 +-- 8 files changed, 43 insertions(+), 45 deletions(-) diff --git a/test/misc/check_uuid_on_connect.result b/test/misc/check_uuid_on_connect.result index 8862e626..8eb71cbb 100644 --- a/test/misc/check_uuid_on_connect.result +++ b/test/misc/check_uuid_on_connect.result @@ -191,12 +191,12 @@ vshard.router.static.route_map[1] = nil vshard.router.bucket_discovery(1) --- - null -- bucket_id: 1 +- replicaset: ac522f65-aa94-4134-9f64-51ee384f1a54 code: 8 - unreachable_uuid: ac522f65-aa94-4134-9f64-51ee384f1a54 + type: ShardingError name: UNREACHABLE_REPLICASET message: There is no active replicas in replicaset ac522f65-aa94-4134-9f64-51ee384f1a54 - type: ShardingError + bucket_id: 1 ... -- Ok to work with correct replicasets. vshard.router.bucket_discovery(2).uuid diff --git a/test/router/master_discovery.result b/test/router/master_discovery.result index 1b88cb6e..ecc26208 100644 --- a/test/router/master_discovery.result +++ b/test/router/master_discovery.result @@ -451,11 +451,11 @@ f1:join() | --- | - true | - null - | - code: 6 + | - replicaset: + | code: 6 | type: ShardingError - | name: MISSING_MASTER - | replicaset_uuid: | message: Master is not configured for replicaset + | name: MISSING_MASTER | ... -- Try to make an RO request but then turn of the auto search. @@ -486,11 +486,11 @@ f2:join() | --- | - true | - null - | - code: 6 + | - replicaset: + | code: 6 | type: ShardingError - | name: MISSING_MASTER - | replicaset_uuid: | message: Master is not configured for replicaset + | name: MISSING_MASTER | ... test_run:cmd('start server storage_1_a') | --- @@ -587,11 +587,11 @@ do end | --- | - null - | - code: 6 + | - replicaset: + | code: 6 | type: ShardingError - | name: MISSING_MASTER - | replicaset_uuid: | message: Master is not configured for replicaset + | name: MISSING_MASTER | ... -- diff --git a/test/router/router.result b/test/router/router.result index 5b7252b3..27bddf07 100644 --- a/test/router/router.result +++ b/test/router/router.result @@ -412,12 +412,12 @@ end) util.check_error(vshard.router.call, 1, 'read', 'echo', {123}) --- - null -- bucket_id: 1 +- replicaset: code: 8 - unreachable_uuid: + type: ShardingError name: UNREACHABLE_REPLICASET message: There is no active replicas in replicaset - type: ShardingError + bucket_id: 1 ... vshard.router.buckets_info(0, 3) --- @@ -1022,8 +1022,8 @@ space_data = {{1000, {{1}, {2}}}} vshard.router.call(bucket_id, 'write', 'vshard.storage.bucket_recv', {new_bid, 'from_uuid', space_data}) --- - null -- {'code': 4, 'type': 'ShardingError', 'message': 'Replicaset from_uuid not found', - 'name': 'NO_SUCH_REPLICASET', 'replicaset_uuid': 'from_uuid'} +- {'replicaset': 'from_uuid', 'code': 4, 'type': 'ShardingError', 'message': 'Replicaset + from_uuid not found', 'name': 'NO_SUCH_REPLICASET'} ... -- -- Monitoring @@ -1425,14 +1425,14 @@ _ = test_run:switch("router_1") util.check_error(vshard.router.call, 1, 'write', 'echo', { 'hello world' }) --- - null -- master_uuid: - replica_uuid: - message: Replica is not a master for replicaset - anymore +- replicaset: + master: + code: 2 type: ShardingError - replicaset_uuid: + replica: name: NON_MASTER - code: 2 + message: Replica is not a master for replicaset + anymore ... -- Reconfigure router and test that the WRITE request does work vshard.router.cfg(cfg) diff --git a/test/storage/storage.result b/test/storage/storage.result index 324dfbef..9a5ada1b 100644 --- a/test/storage/storage.result +++ b/test/storage/storage.result @@ -531,11 +531,11 @@ vshard.storage.call(100500, 'read', 'space_get', {'test', {1}}) vshard.storage.bucket_recv(100, 'from_uuid', {{1000, {{1}}}}) --- - null -- code: 4 +- replicaset: from_uuid + code: 4 type: ShardingError - name: NO_SUCH_REPLICASET - replicaset_uuid: from_uuid message: Replicaset from_uuid not found + name: NO_SUCH_REPLICASET ... -- -- Test not existing space in bucket data. @@ -605,11 +605,11 @@ assert(box.space.test:get{9} == nil and box.space.test:get{10} == nil) vshard.storage.bucket_send(1, 'unknown uuid') --- - null -- code: 4 +- replicaset: unknown uuid + code: 4 type: ShardingError - name: NO_SUCH_REPLICASET - replicaset_uuid: unknown uuid message: Replicaset unknown uuid not found + name: NO_SUCH_REPLICASET ... -- gh-217: transfer to self. vshard.storage.bucket_send(1, util.replicasets[1]) @@ -619,8 +619,8 @@ vshard.storage.bucket_send(1, util.replicasets[1]) code: 5 type: ShardingError name: MOVE_TO_SELF - replicaset_uuid: message: 'Cannot move: bucket 1 is already on replicaset ' + replicaset: ... -- Successful transfer. vshard.storage.bucket_send(1, util.replicasets[2]) diff --git a/test/unit/error.result b/test/unit/error.result index 29e12184..7d48d16c 100644 --- a/test/unit/error.result +++ b/test/unit/error.result @@ -35,8 +35,8 @@ vshard_error = lerror.vshard(lerror.code.UNREACHABLE_MASTER, 'uuid', 'reason') ... tostring(vshard_error) --- -- '{"reason":"reason","code":11,"type":"ShardingError","name":"UNREACHABLE_MASTER","uuid":"uuid","message":"Master - of replicaset uuid is unreachable: reason"}' +- '{"replicaset":"uuid","reason":"reason","code":11,"type":"ShardingError","message":"Master + of replicaset uuid is unreachable: reason","name":"UNREACHABLE_MASTER"}' ... log = require('log') --- diff --git a/vshard/error.lua b/vshard/error.lua index 331cad46..3042f88a 100644 --- a/vshard/error.lua +++ b/vshard/error.lua @@ -20,7 +20,7 @@ local error_message_template = { [2] = { name = 'NON_MASTER', msg = 'Replica %s is not a master for replicaset %s anymore', - args = {'replica_uuid', 'replicaset_uuid', 'master_uuid'} + args = {'replica', 'replicaset', 'master'} }, [3] = { name = 'BUCKET_ALREADY_EXISTS', @@ -30,17 +30,17 @@ local error_message_template = { [4] = { name = 'NO_SUCH_REPLICASET', msg = 'Replicaset %s not found', - args = {'replicaset_uuid'} + args = {'replicaset'} }, [5] = { name = 'MOVE_TO_SELF', msg = 'Cannot move: bucket %d is already on replicaset %s', - args = {'bucket_id', 'replicaset_uuid'} + args = {'bucket_id', 'replicaset'} }, [6] = { name = 'MISSING_MASTER', msg = 'Master is not configured for replicaset %s', - args = {'replicaset_uuid'} + args = {'replicaset'} }, [7] = { name = 'TRANSFER_IS_IN_PROGRESS', @@ -50,7 +50,7 @@ local error_message_template = { [8] = { name = 'UNREACHABLE_REPLICASET', msg = 'There is no active replicas in replicaset %s', - args = {'unreachable_uuid', 'bucket_id'} + args = {'replicaset', 'bucket_id'} }, [9] = { name = 'NO_ROUTE_TO_BUCKET', @@ -64,7 +64,7 @@ local error_message_template = { [11] = { name = 'UNREACHABLE_MASTER', msg = 'Master of replicaset %s is unreachable: %s', - args = {'uuid', 'reason'} + args = {'replicaset', 'reason'} }, [12] = { name = 'OUT_OF_SYNC', @@ -78,7 +78,7 @@ local error_message_template = { [14] = { name = 'UNREACHABLE_REPLICA', msg = "Replica %s isn't active", - args = {'unreachable_uuid'} + args = {'replica'} }, [15] = { name = 'LOW_REDUNDANCY', @@ -157,13 +157,13 @@ local error_message_template = { [31] = { name = 'MULTIPLE_MASTERS_FOUND', msg = 'Found more than one master in replicaset %s on nodes %s and %s', - args = {'replicaset_uuid', 'master1', 'master2'}, + args = {'replicaset', 'master1', 'master2'}, }, [32] = { name = 'REPLICASET_IN_BACKOFF', msg = 'Replicaset %s is in backoff, can\'t take requests right now. '.. 'Last error was %s', - args = {'replicaset_uuid', 'error'} + args = {'replicaset', 'error'} }, [33] = { name = 'STORAGE_IS_DISABLED', diff --git a/vshard/router/init.lua b/vshard/router/init.lua index 70ff306c..f5d85161 100644 --- a/vshard/router/init.lua +++ b/vshard/router/init.lua @@ -699,8 +699,7 @@ local function router_call_impl(router, bucket_id, mode, prefer_replica, return nil, err elseif err.code == lerror.code.NON_MASTER then assert(mode == 'write') - if not replicaset:update_master(err.replica_uuid, - err.master_uuid) then + if not replicaset:update_master(err.replica, err.master) then return nil, err end else diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua index 5f0d8b78..48561993 100644 --- a/vshard/storage/init.lua +++ b/vshard/storage/init.lua @@ -300,8 +300,7 @@ local function master_call(replicaset, func, args, opts) if err.code ~= lerror.code.NON_MASTER then return nil, err end - if not replicaset:update_master(err.replica_uuid, - err.master_uuid) then + if not replicaset:update_master(err.replica, err.master) then return nil, err end local timeout = deadline - fiber_clock()