Skip to content

Commit 740a9f7

Browse files
committed
feat: remove unused code in discovery
Signed-off-by: Manan Gupta <manan@planetscale.com>
1 parent ec29bdb commit 740a9f7

File tree

2 files changed

+4
-61
lines changed

2 files changed

+4
-61
lines changed

go/vt/vtorc/discovery/queue.go

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ import (
3333
"vitess.io/vitess/go/vt/vtorc/config"
3434
)
3535

36-
// QueueMetric contains the queue's active and queued sizes
37-
type QueueMetric struct {
38-
Active int
39-
Queued int
40-
}
41-
4236
// Queue contains information for managing discovery requests
4337
type Queue struct {
4438
sync.Mutex
@@ -48,67 +42,16 @@ type Queue struct {
4842
queue chan string
4943
queuedKeys map[string]time.Time
5044
consumedKeys map[string]time.Time
51-
metrics []QueueMetric
52-
}
53-
54-
// DiscoveryQueue contains the discovery queue which can then be accessed via an API call for monitoring.
55-
// Currently this is accessed by ContinuousDiscovery() but also from http api calls.
56-
// I may need to protect this better?
57-
var discoveryQueue map[string](*Queue)
58-
var dcLock sync.Mutex
59-
60-
func init() {
61-
discoveryQueue = make(map[string](*Queue))
6245
}
6346

64-
// CreateOrReturnQueue allows for creation of a new discovery queue or
65-
// returning a pointer to an existing one given the name.
66-
func CreateOrReturnQueue(name string) *Queue {
67-
dcLock.Lock()
68-
defer dcLock.Unlock()
69-
if q, found := discoveryQueue[name]; found {
70-
return q
71-
}
72-
73-
q := &Queue{
47+
// CreateQueue allows for creation of a new discovery queue
48+
func CreateQueue(name string) *Queue {
49+
return &Queue{
7450
name: name,
7551
queuedKeys: make(map[string]time.Time),
7652
consumedKeys: make(map[string]time.Time),
7753
queue: make(chan string, config.DiscoveryQueueCapacity),
7854
}
79-
go q.startMonitoring()
80-
81-
discoveryQueue[name] = q
82-
83-
return q
84-
}
85-
86-
// monitoring queue sizes until we are told to stop
87-
func (q *Queue) startMonitoring() {
88-
log.Infof("Queue.startMonitoring(%s)", q.name)
89-
ticker := time.NewTicker(time.Second) // hard-coded at every second
90-
91-
for {
92-
select {
93-
case <-ticker.C: // do the periodic expiry
94-
q.collectStatistics()
95-
case <-q.done:
96-
return
97-
}
98-
}
99-
}
100-
101-
// do a check of the entries in the queue, both those active and queued
102-
func (q *Queue) collectStatistics() {
103-
q.Lock()
104-
defer q.Unlock()
105-
106-
q.metrics = append(q.metrics, QueueMetric{Queued: len(q.queuedKeys), Active: len(q.consumedKeys)})
107-
108-
// remove old entries if we get too big
109-
if len(q.metrics) > config.DiscoveryQueueMaxStatisticsSize {
110-
q.metrics = q.metrics[len(q.metrics)-config.DiscoveryQueueMaxStatisticsSize:]
111-
}
11255
}
11356

11457
// QueueLen returns the length of the queue (channel size + queued size)

go/vt/vtorc/logic/vtorc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func waitForLocksRelease() {
108108
// handleDiscoveryRequests iterates the discoveryQueue channel and calls upon
109109
// instance discovery per entry.
110110
func handleDiscoveryRequests() {
111-
discoveryQueue = discovery.CreateOrReturnQueue("DEFAULT")
111+
discoveryQueue = discovery.CreateQueue("DEFAULT")
112112
// create a pool of discovery workers
113113
for i := uint(0); i < config.DiscoveryMaxConcurrency; i++ {
114114
go func() {

0 commit comments

Comments
 (0)