Skip to content

Latest commit

 

History

History
46 lines (37 loc) · 1.17 KB

README.md

File metadata and controls

46 lines (37 loc) · 1.17 KB

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