Skip to content

Commit

Permalink
api: remove RouterMapCallRWImpl method (resolve #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
nurzhan-saktaganov committed Jan 13, 2025
1 parent a284589 commit a38d1e7
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CHANGES:
* 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.
* ReplicaCall, RouterCallImpl, RouterMapCallRWImpl 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.
Expand Down
15 changes: 0 additions & 15 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,21 +539,6 @@ func (r *storageRefResponseProto) DecodeMsgpack(d *msgpack.Decoder) error {
return nil
}

// RouterMapCallRWImpl perform call function on all masters in the cluster
// with a guarantee that in case of success it was executed with all
// buckets being accessible for reads and writes.
// Deprecated: RouterMapCallRWImpl is deprecated.
// Use more general RouterMapCallRW instead.
func (r *Router) RouterMapCallRWImpl(
ctx context.Context,
fnc string,
args interface{},
opts CallOpts,
) (map[string]interface{}, error) {
// nolint:gosimple
return RouterMapCallRW[interface{}](r, ctx, fnc, args, RouterMapCallRWOptions{Timeout: opts.Timeout})
}

type replicasetFuture struct {
// replicaset name
name string
Expand Down
23 changes: 11 additions & 12 deletions tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func BenchmarkCallSimpleSelect_GO_Call(b *testing.B) {
b.ReportAllocs()
}

func TestRouter_RouterMapCallRWImpl(t *testing.T) {
func TestRouter_RouterMapCallRW(t *testing.T) {
t.Parallel()

ctx := context.Background()
Expand All @@ -485,16 +485,16 @@ func TestRouter_RouterMapCallRWImpl(t *testing.T) {
err = router.ClusterBootstrap(ctx, false)
require.NoError(t, err)

callOpts := vshardrouter.CallOpts{}
callOpts := vshardrouter.RouterMapCallRWOptions{}

const arg = "arg1"

// Enusre that RouterMapCallRWImpl works at all
echoArgs := []interface{}{arg}
resp, err := router.RouterMapCallRWImpl(ctx, "echo", echoArgs, callOpts)
respStr, err := vshardrouter.RouterMapCallRW[string](router, ctx, "echo", echoArgs, callOpts)
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err")

for k, v := range resp {
for k, v := range respStr {
require.Equalf(t, arg, v, "RouterMapCallRWImpl value ok for %v", k)
}

Expand All @@ -507,16 +507,16 @@ func TestRouter_RouterMapCallRWImpl(t *testing.T) {

// RouterMapCallRWImpl returns only one value
echoArgs = []interface{}{arg, "arg2"}
resp, err = router.RouterMapCallRWImpl(ctx, "echo", echoArgs, callOpts)
respStr, err = vshardrouter.RouterMapCallRW[string](router, ctx, "echo", echoArgs, callOpts)
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err")

for k, v := range resp {
for k, v := range respStr {
require.Equalf(t, arg, v, "RouterMapCallRWImpl value ok for %v", k)
}

// RouterMapCallRWImpl returns nil when no return value
noArgs := []interface{}{}
resp, err = router.RouterMapCallRWImpl(ctx, "echo", noArgs, callOpts)
resp, err := vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", noArgs, callOpts)
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err")

for k, v := range resp {
Expand All @@ -528,7 +528,7 @@ func TestRouter_RouterMapCallRWImpl(t *testing.T) {
sleepArgs := []interface{}{sleepToSec}

start := time.Now()
_, err = router.RouterMapCallRWImpl(ctx, "sleep", sleepArgs, vshardrouter.CallOpts{
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "sleep", sleepArgs, vshardrouter.RouterMapCallRWOptions{
Timeout: 2 * time.Second, // because default timeout is 0.5 sec
})
duration := time.Since(start)
Expand All @@ -538,21 +538,20 @@ func TestRouter_RouterMapCallRWImpl(t *testing.T) {
require.Less(t, duration, 1200*time.Millisecond, "Requests were send concurrently")

// RouterMapCallRWImpl returns err on raise_luajit_error
_, err = router.RouterMapCallRWImpl(ctx, "raise_luajit_error", noArgs, callOpts)
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "raise_luajit_error", noArgs, callOpts)
require.NotNil(t, err, "RouterMapCallRWImpl raise_luajit_error finished with error")

// RouterMapCallRWImpl invalid usage
_, err = router.RouterMapCallRWImpl(ctx, "echo", nil, callOpts)
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", nil, callOpts)
require.NotNil(t, err, "RouterMapCallRWImpl with nil args finished with error")

// Ensure that RouterMapCallRWImpl doesn't work when it mean't to
for rsInfo := range topology {
errs := router.RemoveReplicaset(ctx, rsInfo.Name)
require.Emptyf(t, errs, "%s successfully removed from router", rsInfo.Name)

break
}

_, err = router.RouterMapCallRWImpl(ctx, "echo", echoArgs, callOpts)
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", echoArgs, callOpts)
require.NotNilf(t, err, "RouterMapCallRWImpl failed on not full cluster")
}
2 changes: 1 addition & 1 deletion tests/tnt/concurrent_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestConncurrentTopologyChange(t *testing.T) {
}

args := []interface{}{"arg1"}
_, _ = router.RouterMapCallRWImpl(ctx, "echo", args, vshardrouter.CallOpts{})
_, _ = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", args, vshardrouter.RouterMapCallRWOptions{})
}
}()

Expand Down
102 changes: 102 additions & 0 deletions tests/tnt/routermap_call_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package tnt

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"
vshardrouter "github.com/tarantool/go-vshard-router"
"github.com/tarantool/go-vshard-router/providers/static"
)

func TestRouterMapCall(t *testing.T) {
skipOnInvalidRun(t)

t.Parallel()

ctx := context.Background()

cfg := getCfg()

router, err := vshardrouter.NewRouter(ctx, vshardrouter.Config{
TopologyProvider: static.NewProvider(cfg),
DiscoveryTimeout: 5 * time.Second,
DiscoveryMode: vshardrouter.DiscoveryModeOn,
TotalBucketCount: totalBucketCount,
User: defaultTntUser,
Password: defaultTntPassword,
})

require.Nil(t, err, "NewRouter finished successfully")

callOpts := vshardrouter.RouterMapCallRWOptions{}

const arg = "arg1"

// Enusre that RouterMapCallRWImpl works at all
echoArgs := []interface{}{arg}
respStr, err := vshardrouter.RouterMapCallRW[string](router, ctx, "echo", echoArgs, callOpts)
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err")

for k, v := range respStr {
require.Equalf(t, arg, v, "RouterMapCallRWImpl value ok for %v", k)
}

echoArgs = []interface{}{1}
respInt, err := vshardrouter.RouterMapCallRW[int](router, ctx, "echo", echoArgs, vshardrouter.RouterMapCallRWOptions{})
require.NoError(t, err, "RouterMapCallRW[int] echo finished with no err")
for k, v := range respInt {
require.Equalf(t, 1, v, "RouterMapCallRW[int] value ok for %v", k)
}

// RouterMapCallRWImpl returns only one value
echoArgs = []interface{}{arg, "arg2"}
respStr, err = vshardrouter.RouterMapCallRW[string](router, ctx, "echo", echoArgs, callOpts)
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err")

for k, v := range respStr {
require.Equalf(t, arg, v, "RouterMapCallRWImpl value ok for %v", k)
}

// RouterMapCallRWImpl returns nil when no return value
noArgs := []interface{}{}
resp, err := vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", noArgs, callOpts)
require.NoError(t, err, "RouterMapCallRWImpl echo finished with no err")

for k, v := range resp {
require.Equalf(t, nil, v, "RouterMapCallRWImpl value ok for %v", k)
}

// Ensure that RouterMapCallRWImpl sends requests concurrently
const sleepToSec int = 1
sleepArgs := []interface{}{sleepToSec}

start := time.Now()
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "sleep", sleepArgs, vshardrouter.RouterMapCallRWOptions{
Timeout: 2 * time.Second, // because default timeout is 0.5 sec
})
duration := time.Since(start)

require.NoError(t, err, "RouterMapCallRWImpl sleep finished with no err")
require.Greater(t, len(cfg), 1, "There are more than one replicasets")
require.Less(t, duration, 1200*time.Millisecond, "Requests were send concurrently")

// RouterMapCallRWImpl returns err on raise_luajit_error
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "raise_luajit_error", noArgs, callOpts)
require.NotNil(t, err, "RouterMapCallRWImpl raise_luajit_error finished with error")

// RouterMapCallRWImpl invalid usage
_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", nil, callOpts)
require.NotNil(t, err, "RouterMapCallRWImpl with nil args finished with error")

// Ensure that RouterMapCallRWImpl doesn't work when it mean't to
for k := range cfg {
errs := router.RemoveReplicaset(ctx, k.UUID)

Check failure on line 95 in tests/tnt/routermap_call_test.go

View workflow job for this annotation

GitHub Actions / all-tests (1.22, 2.8)

cannot use k.UUID (variable of type uuid.UUID) as string value in argument to router.RemoveReplicaset

Check failure on line 95 in tests/tnt/routermap_call_test.go

View workflow job for this annotation

GitHub Actions / all-tests (1.22, 2.10)

cannot use k.UUID (variable of type uuid.UUID) as string value in argument to router.RemoveReplicaset

Check failure on line 95 in tests/tnt/routermap_call_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

cannot use k.UUID (variable of type uuid.UUID) as string value in argument to router.RemoveReplicaset (typecheck)

Check failure on line 95 in tests/tnt/routermap_call_test.go

View workflow job for this annotation

GitHub Actions / all-tests (1.22, master)

cannot use k.UUID (variable of type uuid.UUID) as string value in argument to router.RemoveReplicaset

Check failure on line 95 in tests/tnt/routermap_call_test.go

View workflow job for this annotation

GitHub Actions / all-tests (stable, 2.8)

cannot use k.UUID (variable of type uuid.UUID) as string value in argument to router.RemoveReplicaset

Check failure on line 95 in tests/tnt/routermap_call_test.go

View workflow job for this annotation

GitHub Actions / all-tests (stable, 2.10)

cannot use k.UUID (variable of type uuid.UUID) as string value in argument to router.RemoveReplicaset

Check failure on line 95 in tests/tnt/routermap_call_test.go

View workflow job for this annotation

GitHub Actions / all-tests (stable, master)

cannot use k.UUID (variable of type uuid.UUID) as string value in argument to router.RemoveReplicaset
require.Emptyf(t, errs, "%s successfully removed from router", k.UUID)
break
}

_, err = vshardrouter.RouterMapCallRW[interface{}](router, ctx, "echo", echoArgs, callOpts)
require.NotNilf(t, err, "RouterMapCallRWImpl failed on not full cluster")
}

0 comments on commit a38d1e7

Please sign in to comment.