Skip to content

Commit 3e9359e

Browse files
nurzhan-saktaganovKaymeKaydex
authored andcommitted
api: make api similar to tnt vshard router
* rename RouterRouteAll -> RouteAll, RouterRoute -> Route, RouterBucketIDStrCRC32 -> BucketIDStrCRC32. * remove BucketResolve, BucketDiscovery, RouterBucketID, RouterBucketIDMPCRC32. * update README.md, README_ru.md. * ClusterBootstrap: eliminate direct access to r.idToReplicaset. * remove unused Makefile target. * replace github links to master branch with permalinks. * remove discovery_test.go, move tests/tnt/discovery_test.go -> tarantool_test.go.
1 parent de74a44 commit 3e9359e

16 files changed

+101
-196
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
## Unreleased
22

3+
BUG FIXES:
4+
5+
* ClusterBootstrap: eliminate direct access to r.idToReplicaset.
6+
37
CHANGES:
48

59
* Instance UUID no more required, use instance name instead.
610
* Removed toolchain go1.23.3.
711
* Refactored GetTyped interface and logic. Now we use raw msg buffer instead raw messages. Interface works and looks
812
like go-tarantool response.
9-
* ReplicaCall, RouterCallImpl, RouterMapCallRWImpl methods was removed cause it works invalid and looks useless.
13+
* ReplicaCall, RouterCallImpl, RouterMapCallRWImpl, BucketResolve, BucketDiscovery, RouterBucketID, RouterBucketIDMPCRC32 methods were removed cause they work invalid, look useless or redundant.
1014
* All PR, issue references in #XYZ format in commits older than 42f363775dfb9eaf7ec2a6ed7a999847752cec00 refer to https://github.com/KaymeKaydex/go-vshard-router.
1115
* VshardRouterCallMode type renamed to CallMode for simplicity.
1216
* StorageResultTypedFunc type removed as useless type.
1317
* Updated msgpack version from v5.3.5 to v5.4.1.
1418
* Replicaset identifier now is replicaset name instead uuid.
19+
* Remove unused Makefile target.
20+
* Update README.md, README_ru.md.
21+
* Rename RouterRouteAll -> RouteAll, RouterRoute -> Route, RouterBucketIDStrCRC32 -> BucketIDStrCRC32.
22+
* Replace github links to master branch with permalinks.
1523

1624
TESTS:
1725

@@ -21,6 +29,7 @@ TESTS:
2129
* TestRouterCallProto rewrote.
2230
* Start using constants in tarantool_test.go instead duplicate variables.
2331
* TestRouterMapCall moved to tarantool_test.go and renamed to TestRouter_RouterMapCallRWImpl.
32+
* Remove discovery_test.go, move tests/tnt/discovery_test.go -> tarantool_test.go
2433

2534
## v1.3.2
2635

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ test: prepare-tnt
4444
cover: test ## Generate and open the HTML report for test coverage.
4545
$(GO_CMD) tool cover -html=coverage.out
4646

47-
test/integration:
48-
@$(MAKE) -C ./tests/integration test
4947

5048
generate/mocks:
5149
mockery --name=Pool --case=underscore --output=mocks/pool --outpkg=mockpool # need fix it later

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func main() {
132132
ID: 123,
133133
}
134134

135-
bucketID := vshardrouter.BucketIDStrCRC32(strconv.FormatUint(user.ID, 10), directRouter.RouterBucketCount())
135+
bucketID := directRouter.BucketIDStrCRC32(strconv.FormatUint(user.ID, 10))
136136

137137
resp, err := directRouter.Call(
138138
ctx,

README_ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func main() {
131131
ID: 123,
132132
}
133133

134-
bucketID := vshardrouter.BucketIDStrCRC32(strconv.FormatUint(user.ID, 10), directRouter.RouterBucketCount())
134+
bucketID := directRouter.BucketIDStrCRC32(strconv.FormatUint(user.ID, 10))
135135

136136
resp, err := directRouter.Call(
137137
ctx,

api.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (r *Router) Call(ctx context.Context, bucketID uint64, mode CallMode,
276276

277277
var rs *Replicaset
278278

279-
rs, err = r.BucketResolve(ctx, bucketID)
279+
rs, err = r.Route(ctx, bucketID)
280280
if err != nil {
281281
r.metrics().RetryOnCall("bucket_resolve_error")
282282

@@ -657,14 +657,8 @@ func RouterMapCallRW[T any](r *Router, ctx context.Context,
657657
return nameToResult, nil
658658
}
659659

660-
// RouterRoute get replicaset object by bucket identifier.
661-
// alias to BucketResolve
662-
func (r *Router) RouterRoute(ctx context.Context, bucketID uint64) (*Replicaset, error) {
663-
return r.BucketResolve(ctx, bucketID)
664-
}
665-
666-
// RouterRouteAll return map of all replicasets.
667-
func (r *Router) RouterRouteAll() map[string]*Replicaset {
660+
// RouteAll return map of all replicasets.
661+
func (r *Router) RouteAll() map[string]*Replicaset {
668662
nameToReplicasetRef := r.getNameToReplicaset()
669663

670664
// Do not expose the original map to prevent unauthorized modification.

api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func TestVshardMode_String_NotEmpty(t *testing.T) {
2222

2323
func TestRouter_RouterRouteAll(t *testing.T) {
2424
t.Parallel()
25-
m := emptyRouter.RouterRouteAll()
25+
m := emptyRouter.RouteAll()
2626
require.Empty(t, m)
2727
}

discovery.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
DiscoveryModeOnce
2525
)
2626

27-
// BucketsSearchMode a type, that used to define policy for BucketDiscovery method.
27+
// BucketsSearchMode a type, that used to define policy for Router.Route method.
2828
// See type Config for further details.
2929
type BucketsSearchMode int
3030

@@ -45,8 +45,8 @@ const (
4545
BucketsSearchBatchedFull
4646
)
4747

48-
// BucketDiscovery search bucket in whole cluster
49-
func (r *Router) BucketDiscovery(ctx context.Context, bucketID uint64) (*Replicaset, error) {
48+
// Route get replicaset object by bucket identifier.
49+
func (r *Router) Route(ctx context.Context, bucketID uint64) (*Replicaset, error) {
5050
if bucketID < 1 || r.cfg.TotalBucketCount < bucketID {
5151
return nil, fmt.Errorf("bucket id is out of range: %d (total %d)", bucketID, r.cfg.TotalBucketCount)
5252
}
@@ -182,11 +182,6 @@ func (r *Router) bucketSearchBatched(ctx context.Context, bucketIDToFind uint64)
182182
return rs, nil
183183
}
184184

185-
// BucketResolve resolve bucket id to replicaset
186-
func (r *Router) BucketResolve(ctx context.Context, bucketID uint64) (*Replicaset, error) {
187-
return r.BucketDiscovery(ctx, bucketID)
188-
}
189-
190185
// DiscoveryHandleBuckets arrange downloaded buckets to the route map so as they reference a given replicaset.
191186
func (r *Router) DiscoveryHandleBuckets(ctx context.Context, rs *Replicaset, buckets []uint64) {
192187
view := r.getConsistentView()

discovery_test.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/customer/go-service/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (c *controller) CustomerAddHandler(w http.ResponseWriter, r *http.Request)
115115
return
116116
}
117117

118-
bucketID := c.router.RouterBucketIDStrCRC32(strconv.Itoa(req.CustomerID))
118+
bucketID := c.router.BucketIDStrCRC32(strconv.Itoa(req.CustomerID))
119119

120120
req.BucketId = bucketID
121121

@@ -164,7 +164,7 @@ func (c *controller) CustomerLookupHandler(w http.ResponseWriter, r *http.Reques
164164
return
165165
}
166166

167-
bucketID := c.router.RouterBucketIDStrCRC32(customerID)
167+
bucketID := c.router.BucketIDStrCRC32(customerID)
168168
resp, err := c.router.Call(ctx, bucketID, vshardrouter.CallModeBRO, "customer_lookup", []interface{}{csID}, vshardrouter.CallOpts{
169169
Timeout: time.Minute,
170170
})

replicaset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (rs *Replicaset) bucketsDiscovery(ctx context.Context, from uint64) (bucket
205205
// At each iteration, the algorithm either concludes or disregards at least
206206
// one new overloaded replicaset. Therefore, its time complexity is O(N^2),
207207
// where N is the number of replicasets.
208-
// based on https://github.com/tarantool/vshard/blob/master/vshard/replicaset.lua#L1358
208+
// based on https://github.com/tarantool/vshard/blob/99ceaee014ea3a67424c2026545838e08d69b90c/vshard/replicaset.lua#L1358
209209
func CalculateEtalonBalance(replicasets []Replicaset, bucketCount uint64) error {
210210
isBalanceFound := false
211211
weightSum := 0.0

0 commit comments

Comments
 (0)