An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 8.2% on proxy.golang.org

proxy.golang.org : github.com/comcast/go-leaderelection

Package leaderelection implements a leader election protocol in Go using the Zookeeper leader election recipe. The main steps to implement a leader election as as follows: Before leader election can take place the election needs to be initialized. This involves providing a live connection to Zookeeper and an existing Zookeeper node (resource) that represents the top level of the election to the NewElection function. In the above example if zkConn is not valid or "/election" doesn't already exist an error will be returned. Running an election will register this election instance as interested in becoming leader for the election resource that was provided in the call to NewElection (e.g., "/election"). Multiple candidates may be registered for the same election resource and contend for leadership of the resource. One will be chosen as the leader and the rest will become followers. In the event that the leader exits prior to the election terminating one of the followers will become leader. Example: This registers the candidate that created the election instance as a potential leader for the election resource. As it is started as a goroutine the candidate is expected to monitor one of several election related channels for election events. There are several channels that must be monitored during an election. The first is the channel returned by election.Status(). This channel is used to indicate to a follower that it has become leader. It is also used to signal the end of the election. This signaling occurs when the Election instance closes the Status() channel. When election end has been signaled via the closing of the Status() channel the client is expected to stop using the election. Errors may also be returned via the Status() channel. Errors generally indicate there has been a problem with the election. A network partition from Zookeeper is an example of an error that may occur. Errors are unrecoverable and mean the election is over for that candidate. The connFailCh highlights that the client owns the Zookeeper connection and is responsible for handling any errors associated with the Zookeeper connection. The for-ever loop indicates that the election continues until one of the halting conditions described above occurs. The "case <- connFailCh:" branch is used to monitor for Zookeeper connection problems. It is up to the client to decide what to do in this event. On channel close or Error events the client is expected to resign from the election as shown in the above code snippet. When the leader is done with the work associated with the election it is expected to terminate the election by calling the EndElection method. This is required to properly clean up election resources including termination of any existing followers.

Registry - Source - Documentation - JSON - codemeta.json
purl: pkg:golang/github.com/comcast/go-leaderelection
License: Apache-2.0
Latest release: almost 4 years ago
First release: almost 4 years ago
Namespace: github.com/comcast
Stars: 40 on GitHub
Forks: 15 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: about 21 hours ago

    Loading...
    Readme
    Loading...