memkv

package
v0.0.0-...-c621569 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CheckpointInterval = time.Minute

Variables

View Source
var File_message_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type GetOptions

type GetOptions struct {
	// Requires strong consistent read
	// Guarentees to see all the writes that happens before this read request in physical time
	Linearizability bool
	// The last seen LSN
	// By default session consistency is provided by connecting to the same replica
	// however, in case of failover, a provided SessionLSN will provide the same session
	// consistency guarentee by blocking the request until LSN has been observed by the replica
	// Session consistency provides the following guarentees: Read-your-write, Monotic Read, Read after write
	// Will be ignored if Linearizability is true
	SessionLSN *int64
}

type GetReq

type GetReq struct {
	Key     string
	Options GetOptions
}

type GetResp

type GetResp struct {
	LSN   int64 // the most recent LSN this request had been observed
	Exist bool
	Value []byte
}

type KVRequest

type KVRequest struct {
	OriginNode string `protobuf:"bytes,1,opt,name=origin_node,json=originNode,proto3" json:"origin_node,omitempty"`
	// Types that are assignable to Request:
	//
	//	*KVRequest_Set
	Request isKVRequest_Request `protobuf_oneof:"request"`
	// contains filtered or unexported fields
}

func (*KVRequest) Descriptor deprecated

func (*KVRequest) Descriptor() ([]byte, []int)

Deprecated: Use KVRequest.ProtoReflect.Descriptor instead.

func (*KVRequest) GetOriginNode

func (x *KVRequest) GetOriginNode() string

func (*KVRequest) GetRequest

func (m *KVRequest) GetRequest() isKVRequest_Request

func (*KVRequest) GetSet

func (x *KVRequest) GetSet() *SetRequest

func (*KVRequest) ProtoMessage

func (*KVRequest) ProtoMessage()

func (*KVRequest) ProtoReflect

func (x *KVRequest) ProtoReflect() protoreflect.Message

func (*KVRequest) Reset

func (x *KVRequest) Reset()

func (*KVRequest) String

func (x *KVRequest) String() string

type KVRequest_Set

type KVRequest_Set struct {
	Set *SetRequest `protobuf:"bytes,2,opt,name=set,proto3,oneof"`
}

type KVStore

type KVStore interface {
	Set(req SetReq) (*SetResp, error)
	Get(req GetReq) (*GetResp, error)
}

A key-value store

type MemKvStore

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

A memory based key/value store using Raft All data will be held in memory and we use checkpointing to periodically persist data back to disk along with the last seen LSN. Upon recovery we'll reload the data into memory and replay all raft messages since the last know LSN. So we literally use Raft replication log as the write ahead log for the database

func NewMemKVStore

func NewMemKVStore(config StoreConfig, raft raft.Raft, logger *log.Logger) *MemKvStore

func (*MemKvStore) Get

func (s *MemKvStore) Get(req GetReq) (*GetResp, error)

func (*MemKvStore) Set

func (s *MemKvStore) Set(req SetReq) (*SetResp, error)

func (*MemKvStore) Start

func (s *MemKvStore) Start()

func (*MemKvStore) Stop

func (s *MemKvStore) Stop()

type SetOptions

type SetOptions struct {
	// concurrency control
	// only proceed the operation if timestamp matches
	IfValueIs []byte
	IfLSNIs   *int64
	IfExistIs *bool
}

type SetReq

type SetReq struct {
	Key   string
	Value []byte
	// Set true to delete the value
	Delete  bool
	Options SetOptions
}

type SetRequest

type SetRequest struct {
	RequestId  string `protobuf:"bytes,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`
	Key        string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
	Value      []byte `protobuf:"bytes,3,opt,name=value,proto3,oneof" json:"value,omitempty"`
	Delete     *bool  `protobuf:"varint,4,opt,name=delete,proto3,oneof" json:"delete,omitempty"`
	IfValueIs  []byte `protobuf:"bytes,5,opt,name=if_value_is,json=ifValueIs,proto3,oneof" json:"if_value_is,omitempty"`
	IfLsnIs    *int64 `protobuf:"varint,6,opt,name=if_lsn_is,json=ifLsnIs,proto3,oneof" json:"if_lsn_is,omitempty"`
	IfExistsIs *bool  `protobuf:"varint,7,opt,name=if_exists_is,json=ifExistsIs,proto3,oneof" json:"if_exists_is,omitempty"`
	// contains filtered or unexported fields
}

func (*SetRequest) Descriptor deprecated

func (*SetRequest) Descriptor() ([]byte, []int)

Deprecated: Use SetRequest.ProtoReflect.Descriptor instead.

func (*SetRequest) GetDelete

func (x *SetRequest) GetDelete() bool

func (*SetRequest) GetIfExistsIs

func (x *SetRequest) GetIfExistsIs() bool

func (*SetRequest) GetIfLsnIs

func (x *SetRequest) GetIfLsnIs() int64

func (*SetRequest) GetIfValueIs

func (x *SetRequest) GetIfValueIs() []byte

func (*SetRequest) GetKey

func (x *SetRequest) GetKey() string

func (*SetRequest) GetRequestId

func (x *SetRequest) GetRequestId() string

func (*SetRequest) GetValue

func (x *SetRequest) GetValue() []byte

func (*SetRequest) ProtoMessage

func (*SetRequest) ProtoMessage()

func (*SetRequest) ProtoReflect

func (x *SetRequest) ProtoReflect() protoreflect.Message

func (*SetRequest) Reset

func (x *SetRequest) Reset()

func (*SetRequest) String

func (x *SetRequest) String() string

type SetResp

type SetResp struct {
	Success bool

	// current LSN
	LSN int64
}

type StoreConfig

type StoreConfig struct {
	DatafilePath   string
	DatafilePrefix string
}

Jump to

Keyboard shortcuts

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