Skip to content

Commit

Permalink
error: more generic argument names
Browse files Browse the repository at this point in the history
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 tarantool#426

NO_DOC=refactoring
  • Loading branch information
Serpentian committed Dec 12, 2023
1 parent 937306d commit 5da1477
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 45 deletions.
6 changes: 3 additions & 3 deletions test/misc/check_uuid_on_connect.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions test/router/master_discovery.result
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ f1:join()
| ---
| - true
| - null
| - code: 6
| - replicaset: <replicaset_1>
| code: 6
| type: ShardingError
| name: MISSING_MASTER
| replicaset_uuid: <replicaset_1>
| message: Master is not configured for replicaset <replicaset_1>
| name: MISSING_MASTER
| ...

-- Try to make an RO request but then turn of the auto search.
Expand Down Expand Up @@ -486,11 +486,11 @@ f2:join()
| ---
| - true
| - null
| - code: 6
| - replicaset: <replicaset_1>
| code: 6
| type: ShardingError
| name: MISSING_MASTER
| replicaset_uuid: <replicaset_1>
| message: Master is not configured for replicaset <replicaset_1>
| name: MISSING_MASTER
| ...
test_run:cmd('start server storage_1_a')
| ---
Expand Down Expand Up @@ -587,11 +587,11 @@ do
end
| ---
| - null
| - code: 6
| - replicaset: <replicaset_1>
| code: 6
| type: ShardingError
| name: MISSING_MASTER
| replicaset_uuid: <replicaset_1>
| message: Master is not configured for replicaset <replicaset_1>
| name: MISSING_MASTER
| ...

--
Expand Down
22 changes: 11 additions & 11 deletions test/router/router.result
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ end)
util.check_error(vshard.router.call, 1, 'read', 'echo', {123})
---
- null
- bucket_id: 1
- replicaset: <replicaset_2>
code: 8
unreachable_uuid: <replicaset_2>
type: ShardingError
name: UNREACHABLE_REPLICASET
message: There is no active replicas in replicaset <replicaset_2>
type: ShardingError
bucket_id: 1
...
vshard.router.buckets_info(0, 3)
---
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1425,14 +1425,14 @@ _ = test_run:switch("router_1")
util.check_error(vshard.router.call, 1, 'write', 'echo', { 'hello world' })
---
- null
- master_uuid: <storage_2_b>
replica_uuid: <storage_2_a>
message: Replica <storage_2_a> is not a master for replicaset
<replicaset_2> anymore
- replicaset: <replicaset_2>
master: <storage_2_b>
code: 2
type: ShardingError
replicaset_uuid: <replicaset_2>
replica: <storage_2_a>
name: NON_MASTER
code: 2
message: Replica <storage_2_a> is not a master for replicaset
<replicaset_2> anymore
...
-- Reconfigure router and test that the WRITE request does work
vshard.router.cfg(cfg)
Expand Down
14 changes: 7 additions & 7 deletions test/storage/storage.result
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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])
Expand All @@ -619,8 +619,8 @@ vshard.storage.bucket_send(1, util.replicasets[1])
code: 5
type: ShardingError
name: MOVE_TO_SELF
replicaset_uuid: <replicaset_1>
message: 'Cannot move: bucket 1 is already on replicaset <replicaset_1>'
replicaset: <replicaset_1>
...
-- Successful transfer.
vshard.storage.bucket_send(1, util.replicasets[2])
Expand Down
4 changes: 2 additions & 2 deletions test/unit/error.result
Original file line number Diff line number Diff line change
Expand Up @@ -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')
---
Expand Down
18 changes: 9 additions & 9 deletions vshard/error.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions vshard/router/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions vshard/storage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5da1477

Please sign in to comment.