Skip to content

Instantly share code, notes, and snippets.

View xiang90's full-sized avatar

Xiang xiang90

  • Bay Area
View GitHub Profile
package main
import (
"fmt"
"github.com/boltdb/bolt"
)
func main() {
iterateBucket("db", "key")
@xiang90
xiang90 / raft.go
Last active August 29, 2015 14:06
// raft implements the raft protocol
type raft interface {
step(m Message)
messages() []Message
proposal(data []byte)
applyPeerAdd(pi PeerInfo) // or using step through messaging?
applyPeerRemove(pi PeerInfo) // or using step through messaging?
}
// a log interface used by raft pkg.
@xiang90
xiang90 / ttl.md
Created November 7, 2013 06:55
ttl

TTL Solution

One constraint: we are not able to sync time. So we just do best effort.

##Solution: ###Changes in raft

  1. Add a sync command in raft
type SyncCommand struct {
 Time time.Time `json:"time"`
package main
import (
"fmt"
"net/http"
"time"
)
func main() {
tr := &http.Transport{

TTL Solution

One constraint: we are not able to sync time. So we just do best effort.

##Solution:

  1. Add a expiration command:
type ExpirationCommand struct {
    Key         string    `json:"key"`
	CreateIndex uint64 `json:"createIndex"`