Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit 275893e

Browse files
resolve #88
* fix decoding fields for StorageCallVShardError (MasterUUID, ReplicasetUUID). * add ReplicaUUID to the StorageCallVShardError struct. * use constants for vshard error names. * add comment why and how we handle "NON_MASTER" vshard error.
1 parent dd210df commit 275893e

File tree

5 files changed

+125
-237
lines changed

5 files changed

+125
-237
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22

33
CHANGES:
44
* We don't support LogProvider interface anymore, only LogfProvider should be used.
5+
* Add comment why and how we handle "NON_MASTER" vshard error.
6+
* Don't support 'type Error struct' anymore.
57

68
BUG FIXES:
79
* RouterCallImpl: retry on BucketResolve error.
810
* RouterCallImpl: do not retry on vshard error "TRANSFER_IS_IN_PROGRESS".
911
* RouterCallImpl: remove misleading RetryOnCall.
1012
* AddInstance bugfix: pass r.cfg.PoolOpts to new instance.
13+
* Fix decoding fields for StorageCallVShardError (MasterUUID, ReplicasetUUID).
1114

1215
FEATURES:
1316

1417
* Support StdoutLoggerf that allows control log level (resolve issue #84).
1518
* Support new BucketsSearchMode config to set policy for BucketDiscovery (resolve #71).
1619
* Implemented CalculateEtalonBalance based on lua router (part of #32).
20+
* Add ReplicaUUID to the StorageCallVShardError struct.
1721

1822
REFACTOR:
1923

2024
* Func bucketSearchLegacy: log error from bucketStatWait (except bucketStatError).
2125
* New bucketsDiscoveryAsync, bucketsDiscoveryWait, bucketsDiscovery methods for buckets discovery pagination.
2226
* Support bucketSearchBatched method for batched buckets discovery (resolve #71).
27+
* Use constants for vshard error names and codes.
2328

2429
TESTS:
2530
* Tests for BucketsSearchMode (tnt/discovery_test.go).

api.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ func (s storageCallAssertError) Error() string {
4141
}
4242

4343
type StorageCallVShardError struct {
44-
BucketID uint64 `msgpack:"bucket_id" mapstructure:"bucket_id"`
45-
Reason string `msgpack:"reason"`
46-
Code int `msgpack:"code"`
47-
Type string `msgpack:"type"`
48-
Message string `msgpack:"message"`
49-
Name string `msgpack:"name"`
50-
MasterUUID *string `msgpack:"master_uuid" mapstructure:"master_uuid"` // mapstructure cant decode to source uuid type
51-
ReplicasetUUID *string `msgpack:"replicaset_uuid" mapstructure:"replicaset_uuid"` // mapstructure cant decode to source uuid type
44+
BucketID uint64 `msgpack:"bucket_id" mapstructure:"bucket_id"`
45+
Reason string `msgpack:"reason"`
46+
Code int `msgpack:"code"`
47+
Type string `msgpack:"type"`
48+
Message string `msgpack:"message"`
49+
Name string `msgpack:"name"`
50+
// These 3 fields below are send as string by vshard storage, so we decode them into string, not uuid.UUID type
51+
// Example: 00000000-0000-0002-0002-000000000000
52+
MasterUUID string `msgpack:"master" mapstructure:"master"`
53+
ReplicasetUUID string `msgpack:"replicaset" mapstructure:"replicaset"`
54+
ReplicaUUID string `msgpack:"replica" mapstructure:"replica"`
5255
}
5356

5457
func (s StorageCallVShardError) Error() string {
@@ -165,7 +168,7 @@ func (r *Router) RouterCallImpl(ctx context.Context,
165168
}
166169

167170
switch vshardError.Name {
168-
case "WRONG_BUCKET", "BUCKET_IS_LOCKED":
171+
case VShardErrNameWrongBucket, VShardErrNameBucketIsLocked:
169172
r.BucketReset(bucketID)
170173

171174
// TODO we should inspect here err.destination like lua vshard router does,
@@ -179,15 +182,17 @@ func (r *Router) RouterCallImpl(ctx context.Context,
179182
// this vshardError will be returned to a caller in case of timeout
180183
err = &vshardError
181184
continue
182-
case "TRANSFER_IS_IN_PROGRESS":
185+
case VShardErrNameTransferIsInProgress:
183186
// Since lua vshard router doesn't retry here, we don't retry too.
184187
// There is a comment why lua vshard router doesn't retry:
185188
// https://github.com/tarantool/vshard/blob/b6fdbe950a2e4557f05b83bd8b846b126ec3724e/vshard/router/init.lua#L697
186189
r.BucketReset(bucketID)
187190
return nil, nil, &vshardError
188-
case "NON_MASTER":
189-
// We don't know how to handle this case yet, so just return it for now.
190-
// Here is issue for it: https://github.com/KaymeKaydex/go-vshard-router/issues/88
191+
case VShardErrNameNonMaster:
192+
// vshard.storage has returned NON_MASTER error, lua vshard router updates info about master in this case:
193+
// See: https://github.com/tarantool/vshard/blob/b6fdbe950a2e4557f05b83bd8b846b126ec3724e/vshard/router/init.lua#L704.
194+
// Since we use go-tarantool library, and go-tarantool library doesn't provide API to update info about current master,
195+
// we just return this error as is.
191196
return nil, nil, &vshardError
192197
default:
193198
return nil, nil, &vshardError

discovery.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (r *Router) bucketSearchLegacy(ctx context.Context, bucketID uint64) (*Repl
100100
rs, err := r.BucketSet(bucketID, rsFuture.rsID)
101101
if err != nil {
102102
r.log().Errorf(ctx, "bucketSearchLegacy: can't set rsID %v for bucketID %d: %v", rsFuture.rsID, bucketID, err)
103-
return nil, Errors[9] // NO_ROUTE_TO_BUCKET
103+
return nil, newVShardErrorNoRouteToBucket(bucketID)
104104
}
105105

106106
// TODO: should we release resources for unhandled futures?
@@ -116,7 +116,7 @@ func (r *Router) bucketSearchLegacy(ctx context.Context, bucketID uint64) (*Repl
116116
-- discovery).
117117
*/
118118

119-
return nil, Errors[9] // NO_ROUTE_TO_BUCKET
119+
return nil, newVShardErrorNoRouteToBucket(bucketID)
120120
}
121121

122122
// The approach in bucketSearchLegacy is very ineffective because
@@ -177,7 +177,7 @@ func (r *Router) bucketSearchBatched(ctx context.Context, bucketIDToFind uint64)
177177
}
178178

179179
if rs == nil {
180-
return nil, Errors[9] // NO_ROUTE_TO_BUCKET
180+
return nil, newVShardErrorNoRouteToBucket(bucketIDToFind)
181181
}
182182

183183
return rs, nil

0 commit comments

Comments
 (0)