Skip to content

yehohanan7/glock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Glock Build Status Go Report Card

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

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

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")
		}
	}
}

Releases

No releases published

Packages

No packages published