Skip to content

Commit

Permalink
Reworked attributes, decoding logic, removed deprecated methods, and …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
maksim.konovalov committed Jan 11, 2025
1 parent 52f4c34 commit f2d3654
Show file tree
Hide file tree
Showing 18 changed files with 554 additions and 851 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
## Unreleased

CHANGES:

* Instance UUID no more required, use instance name instead.
* Removed toolchain go1.23.3.
* Refactored GetTyped interface and logic. Now we use raw msg buffer instead raw messages. Interface works and looks
like go-tarantool response.
* ReplicaCall, RouterCallImpl methods was removed cause it works invalid and looks useless.
* All PR, issue references in #XYZ format in commits older than 42f363775dfb9eaf7ec2a6ed7a999847752cec00 refer to https://github.com/KaymeKaydex/go-vshard-router.
* VshardRouterCallMode type renamed to CallMode for simplicity.
* StorageResultTypedFunc type removed as useless type.
* Updated msgpack version from v5.3.5 to v5.4.1.

TESTS:

* Write tests in tests/tnt folder are deprecated.
* Removed empty todo tests from tests/tnt.
* Moved TestReplicasetReplicaCall and Go benches from tests/tnt to tarantool_test.go .
* TestRouterCallProto rewrote.
* Start using constants in tarantool_test.go instead duplicate variables.

## v1.3.2

Expand Down
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ import (

"github.com/google/uuid"
"github.com/tarantool/go-tarantool/v2"
"github.com/tarantool/go-tarantool/v2/pool"
)

func main() {
Expand All @@ -115,11 +114,11 @@ func main() {
}: {
{
Addr: "127.0.0.1:1001",
UUID: uuid.New(),
Name: "1_1",
},
{
Addr: "127.0.0.1:1002",
UUID: uuid.New(),
Name: "1_2",
},
},
vshardrouter.ReplicasetInfo{
Expand All @@ -128,11 +127,11 @@ func main() {
}: {
{
Addr: "127.0.0.1:2001",
UUID: uuid.New(),
Name: "2_1",
},
{
Addr: "127.0.0.1:2002",
UUID: uuid.New(),
Name: "2_2",
},
},
}),
Expand All @@ -153,10 +152,10 @@ func main() {

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

interfaceResult, getTyped, err := directRouter.RouterCallImpl(
resp, err := directRouter.Call(
ctx,
bucketID,
vshardrouter.CallOpts{VshardMode: vshardrouter.ReadMode, PoolMode: pool.PreferRO, Timeout: time.Second * 2},
vshardrouter.CallModeBRO,
"storage.api.get_user_info",
[]interface{}{&struct {
BucketID uint64 `msgpack:"bucket_id" json:"bucket_id,omitempty"`
Expand All @@ -166,14 +165,22 @@ func main() {
Body: map[string]interface{}{
"user_id": "123456",
},
}},
}}, vshardrouter.CallOpts{Timeout: time.Second * 2},
)
if err != nil {
panic(err)
}

info := &struct {
BirthDay int
}{}

err = getTyped(&[]interface{}{info})
err = resp.GetTyped(&[]interface{}{info})
if err != nil {
panic(err)
}

interfaceResult, err := resp.Get()
if err != nil {
panic(err)
}
Expand Down
180 changes: 93 additions & 87 deletions README_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,99 +88,105 @@ $ go get -u github.com/tarantool/go-vshard-router
package main

import (
"context"
"fmt"
"strconv"
"time"
"context"
"fmt"
"strconv"
"time"

vshardrouter "github.com/tarantool/go-vshard-router"
"github.com/tarantool/go-vshard-router/providers/static"
vshardrouter "github.com/tarantool/go-vshard-router"
"github.com/tarantool/go-vshard-router/providers/static"

"github.com/google/uuid"
"github.com/tarantool/go-tarantool/v2"
"github.com/tarantool/go-tarantool/v2/pool"
"github.com/google/uuid"
"github.com/tarantool/go-tarantool/v2"
)

func main() {
ctx := context.Background()

directRouter, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
DiscoveryTimeout: time.Minute,
DiscoveryMode: vshardrouter.DiscoveryModeOn,
TopologyProvider: static.NewProvider(map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo{
vshardrouter.ReplicasetInfo{
Name: "replcaset_1",
UUID: uuid.New(),
}: {
{
Addr: "127.0.0.1:1001",
UUID: uuid.New(),
},
{
Addr: "127.0.0.1:1002",
UUID: uuid.New(),
},
},
vshardrouter.ReplicasetInfo{
Name: "replcaset_2",
UUID: uuid.New(),
}: {
{
Addr: "127.0.0.1:2001",
UUID: uuid.New(),
},
{
Addr: "127.0.0.1:2002",
UUID: uuid.New(),
},
},
}),
TotalBucketCount: 128000,
PoolOpts: tarantool.Opts{
Timeout: time.Second,
},
})
if err != nil {
panic(err)
}

user := struct {
ID uint64
}{
ID: 123,
}

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

interfaceResult, getTyped, err := directRouter.RouterCallImpl(
ctx,
bucketID,
vshardrouter.CallOpts{VshardMode: vshardrouter.ReadMode, PoolMode: pool.PreferRO, Timeout: time.Second * 2},
"storage.api.get_user_info",
[]interface{}{&struct {
BucketID uint64 `msgpack:"bucket_id" json:"bucket_id,omitempty"`
Body map[string]interface{} `msgpack:"body"`
}{
BucketID: bucketID,
Body: map[string]interface{}{
"user_id": "123456",
},
}},
)

info := &struct {
BirthDay int
}{}

err = getTyped(&[]interface{}{info})
if err != nil {
panic(err)
}

fmt.Printf("interface result: %v", interfaceResult)
fmt.Printf("get typed result: %v", info)
ctx := context.Background()

directRouter, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
DiscoveryTimeout: time.Minute,
DiscoveryMode: vshardrouter.DiscoveryModeOn,
TopologyProvider: static.NewProvider(map[vshardrouter.ReplicasetInfo][]vshardrouter.InstanceInfo{
vshardrouter.ReplicasetInfo{
Name: "replcaset_1",
UUID: uuid.New(),
}: {
{
Addr: "127.0.0.1:1001",
Name: "1_1",
},
{
Addr: "127.0.0.1:1002",
Name: "1_2",
},
},
vshardrouter.ReplicasetInfo{
Name: "replcaset_2",
UUID: uuid.New(),
}: {
{
Addr: "127.0.0.1:2001",
Name: "2_1",
},
{
Addr: "127.0.0.1:2002",
Name: "2_2",
},
},
}),
TotalBucketCount: 128000,
PoolOpts: tarantool.Opts{
Timeout: time.Second,
},
})
if err != nil {
panic(err)
}

user := struct {
ID uint64
}{
ID: 123,
}

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

resp, err := directRouter.Call(
ctx,
bucketID,
vshardrouter.CallModeBRO,
"storage.api.get_user_info",
[]interface{}{&struct {
BucketID uint64 `msgpack:"bucket_id" json:"bucket_id,omitempty"`
Body map[string]interface{} `msgpack:"body"`
}{
BucketID: bucketID,
Body: map[string]interface{}{
"user_id": "123456",
},
}}, vshardrouter.CallOpts{Timeout: time.Second * 2},
)
if err != nil {
panic(err)
}

info := &struct {
BirthDay int
}{}

err = resp.GetTyped(&[]interface{}{info})
if err != nil {
panic(err)
}

interfaceResult, err := resp.Get()
if err != nil {
panic(err)
}

fmt.Printf("interface result: %v", interfaceResult)
fmt.Printf("get typed result: %v", info)
}

```

### Провайдеры
Expand Down
Loading

0 comments on commit f2d3654

Please sign in to comment.