From 6e5bd6e899dc140bec37e92aea7a5538cb6c5154 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Thu, 7 Dec 2023 10:58:34 -0500 Subject: [PATCH] go/vt/topo: fix nilness issues and unused variables (#14709) --- go/vt/topo/srv_keyspace.go | 14 ++++++-------- go/vt/topo/tablet.go | 19 +++++++++---------- go/vt/topo/test/trylock.go | 2 +- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/go/vt/topo/srv_keyspace.go b/go/vt/topo/srv_keyspace.go index 8054764eeff..11e49f3c569 100644 --- a/go/vt/topo/srv_keyspace.go +++ b/go/vt/topo/srv_keyspace.go @@ -137,7 +137,7 @@ func (ts *Server) GetShardServingCells(ctx context.Context, si *ShardInfo) (serv var mu sync.Mutex for _, cell := range cells { wg.Add(1) - go func(cell, keyspace string) { + go func(cell string) { defer wg.Done() srvKeyspace, err := ts.GetSrvKeyspace(ctx, cell, si.keyspace) switch { @@ -166,7 +166,7 @@ func (ts *Server) GetShardServingCells(ctx context.Context, si *ShardInfo) (serv rec.RecordError(err) return } - }(cell, si.Keyspace()) + }(cell) } wg.Wait() if rec.HasErrors() { @@ -188,7 +188,7 @@ func (ts *Server) GetShardServingTypes(ctx context.Context, si *ShardInfo) (serv var mu sync.Mutex for _, cell := range cells { wg.Add(1) - go func(cell, keyspace string) { + go func(cell string) { defer wg.Done() srvKeyspace, err := ts.GetSrvKeyspace(ctx, cell, si.keyspace) switch { @@ -223,7 +223,7 @@ func (ts *Server) GetShardServingTypes(ctx context.Context, si *ShardInfo) (serv rec.RecordError(err) return } - }(cell, si.Keyspace()) + }(cell) } wg.Wait() if rec.HasErrors() { @@ -613,10 +613,8 @@ func (ts *Server) MigrateServedType(ctx context.Context, keyspace string, shards case IsErrType(err, NoNode): // Assuming this cell is not active, nothing to do. default: - if err != nil { - rec.RecordError(err) - return - } + rec.RecordError(err) + return } }(cell, keyspace) } diff --git a/go/vt/topo/tablet.go b/go/vt/topo/tablet.go index d17235f6948..5254252db1c 100644 --- a/go/vt/topo/tablet.go +++ b/go/vt/topo/tablet.go @@ -443,21 +443,20 @@ func (ts *Server) CreateTablet(ctx context.Context, tablet *topodatapb.Tablet) e return err } tabletPath := path.Join(TabletsPath, topoproto.TabletAliasString(tablet.Alias), TabletFile) - if _, err = conn.Create(ctx, tabletPath, data); err != nil { + if _, err := conn.Create(ctx, tabletPath, data); err != nil { return err } - if updateErr := UpdateTabletReplicationData(ctx, ts, tablet); updateErr != nil { - return updateErr + if err := UpdateTabletReplicationData(ctx, ts, tablet); err != nil { + return err } - if err == nil { - event.Dispatch(&events.TabletChange{ - Tablet: tablet, - Status: "created", - }) - } - return err + event.Dispatch(&events.TabletChange{ + Tablet: tablet, + Status: "created", + }) + + return nil } // DeleteTablet wraps the underlying conn.Delete diff --git a/go/vt/topo/test/trylock.go b/go/vt/topo/test/trylock.go index 4519d1bcaab..c553e74bb61 100644 --- a/go/vt/topo/test/trylock.go +++ b/go/vt/topo/test/trylock.go @@ -138,7 +138,7 @@ func checkTryLockTimeout(ctx context.Context, t *testing.T, conn topo.Conn) { // test we can't unlock again if err := lockDescriptor.Unlock(ctx); err == nil { - require.Fail(t, "Unlock failed", err.Error()) + require.Fail(t, "Unlock succeeded but should not have") } }