From 6c6817748c99f43a3caeddf55c4a5036a3fbfb25 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Fri, 23 Feb 2024 14:52:06 +0100 Subject: [PATCH] discovery: Remove unused code (#15332) Signed-off-by: Dirkjan Bussink --- go/vt/discovery/utils.go | 22 ------ go/vt/discovery/utils_test.go | 134 ---------------------------------- 2 files changed, 156 deletions(-) delete mode 100644 go/vt/discovery/utils_test.go diff --git a/go/vt/discovery/utils.go b/go/vt/discovery/utils.go index 3a601830d35..253fead89a8 100644 --- a/go/vt/discovery/utils.go +++ b/go/vt/discovery/utils.go @@ -26,28 +26,6 @@ import ( // This file contains helper filter methods to process the unfiltered list of // tablets returned by HealthCheckImpl.GetTabletHealth*. -func TabletHealthReferenceListToValue(thl []*TabletHealth) []TabletHealth { - newTh := []TabletHealth{} - for _, th := range thl { - newTh = append(newTh, *th) - } - return newTh -} - -// RemoveUnhealthyTablets filters all unhealthy tablets out. -// NOTE: Non-serving tablets are considered healthy. -func RemoveUnhealthyTablets(tabletStatsList []TabletHealth) []TabletHealth { - result := make([]TabletHealth, 0, len(tabletStatsList)) - for _, ts := range tabletStatsList { - // Note we do not check the 'Serving' flag here. - if ts.LastError != nil || ts.Stats != nil && (ts.Stats.HealthError != "" || IsReplicationLagHigh(&ts)) { - continue - } - result = append(result, ts) - } - return result -} - func ParseTabletTypesAndOrder(tabletTypesStr string) ([]topodatapb.TabletType, bool, error) { inOrder := false if strings.HasPrefix(tabletTypesStr, InOrderHint) { diff --git a/go/vt/discovery/utils_test.go b/go/vt/discovery/utils_test.go deleted file mode 100644 index edca8c17602..00000000000 --- a/go/vt/discovery/utils_test.go +++ /dev/null @@ -1,134 +0,0 @@ -/* -Copyright 2018 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 discovery - -import ( - "errors" - "testing" - - querypb "vitess.io/vitess/go/vt/proto/query" - topodatapb "vitess.io/vitess/go/vt/proto/topodata" -) - -func TestRemoveUnhealthyTablets(t *testing.T) { - var testcases = []struct { - desc string - input []TabletHealth - want []TabletHealth - }{{ - desc: "tablets missing Stats", - input: []TabletHealth{replica(1), replica(2)}, - want: []TabletHealth{replica(1), replica(2)}, - }, { - desc: "all tablets healthy", - input: []TabletHealth{healthy(replica(1)), healthy(replica(2))}, - want: []TabletHealth{healthy(replica(1)), healthy(replica(2))}, - }, { - desc: "one unhealthy tablet (error)", - input: []TabletHealth{healthy(replica(1)), unhealthyError(replica(2))}, - want: []TabletHealth{healthy(replica(1))}, - }, { - desc: "one error tablet", - input: []TabletHealth{healthy(replica(1)), unhealthyLastError(replica(2))}, - want: []TabletHealth{healthy(replica(1))}, - }, { - desc: "one unhealthy tablet (lag)", - input: []TabletHealth{healthy(replica(1)), unhealthyLag(replica(2))}, - want: []TabletHealth{healthy(replica(1))}, - }, { - desc: "no filtering by tablet type", - input: []TabletHealth{healthy(primary(1)), healthy(replica(2)), healthy(rdonly(3))}, - want: []TabletHealth{healthy(primary(1)), healthy(replica(2)), healthy(rdonly(3))}, - }, { - desc: "non-serving tablets won't be removed", - input: []TabletHealth{notServing(healthy(replica(1)))}, - want: []TabletHealth{notServing(healthy(replica(1)))}, - }} - - for _, tc := range testcases { - t.Run(tc.desc, func(t *testing.T) { - got := RemoveUnhealthyTablets(tc.input) - if len(got) != len(tc.want) { - t.Errorf("test case '%v' failed: RemoveUnhealthyTablets(%v) = %#v, want: %#v", tc.desc, tc.input, got, tc.want) - } else { - for i := range tc.want { - if !got[i].DeepEqual(&tc.want[i]) { - t.Errorf("test case '%v' failed: RemoveUnhealthyTablets(%v) = %#v, want: %#v", tc.desc, tc.input, got, tc.want) - } - } - } - }) - } -} - -func primary(uid uint32) TabletHealth { - return minimalTabletStats(uid, topodatapb.TabletType_PRIMARY) -} - -func replica(uid uint32) TabletHealth { - return minimalTabletStats(uid, topodatapb.TabletType_REPLICA) -} - -func rdonly(uid uint32) TabletHealth { - return minimalTabletStats(uid, topodatapb.TabletType_RDONLY) -} - -func minimalTabletStats(uid uint32, tabletType topodatapb.TabletType) TabletHealth { - return TabletHealth{ - Tablet: &topodatapb.Tablet{ - Alias: &topodatapb.TabletAlias{ - Uid: uid}, - }, - Target: &querypb.Target{ - Keyspace: "test_keyspace", - Shard: "-80", - TabletType: tabletType, - }, - Serving: true, - } -} - -func healthy(ts TabletHealth) TabletHealth { - ts.Stats = &querypb.RealtimeStats{ - ReplicationLagSeconds: uint32(1), - } - return ts -} - -func unhealthyLag(ts TabletHealth) TabletHealth { - ts.Stats = &querypb.RealtimeStats{ - ReplicationLagSeconds: uint32(3600), - } - return ts -} - -func unhealthyError(ts TabletHealth) TabletHealth { - ts.Stats = &querypb.RealtimeStats{ - HealthError: "unhealthy", - } - return ts -} - -func unhealthyLastError(ts TabletHealth) TabletHealth { - ts.LastError = errors.New("err") - return ts -} - -func notServing(ts TabletHealth) TabletHealth { - ts.Serving = false - return ts -}