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

vtorc: Cleanup unused code #15508

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions go/vt/vtorc/collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
36 changes: 0 additions & 36 deletions go/vt/vtorc/collection/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand All @@ -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)
Expand All @@ -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")
Expand Down
11 changes: 0 additions & 11 deletions go/vt/vtorc/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions go/vt/vtorc/discovery/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
95 changes: 0 additions & 95 deletions go/vt/vtorc/discovery/queue_aggregated_stats.go

This file was deleted.

11 changes: 0 additions & 11 deletions go/vt/vtorc/inst/instance_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package inst

import (
"regexp"
"strings"
)

Expand All @@ -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
}
30 changes: 0 additions & 30 deletions go/vt/vtorc/inst/instance_utils_test.go

This file was deleted.

47 changes: 0 additions & 47 deletions go/vt/vtorc/inst/oracle_gtid_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 0 additions & 24 deletions go/vt/vtorc/inst/oracle_gtid_set_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Loading
Loading