paxoskv

package
v0.0.0-...-9789875 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package paxoskv provides fault-tolerant KV-store components based on paxos, including service and client.

Every KVPaxos wrap a paxos peer to do the consensus thing. All the KVPaxos cooperate as whole fault-tolerant KV-store system. The system will get an agreement on the Ops with the consecutive numbers, i.e. the paxos instance. The consecutive Ops construct a State Machine, representing the actions on the key-value pairs in the KV-store.

The ops are three kinds: Get/Put/Append. We can records all the ops in the State Machine, so we can fetch the acual value of the specific key. Using the State Machine to log the actions on the data is a popular way to write and read the data. Because we needn't modify the data directly, we could undo the ops to recover the data, or replay ops to make a replication.

Refer to the chapter 3 "Implementing a State Machine" in Leslie Lamport's paper "Paxos Made Simple" about how to use a state machine to represent the states in a system. Likewise, the key-value pairs are values of the KV-store.

Index

Constants

View Source
const (
	OK           = "OK"
	ErrNoKey     = "ErrNoKey"
	ErrPending   = "ErrPending"
	ErrForgotten = "ErrForgotten"
)

Errors for PutAppend and Get RPC call.

View Source
const (
	Get    = "Get"
	Put    = "Put"
	Append = "Append"
)

Three kinds of Ops.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is for the Paxos-based KV-store service.

func MakeClient

func MakeClient(servers []string) *Client

MakeClient inits a new Client with the servers addresses.

func (*Client) Append

func (ck *Client) Append(key string, value string)

Append a value to the original value of the specific key.

func (*Client) Get

func (ck *Client) Get(key string) string

Get gets the corresponding value for the specific key. Return "" if the key doesn't exist. It tries forever in the face of all other errors (i.e. except for OK and ErrNoKey).

func (*Client) Put

func (ck *Client) Put(key string, value string)

Put puts the key-value pair into the database.

func (*Client) PutAppend

func (ck *Client) PutAppend(key string, value string, op string)

PutAppend puts or append a value onto the specific key. Op arg indicates the type of operations, "Put" or "Append".

type GetArgs

type GetArgs struct {
	Key string
	// You'll have to add definitions here.
	ID int64
}

GetArgs is the args for Get RPC call.

type GetReply

type GetReply struct {
	Err   string
	Value string
}

GetReply is the reply for Get RPC call.

type KVPaxos

type KVPaxos struct {
	// contains filtered or unexported fields
}

KVPaxos is a peer in the KVPaxos group, which cooperate as a whole fault-tolerant KV-store. Every KVPaxos wraps a paxos peer to do the consensus thing, i.e. agreeing every Op in the State Machine.

func StartServer

func StartServer(servers []string, me int) *KVPaxos

StartServer init a KV-store server based on the paxos. servers[] contains the addresses of the set of KV-stores servers that will coopreate via paxos to form a whole fault-tolerant key-value service. me is the index of the current server in servers[].

func (*KVPaxos) Get

func (kv *KVPaxos) Get(args *GetArgs, reply *GetReply) error

Get is RPC routine invoked by paxoskv.Client to get the corresponding value of the specific key.

func (*KVPaxos) PutAppend

func (kv *KVPaxos) PutAppend(args *PutAppendArgs, reply *PutAppendReply) error

PutAppend is RPC routine invoked by paxoskv.Client to put or append a value for the specific key.

func (*KVPaxos) TryDecide

func (kv *KVPaxos) TryDecide(op Op) (string, string)

TryDecide try to get an aggrement on the operation in one of the paxos instance. The seq will be increased until deciding the op in the State Machine. Then the chosen value by the paxos peers could be applied to the KV-store. Note that not every chosen value must be applied to the key-values immediately. Please consider that Put and Append operations don't return the actual value of the specific key.

type Op

type Op struct {
	// Your definitions here.
	// Field names must start with capital letters,
	// otherwise RPC will break.
	OpName string
	Key    string
	Value  string
	ID     int64
}

Op is a Operation in the State Machine, representing an action on the key-value pairs. In the KV-store, there are three types of operations: Get/Put/Append. Every Op is the object, which will be gotten an agreement on the paxos peers.

type PutAppendArgs

type PutAppendArgs struct {
	// You'll have to add definitions here.
	Key   string
	Value string
	Op    string // "Put" or "Append"
	ID    int64
}

PutAppendArgs is the args for PutAppend RPC call.

type PutAppendReply

type PutAppendReply struct {
	Err string
}

PutAppendReply is the reply for PutAppend RPC call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL