Skip to content

Commit

Permalink
refac: deprecate vitess/go/maps2 for golang.org/x/exp/maps (#14960)
Browse files Browse the repository at this point in the history
Signed-off-by: Eshaan Aggarwal <[email protected]>
  • Loading branch information
EshaanAgg authored Jan 17, 2024
1 parent 44299cf commit 7a3ce0a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 52 deletions.
37 changes: 0 additions & 37 deletions go/maps2/maps.go

This file was deleted.

5 changes: 3 additions & 2 deletions go/vt/vtctl/workflow/switcher_dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
"strings"
"time"

"vitess.io/vitess/go/maps2"
"golang.org/x/exp/maps"

"vitess.io/vitess/go/mysql/replication"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
Expand Down Expand Up @@ -380,7 +381,7 @@ func (dr *switcherDryRun) resetSequences(ctx context.Context) error {
}

func (dr *switcherDryRun) initializeTargetSequences(ctx context.Context, sequencesByBackingTable map[string]*sequenceMetadata) error {
sortedBackingTableNames := maps2.Keys(sequencesByBackingTable)
sortedBackingTableNames := maps.Keys(sequencesByBackingTable)
slices.Sort(sortedBackingTableNames)
dr.drLog.Log(fmt.Sprintf("The following sequence backing tables used by tables being moved will be initialized: %s",
strings.Join(sortedBackingTableNames, ",")))
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtctl/workflow/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"sync"
"time"

"golang.org/x/exp/maps"
"golang.org/x/sync/errgroup"

"vitess.io/vitess/go/json2"
"vitess.io/vitess/go/maps2"
"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/binlog/binlogplayer"
Expand Down Expand Up @@ -1347,7 +1347,7 @@ func (ts *trafficSwitcher) getTargetSequenceMetadata(ctx context.Context) (map[s
// error if any is seen.
func (ts *trafficSwitcher) findSequenceUsageInKeyspace(vschema *vschemapb.Keyspace) (map[string]*sequenceMetadata, bool, error) {
allFullyQualified := true
targets := maps2.Values(ts.Targets())
targets := maps.Values(ts.Targets())
if len(targets) == 0 || targets[0].GetPrimary() == nil { // This should never happen
return nil, false, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "no primary tablet found for target keyspace %s", ts.targetKeyspace)
}
Expand Down
8 changes: 4 additions & 4 deletions go/vt/vttablet/tabletserver/schema/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

"vitess.io/vitess/go/constants/sidecar"
"vitess.io/vitess/go/maps2"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/config"
"vitess.io/vitess/go/mysql/fakesqldb"
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestGetChangedViewNames(t *testing.T) {
got, err := getChangedViewNames(context.Background(), conn, true)
require.NoError(t, err)
require.Len(t, got, 3)
require.ElementsMatch(t, maps2.Keys(got), []string{"v1", "v2", "lead"})
require.ElementsMatch(t, maps.Keys(got), []string{"v1", "v2", "lead"})
require.NoError(t, db.LastError())

// Not serving primary
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestGetViewDefinition(t *testing.T) {
got, err := collectGetViewDefinitions(conn, bv)
require.NoError(t, err)
require.Len(t, got, 2)
require.ElementsMatch(t, maps2.Keys(got), []string{"v1", "lead"})
require.ElementsMatch(t, maps.Keys(got), []string{"v1", "lead"})
require.Equal(t, "create_view_v1", got["v1"])
require.Equal(t, "create_view_lead", got["lead"])
require.NoError(t, db.LastError())
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestGetMismatchedTableNames(t *testing.T) {
if tc.expectedError != "" {
require.ErrorContains(t, err, tc.expectedError)
} else {
require.ElementsMatch(t, maps2.Keys(mismatchedTableNames), tc.expectedTableNames)
require.ElementsMatch(t, maps.Keys(mismatchedTableNames), tc.expectedTableNames)
require.NoError(t, db.LastError())
}
})
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"net/http"
"strings"
"sync"
"time"

"golang.org/x/exp/maps"

"vitess.io/vitess/go/constants/sidecar"
"vitess.io/vitess/go/maps2"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/config"
"vitess.io/vitess/go/mysql/replication"
Expand Down Expand Up @@ -589,7 +589,7 @@ func (se *Engine) getDroppedTables(curTables map[string]bool, changedViews map[s
}
}

return maps2.Values(dropped)
return maps.Values(dropped)
}

func getTableData(ctx context.Context, conn *connpool.Conn, includeStats bool) (*sqltypes.Result, error) {
Expand Down
5 changes: 3 additions & 2 deletions go/vt/wrangler/switcher_dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
"strings"
"time"

"vitess.io/vitess/go/maps2"
"golang.org/x/exp/maps"

"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/vt/vtctl/workflow"

Expand Down Expand Up @@ -399,7 +400,7 @@ func (dr *switcherDryRun) resetSequences(ctx context.Context) error {
}

func (dr *switcherDryRun) initializeTargetSequences(ctx context.Context, sequencesByBackingTable map[string]*sequenceMetadata) error {
sortedBackingTableNames := maps2.Keys(sequencesByBackingTable)
sortedBackingTableNames := maps.Keys(sequencesByBackingTable)
slices.Sort(sortedBackingTableNames)
dr.drLog.Log(fmt.Sprintf("The following sequence backing tables used by tables being moved will be initialized: %s",
strings.Join(sortedBackingTableNames, ",")))
Expand Down
4 changes: 2 additions & 2 deletions go/vt/wrangler/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"sync"
"time"

"golang.org/x/exp/maps"
"golang.org/x/sync/errgroup"

"vitess.io/vitess/go/mysql/collations"

"vitess.io/vitess/go/json2"
"vitess.io/vitess/go/maps2"
"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/binlog/binlogplayer"
Expand Down Expand Up @@ -2108,7 +2108,7 @@ func (ts *trafficSwitcher) getTargetSequenceMetadata(ctx context.Context) (map[s
// error if any is seen.
func (ts *trafficSwitcher) findSequenceUsageInKeyspace(vschema *vschemapb.Keyspace) (map[string]*sequenceMetadata, bool, error) {
allFullyQualified := true
targets := maps2.Values(ts.Targets())
targets := maps.Values(ts.Targets())
if len(targets) == 0 || targets[0].GetPrimary() == nil { // This should never happen
return nil, false, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "no primary tablet found for target keyspace %s", ts.targetKeyspace)
}
Expand Down

0 comments on commit 7a3ce0a

Please sign in to comment.