From 7a3ce0ad250241317e31745c40c8a061aa60638a Mon Sep 17 00:00:00 2001 From: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:35:41 +0530 Subject: [PATCH] refac: deprecate `vitess/go/maps2` for `golang.org/x/exp/maps` (#14960) Signed-off-by: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com> --- go/maps2/maps.go | 37 ------------------- go/vt/vtctl/workflow/switcher_dry_run.go | 5 ++- go/vt/vtctl/workflow/traffic_switcher.go | 4 +- go/vt/vttablet/tabletserver/schema/db_test.go | 8 ++-- go/vt/vttablet/tabletserver/schema/engine.go | 6 +-- go/vt/wrangler/switcher_dry_run.go | 5 ++- go/vt/wrangler/traffic_switcher.go | 4 +- 7 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 go/maps2/maps.go diff --git a/go/maps2/maps.go b/go/maps2/maps.go deleted file mode 100644 index 56191bea1a7..00000000000 --- a/go/maps2/maps.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2023 The Vitess Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package maps2 - -// Keys returns the keys of the map m. -// The keys will be in an indeterminate order. -func Keys[M ~map[K]V, K comparable, V any](m M) []K { - r := make([]K, 0, len(m)) - for k := range m { - r = append(r, k) - } - return r -} - -// Values returns the values of the map m. -// The values will be in an indeterminate order. -func Values[M ~map[K]V, K comparable, V any](m M) []V { - r := make([]V, 0, len(m)) - for _, v := range m { - r = append(r, v) - } - return r -} diff --git a/go/vt/vtctl/workflow/switcher_dry_run.go b/go/vt/vtctl/workflow/switcher_dry_run.go index 1932e48fe20..21b975a0d6b 100644 --- a/go/vt/vtctl/workflow/switcher_dry_run.go +++ b/go/vt/vtctl/workflow/switcher_dry_run.go @@ -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" @@ -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, ","))) diff --git a/go/vt/vtctl/workflow/traffic_switcher.go b/go/vt/vtctl/workflow/traffic_switcher.go index 871b4b6c10a..47a29100cd5 100644 --- a/go/vt/vtctl/workflow/traffic_switcher.go +++ b/go/vt/vtctl/workflow/traffic_switcher.go @@ -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" @@ -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) } diff --git a/go/vt/vttablet/tabletserver/schema/db_test.go b/go/vt/vttablet/tabletserver/schema/db_test.go index 740ec847e71..5e1bc429136 100644 --- a/go/vt/vttablet/tabletserver/schema/db_test.go +++ b/go/vt/vttablet/tabletserver/schema/db_test.go @@ -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" @@ -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 @@ -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()) @@ -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()) } }) diff --git a/go/vt/vttablet/tabletserver/schema/engine.go b/go/vt/vttablet/tabletserver/schema/engine.go index 6117840a097..32828d78acb 100644 --- a/go/vt/vttablet/tabletserver/schema/engine.go +++ b/go/vt/vttablet/tabletserver/schema/engine.go @@ -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" @@ -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) { diff --git a/go/vt/wrangler/switcher_dry_run.go b/go/vt/wrangler/switcher_dry_run.go index 0c1a1f1acbf..6c1b48bb5c6 100644 --- a/go/vt/wrangler/switcher_dry_run.go +++ b/go/vt/wrangler/switcher_dry_run.go @@ -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" @@ -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, ","))) diff --git a/go/vt/wrangler/traffic_switcher.go b/go/vt/wrangler/traffic_switcher.go index 2f75cadf06c..9cc0eea554c 100644 --- a/go/vt/wrangler/traffic_switcher.go +++ b/go/vt/wrangler/traffic_switcher.go @@ -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" @@ -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) }