Skip to content

A Go implementation of Raft Algorithm & A fault-tolerant primary/backup K/V storage system that use the implementation. Written just as learning project.

License

Notifications You must be signed in to change notification settings

HuyuYasumi/raft-kv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raft & KV

A Go implementation of Raft Algorithm & A fault-tolerant primary/backup K/V storage system that use the implementation.

Get the module

go get github.com/HuyuYasumi/raft-kv

Raft

See the implementation: raft

Primary/backup K/V storage system

Example

Run three k/v storage server instances

go run server/kvserver.go example/config/server1.yml
go run server/kvserver.go example/config/server2.yml
go run server/kvserver.go example/config/server3.yml

The number of servers must be odd and greater than or equal to 3.

# example/config/server1.yml

servers: # address list of all k/v servers
  - ip: 127.0.0.1
    port: 10001
  - ip: 127.0.0.1
    port: 10002
  - ip: 127.0.0.1
    port: 10003
me: 0 # index of my address in address list

You can use the simple command line client to communicate with k/v storage service

go run cli/kvcli.go example/config/client.yml
# example/config/client.yml

servers: # address list of all k/v servers
  - ip: 127.0.0.1
    port: 10001
  - ip: 127.0.0.1
    port: 10002
  - ip: 127.0.0.1
    port: 10003

Or use the client api

package main

import (
	"fmt"

	"github.com/HuyuYasumi/raft-kv/kv"
)

func main() {
	clientEnds := kv.GetClientEnds("example/config/client.yml")

	clerk := kv.MakeClerk(clientEnds)

	fmt.Printf("k1=%v\n", clerk.Get("k1"))

	clerk.Put("k1", "3")
	fmt.Printf("k1=%v\n", clerk.Get("k1"))

	clerk.Append("k1", "4")
	fmt.Printf("k1=%v\n", clerk.Get("k1"))
}

About

A Go implementation of Raft Algorithm & A fault-tolerant primary/backup K/V storage system that use the implementation. Written just as learning project.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages