Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diamanticom/etcd-lock
Distributed lock implementation using etcd
https://github.com/diamanticom/etcd-lock
Last synced: 4 days ago
JSON representation
Distributed lock implementation using etcd
- Host: GitHub
- URL: https://github.com/diamanticom/etcd-lock
- Owner: diamanticom
- License: apache-2.0
- Created: 2014-11-24T18:51:28.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-10-18T08:50:26.000Z (about 8 years ago)
- Last Synced: 2024-07-12T02:06:54.253Z (4 months ago)
- Language: Go
- Size: 193 KB
- Stars: 75
- Watchers: 12
- Forks: 23
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
etcd-lock
=========master.go
- Master election using etcd.
- TTL is refreshed by the lockholder.
- Master failure results in another node acquiring the lock and becoming master.
- Sample usage below.rwlock.go
- Distributed read write lock implementation using etcd.
- Implemented using CreateInOrder (queue).
- Fairness ensured by not letting reads leapfrog writes.
- Queue TTL protects against node failures after requesting a lock.
- Lock TTL protects against node failures after acquiring a lock.Sample usage
============
```
import ".../utils"func someFunc() {
// Create an etcd client and a lock.
lock, err := utils.NewMaster(utils.NewEtcdRegistry(), "foo", "172.16.1.101", 30)// Start a go routine to process events.
go processEvents(lock.EventsChan())// Start the attempt to acquire the lock.
lock.Start()
}func processEvents(eventsCh <-chan utils.MasterEvent) {
for {
select {
case e := <-k.eventsCh:
if e.Type == utils.MasterAdded {
// Acquired the lock.
} else if e.Type == utils.MasterDeleted {
// Lost the lock.
} else {
// Lock ownership changed.
}
...
}
}
}
```