keystore

package
v0.0.0-...-71b6798 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Operation Operation `json:"command"`
	Key       string    `json:"key"`
	Value     string    `json:"value,omitempty"`
}

func GetCommand

func GetCommand(data []byte) (*Command, error)

GetCommand: creates an Command object from raw byte data

type ErrUnknownCommand

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

func (*ErrUnknownCommand) Error

func (err *ErrUnknownCommand) Error() string

type KeyStore

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

KeyStore is the distributed Key-value store It uses `Raft` internally to get consensus from the peers

func New

func New(nodeID, address string, bootstrap_cluster bool) *KeyStore

Create new KeyStore. bootstrap_cluster is flag; whether to create a Raft cluster. This only needs to be ran once in the lifespan of a cluster

func (*KeyStore) Delete

func (store *KeyStore) Delete(key string) error

Delete, deletes the given key in highly consistent manner

It must be called through leader otherwise it will return an error

func (*KeyStore) Get

func (store *KeyStore) Get(key string) (string, bool)

Get the Value from data backend

func (*KeyStore) GetOrCreate

func (store *KeyStore) GetOrCreate(key, value string) (bool, string, error)

GetOrCreate, gets the given key or creates incase it doesn't exist in highly consistent manner

It must be called through leader otherwise it will return an error returns: created, value, error

func (*KeyStore) Replicate

func (store *KeyStore) Replicate(nodeID, address string)

Add voters to the cluster, must be ran from leader otherwise it will fail Our Consesnsus will make sure to bring the replica to the latest state

func (*KeyStore) Set

func (store *KeyStore) Set(key, value string) error

Set, sets the given key with value in highly consistent manner

It must be called through leader otherwise it will return an error

type KeyStoreFSM

type KeyStoreFSM KeyStore

KeyStoreFSM implements the raft.FSM interface for the KeyStore

It is basically a KeyStore, but it's FSM implementation is extracted out for maintainablity purpose.

func (*KeyStoreFSM) Apply

func (store *KeyStoreFSM) Apply(log *raft_lib.Log) interface{}

Apply is called once a log entry is committed by a majority of the cluster.

Apply should apply the log to the FSM. Apply must be deterministic and produce the same result on all peers in the cluster.

The returned value is returned to the client as the ApplyFuture.Response.

func (*KeyStoreFSM) Restore

func (store *KeyStoreFSM) Restore(snapshot io.ReadCloser) error

Implements Restore, It will restore the snapshopt back to the KeyStore

func (*KeyStoreFSM) Snapshot

func (store *KeyStoreFSM) Snapshot() (raft_lib.FSMSnapshot, error)

Implements Snapshot, this helps raft to not have unbounded logs, And data can be recovered later on

type KeyStoreSnapshot

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

KeyStoreSnapshot holds snapshot data returned by FSM, which will be saved to the SnapshotStore which then later can be recoved.

func (*KeyStoreSnapshot) Persist

func (snap *KeyStoreSnapshot) Persist(sink raft_lib.SnapshotSink) error

Persist is an implementation to write Snapshot data so that it can be saved

func (*KeyStoreSnapshot) Release

func (snap *KeyStoreSnapshot) Release()

This implements Release, it will be called when we will be done with the snapshot

type Operation

type Operation string
const (
	GET           Operation = "GET"
	SET           Operation = "SET"
	DELETE        Operation = "DELETE"
	GET_OR_CREATE Operation = "GET_OR_CREATE"
)

Operations that can be performed on the KeyStore

Jump to

Keyboard shortcuts

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