Skip to content

Commit

Permalink
v15 tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Sep 30, 2024
1 parent 55a5e35 commit c7c33ac
Show file tree
Hide file tree
Showing 4 changed files with 562 additions and 45,428 deletions.
17 changes: 15 additions & 2 deletions go/vt/topotools/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"context"
"errors"
"fmt"
"maps"

"google.golang.org/protobuf/proto"

Expand All @@ -61,14 +60,28 @@ func ConfigureTabletHook(hk *hook.Hook, tabletAlias *topodatapb.TabletAlias) {
hk.ExtraEnv["TABLET_ALIAS"] = topoproto.TabletAliasString(tabletAlias)
}

// isMapsEqual simulates maps.Equal() from go1.23+.
func isMapsEqual(a, b map[string]string) bool {
if len(a) != len(b) {
return false
}
for key, valA := range a {
valB, ok := b[key]
if !ok || valB != valA {
return false
}
}
return true
}

// ChangeTags changes the tags of the tablet. Make this external, since these
// transitions need to be forced from time to time.
//
// If successful, the updated tablet record is returned.
func ChangeTags(ctx context.Context, ts *topo.Server, tabletAlias *topodatapb.TabletAlias, tabletTags map[string]string, replace bool) (map[string]string, error) {
var result map[string]string
_, err := ts.UpdateTabletFields(ctx, tabletAlias, func(tablet *topodatapb.Tablet) error {
if replace && maps.Equal(tablet.Tags, tabletTags) {
if replace && isMapsEqual(tablet.Tags, tabletTags) {
result = tablet.Tags
return topo.NewError(topo.NoUpdateNeeded, topoproto.TabletAliasString(tabletAlias))
}
Expand Down
9 changes: 4 additions & 5 deletions go/vt/vtctl/grpcvtctldserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vtctl/grpcvtctldserver/testutil"
"vitess.io/vitess/go/vt/vtctl/localvtctldclient"
"vitess.io/vitess/go/vt/vtenv"
"vitess.io/vitess/go/vt/vttablet/tmclient"
"vitess.io/vitess/go/vt/vttablet/tmclienttest"

Expand Down Expand Up @@ -1152,11 +1151,11 @@ func TestChangeTabletTags(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ts := memorytopo.NewServer(ctx, tt.cells...)
ts := memorytopo.NewServer(tt.cells...)

Check failure on line 1154 in go/vt/vtctl/grpcvtctldserver/server_test.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

loopclosure: loop variable tt captured by func literal (govet)

Check failure on line 1154 in go/vt/vtctl/grpcvtctldserver/server_test.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

loopclosure: loop variable tt captured by func literal (govet)
vtctld := testutil.NewVtctldServerWithTabletManagerClient(t, ts, &testutil.TabletManagerClient{
TopoServer: ts,
}, func(ts *topo.Server) vtctlservicepb.VtctldServer {
return NewVtctldServer(vtenv.NewTestEnv(), ts)
return NewVtctldServer(ts)
})

testutil.AddTablets(ctx, t, ts, &testutil.AddTabletOptions{
Expand All @@ -1182,11 +1181,11 @@ func TestChangeTabletTags(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ts := memorytopo.NewServer(ctx, "zone1")
ts := memorytopo.NewServer("zone1")
vtctld := testutil.NewVtctldServerWithTabletManagerClient(t, ts, &testutil.TabletManagerClient{
TopoServer: nil,
}, func(ts *topo.Server) vtctlservicepb.VtctldServer {
return NewVtctldServer(vtenv.NewTestEnv(), ts)
return NewVtctldServer(ts)
})

testutil.AddTablet(ctx, t, ts, &topodatapb.Tablet{
Expand Down
Loading

0 comments on commit c7c33ac

Please sign in to comment.