Skip to content

Commit e035244

Browse files
author
maksim.konovalov
committed
Reworked attributes, decoding logic, removed deprecated methods, and added custom decoding support.
In this fix we have deeply reworked many attributes. Interfaces and decoding logic have been redesigned. Some deprecated methods have been removed. Some tests have been moved to a valid location. Decoding now works with custom decoding logic.
1 parent 52f4c34 commit e035244

18 files changed

+551
-848
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
## Unreleased
22

33
CHANGES:
4+
45
* Instance UUID no more required, use instance name instead.
56
* Removed toolchain go1.23.3.
7+
* Refactored GetTyped interface and logic. Now we use raw msg buffer instead raw messages. Interface works and looks
8+
like go-tarantool response.
9+
* ReplicaCall, RouterCallImpl methods was removed cause it works invalid and looks useless.
10+
* All PR, issue references in #XYZ format in commits older than 42f363775dfb9eaf7ec2a6ed7a999847752cec00 refer to https://github.com/KaymeKaydex/go-vshard-router.
11+
* VshardRouterCallMode type renamed to CallMode for simplicity.
12+
* StorageResultTypedFunc type removed as useless type.
13+
* Updated msgpack version from v5.3.5 to v5.4.1.
14+
15+
TESTS:
16+
17+
* Write tests in tests/tnt folder are deprecated.
18+
* Removed empty todo tests from tests/tnt.
19+
* Moved TestReplicasetReplicaCall and Go benches from tests/tnt to tarantool_test.go .
20+
* TestRouterCallProto rewrote.
21+
* Start using constants in tarantool_test.go instead duplicate variables.
622

723
## v1.3.2
824

README.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ import (
9999

100100
"github.com/google/uuid"
101101
"github.com/tarantool/go-tarantool/v2"
102-
"github.com/tarantool/go-tarantool/v2/pool"
103102
)
104103

105104
func main() {
@@ -115,11 +114,11 @@ func main() {
115114
}: {
116115
{
117116
Addr: "127.0.0.1:1001",
118-
UUID: uuid.New(),
117+
Name: "1_1",
119118
},
120119
{
121120
Addr: "127.0.0.1:1002",
122-
UUID: uuid.New(),
121+
Name: "1_2",
123122
},
124123
},
125124
vshardrouter.ReplicasetInfo{
@@ -128,11 +127,11 @@ func main() {
128127
}: {
129128
{
130129
Addr: "127.0.0.1:2001",
131-
UUID: uuid.New(),
130+
Name: "2_1",
132131
},
133132
{
134133
Addr: "127.0.0.1:2002",
135-
UUID: uuid.New(),
134+
Name: "2_2",
136135
},
137136
},
138137
}),
@@ -153,10 +152,10 @@ func main() {
153152

154153
bucketID := vshardrouter.BucketIDStrCRC32(strconv.FormatUint(user.ID, 10), directRouter.RouterBucketCount())
155154

156-
interfaceResult, getTyped, err := directRouter.RouterCallImpl(
155+
resp, err := directRouter.Call(
157156
ctx,
158157
bucketID,
159-
vshardrouter.CallOpts{VshardMode: vshardrouter.ReadMode, PoolMode: pool.PreferRO, Timeout: time.Second * 2},
158+
vshardrouter.CallModeBRO,
160159
"storage.api.get_user_info",
161160
[]interface{}{&struct {
162161
BucketID uint64 `msgpack:"bucket_id" json:"bucket_id,omitempty"`
@@ -166,14 +165,22 @@ func main() {
166165
Body: map[string]interface{}{
167166
"user_id": "123456",
168167
},
169-
}},
168+
}}, vshardrouter.CallOpts{Timeout: time.Second * 2},
170169
)
170+
if err != nil {
171+
panic(err)
172+
}
171173

172174
info := &struct {
173175
BirthDay int
174176
}{}
175177

176-
err = getTyped(&[]interface{}{info})
178+
err = resp.GetTyped(&[]interface{}{info})
179+
if err != nil {
180+
panic(err)
181+
}
182+
183+
interfaceResult, err := resp.Get()
177184
if err != nil {
178185
panic(err)
179186
}

README_ru.md

+93-87
Original file line numberDiff line numberDiff line change
@@ -88,99 +88,105 @@ $ go get -u github.com/tarantool/go-vshard-router
8888
package main
8989

9090
import (
91-
"context"
92-
"fmt"
93-
"strconv"
94-
"time"
91+
"context"
92+
"fmt"
93+
"strconv"
94+
"time"
9595

96-
vshardrouter "github.com/tarantool/go-vshard-router"
97-
"github.com/tarantool/go-vshard-router/providers/static"
96+
vshardrouter "github.com/tarantool/go-vshard-router"
97+
"github.com/tarantool/go-vshard-router/providers/static"
9898

99-
"github.com/google/uuid"
100-
"github.com/tarantool/go-tarantool/v2"
101-
"github.com/tarantool/go-tarantool/v2/pool"
99+
"github.com/google/uuid"
100+
"github.com/tarantool/go-tarantool/v2"
102101
)
103102

104103
func main() {
105-
ctx := context.Background()
106-
107-
directRouter, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
108-
DiscoveryTimeout: time.Minute,
109-
DiscoveryMode: vshardrouter.DiscoveryModeOn,
110-
TopologyProvider: static.NewProvider(map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo{
111-
vshardrouter.ReplicasetInfo{
112-
Name: "replcaset_1",
113-
UUID: uuid.New(),
114-
}: {
115-
{
116-
Addr: "127.0.0.1:1001",
117-
UUID: uuid.New(),
118-
},
119-
{
120-
Addr: "127.0.0.1:1002",
121-
UUID: uuid.New(),
122-
},
123-
},
124-
vshardrouter.ReplicasetInfo{
125-
Name: "replcaset_2",
126-
UUID: uuid.New(),
127-
}: {
128-
{
129-
Addr: "127.0.0.1:2001",
130-
UUID: uuid.New(),
131-
},
132-
{
133-
Addr: "127.0.0.1:2002",
134-
UUID: uuid.New(),
135-
},
136-
},
137-
}),
138-
TotalBucketCount: 128000,
139-
PoolOpts: tarantool.Opts{
140-
Timeout: time.Second,
141-
},
142-
})
143-
if err != nil {
144-
panic(err)
145-
}
146-
147-
user := struct {
148-
ID uint64
149-
}{
150-
ID: 123,
151-
}
152-
153-
bucketID := vshardrouter.BucketIDStrCRC32(strconv.FormatUint(user.ID, 10), directRouter.RouterBucketCount())
154-
155-
interfaceResult, getTyped, err := directRouter.RouterCallImpl(
156-
ctx,
157-
bucketID,
158-
vshardrouter.CallOpts{VshardMode: vshardrouter.ReadMode, PoolMode: pool.PreferRO, Timeout: time.Second * 2},
159-
"storage.api.get_user_info",
160-
[]interface{}{&struct {
161-
BucketID uint64 `msgpack:"bucket_id" json:"bucket_id,omitempty"`
162-
Body map[string]interface{} `msgpack:"body"`
163-
}{
164-
BucketID: bucketID,
165-
Body: map[string]interface{}{
166-
"user_id": "123456",
167-
},
168-
}},
169-
)
170-
171-
info := &struct {
172-
BirthDay int
173-
}{}
174-
175-
err = getTyped(&[]interface{}{info})
176-
if err != nil {
177-
panic(err)
178-
}
179-
180-
fmt.Printf("interface result: %v", interfaceResult)
181-
fmt.Printf("get typed result: %v", info)
104+
ctx := context.Background()
105+
106+
directRouter, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
107+
DiscoveryTimeout: time.Minute,
108+
DiscoveryMode: vshardrouter.DiscoveryModeOn,
109+
TopologyProvider: static.NewProvider(map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo{
110+
vshardrouter.ReplicasetInfo{
111+
Name: "replcaset_1",
112+
UUID: uuid.New(),
113+
}: {
114+
{
115+
Addr: "127.0.0.1:1001",
116+
Name: "1_1",
117+
},
118+
{
119+
Addr: "127.0.0.1:1002",
120+
Name: "1_2",
121+
},
122+
},
123+
vshardrouter.ReplicasetInfo{
124+
Name: "replcaset_2",
125+
UUID: uuid.New(),
126+
}: {
127+
{
128+
Addr: "127.0.0.1:2001",
129+
Name: "2_1",
130+
},
131+
{
132+
Addr: "127.0.0.1:2002",
133+
Name: "2_2",
134+
},
135+
},
136+
}),
137+
TotalBucketCount: 128000,
138+
PoolOpts: tarantool.Opts{
139+
Timeout: time.Second,
140+
},
141+
})
142+
if err != nil {
143+
panic(err)
144+
}
145+
146+
user := struct {
147+
ID uint64
148+
}{
149+
ID: 123,
150+
}
151+
152+
bucketID := vshardrouter.BucketIDStrCRC32(strconv.FormatUint(user.ID, 10), directRouter.RouterBucketCount())
153+
154+
resp, err := directRouter.Call(
155+
ctx,
156+
bucketID,
157+
vshardrouter.CallModeBRO,
158+
"storage.api.get_user_info",
159+
[]interface{}{&struct {
160+
BucketID uint64 `msgpack:"bucket_id" json:"bucket_id,omitempty"`
161+
Body map[string]interface{} `msgpack:"body"`
162+
}{
163+
BucketID: bucketID,
164+
Body: map[string]interface{}{
165+
"user_id": "123456",
166+
},
167+
}}, vshardrouter.CallOpts{Timeout: time.Second * 2},
168+
)
169+
if err != nil {
170+
panic(err)
171+
}
172+
173+
info := &struct {
174+
BirthDay int
175+
}{}
176+
177+
err = resp.GetTyped(&[]interface{}{info})
178+
if err != nil {
179+
panic(err)
180+
}
181+
182+
interfaceResult, err := resp.Get()
183+
if err != nil {
184+
panic(err)
185+
}
186+
187+
fmt.Printf("interface result: %v", interfaceResult)
188+
fmt.Printf("get typed result: %v", info)
182189
}
183-
184190
```
185191

186192
### Провайдеры

0 commit comments

Comments
 (0)