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

futures can react to shutdown #390

Merged
merged 1 commit into from
Feb 27, 2020
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
13 changes: 9 additions & 4 deletions future.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ func (e errorFuture) Index() uint64 {
// deferError can be embedded to allow a future
// to provide an error in the future.
type deferError struct {
err error
errCh chan error
responded bool
err error
errCh chan error
responded bool
ShutdownCh chan struct{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nit picky - can this field be private like the rest?

}

func (d *deferError) init() {
Expand All @@ -103,7 +104,11 @@ func (d *deferError) Error() error {
if d.errCh == nil {
panic("waiting for response on nil channel")
}
d.err = <-d.errCh
select {
case d.err = <-d.errCh:
case <-d.ShutdownCh:
d.err = ErrRaftShutdown
}
return d.err
}

Expand Down
1 change: 1 addition & 0 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (r *Raft) takeSnapshot() (string, error) {
// We have to use the future here to safely get this information since
// it is owned by the main thread.
configReq := &configurationsFuture{}
configReq.ShutdownCh = r.shutdownCh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be nice to document when ShutdownCh needs to be set and what makes snapshotting special. I assume it's because snapshotting runs in an internal gorotouine and can run regardless of leadership. Other futures will be responded to immediately when not leader, or when raft loses leadership as a result of shutting down?

configReq.init()
select {
case r.configurationsCh <- configReq:
Expand Down