Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked attributes, decoding logic, removed deprecated methods, and added custom decoding support. #25

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
## Unreleased

CHANGES:

KaymeKaydex marked this conversation as resolved.
Show resolved Hide resolved
* 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
Loading