phalanx

package module
v0.0.0-...-5d151e8 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound represnts that the key is not found in the stable store
	ErrKeyNotFound = errors.New("not found")
)

Functions

func NewNode

func NewNode(
	id int,
	peers []string,
	join bool,
	getSnapshot func() ([]byte, error),
	proposeC <-chan []byte,
	confChangeC <-chan raftpb.ConfChange,
	walDir string,
	snapDir string,
) (
	chan []byte,
	chan error,
	chan *snap.Snapshotter,
)

NewNode creates new phalanx node

func RegisterStableStore

func RegisterStableStore(
	driverName string,
	driver StableStoreDriver)

RegisterStableStore registers the given driver

Types

type Batch

type Batch interface {
	Put(region string, key, value []byte)
	Delete(region string, key []byte)
	Len() int
	Reset()
}

Batch is a write batch

type CommandHandler

type CommandHandler interface {
	// Apply applies the command to the stableStorage
	Apply(
		regioin string,
		command *phalanxpb.Command,
		stableStorage StableStore,
	)
}

CommandHandler provides command hadler

type DB

type DB interface {
	Get(key []byte) ([]byte, error)
	Propose(command *phalanxpb.Command) error
}

DB is distributed embeddable db

func NewDB

func NewDB(
	regionName string,
	snapshotter *snap.Snapshotter,
	proposeC chan []byte,
	commitC chan []byte,
	errorC chan error,
	stableStore StableStore,
	commandHander CommandHandler,
) DB

NewDB creates new db

type ErrLogStoreDriverNotFound

type ErrLogStoreDriverNotFound struct {
	DriverName string
}

ErrLogStoreDriverNotFound is T/O

func (*ErrLogStoreDriverNotFound) Error

func (e *ErrLogStoreDriverNotFound) Error() string

type ErrRegionAlreadyExists

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

ErrRegionAlreadyExists is T/O

func NewErrRegionAlreadyExists

func NewErrRegionAlreadyExists(region string) *ErrRegionAlreadyExists

NewErrRegionAlreadyExists creates ErrRegionAlreadyExists

func (*ErrRegionAlreadyExists) Error

func (e *ErrRegionAlreadyExists) Error() string

type ErrRegionNotFound

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

ErrRegionNotFound is T/O

func NewRegionNotFound

func NewRegionNotFound(region string) *ErrRegionNotFound

NewRegionNotFound creates ErrRegionNotFound

func (*ErrRegionNotFound) Error

func (e *ErrRegionNotFound) Error() string

type ErrStableStoreDriverNotFound

type ErrStableStoreDriverNotFound struct {
	DriverName string
}

ErrStableStoreDriverNotFound is T/O

func (*ErrStableStoreDriverNotFound) Error

type Iterator

type Iterator interface {
	Key() []byte
	Value() []byte
	Release()
	Error() error
	// First moves the iterator to the first key/value pair. If the iterator
	// only contains one key/value pair then First and Last would moves
	// to the same key/value pair.
	// It returns whether such pair exist.
	First() bool

	// Last moves the iterator to the last key/value pair. If the iterator
	// only contains one key/value pair then First and Last would moves
	// to the same key/value pair.
	// It returns whether such pair exist.
	Last() bool

	// Seek moves the iterator to the first key/value pair whose key is greater
	// than or equal to the given key.
	// It returns whether such pair exist.
	//
	// It is safe to modify the contents of the argument after Seek returns.
	Seek(key []byte) bool

	// Next moves the iterator to the next key/value pair.
	// It returns false if the iterator is exhausted.
	Next() bool

	// Prev moves the iterator to the previous key/value pair.
	// It returns false if the iterator is exhausted.
	Prev() bool
}

Iterator is an iterator of db not thread safe

type Range

type Range struct {
	Start []byte
	End   []byte
}

Range is a key range

func BytesPrefixRange

func BytesPrefixRange(prefix []byte) *Range

BytesPrefixRange returns Range of the givein prefix

func FullScanRange

func FullScanRange() *Range

FullScanRange returns full scan range

type Snapshot

type Snapshot interface {
	Get(region string, key []byte) (value []byte, err error)
	MultiGet(region string, keys ...[]byte) (values [][]byte, err error)
	Has(region string, key []byte) (ret bool, err error)
	NewIterator(region string, slice *Range) (Iterator, error)
	Release()
}

Snapshot is a snapshot of StableStorage

type StableStore

type StableStore interface {
	// CreateBatch creates batch
	CreateBatch() Batch
	// Write apply the given batch to the StableStorage
	Write(batch Batch) error
	// Close Close closes the StableStorage
	Close() error
	// GetSnapshot returns snapshot
	GetSnapshot() (Snapshot, error)
	// CreateCheckpoint creates a checkpoint of the given region
	// In creating checkpoint, StableStore must be able to get keys
	// CreateCheckpoint returns checkpointInfo which enable stable store to restore to the checkpoint
	// For example, marshaled Amazon S3 bucket and object name.
	CreateCheckpoint(region string) ([]byte, error)
	// RestoreToCheckpoint restores the given region to checkpoint
	RestoreToCheckpoint(region string, checkpointInfo []byte) error
	// CreateRegion creates a region
	CreateRegion(name string) error
	// DropRegion drop a region
	DropRegion(name string) error
	// HasRegion returns if a region exists
	HasRegion(name string) bool
}

StableStore is a local persistent storage.

func NewStableStore

func NewStableStore(name string, path string) (StableStore, error)

NewStableStore creates new stable store

type StableStoreDriver

type StableStoreDriver interface {
	New(path string) (StableStore, error)
}

StableStoreDriver is driver of stable store

Directories

Path Synopsis
examples
stablestore

Jump to

Keyboard shortcuts

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