Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
add logs about replicaset Topology changes (#89)
Browse files Browse the repository at this point in the history
* add logs about replicaset Topology changes

* add empty loggers for unit testing routers

* fixed changelogs

---------

Co-authored-by: Maksim Konovalov <[email protected]>
  • Loading branch information
KaymeKaydex and Maksim Konovalov authored Sep 28, 2024
1 parent b086a19 commit a5344ac
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 7 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ BUG FIXES:

TESTS:

* Simplify test/tnt/{Makefile,router.lua)
* Indent fix for test/tnt/storage.lua
* Simplify test/tnt/{Makefile,router.lua).
* Indent fix for test/tnt/storage.lua.

FEATURES:
* now we write topology changes to debug logs.
* now we write info logs about new replicaset adding and nodes state.

## v1.0.1

Expand Down
2 changes: 1 addition & 1 deletion examples/customer/go-service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/uuid v1.6.0
github.com/spf13/viper v1.18.2
github.com/swaggo/swag v1.16.3
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240507091106-8b2be0133e9d
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240922082035-592db69eed86
)

require (
Expand Down
1 change: 1 addition & 0 deletions examples/customer/go-service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ github.com/tarantool/go-iproto v1.0.0 h1:quC4hdFhCuFYaCqOFgUxH2foRkhAy+TlEy7gQLh
github.com/tarantool/go-iproto v1.0.0/go.mod h1:LNCtdyZxojUed8SbOiYHoc3v9NvaZTB7p96hUySMlIo=
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240507091106-8b2be0133e9d h1:L8E9ZtHsGYACsBGU6EtN3fEhLeneVnQ5KwxEeZQk6rk=
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240507091106-8b2be0133e9d/go.mod h1:hjm1qFxll+hs9VoU74MrvwKrXZKv8WGQLhkyeDTHh7Y=
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240922082035-592db69eed86/go.mod h1:hjm1qFxll+hs9VoU74MrvwKrXZKv8WGQLhkyeDTHh7Y=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/snksoft/crc v1.1.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240507091106-8b2be0133e9d
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240922082035-592db69eed86
github.com/vmihailenco/msgpack/v5 v5.3.5
go.etcd.io/etcd/client/v2 v2.305.10
golang.org/x/sync v0.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ github.com/tarantool/go-iproto v1.0.0 h1:quC4hdFhCuFYaCqOFgUxH2foRkhAy+TlEy7gQLh
github.com/tarantool/go-iproto v1.0.0/go.mod h1:LNCtdyZxojUed8SbOiYHoc3v9NvaZTB7p96hUySMlIo=
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240507091106-8b2be0133e9d h1:L8E9ZtHsGYACsBGU6EtN3fEhLeneVnQ5KwxEeZQk6rk=
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240507091106-8b2be0133e9d/go.mod h1:hjm1qFxll+hs9VoU74MrvwKrXZKv8WGQLhkyeDTHh7Y=
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240922082035-592db69eed86 h1:2okp3EGd44Bb9+bFhvs75NgXPkIdXPbHhZi1vwBhMHo=
github.com/tarantool/go-tarantool/v2 v2.1.1-0.20240922082035-592db69eed86/go.mod h1:hjm1qFxll+hs9VoU74MrvwKrXZKv8WGQLhkyeDTHh7Y=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
Expand Down
2 changes: 1 addition & 1 deletion providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
_ LogProvider = (*StdoutLogger)(nil)
)

// A legacy interface for backward compatibility
// LogProvider is a legacy interface for backward compatibility.
type LogProvider interface {
Info(context.Context, string)
Debug(context.Context, string)
Expand Down
22 changes: 20 additions & 2 deletions topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func (r *Router) Topology() TopologyController {
}

func (r *Router) AddInstance(ctx context.Context, rsID uuid.UUID, info InstanceInfo) error {
r.log().Debugf(ctx, "trying to add instance %s to router topology in rs %s", info, rsID)

err := info.Validate()
if err != nil {
return err
Expand All @@ -69,7 +71,9 @@ func (r *Router) AddInstance(ctx context.Context, rsID uuid.UUID, info InstanceI
return rs.conn.Add(ctx, instance)
}

func (r *Router) RemoveInstance(_ context.Context, rsID, instanceID uuid.UUID) error {
func (r *Router) RemoveInstance(ctx context.Context, rsID, instanceID uuid.UUID) error {
r.log().Debugf(ctx, "trying to remove instance %s from router topology in rs %s", instanceID, rsID)

idToReplicasetRef := r.getIDToReplicaset()

rs := idToReplicasetRef[rsID]
Expand All @@ -81,6 +85,8 @@ func (r *Router) RemoveInstance(_ context.Context, rsID, instanceID uuid.UUID) e
}

func (r *Router) AddReplicaset(ctx context.Context, rsInfo ReplicasetInfo, instances []InstanceInfo) error {
r.log().Debugf(ctx, "trying to add replicaset %s to router topology", rsInfo)

idToReplicasetOld := r.getIDToReplicaset()

if _, ok := idToReplicasetOld[rsInfo.UUID]; ok {
Expand Down Expand Up @@ -112,6 +118,16 @@ func (r *Router) AddReplicaset(ctx context.Context, rsInfo ReplicasetInfo, insta
return err
}

poolInfo := conn.GetInfo()
for instName, instConnInfo := range poolInfo {
connectStatus := "connected now"
if !instConnInfo.ConnectedNow {
connectStatus = "not connected"
}

r.log().Infof(ctx, "[replicaset %s ] instance %s %s in role %s", rsInfo, instName, connectStatus, instConnInfo.ConnRole)
}

isConnected, err := conn.ConnectedNow(pool.RW)
if err != nil {
return fmt.Errorf("cant check rs pool conntected rw now with error: %s", err)
Expand Down Expand Up @@ -154,7 +170,9 @@ func (r *Router) AddReplicasets(ctx context.Context, replicasets map[ReplicasetI
return nil
}

func (r *Router) RemoveReplicaset(_ context.Context, rsID uuid.UUID) []error {
func (r *Router) RemoveReplicaset(ctx context.Context, rsID uuid.UUID) []error {
r.log().Debugf(ctx, "trying to remove replicaset %s from router topology", rsID)

idToReplicasetOld := r.getIDToReplicaset()

rs := idToReplicasetOld[rsID]
Expand Down
15 changes: 15 additions & 0 deletions topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func TestController_AddInstance(t *testing.T) {
t.Run("no such replicaset", func(t *testing.T) {
router := Router{
idToReplicaset: map[uuid.UUID]*Replicaset{},
cfg: Config{
Loggerf: &emptyLogger{},
},
}

err := router.Topology().AddInstance(ctx, uuid.New(), InstanceInfo{
Expand All @@ -34,6 +37,9 @@ func TestController_AddInstance(t *testing.T) {
t.Run("invalid instance info", func(t *testing.T) {
router := Router{
idToReplicaset: map[uuid.UUID]*Replicaset{},
cfg: Config{
Loggerf: &emptyLogger{},
},
}

err := router.Topology().AddInstance(ctx, uuid.New(), InstanceInfo{})
Expand All @@ -47,6 +53,9 @@ func TestController_RemoveInstance(t *testing.T) {
t.Run("no such replicaset", func(t *testing.T) {
router := Router{
idToReplicaset: map[uuid.UUID]*Replicaset{},
cfg: Config{
Loggerf: &emptyLogger{},
},
}

err := router.Topology().RemoveInstance(ctx, uuid.New(), uuid.New())
Expand All @@ -65,6 +74,9 @@ func TestController_RemoveReplicaset(t *testing.T) {
idToReplicaset: map[uuid.UUID]*Replicaset{
uuidToRemove: {conn: mPool},
},
cfg: Config{
Loggerf: &emptyLogger{},
},
}

t.Run("no such replicaset", func(t *testing.T) {
Expand All @@ -88,6 +100,9 @@ func TestRouter_AddReplicaset_AlreadyExists(t *testing.T) {
idToReplicaset: map[uuid.UUID]*Replicaset{
alreadyExistingRsUUID: {},
},
cfg: Config{
Loggerf: &emptyLogger{},
},
}

// Test that such replicaset already exists
Expand Down
4 changes: 4 additions & 0 deletions vshard.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ type InstanceInfo struct {
UUID uuid.UUID
}

func (ii InstanceInfo) String() string {
return fmt.Sprintf("{name: %s, uuid: %s, addr: %s}", ii.Name, ii.UUID, ii.Addr)
}

func (ii InstanceInfo) Validate() error {
if ii.UUID == uuid.Nil {
return fmt.Errorf("%w: empty uuid", ErrInvalidInstanceInfo)
Expand Down

0 comments on commit a5344ac

Please sign in to comment.