Skip to content

Commit

Permalink
Ignore instance uuid field
Browse files Browse the repository at this point in the history
Instance uuid is no longer required as it does not cause problems with both tarantool 2 and tarantool 3
  • Loading branch information
maksim.konovalov committed Jan 9, 2025
1 parent c7de391 commit 5507cd5
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

CHANGES:
* Instance UUID no more required, use instance name instead.
* Removed toolchain go1.23.3.

## v1.3.2

CHANGES:
Expand Down
2 changes: 2 additions & 0 deletions tests/tnt/cfgmaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ func (c cfgmaker) clusterCfg() map[vshardrouter.ReplicasetInfo][]vshardrouter.In
Name: fmt.Sprintf("replicaset_%d", rsID),
UUID: c.replicasetUUID(rsID),
}] = []vshardrouter.InstanceInfo{{
Name: "inst_1",
Addr: c.masterAddr(rsID),
UUID: c.masterUUID(rsID),
}, {
Name: "inst_2",
Addr: c.followerAddr(rsID),
UUID: c.followerUUID(rsID),
}}
Expand Down
2 changes: 1 addition & 1 deletion tests/tnt/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestTopology(t *testing.T) {
require.Nil(t, err, "AddReplicasets finished successfully")

// remove some random instance
err = router.RemoveInstance(ctx, rsInfo.UUID, insInfo.UUID)
err = router.RemoveInstance(ctx, rsInfo.UUID, insInfo.Name)
require.Nil(t, err, "RemoveInstance finished successfully")

// add it again
Expand Down
10 changes: 5 additions & 5 deletions topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
type TopologyController interface {
AddInstance(ctx context.Context, rsID uuid.UUID, info InstanceInfo) error
RemoveReplicaset(ctx context.Context, rsID uuid.UUID) []error
RemoveInstance(ctx context.Context, rsID, instanceID uuid.UUID) error
RemoveInstance(ctx context.Context, rsID uuid.UUID, instanceName string) error
AddReplicaset(ctx context.Context, rsInfo ReplicasetInfo, instances []InstanceInfo) error
AddReplicasets(ctx context.Context, replicasets map[ReplicasetInfo][]InstanceInfo) error
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func (r *Router) AddInstance(ctx context.Context, rsID uuid.UUID, info InstanceI
}

instance := pool.Instance{
Name: info.UUID.String(),
Name: info.Name,
Dialer: tarantool.NetDialer{
Address: info.Addr,
User: r.cfg.User,
Expand All @@ -72,8 +72,8 @@ func (r *Router) AddInstance(ctx context.Context, rsID uuid.UUID, info InstanceI
return rs.conn.Add(ctx, instance)
}

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)
func (r *Router) RemoveInstance(ctx context.Context, rsID uuid.UUID, instanceName string) error {
r.log().Debugf(ctx, "Trying to remove instance %s from router topology in rs %s", instanceName, rsID)

idToReplicasetRef := r.getIDToReplicaset()

Expand All @@ -82,7 +82,7 @@ func (r *Router) RemoveInstance(ctx context.Context, rsID, instanceID uuid.UUID)
return ErrReplicasetNotExists
}

return rs.conn.Remove(instanceID.String())
return rs.conn.Remove(instanceName)
}

func (r *Router) AddReplicaset(ctx context.Context, rsInfo ReplicasetInfo, instances []InstanceInfo) error {
Expand Down
4 changes: 2 additions & 2 deletions topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestController_AddInstance(t *testing.T) {

err := router.Topology().AddInstance(ctx, uuid.New(), InstanceInfo{
Addr: "127.0.0.1:8060",
UUID: uuid.New(),
Name: "instance_001",
})
require.True(t, errors.Is(err, ErrReplicasetNotExists))
})
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestController_RemoveInstance(t *testing.T) {
},
}

err := router.Topology().RemoveInstance(ctx, uuid.New(), uuid.New())
err := router.Topology().RemoveInstance(ctx, uuid.New(), "")
require.True(t, errors.Is(err, ErrReplicasetNotExists))
})
}
Expand Down
25 changes: 20 additions & 5 deletions vshard.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,37 @@ func (bsi *BucketStatInfo) DecodeMsgpack(d *msgpack.Decoder) error {
return nil
}

// InstanceInfo represents the information about an instance.
// This struct holds the necessary details such as the name, address, and UUID of the instance.
type InstanceInfo struct {
// Name is human-readable id for instance
// Starting with tarantool 3.0, the definition is made into a human-readable name,
// so far it is not used directly inside the library
// Name is a required field for the instance.
// Starting with Tarantool 3.0, this definition is made into a human-readable name,
// and it is now mandatory for use in the library.
// The Name should be a unique identifier for the instance.
Name string

// Addr specifies the address of the instance.
// This can be an IP address or a domain name, depending on how the instance is accessed.
// It is necessary for connecting to the instance or identifying its location.
Addr string

// UUID is an optional field that provides a globally unique identifier (UUID) for the instance.
// While this information is not mandatory, it can be useful for internal management or tracking purposes.
// The UUID ensures that each instance can be identified uniquely, but it is not required for basic operations.
UUID uuid.UUID
}

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

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)
if ii.Name == "" {
return fmt.Errorf("%w: empty name", ErrInvalidInstanceInfo)
}

if ii.Addr == "" {
Expand Down
10 changes: 5 additions & 5 deletions vshard_shadow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ func TestInstanceInfo_Validate(t *testing.T) {
Valid: false,
},
{
Name: "no uuid",
II: vshardrouter.InstanceInfo{Addr: "first.internal:1212"},
Valid: false,
Name: "no uuid - ok",
II: vshardrouter.InstanceInfo{Addr: "first.internal:1212", Name: "instance_123"},
Valid: true,
},
{
Name: "no addr",
II: vshardrouter.InstanceInfo{UUID: uuid.New()},
Valid: false,
},
{
Name: "ok",
Name: "no instance name",
II: vshardrouter.InstanceInfo{UUID: uuid.New(), Addr: "first.internal:1212"},
Valid: true,
Valid: false,
},
}

Expand Down

0 comments on commit 5507cd5

Please sign in to comment.