Skip to content

Make newest {Server,Cluster}Desc available on monitor chan #3

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 5 additions & 4 deletions core/cluster_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ func StartClusterMonitor(opts ClusterOptions) (*ClusterMonitor, error) {
m.descLock.Lock()
m.desc = desc
m.descLock.Unlock()
select { // non-blocking send
case c <- desc:
select {
case <-c:
// drain the channel if full
default:
// TODO: drain channel to make the next
// change visible
// if it's empty, do nothing
}
c <- desc
}
close(c)
}()
Expand Down
10 changes: 4 additions & 6 deletions core/server_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func StartServerMonitor(opts ServerOptions) (*ServerMonitor, error) {

opts.fillDefaults()

// TODO: should really be using a ring buffer. We want
// to throw away the oldest data, not the newest.
c := make(chan *ServerDesc, 1)
done := make(chan struct{}, 1)
m := &ServerMonitor{
Expand All @@ -33,17 +31,17 @@ func StartServerMonitor(opts ServerOptions) (*ServerMonitor, error) {
for {
select {
case <-timer.C:
// weird syntax for a non-blocking send...
desc := m.heartbeat()
m.descLock.Lock()
m.desc = desc
m.descLock.Unlock()
select {
case c <- desc:
case <-c:
// drain the channel if full
default:
// TODO: drain the channel to make the next
// write visible
// if it's empty, do nothing
}
c <- desc
timer.Stop()
timer.Reset(opts.HeartbeatInterval)
case <-done:
Expand Down