From 52ca4975b93f8d9005b77c26f3c9f5ef962d6813 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Mon, 18 Mar 2024 15:06:50 +0100 Subject: [PATCH] vtorc: Cleanup unused code (#15508) Signed-off-by: Dirkjan Bussink --- go/vt/vtorc/collection/collection.go | 21 --- go/vt/vtorc/collection/collection_test.go | 36 ----- go/vt/vtorc/db/db.go | 11 -- go/vt/vtorc/discovery/funcs.go | 9 -- .../vtorc/discovery/queue_aggregated_stats.go | 95 ------------ go/vt/vtorc/inst/instance_utils.go | 11 -- go/vt/vtorc/inst/instance_utils_test.go | 30 ---- go/vt/vtorc/inst/oracle_gtid_set.go | 47 ------ go/vt/vtorc/inst/oracle_gtid_set_entry.go | 24 --- go/vt/vtorc/inst/oracle_gtid_set_test.go | 138 ------------------ go/vt/vtorc/metrics/query/aggregated.go | 76 ---------- go/vt/vtorc/process/election_dao.go | 26 ---- go/vt/vtorc/util/token.go | 11 -- 13 files changed, 535 deletions(-) delete mode 100644 go/vt/vtorc/discovery/queue_aggregated_stats.go delete mode 100644 go/vt/vtorc/inst/instance_utils_test.go delete mode 100644 go/vt/vtorc/metrics/query/aggregated.go diff --git a/go/vt/vtorc/collection/collection.go b/go/vt/vtorc/collection/collection.go index 4f679286978..753e24fd2c1 100644 --- a/go/vt/vtorc/collection/collection.go +++ b/go/vt/vtorc/collection/collection.go @@ -128,13 +128,6 @@ func (c *Collection) SetExpirePeriod(duration time.Duration) { c.expirePeriod = duration } -// ExpirePeriod returns the currently configured expiration period -func (c *Collection) ExpirePeriod() time.Duration { - c.Lock() - defer c.Unlock() - return c.expirePeriod -} - // StopAutoExpiration prepares to stop by terminating the auto-expiration process func (c *Collection) StopAutoExpiration() { if c == nil { @@ -181,20 +174,6 @@ func (c *Collection) StartAutoExpiration() { } } -// Metrics returns a slice containing all the metric values -func (c *Collection) Metrics() []Metric { - if c == nil { - return nil - } - c.Lock() - defer c.Unlock() - - if len(c.collection) == 0 { - return nil // nothing to return - } - return c.collection -} - // Since returns the Metrics on or after the given time. We assume // the metrics are stored in ascending time. // Iterate backwards until we reach the first value before the given time diff --git a/go/vt/vtorc/collection/collection_test.go b/go/vt/vtorc/collection/collection_test.go index 16ea6943dc7..9a336f970f8 100644 --- a/go/vt/vtorc/collection/collection_test.go +++ b/go/vt/vtorc/collection/collection_test.go @@ -61,27 +61,6 @@ func TestCreateOrReturnCollection(t *testing.T) { } } -// TestExpirePeriod checks that the set expire period is returned -func TestExpirePeriod(t *testing.T) { - oneSecond := time.Second - twoSeconds := 2 * oneSecond - - // create a new collection - c := &Collection{} - - // check if we change it we get back the value we provided - c.SetExpirePeriod(oneSecond) - if c.ExpirePeriod() != oneSecond { - t.Errorf("TestExpirePeriod: did not get back oneSecond") - } - - // change the period and check again - c.SetExpirePeriod(twoSeconds) - if c.ExpirePeriod() != twoSeconds { - t.Errorf("TestExpirePeriod: did not get back twoSeconds") - } -} - // dummy structure for testing type testMetric struct { } @@ -100,18 +79,6 @@ func (tm *testMetric2) When() time.Time { // check that Append() works as expected func TestAppend(t *testing.T) { c := &Collection{} - - if len(c.Metrics()) != 0 { - t.Errorf("TestAppend: len(Metrics) = %d, expecting %d", len(c.Metrics()), 0) - } - for _, v := range []int{1, 2, 3} { - tm := &testMetric{} - _ = c.Append(tm) - if len(c.Metrics()) != v { - t.Errorf("TestExpirePeriod: len(Metrics) = %d, expecting %d", len(c.Metrics()), v) - } - } - // Test for nil metric err := c.Append(nil) assert.Error(t, err) @@ -121,9 +88,6 @@ func TestAppend(t *testing.T) { func TestNilCollection(t *testing.T) { var c *Collection - metrics := c.Metrics() - assert.Nil(t, metrics) - err := c.Append(nil) assert.Error(t, err) assert.Equal(t, err.Error(), "Collection.Append: c == nil") diff --git a/go/vt/vtorc/db/db.go b/go/vt/vtorc/db/db.go index 92657eddc3f..00f5b5b2550 100644 --- a/go/vt/vtorc/db/db.go +++ b/go/vt/vtorc/db/db.go @@ -42,17 +42,6 @@ func (m *vtorcDB) QueryVTOrc(query string, argsArray []any, onRow func(sqlutils. return QueryVTOrc(query, argsArray, onRow) } -type DummySQLResult struct { -} - -func (dummyRes DummySQLResult) LastInsertId() (int64, error) { - return 0, nil -} - -func (dummyRes DummySQLResult) RowsAffected() (int64, error) { - return 1, nil -} - // OpenTopology returns the DB instance for the vtorc backed database func OpenVTOrc() (db *sql.DB, err error) { var fromCache bool diff --git a/go/vt/vtorc/discovery/funcs.go b/go/vt/vtorc/discovery/funcs.go index e468d10a420..eeafe2e20a4 100644 --- a/go/vt/vtorc/discovery/funcs.go +++ b/go/vt/vtorc/discovery/funcs.go @@ -47,15 +47,6 @@ func max(values stats.Float64Data) float64 { return s } -// internal routine to return the minimum value or 9e9 -func min(values stats.Float64Data) float64 { - s, err := stats.Min(values) - if err != nil { - return 9e9 // a large number (should use something better than this but it's ok for now) - } - return s -} - // internal routine to return the median or 0 func median(values stats.Float64Data) float64 { s, err := stats.Median(values) diff --git a/go/vt/vtorc/discovery/queue_aggregated_stats.go b/go/vt/vtorc/discovery/queue_aggregated_stats.go deleted file mode 100644 index 79f2e310a58..00000000000 --- a/go/vt/vtorc/discovery/queue_aggregated_stats.go +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright 2017 Simon J Mudd - - 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 ( - "github.com/montanaflynn/stats" - - "vitess.io/vitess/go/vt/log" -) - -// AggregatedQueueMetrics contains aggregate information some part queue metrics -type AggregatedQueueMetrics struct { - ActiveMinEntries float64 - ActiveMeanEntries float64 - ActiveMedianEntries float64 - ActiveP95Entries float64 - ActiveMaxEntries float64 - QueuedMinEntries float64 - QueuedMeanEntries float64 - QueuedMedianEntries float64 - QueuedP95Entries float64 - QueuedMaxEntries float64 -} - -// we pull out values in ints so convert to float64 for metric calculations -func intSliceToFloat64Slice(someInts []int) stats.Float64Data { - var slice stats.Float64Data - - for _, v := range someInts { - slice = append(slice, float64(v)) - } - - return slice -} - -// DiscoveryQueueMetrics returns some raw queue metrics based on the -// period (last N entries) requested. -func (q *Queue) DiscoveryQueueMetrics(period int) []QueueMetric { - q.Lock() - defer q.Unlock() - - // adjust period in case we ask for something that's too long - if period > len(q.metrics) { - log.Infof("DiscoveryQueueMetrics: wanted: %d, adjusting period to %d", period, len(q.metrics)) - period = len(q.metrics) - } - - a := q.metrics[len(q.metrics)-period:] - log.Infof("DiscoveryQueueMetrics: returning values: %+v", a) - return a -} - -// AggregatedDiscoveryQueueMetrics Returns some aggregate statistics -// based on the period (last N entries) requested. We store up to -// config.Config.DiscoveryQueueMaxStatisticsSize values and collect once -// a second so we expect period to be a smaller value. -func (q *Queue) AggregatedDiscoveryQueueMetrics(period int) *AggregatedQueueMetrics { - wanted := q.DiscoveryQueueMetrics(period) - - var activeEntries, queuedEntries []int - // fill vars - for i := range wanted { - activeEntries = append(activeEntries, wanted[i].Active) - queuedEntries = append(queuedEntries, wanted[i].Queued) - } - - a := &AggregatedQueueMetrics{ - ActiveMinEntries: min(intSliceToFloat64Slice(activeEntries)), - ActiveMeanEntries: mean(intSliceToFloat64Slice(activeEntries)), - ActiveMedianEntries: median(intSliceToFloat64Slice(activeEntries)), - ActiveP95Entries: percentile(intSliceToFloat64Slice(activeEntries), 95), - ActiveMaxEntries: max(intSliceToFloat64Slice(activeEntries)), - QueuedMinEntries: min(intSliceToFloat64Slice(queuedEntries)), - QueuedMeanEntries: mean(intSliceToFloat64Slice(queuedEntries)), - QueuedMedianEntries: median(intSliceToFloat64Slice(queuedEntries)), - QueuedP95Entries: percentile(intSliceToFloat64Slice(queuedEntries), 95), - QueuedMaxEntries: max(intSliceToFloat64Slice(queuedEntries)), - } - log.Infof("AggregatedDiscoveryQueueMetrics: returning values: %+v", a) - return a -} diff --git a/go/vt/vtorc/inst/instance_utils.go b/go/vt/vtorc/inst/instance_utils.go index f6bde729822..01302f00b4c 100644 --- a/go/vt/vtorc/inst/instance_utils.go +++ b/go/vt/vtorc/inst/instance_utils.go @@ -17,7 +17,6 @@ package inst import ( - "regexp" "strings" ) @@ -29,13 +28,3 @@ func MajorVersion(version string) []string { } return tokens[:2] } - -// RegexpMatchPatterns returns true if s matches any of the provided regexpPatterns -func RegexpMatchPatterns(s string, regexpPatterns []string) bool { - for _, filter := range regexpPatterns { - if matched, err := regexp.MatchString(filter, s); err == nil && matched { - return true - } - } - return false -} diff --git a/go/vt/vtorc/inst/instance_utils_test.go b/go/vt/vtorc/inst/instance_utils_test.go deleted file mode 100644 index f6247d5d6d0..00000000000 --- a/go/vt/vtorc/inst/instance_utils_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package inst - -import ( - "testing" -) - -type testPatterns struct { - s string - patterns []string - expected bool -} - -func TestRegexpMatchPatterns(t *testing.T) { - patterns := []testPatterns{ - {"hostname", []string{}, false}, - {"hostname", []string{"blah"}, false}, - {"hostname", []string{"blah", "blah"}, false}, - {"hostname", []string{"host", "blah"}, true}, - {"hostname", []string{"blah", "host"}, true}, - {"hostname", []string{"ho.tname"}, true}, - {"hostname", []string{"ho.tname2"}, false}, - {"hostname", []string{"ho.*me"}, true}, - } - - for _, p := range patterns { - if match := RegexpMatchPatterns(p.s, p.patterns); match != p.expected { - t.Errorf("RegexpMatchPatterns failed with: %q, %+v, got: %+v, expected: %+v", p.s, p.patterns, match, p.expected) - } - } -} diff --git a/go/vt/vtorc/inst/oracle_gtid_set.go b/go/vt/vtorc/inst/oracle_gtid_set.go index 0ddab05ef55..711232692f8 100644 --- a/go/vt/vtorc/inst/oracle_gtid_set.go +++ b/go/vt/vtorc/inst/oracle_gtid_set.go @@ -69,53 +69,6 @@ func (oracleGTIDSet *OracleGtidSet) RemoveUUID(uuid string) (removed bool) { return removed } -// RetainUUID retains only entries that belong to given UUID. -func (oracleGTIDSet *OracleGtidSet) RetainUUID(uuid string) (anythingRemoved bool) { - return oracleGTIDSet.RetainUUIDs([]string{uuid}) -} - -// RetainUUIDs retains only entries that belong to given UUIDs. -func (oracleGTIDSet *OracleGtidSet) RetainUUIDs(uuids []string) (anythingRemoved bool) { - retainUUIDs := map[string]bool{} - for _, uuid := range uuids { - retainUUIDs[uuid] = true - } - var filteredEntries []*OracleGtidSetEntry - for _, entry := range oracleGTIDSet.GtidEntries { - if retainUUIDs[entry.UUID] { - filteredEntries = append(filteredEntries, entry) - } else { - anythingRemoved = true - } - } - if anythingRemoved { - oracleGTIDSet.GtidEntries = filteredEntries - } - return anythingRemoved -} - -// SharedUUIDs returns UUIDs (range-less) that are shared between the two sets -func (oracleGTIDSet *OracleGtidSet) SharedUUIDs(other *OracleGtidSet) (shared []string) { - thisUUIDs := map[string]bool{} - for _, entry := range oracleGTIDSet.GtidEntries { - thisUUIDs[entry.UUID] = true - } - for _, entry := range other.GtidEntries { - if thisUUIDs[entry.UUID] { - shared = append(shared, entry.UUID) - } - } - return shared -} - -// Explode returns a user-friendly string representation of this entry -func (oracleGTIDSet *OracleGtidSet) Explode() (result []*OracleGtidSetEntry) { - for _, entries := range oracleGTIDSet.GtidEntries { - result = append(result, entries.Explode()...) - } - return result -} - func (oracleGTIDSet *OracleGtidSet) String() string { var tokens []string for _, entry := range oracleGTIDSet.GtidEntries { diff --git a/go/vt/vtorc/inst/oracle_gtid_set_entry.go b/go/vt/vtorc/inst/oracle_gtid_set_entry.go index 3affd326735..704b38760ef 100644 --- a/go/vt/vtorc/inst/oracle_gtid_set_entry.go +++ b/go/vt/vtorc/inst/oracle_gtid_set_entry.go @@ -18,16 +18,9 @@ package inst import ( "fmt" - "regexp" - "strconv" "strings" ) -var ( - singleValueInterval = regexp.MustCompile("^([0-9]+)$") - multiValueInterval = regexp.MustCompile("^([0-9]+)[-]([0-9]+)$") -) - // OracleGtidSetEntry represents an entry in a set of GTID ranges, // for example, the entry: "316d193c-70e5-11e5-adb2-ecf4bb2262ff:1-8935:8984-6124596" (may include gaps) type OracleGtidSetEntry struct { @@ -56,20 +49,3 @@ func NewOracleGtidSetEntry(gtidRangeString string) (*OracleGtidSetEntry, error) func (oracleGTIDSetEntry *OracleGtidSetEntry) String() string { return fmt.Sprintf("%s:%s", oracleGTIDSetEntry.UUID, oracleGTIDSetEntry.Ranges) } - -// String returns a user-friendly string representation of this entry -func (oracleGTIDSetEntry *OracleGtidSetEntry) Explode() (result [](*OracleGtidSetEntry)) { - intervals := strings.Split(oracleGTIDSetEntry.Ranges, ":") - for _, interval := range intervals { - if submatch := multiValueInterval.FindStringSubmatch(interval); submatch != nil { - intervalStart, _ := strconv.Atoi(submatch[1]) - intervalEnd, _ := strconv.Atoi(submatch[2]) - for i := intervalStart; i <= intervalEnd; i++ { - result = append(result, &OracleGtidSetEntry{UUID: oracleGTIDSetEntry.UUID, Ranges: fmt.Sprintf("%d", i)}) - } - } else if submatch := singleValueInterval.FindStringSubmatch(interval); submatch != nil { - result = append(result, &OracleGtidSetEntry{UUID: oracleGTIDSetEntry.UUID, Ranges: interval}) - } - } - return result -} diff --git a/go/vt/vtorc/inst/oracle_gtid_set_test.go b/go/vt/vtorc/inst/oracle_gtid_set_test.go index b62f9475696..7e5b61fe448 100644 --- a/go/vt/vtorc/inst/oracle_gtid_set_test.go +++ b/go/vt/vtorc/inst/oracle_gtid_set_test.go @@ -28,54 +28,6 @@ func TestNewOracleGtidSetEntry(t *testing.T) { } } -func TestExplode(t *testing.T) { - { - uuidSet := "00020194-3333-3333-3333-333333333333:7" - entry, err := NewOracleGtidSetEntry(uuidSet) - require.NoError(t, err) - - exploded := entry.Explode() - require.Equal(t, len(exploded), 1) - require.Equal(t, exploded[0].String(), "00020194-3333-3333-3333-333333333333:7") - } - { - uuidSet := "00020194-3333-3333-3333-333333333333:1-3" - entry, err := NewOracleGtidSetEntry(uuidSet) - require.NoError(t, err) - - exploded := entry.Explode() - require.Equal(t, len(exploded), 3) - require.Equal(t, exploded[0].String(), "00020194-3333-3333-3333-333333333333:1") - require.Equal(t, exploded[1].String(), "00020194-3333-3333-3333-333333333333:2") - require.Equal(t, exploded[2].String(), "00020194-3333-3333-3333-333333333333:3") - } - { - uuidSet := "00020194-3333-3333-3333-333333333333:1-3:6-7" - entry, err := NewOracleGtidSetEntry(uuidSet) - require.NoError(t, err) - - exploded := entry.Explode() - require.Equal(t, len(exploded), 5) - require.Equal(t, exploded[0].String(), "00020194-3333-3333-3333-333333333333:1") - require.Equal(t, exploded[1].String(), "00020194-3333-3333-3333-333333333333:2") - require.Equal(t, exploded[2].String(), "00020194-3333-3333-3333-333333333333:3") - require.Equal(t, exploded[3].String(), "00020194-3333-3333-3333-333333333333:6") - require.Equal(t, exploded[4].String(), "00020194-3333-3333-3333-333333333333:7") - } - { - gtidSetVal := "00020192-1111-1111-1111-111111111111:29-30, 00020194-3333-3333-3333-333333333333:7-8" - gtidSet, err := NewOracleGtidSet(gtidSetVal) - require.NoError(t, err) - - exploded := gtidSet.Explode() - require.Equal(t, len(exploded), 4) - require.Equal(t, exploded[0].String(), "00020192-1111-1111-1111-111111111111:29") - require.Equal(t, exploded[1].String(), "00020192-1111-1111-1111-111111111111:30") - require.Equal(t, exploded[2].String(), "00020194-3333-3333-3333-333333333333:7") - require.Equal(t, exploded[3].String(), "00020194-3333-3333-3333-333333333333:8") - } -} - func TestNewOracleGtidSet(t *testing.T) { { gtidSetVal := "00020192-1111-1111-1111-111111111111:20-30, 00020194-3333-3333-3333-333333333333:7-8" @@ -135,93 +87,3 @@ func TestRemoveUUID(t *testing.T) { require.True(t, gtidSet.IsEmpty()) } } - -func TestRetainUUID(t *testing.T) { - gtidSetVal := "00020192-1111-1111-1111-111111111111:20-30, 00020194-3333-3333-3333-333333333333:7-8" - { - gtidSet, err := NewOracleGtidSet(gtidSetVal) - require.NoError(t, err) - - require.Equal(t, len(gtidSet.GtidEntries), 2) - removed := gtidSet.RetainUUID("00020194-3333-3333-3333-333333333333") - require.True(t, removed) - require.Equal(t, len(gtidSet.GtidEntries), 1) - require.Equal(t, gtidSet.GtidEntries[0].String(), "00020194-3333-3333-3333-333333333333:7-8") - - removed = gtidSet.RetainUUID("00020194-3333-3333-3333-333333333333") - require.False(t, removed) - require.Equal(t, len(gtidSet.GtidEntries), 1) - require.Equal(t, gtidSet.GtidEntries[0].String(), "00020194-3333-3333-3333-333333333333:7-8") - - removed = gtidSet.RetainUUID("230ea8ea-81e3-11e4-972a-e25ec4bd140a") - require.True(t, removed) - require.Equal(t, len(gtidSet.GtidEntries), 0) - } -} - -func TestRetainUUIDs(t *testing.T) { - gtidSetVal := "00020192-1111-1111-1111-111111111111:20-30, 00020194-3333-3333-3333-333333333333:7-8" - { - gtidSet, err := NewOracleGtidSet(gtidSetVal) - require.NoError(t, err) - - require.Equal(t, len(gtidSet.GtidEntries), 2) - removed := gtidSet.RetainUUIDs([]string{"00020194-3333-3333-3333-333333333333", "00020194-5555-5555-5555-333333333333"}) - require.True(t, removed) - require.Equal(t, len(gtidSet.GtidEntries), 1) - require.Equal(t, gtidSet.GtidEntries[0].String(), "00020194-3333-3333-3333-333333333333:7-8") - - removed = gtidSet.RetainUUIDs([]string{"00020194-3333-3333-3333-333333333333", "00020194-5555-5555-5555-333333333333"}) - require.False(t, removed) - require.Equal(t, len(gtidSet.GtidEntries), 1) - require.Equal(t, gtidSet.GtidEntries[0].String(), "00020194-3333-3333-3333-333333333333:7-8") - - removed = gtidSet.RetainUUIDs([]string{"230ea8ea-81e3-11e4-972a-e25ec4bd140a"}) - require.True(t, removed) - require.Equal(t, len(gtidSet.GtidEntries), 0) - } -} - -func TestSharedUUIDs(t *testing.T) { - gtidSetVal := "00020192-1111-1111-1111-111111111111:20-30, 00020194-3333-3333-3333-333333333333:7-8" - gtidSet, err := NewOracleGtidSet(gtidSetVal) - require.NoError(t, err) - { - otherSet, err := NewOracleGtidSet("00020194-3333-3333-3333-333333333333:7-8,230ea8ea-81e3-11e4-972a-e25ec4bd140a:1-2") - require.NoError(t, err) - { - shared := gtidSet.SharedUUIDs(otherSet) - require.Equal(t, len(shared), 1) - require.Equal(t, shared[0], "00020194-3333-3333-3333-333333333333") - } - { - shared := otherSet.SharedUUIDs(gtidSet) - require.Equal(t, len(shared), 1) - require.Equal(t, shared[0], "00020194-3333-3333-3333-333333333333") - } - } - { - otherSet, err := NewOracleGtidSet("00020194-4444-4444-4444-333333333333:7-8,230ea8ea-81e3-11e4-972a-e25ec4bd140a:1-2") - require.NoError(t, err) - { - shared := gtidSet.SharedUUIDs(otherSet) - require.Equal(t, len(shared), 0) - } - { - shared := otherSet.SharedUUIDs(gtidSet) - require.Equal(t, len(shared), 0) - } - } - { - otherSet, err := NewOracleGtidSet("00020194-3333-3333-3333-333333333333:7-8,00020192-1111-1111-1111-111111111111:1-2") - require.NoError(t, err) - { - shared := gtidSet.SharedUUIDs(otherSet) - require.Equal(t, len(shared), 2) - } - { - shared := otherSet.SharedUUIDs(gtidSet) - require.Equal(t, len(shared), 2) - } - } -} diff --git a/go/vt/vtorc/metrics/query/aggregated.go b/go/vt/vtorc/metrics/query/aggregated.go deleted file mode 100644 index a284ca6f74d..00000000000 --- a/go/vt/vtorc/metrics/query/aggregated.go +++ /dev/null @@ -1,76 +0,0 @@ -// Package query provides query metrics with this file providing -// aggregated metrics based on the underlying values. -package query - -import ( - "time" - - "github.com/montanaflynn/stats" - - "vitess.io/vitess/go/vt/vtorc/collection" -) - -type AggregatedQueryMetrics struct { - // fill me in here - Count int - MaxLatencySeconds float64 - MeanLatencySeconds float64 - MedianLatencySeconds float64 - P95LatencySeconds float64 - MaxWaitSeconds float64 - MeanWaitSeconds float64 - MedianWaitSeconds float64 - P95WaitSeconds float64 -} - -// AggregatedSince returns the aggregated query metrics for the period -// given from the values provided. -func AggregatedSince(c *collection.Collection, t time.Time) AggregatedQueryMetrics { - - // Initialise timing metrics - var waitTimings []float64 - var queryTimings []float64 - - // Retrieve values since the time specified - values, err := c.Since(t) - a := AggregatedQueryMetrics{} - if err != nil { - return a // empty data - } - - // generate the metrics - for _, v := range values { - waitTimings = append(waitTimings, v.(*Metric).WaitLatency.Seconds()) - queryTimings = append(queryTimings, v.(*Metric).ExecuteLatency.Seconds()) - } - - a.Count = len(waitTimings) - - // generate aggregate values - if s, err := stats.Max(stats.Float64Data(waitTimings)); err == nil { - a.MaxWaitSeconds = s - } - if s, err := stats.Mean(stats.Float64Data(waitTimings)); err == nil { - a.MeanWaitSeconds = s - } - if s, err := stats.Median(stats.Float64Data(waitTimings)); err == nil { - a.MedianWaitSeconds = s - } - if s, err := stats.Percentile(stats.Float64Data(waitTimings), 95); err == nil { - a.P95WaitSeconds = s - } - if s, err := stats.Max(stats.Float64Data(queryTimings)); err == nil { - a.MaxLatencySeconds = s - } - if s, err := stats.Mean(stats.Float64Data(queryTimings)); err == nil { - a.MeanLatencySeconds = s - } - if s, err := stats.Median(stats.Float64Data(queryTimings)); err == nil { - a.MedianLatencySeconds = s - } - if s, err := stats.Percentile(stats.Float64Data(queryTimings), 95); err == nil { - a.P95LatencySeconds = s - } - - return a -} diff --git a/go/vt/vtorc/process/election_dao.go b/go/vt/vtorc/process/election_dao.go index f723bd48dde..aa2bfbc2dee 100644 --- a/go/vt/vtorc/process/election_dao.go +++ b/go/vt/vtorc/process/election_dao.go @@ -107,32 +107,6 @@ func AttemptElection() (bool, error) { return false, nil } -// GrabElection forcibly grabs leadership. Use with care!! -func GrabElection() error { - _, err := db.ExecVTOrc(` - replace into active_node ( - anchor, hostname, token, first_seen_active, last_seen_active - ) values ( - 1, ?, ?, now(), now() - ) - `, - ThisHostname, util.ProcessToken.Hash, - ) - if err != nil { - log.Error(err) - } - return err -} - -// Reelect clears the way for re-elections. Active node is immediately demoted. -func Reelect() error { - _, err := db.ExecVTOrc(`delete from active_node where anchor = 1`) - if err != nil { - log.Error(err) - } - return err -} - // ElectedNode returns the details of the elected node, as well as answering the question "is this process the elected one"? func ElectedNode() (node *NodeHealth, isElected bool, err error) { node = &NodeHealth{} diff --git a/go/vt/vtorc/util/token.go b/go/vt/vtorc/util/token.go index ff60e3e18ea..940f7a44698 100644 --- a/go/vt/vtorc/util/token.go +++ b/go/vt/vtorc/util/token.go @@ -24,10 +24,6 @@ import ( "time" ) -const ( - shortTokenLength = 8 -) - func toHash(input []byte) string { hasher := sha256.New() hasher.Write(input) @@ -50,13 +46,6 @@ type Token struct { Hash string } -func (token *Token) Short() string { - if len(token.Hash) <= shortTokenLength { - return token.Hash - } - return token.Hash[0:shortTokenLength] -} - var ProcessToken = NewToken() func NewToken() *Token {