Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve efficiency of vtorc topo calls #17071

Merged
merged 12 commits into from
Nov 6, 2024
Prev Previous commit
Next Next commit
moved sort to test only
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Nov 5, 2024
commit 148b192b51650c84dbf12f424a2716c0525a3ee1
5 changes: 0 additions & 5 deletions go/vt/topo/tablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ limitations under the License.
package topo

import (
"cmp"
"context"
"fmt"
"path"
"slices"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -289,9 +287,6 @@ func (ts *Server) GetTabletsByCell(ctx context.Context, cellAlias string, opt *G
}
tablets = append(tablets, &TabletInfo{Tablet: tablet, version: listResults[n].Version})
}
slices.SortFunc(tablets, func(i, j *TabletInfo) int {
return cmp.Compare(i.Alias.Uid, j.Alias.Uid)
})
return tablets, nil
}

Expand Down
6 changes: 6 additions & 0 deletions go/vt/topo/tablet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ limitations under the License.
package topo_test

import (
"cmp"
"context"
"errors"
"slices"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -374,6 +376,10 @@ func TestServerGetTabletsByCell(t *testing.T) {
require.NoError(t, err)
require.Len(t, out, len(tt.expectedTablets))

slices.SortFunc(out, func(i, j *topo.TabletInfo) int {
return cmp.Compare(i.Alias.Uid, j.Alias.Uid)
})

for i, tablet := range out {
expected := tt.expectedTablets[i]
require.Equal(t, expected.Alias.String(), tablet.Alias.String())
Expand Down
Loading