https://github.com/yehohanan7/glock
Optimistic lock using persistent stores
https://github.com/yehohanan7/glock
cassandra consensus optimistic-locking optimisticlock
Last synced: about 2 months ago
JSON representation
Optimistic lock using persistent stores
- Host: GitHub
- URL: https://github.com/yehohanan7/glock
- Owner: yehohanan7
- Created: 2017-11-07T16:52:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-10T16:37:48.000Z (over 8 years ago)
- Last Synced: 2025-06-25T02:44:14.783Z (about 1 year ago)
- Topics: cassandra, consensus, optimistic-locking, optimisticlock
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Glock [](https://travis-ci.org/yehohanan7/glock?branch=master) [](https://goreportcard.com/report/github.com/yehohanan7/glock)
## Introduction
Glock is used to achieve consensus between different hosts using a persistent stores.
### Glock with Cassandra
The cassandra implementation is based on the article here: https://www.datastax.com/dev/blog/consensus-on-cassandra
#### Setup
```bash
CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': 1};
CREATE TABLE test.lock (id text, owner text, PRIMARY KEY (id)) WITH default_time_to_live = 5;
```
#### Glock example
```go
import (
"github.com/gocql/gocql"
"github.com/yehohanan7/glock"
)
session := //initialize a cassandra session using gocql
config := glock.Config{
"host1",
time.NewTicker(2 * time.Second),
glock.NewCassandraStore(session),
notifyCh,
stopCh,
}
go glock.Start(config)
for {
select {
case state := <-notifyCh:
if state == "master" {
fmt.Println("became master")
}
if state == "slave" {
fmt.Println("became slave")
}
}
}
```