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

Rewrite a paragraph in the README and a couple trivial fixes #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ Currently, this implementation only has two implementations:
The [`Config`] struct contains callbacks and tunables for the leader election
"campaign".

Each process that would like to acquire leadership must register callbacks for
all three of `OnElected`, `OnOusting` and `LeaderChanged`, as well as specify
unique `LeaderID` and `HostPort`s (the latter two are used for communication, so
some use-cases may be able to ignore them)
Each "candidate" contending for leadership must register an `OnElected` callback
and a `LeaderID` (which is often a random string). Additionally, it is
recommended to specify `HostPort`, which makes it possible to leverage the
`legrpc` package and have other clients using the `WatchConfig{}.Watch()` method
connect to the current leader. (it can also be useful for debugging)

Optionally, one can specify `LeaderChanged` and `OnOusting` callbacks which are
called when the current leader changes and an instance has lost/ceded its
election, respectively. If set, `OnOusting` is guaranteed to be called after
losing leadership, whether that's by losing the election, or by its context
being canceled.

The `TermLength` is the length of time that a leader acquires leadership for,
and the length of any extension. This duration should be long enough to get
Expand Down
4 changes: 2 additions & 2 deletions campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c Config) Acquire(ctx context.Context) error {
wg := sync.WaitGroup{}
defer wg.Wait()
for {
switch acquiredEntry, err := cmp.acquireOnce(ctx, lastEntry); err {
switch acquiredEntry, aqErr := cmp.acquireOnce(ctx, lastEntry); aqErr {
case nil:
b.Reset()
if c.LeaderChanged != nil {
Expand Down Expand Up @@ -108,7 +108,7 @@ func (c Config) Acquire(ctx context.Context) error {
// WriteEntry should fail immediately.
}
default:
return err
return aqErr
}
if lastEntry.ElectionNumber == entry.NoElections {
// There haven't been any elections yet, just loop and
Expand Down
2 changes: 1 addition & 1 deletion gcs/decider.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type failedAcquisitionErr struct {
}

func (f *failedAcquisitionErr) Error() string {
return fmt.Sprintf("failed to acquire lock: %s", f.err)
return "failed to acquire lock: " + f.err.Error()
}

func (f *failedAcquisitionErr) Unwrap() error {
Expand Down