hexalog

package module
v0.0.0-...-0c69f90 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2017 License: MPL-2.0 Imports: 19 Imported by: 3 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hexalog Build Status

Hexalog implements a consensus protocol in a peer-to-peer system leveraging the underlying overlay network.

Hexalog is unique in that it does not have a dedicated master or a leader-follower setup.
Instead a set of peers participating in the cluster, vote amongst themselves to come to
come to consensus.

Roadmap
  • Persistence
  • Signing & verification

Documentation

Overview

Package hexalog is a generated protocol buffer package.

It is generated from these files:

rpc.proto

It has these top-level messages:

Entry
UnsafeKeylogIndex
KeySeed
ReqResp
RequestOptions
Participant

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHexalogRPCServer

func RegisterHexalogRPCServer(s *grpc.Server, srv HexalogRPCServer)

Types

type Ballot

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

Ballot holds information to execute a singular distributed operation ensuring consistency. It is primarily used to track the state of proposal and commit votes to appropriately handle an operation.

func (*Ballot) Closed

func (b *Ballot) Closed() bool

Closed returns whether or not a ballot has been closed

func (*Ballot) Commits

func (b *Ballot) Commits() int

Commits safely returns the number of current commits

func (*Ballot) Error

func (b *Ballot) Error() error

Error returns the error the ballot was closed with if any

func (*Ballot) Future

func (b *Ballot) Future() *FutureEntry

Future returns a FutureEntry associated to the ballot. It is the entry being voted on and can be used to wait for it to be applied to the FSM.

func (*Ballot) Proposals

func (b *Ballot) Proposals() int

Proposals safely returns the number of current proposals

func (*Ballot) Runtime

func (b *Ballot) Runtime() time.Duration

Runtime returns the amount of time taken for this ballot to complete

func (*Ballot) Wait

func (b *Ballot) Wait() error

Wait blocks until voting on the ballot is complete

type Config

type Config struct {
	AdvertiseHost      string
	HealBufSize        int                    // Buffer size for heal requests
	BroadcastBufSize   int                    // proposal and commit broadcast buffer
	BallotReapInterval time.Duration          // interval at which old ballots are cleaned up
	TTL                time.Duration          // ttl for each ballot
	Votes              int                    // minimum default votes required if not supplied
	LamportClock       *hexatype.LamportClock // Cluster clock
	Hasher             func() hash.Hash
	// contains filtered or unexported fields
}

Config holds the configuration for the log. This is used to initialize the log.

func DefaultConfig

func DefaultConfig(advHost string) *Config

DefaultConfig returns a sane set of default configurations. The default hash function used is SHA1

type EchoFSM

type EchoFSM struct{}

EchoFSM implements the FSM interface that simply echos the entry to stdout. It exists simplying for testing and debug purposes.

func (*EchoFSM) Apply

func (fsm *EchoFSM) Apply(entryID []byte, entry *Entry) interface{}

Apply simply logs the Entry to stdout

type Entry

type Entry struct {
	Key       []byte `protobuf:"bytes,1,opt,name=Key,proto3" json:"Key,omitempty"`
	Previous  []byte `protobuf:"bytes,2,opt,name=Previous,proto3" json:"Previous,omitempty"`
	Height    uint32 `protobuf:"varint,3,opt,name=Height" json:"Height,omitempty"`
	Timestamp uint64 `protobuf:"varint,4,opt,name=Timestamp" json:"Timestamp,omitempty"`
	LTime     uint64 `protobuf:"varint,5,opt,name=LTime" json:"LTime,omitempty"`
	Data      []byte `protobuf:"bytes,6,opt,name=Data,proto3" json:"Data,omitempty"`
}

Hexalog entry

func (*Entry) Clone

func (entry *Entry) Clone() *Entry

Clone clones an entry

func (*Entry) Descriptor

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

func (*Entry) GetData

func (m *Entry) GetData() []byte

func (*Entry) GetHeight

func (m *Entry) GetHeight() uint32

func (*Entry) GetKey

func (m *Entry) GetKey() []byte

func (*Entry) GetLTime

func (m *Entry) GetLTime() uint64

func (*Entry) GetPrevious

func (m *Entry) GetPrevious() []byte

func (*Entry) GetTimestamp

func (m *Entry) GetTimestamp() uint64

func (*Entry) Hash

func (entry *Entry) Hash(hashFunc hash.Hash) []byte

Hash computes the hash of the entry using the hash function

func (Entry) MarshalJSON

func (entry Entry) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaler for Entry

func (*Entry) ProtoMessage

func (*Entry) ProtoMessage()

func (*Entry) Reset

func (m *Entry) Reset()

func (*Entry) String

func (m *Entry) String() string

type EntryStore

type EntryStore interface {
	// Name of store
	Name() string

	// Get an entry by id
	Get(id []byte) (*Entry, error)

	// Set an entry by the id
	Set(id []byte, entry *Entry) error

	// Delete an entry by id
	Delete(id []byte) error

	// Returns the number of entries in the store
	Count() int64

	// Close the store
	Close() error
}

EntryStore implements a datastore for log entries.

type FSM

type FSM interface {
	Apply(entryID []byte, entry *Entry) interface{}
}

FSM is the application finite-state-machine. This is implemented by the application using the library. It should return an interface or an error. The return value is only checked for an error type internally.

type FutureEntry

type FutureEntry struct {

	// Entry to be applied
	Entry *Entry
	// contains filtered or unexported fields
}

FutureEntry is an entry that been committed to the stable store but has not yet been applied to the FSM.

func NewFutureEntry

func NewFutureEntry(id []byte, entry *Entry) *FutureEntry

NewFutureEntry instantiates a new FutureEntry with an Entry. It is an entry that is yet to be applied to the log. It can be used to wait for the entry to be applied. It takes the hash id of the entry and entry as parameters.

func (*FutureEntry) ID

func (entry *FutureEntry) ID() []byte

ID returns the id provided upon initiation. It is used to verify the entry by computing the hash of the entry and comparing against this id.

func (FutureEntry) MarshalJSON

func (entry FutureEntry) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaller for a FutureEntry

func (*FutureEntry) Runtime

func (entry *FutureEntry) Runtime() time.Duration

Runtime returns the time taken from when the entry was set to be applied to the FSM until it was actually applied to the FSM

func (*FutureEntry) Wait

func (entry *FutureEntry) Wait(timeout time.Duration) (resp interface{}, err error)

Wait blocks until the entry has been applied to the FSM or the timeout has been reached It returns data from the fsm.Apply response or an error

type Hexalog

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

Hexalog is the core log that is responsible for consensus, voting, election, serialization and all other aspects pertaining to the log consistency

func NewHexalog

func NewHexalog(conf *Config, appFSM FSM, entries EntryStore, index IndexStore, stableStore StableStore,
	trans Transport) (*Hexalog, error)

NewHexalog initializes a new Hexalog and starts the entry broadcaster. This call will block until fsm checks are performed. ie. the log is caught up based on the stable store. The transport must be registered to grpc before passing it to hexalog

func (*Hexalog) Commit

func (hlog *Hexalog) Commit(entry *Entry, opts *RequestOptions) (*Ballot, error)

Commit tries to commit an already proposed entry to the log.

func (*Hexalog) Get

func (hlog *Hexalog) Get(key, id []byte) (*Entry, error)

Get returns an entry for a key by the id

func (*Hexalog) Heal

func (hlog *Hexalog) Heal(key []byte, opts *RequestOptions) error

Heal submits a heal request for the given key. It returns an error if the options are invalid.

func (*Hexalog) Leader

func (hlog *Hexalog) Leader(key []byte, locs []*Participant) (*KeyLeader, error)

Leader returns the leader for a key. It gets the last entry from the given location set and finds the one with the max height which it considered to be the leader. This is technically the pseudo-leader

func (*Hexalog) New

func (hlog *Hexalog) New(key []byte) *Entry

New returns a new Entry to be appended to the log for the given key.

func (*Hexalog) Propose

func (hlog *Hexalog) Propose(entry *Entry, opts *RequestOptions) (*Ballot, error)

Propose proposes an entry to the log. It votes on a ballot if it exists or creates one then votes. If required votes has been reach it also moves to the commit phase.

func (*Hexalog) Seed

func (hlog *Hexalog) Seed(existing string, bufsize, parallel int) error

Seed gets seed keys from host and starts seeding the local log. bufsize is the seed buffer size, parallel is the number of parallel keys to seed.

func (*Hexalog) Shutdown

func (hlog *Hexalog) Shutdown()

Shutdown signals a shutdown and waits for all go-routines to exit before returning. It will take atleast the amount of time specified as the ballot reap interval as shutdown for the ballot reaper is checked at the top of the loop. It does not shutdown the stores as they may be in use by other components

func (*Hexalog) Stats

func (hlog *Hexalog) Stats() *Stats

Stats returns internal information of the log regarding its current activity

type HexalogRPCClient

type HexalogRPCClient interface {
	ProposeRPC(ctx context.Context, in *ReqResp, opts ...grpc.CallOption) (*ReqResp, error)
	CommitRPC(ctx context.Context, in *ReqResp, opts ...grpc.CallOption) (*ReqResp, error)
	NewRPC(ctx context.Context, in *ReqResp, opts ...grpc.CallOption) (*ReqResp, error)
	GetRPC(ctx context.Context, in *ReqResp, opts ...grpc.CallOption) (*ReqResp, error)
	LastRPC(ctx context.Context, in *ReqResp, opts ...grpc.CallOption) (*ReqResp, error)
	// Push a keylog from a given seek position
	PushKeylogRPC(ctx context.Context, opts ...grpc.CallOption) (HexalogRPC_PushKeylogRPCClient, error)
	// Pull a keylog
	PullKeylogRPC(ctx context.Context, opts ...grpc.CallOption) (HexalogRPC_PullKeylogRPCClient, error)
	// Seed keys to build the log
	SeedKeysRPC(ctx context.Context, in *ReqResp, opts ...grpc.CallOption) (HexalogRPC_SeedKeysRPCClient, error)
}

func NewHexalogRPCClient

func NewHexalogRPCClient(cc *grpc.ClientConn) HexalogRPCClient

type HexalogRPCServer

type HexalogRPCServer interface {
	ProposeRPC(context.Context, *ReqResp) (*ReqResp, error)
	CommitRPC(context.Context, *ReqResp) (*ReqResp, error)
	NewRPC(context.Context, *ReqResp) (*ReqResp, error)
	GetRPC(context.Context, *ReqResp) (*ReqResp, error)
	LastRPC(context.Context, *ReqResp) (*ReqResp, error)
	// Push a keylog from a given seek position
	PushKeylogRPC(HexalogRPC_PushKeylogRPCServer) error
	// Pull a keylog
	PullKeylogRPC(HexalogRPC_PullKeylogRPCServer) error
	// Seed keys to build the log
	SeedKeysRPC(*ReqResp, HexalogRPC_SeedKeysRPCServer) error
}

type HexalogRPC_PullKeylogRPCClient

type HexalogRPC_PullKeylogRPCClient interface {
	Send(*ReqResp) error
	Recv() (*ReqResp, error)
	grpc.ClientStream
}

type HexalogRPC_PullKeylogRPCServer

type HexalogRPC_PullKeylogRPCServer interface {
	Send(*ReqResp) error
	Recv() (*ReqResp, error)
	grpc.ServerStream
}

type HexalogRPC_PushKeylogRPCClient

type HexalogRPC_PushKeylogRPCClient interface {
	Send(*ReqResp) error
	Recv() (*ReqResp, error)
	grpc.ClientStream
}

type HexalogRPC_PushKeylogRPCServer

type HexalogRPC_PushKeylogRPCServer interface {
	Send(*ReqResp) error
	Recv() (*ReqResp, error)
	grpc.ServerStream
}

type HexalogRPC_SeedKeysRPCClient

type HexalogRPC_SeedKeysRPCClient interface {
	Recv() (*KeySeed, error)
	grpc.ClientStream
}

type HexalogRPC_SeedKeysRPCServer

type HexalogRPC_SeedKeysRPCServer interface {
	Send(*KeySeed) error
	grpc.ServerStream
}

type InMemEntryStore

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

InMemEntryStore is an in-memory implementation of an EntryStore

func NewInMemEntryStore

func NewInMemEntryStore() *InMemEntryStore

NewInMemEntryStore creates a new in memory EntryStore initializing the internal map

func (*InMemEntryStore) Close

func (store *InMemEntryStore) Close() error

Close is a no-op to satisfy the EntryStore interface

func (*InMemEntryStore) Count

func (store *InMemEntryStore) Count() int64

Count returns the number of entries currently in the store.

func (*InMemEntryStore) Delete

func (store *InMemEntryStore) Delete(id []byte) error

Delete removes an entry from the store by the given id. It returns an error if the entry does not exist.

func (*InMemEntryStore) Get

func (store *InMemEntryStore) Get(id []byte) (*Entry, error)

Get tries to get an entry by or returns an error

func (*InMemEntryStore) Name

func (store *InMemEntryStore) Name() string

Name returns the name of the entry store

func (*InMemEntryStore) Set

func (store *InMemEntryStore) Set(id []byte, entry *Entry) error

Set sets the entry in the store by the given id. It returns no errors

type InMemIndexStore

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

InMemIndexStore implements an in-memory KeylogIndex store interface

func NewInMemIndexStore

func NewInMemIndexStore() *InMemIndexStore

NewInMemIndexStore initializes an in-memory store for KeylogIndexes.

func (*InMemIndexStore) Close

func (store *InMemIndexStore) Close() error

Close is a noop

func (*InMemIndexStore) Count

func (store *InMemIndexStore) Count() int64

Count returns the total number of keys in the index

func (*InMemIndexStore) GetKey

func (store *InMemIndexStore) GetKey(key []byte) (KeylogIndex, error)

GetKey returns a KeylogIndex from the store or an error if not found

func (*InMemIndexStore) Iter

func (store *InMemIndexStore) Iter(cb func([]byte, KeylogIndex) error) error

Iter iterates over each key and index

func (*InMemIndexStore) MarkKey

func (store *InMemIndexStore) MarkKey(key, marker []byte) (KeylogIndex, error)

MarkKey sets the marker on the key key. If the key does not exist a new one is created. It returns the KeylogIndex or an error.

func (*InMemIndexStore) Name

func (store *InMemIndexStore) Name() string

Name returns the name of the index store

func (*InMemIndexStore) NewKey

func (store *InMemIndexStore) NewKey(key []byte) (KeylogIndex, error)

NewKey creates a new KeylogIndex and adds it to the store. It returns an error if it already exists

func (*InMemIndexStore) RemoveKey

func (store *InMemIndexStore) RemoveKey(key []byte) error

RemoveKey removes the given key's index from the store. It does NOT remove the associated entry hash id's

type InMemStableStore

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

InMemStableStore implements an in-memory StableStore interface

func (*InMemStableStore) Close

func (store *InMemStableStore) Close() error

Close does nothing aside from satsifying the StableStore interface

func (*InMemStableStore) Get

func (store *InMemStableStore) Get(key []byte) ([]byte, error)

Get gets a key from the in-memory data structure

func (*InMemStableStore) Iter

func (store *InMemStableStore) Iter(cb func([]byte, []byte) error) error

Iter iterates over each key issuing the callback for each key and entry pair. The keys are not sorted.

func (*InMemStableStore) Name

func (store *InMemStableStore) Name() string

Name returns the name of the stable store

func (*InMemStableStore) Open

func (store *InMemStableStore) Open() error

Open initializes the in-memory data structure to begin writing. This must be called before attempting to write or read data.

func (*InMemStableStore) Set

func (store *InMemStableStore) Set(key, value []byte) error

Set sets a key to the value to the in memory structure

type IndexStore

type IndexStore interface {
	// Name of the store
	Name() string

	// Create a new KeylogIndex and add it to the store.
	NewKey(key []byte) (KeylogIndex, error)

	// Get a KeylogIndex from the store
	GetKey(key []byte) (KeylogIndex, error)

	// Create and/or get a KeylogIndex setting the marker if it is created.
	MarkKey(key []byte, marker []byte) (KeylogIndex, error)

	// Remove key if exists or return an error
	RemoveKey(key []byte) error

	// Iterate over each keylog index
	Iter(cb func(key []byte, kli KeylogIndex) error) error

	// Total number of keys in the index
	Count() int64

	// Close the index store
	Close() error
}

IndexStore implements a datastore for the log indexes. It contains all keys on a node with their associated keylog. The interface must be thread-safe

type KeyLeader

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

KeyLeader represens a leader for a key for a location set.

func (*KeyLeader) Entries

func (l *KeyLeader) Entries() []*Entry

Entries returns the last entries for each location

func (*KeyLeader) IsConsistent

func (l *KeyLeader) IsConsistent() (bool, *Participant)

IsConsistent returns true if all entries are consistent i.e all last entries for each location are the same. If consistent the natural key location is returned; if the key is inconsistent then the first inconsistent location is returned.

func (*KeyLeader) Key

func (l *KeyLeader) Key() []byte

Key returns the key in question

func (*KeyLeader) LastEntry

func (l *KeyLeader) LastEntry() *Entry

LastEntry returns the last entry of the leader

func (*KeyLeader) Location

func (l *KeyLeader) Location() *Participant

Location returns the Location of the leader

func (*KeyLeader) LocationSet

func (l *KeyLeader) LocationSet() []*Participant

LocationSet returns a slice of participating locations

func (KeyLeader) MarshalJSON

func (l KeyLeader) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaller to output a user friendly structure.

type KeySeed

type KeySeed struct {
	Key    []byte `protobuf:"bytes,1,opt,name=Key,proto3" json:"Key,omitempty"`
	Height uint32 `protobuf:"varint,2,opt,name=Height" json:"Height,omitempty"`
	Marker []byte `protobuf:"bytes,3,opt,name=Marker,proto3" json:"Marker,omitempty"`
	LTime  uint64 `protobuf:"varint,4,opt,name=LTime" json:"LTime,omitempty"`
}

func (*KeySeed) Descriptor

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

func (*KeySeed) GetHeight

func (m *KeySeed) GetHeight() uint32

func (*KeySeed) GetKey

func (m *KeySeed) GetKey() []byte

func (*KeySeed) GetLTime

func (m *KeySeed) GetLTime() uint64

func (*KeySeed) GetMarker

func (m *KeySeed) GetMarker() []byte

func (*KeySeed) ProtoMessage

func (*KeySeed) ProtoMessage()

func (*KeySeed) Reset

func (m *KeySeed) Reset()

func (*KeySeed) String

func (m *KeySeed) String() string

type KeySeedStream

type KeySeedStream struct {
	HexalogRPC_SeedKeysRPCClient
	// contains filtered or unexported fields
}

KeySeedStream is used to stream seed keys

func (*KeySeedStream) Recycle

func (stream *KeySeedStream) Recycle()

Recycle recycles the stream returning the conn back to the pool

type Keylog

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

Keylog represents a log for a given key. It manages operations against log entries for a key.

func NewKeylog

func NewKeylog(entries EntryStore, idx KeylogIndex, hasher func() hash.Hash) *Keylog

NewKeylog initializes a new log for a key. It takes a key, location id and hash function used to compute hash id's of log entries.

func (*Keylog) AppendEntry

func (keylog *Keylog) AppendEntry(entry *Entry) (err error)

AppendEntry appends an entry to the log. It returns an error if there is a previous hash mismatch

func (*Keylog) Close

func (keylog *Keylog) Close() error

Close the underlying index

func (*Keylog) GetEntry

func (keylog *Keylog) GetEntry(id []byte) (*Entry, error)

GetEntry gets and entry from the Keylog

func (*Keylog) GetIndex

func (keylog *Keylog) GetIndex() UnsafeKeylogIndex

GetIndex returns a KeylogIndex struct

func (*Keylog) Iter

func (keylog *Keylog) Iter(seek []byte, cb func(id []byte, entry *Entry) error) error

Iter iterates over entries starting from the seek position. It iterates over all entries if seek is nil

func (*Keylog) LastEntry

func (keylog *Keylog) LastEntry() *Entry

LastEntry returns the last entry in the Keylog. If there are no entries in the log , nil is returned.

func (*Keylog) RollbackEntry

func (keylog *Keylog) RollbackEntry(entry *Entry) (int, error)

RollbackEntry rolls the keylog back by the entry. It only rolls back if the entry is the last entry. It returns the number of entries remaining in the log and any errors occurred

type KeylogIndex

type KeylogIndex interface {
	// Key for the keylog index
	Key() []byte
	// SetMarker sets the marker
	SetMarker(id []byte) (bool, error)
	// returns the marker
	Marker() []byte

	// Append id checking previous is equal to prev.  Ltime is lamport time
	// attached to the entry
	Append(id, prev []byte, ltime uint64) error

	// Remove last entry and set the ltime.  The ltime here should be that of
	// the previous entry
	Rollback(ltime uint64) (int, bool)

	// Last entry id
	Last() []byte
	// Contains the entry id or not
	Contains(id []byte) bool
	// Iterate each entry id issuing the callback for each bailing on error
	Iter(seek []byte, cb func(id []byte) error) error
	// Number of entries
	Count() int
	// Height of the keylog
	Height() uint32
	// Index object used as readonly
	Index() UnsafeKeylogIndex
	// Flush to disk and remove from mem
	Close() error
}

KeylogIndex is the index interface for a keylog.

type LogStore

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

LogStore is the whole log containing all keys. It manages serialization of operations and all validation and checks required therein.

func NewLogStore

func NewLogStore(entries EntryStore, index IndexStore, hasher func() hash.Hash) *LogStore

NewLogStore initializes a new in-memory log store

func (*LogStore) AppendEntry

func (hlog *LogStore) AppendEntry(entry *Entry) error

AppendEntry appends an entry to a KeyLog. If the key does not exist it returns an error

func (*LogStore) GetEntry

func (hlog *LogStore) GetEntry(key, id []byte) (*Entry, error)

GetEntry gets an entry by key and id of the entry

func (*LogStore) GetKey

func (hlog *LogStore) GetKey(key []byte) (keylog *Keylog, err error)

GetKey returns the log for the given key

func (*LogStore) IterKeySeed

func (hlog *LogStore) IterKeySeed(f func(*KeySeed) error) error

IterKeySeed iterates of KeySeed objects

func (*LogStore) LastEntry

func (hlog *LogStore) LastEntry(key []byte) *Entry

LastEntry gets the last entry for a key form the log

func (*LogStore) NewEntry

func (hlog *LogStore) NewEntry(key []byte) *Entry

NewEntry sets the previous hash and height for a new Entry and returns it

func (*LogStore) NewKey

func (hlog *LogStore) NewKey(key []byte) (keylog *Keylog, err error)

NewKey creates a new keylog for a key. It returns an error if the key already exists

func (*LogStore) RemoveKey

func (hlog *LogStore) RemoveKey(key []byte) error

RemoveKey marks a key log to be removed. It is actually removed during compaction

func (*LogStore) RollbackEntry

func (hlog *LogStore) RollbackEntry(entry *Entry) error

RollbackEntry rolls the log back to the given entry. The entry must be the last entry in the log

func (*LogStore) Stats

func (hlog *LogStore) Stats() *Stats

Stats returns a Stats object with the store related stats only

type NetTransport

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

NetTransport is the network transport interface used to make remote calls.

func NewNetTransport

func NewNetTransport(reapInterval, maxConnIdle time.Duration) *NetTransport

NewNetTransport initializes a NetTransport with an outbound connection pool.

func (*NetTransport) CommitEntry

func (trans *NetTransport) CommitEntry(ctx context.Context, host string, entry *Entry, opts *RequestOptions) error

CommitEntry makes a Commit request on a remote host

func (*NetTransport) CommitRPC

func (trans *NetTransport) CommitRPC(ctx context.Context, req *ReqResp) (*ReqResp, error)

CommitRPC serves a Commit request. The underlying ballot from the local log is ignored

func (*NetTransport) GetEntry

func (trans *NetTransport) GetEntry(host string, key, id []byte, opts *RequestOptions) (*Entry, error)

GetEntry makes a Get request to retrieve an Entry from a remote host.

func (*NetTransport) GetRPC

func (trans *NetTransport) GetRPC(ctx context.Context, req *ReqResp) (resp *ReqResp, err error)

GetRPC serves a Commit request. The underlying ballot from the local log is ignored

func (*NetTransport) GetSeedKeys

func (trans *NetTransport) GetSeedKeys(host string) (*KeySeedStream, error)

GetSeedKeys gets KeySeeds from a host.

func (*NetTransport) LastEntry

func (trans *NetTransport) LastEntry(host string, key []byte, opts *RequestOptions) (*Entry, error)

LastEntry retrieves the last entry for the given key from a remote host.

func (*NetTransport) LastRPC

func (trans *NetTransport) LastRPC(ctx context.Context, req *ReqResp) (resp *ReqResp, err error)

LastRPC serves a LastEntry request. It returns the local last entry for a key.

func (*NetTransport) NewEntry

func (trans *NetTransport) NewEntry(host string, key []byte, opts *RequestOptions) (*Entry, error)

NewEntry requests a new Entry for a given key from the remote host.

func (*NetTransport) NewRPC

func (trans *NetTransport) NewRPC(ctx context.Context, req *ReqResp) (*ReqResp, error)

NewRPC serves a NewEntry request from the local log

func (*NetTransport) ProposeEntry

func (trans *NetTransport) ProposeEntry(ctx context.Context, host string, entry *Entry, opts *RequestOptions) (*ReqResp, error)

ProposeEntry makes a Propose request on a remote host

func (*NetTransport) ProposeRPC

func (trans *NetTransport) ProposeRPC(ctx context.Context, req *ReqResp) (*ReqResp, error)

ProposeRPC serves a Propose request. The underlying ballot from the local log is ignored

func (*NetTransport) PullKeylog

func (trans *NetTransport) PullKeylog(host string, entry *Entry, opts *RequestOptions) (*FutureEntry, error)

PullKeylog fetches the key log from the given host starting at the entry. If the previous hash of the entry is nil, then all entries for the key are fetched. It appends each entry directly to the log and submits to the FSM and returns a FutureEntry which is the last entry that was appended to the key log and/or an error. The keylog must exist in order for the log to be sucessfully fetched.

func (*NetTransport) PullKeylogRPC

func (trans *NetTransport) PullKeylogRPC(stream HexalogRPC_PullKeylogRPCServer) error

PullKeylogRPC streams log entries for key to the caller based on the request

func (*NetTransport) PushKeylog

func (trans *NetTransport) PushKeylog(host string, key []byte, opts *RequestOptions) error

PushKeylog pushes a key log directly from the local store to the remote host

func (*NetTransport) PushKeylogRPC

func (trans *NetTransport) PushKeylogRPC(stream HexalogRPC_PushKeylogRPCServer) error

PushKeylogRPC accepts a transfer request for a key initiated by a remote host. The key must first be initialized before a transfer is accepted. It returns an ErrKeyNotFound if the key has not been locally initialized or any underlying error

func (*NetTransport) Register

func (trans *NetTransport) Register(hlog *Hexalog)

Register registers the log with the transport to serve RPC requests to the log

func (*NetTransport) SeedKeysRPC

func (trans *NetTransport) SeedKeysRPC(req *ReqResp, stream HexalogRPC_SeedKeysRPCServer) error

SeedKeysRPC builds KeySeeds using the last entry for a key and streams them to the requestor

func (*NetTransport) Shutdown

func (trans *NetTransport) Shutdown()

Shutdown signals the transport to be shutdown and closes all outbound connections.

type Participant

type Participant struct {
	ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
	// Host:port
	Host string `protobuf:"bytes,2,opt,name=Host" json:"Host,omitempty"`
	// Priority among locations in a set
	Priority int32 `protobuf:"varint,3,opt,name=Priority" json:"Priority,omitempty"`
	// Index within location group
	Index int32 `protobuf:"varint,4,opt,name=Index" json:"Index,omitempty"`
}

func (*Participant) Descriptor

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

func (*Participant) GetHost

func (m *Participant) GetHost() string

func (*Participant) GetID

func (m *Participant) GetID() []byte

func (*Participant) GetIndex

func (m *Participant) GetIndex() int32

func (*Participant) GetPriority

func (m *Participant) GetPriority() int32

func (Participant) MarshalJSON

func (part Participant) MarshalJSON() ([]byte, error)

MarshalJSON is used to marshal id to hex string

func (*Participant) ProtoMessage

func (*Participant) ProtoMessage()

func (*Participant) Reset

func (m *Participant) Reset()

func (*Participant) String

func (m *Participant) String() string

type ReqResp

type ReqResp struct {
	// ID is based on the request/response
	ID      []byte          `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
	Entry   *Entry          `protobuf:"bytes,2,opt,name=Entry" json:"Entry,omitempty"`
	Options *RequestOptions `protobuf:"bytes,3,opt,name=Options" json:"Options,omitempty"`
	// Response fields
	BallotTime int64 `protobuf:"varint,4,opt,name=BallotTime" json:"BallotTime,omitempty"`
	ApplyTime  int64 `protobuf:"varint,5,opt,name=ApplyTime" json:"ApplyTime,omitempty"`
}

Request and response shared structure for hexalog

func (*ReqResp) Descriptor

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

func (*ReqResp) GetApplyTime

func (m *ReqResp) GetApplyTime() int64

func (*ReqResp) GetBallotTime

func (m *ReqResp) GetBallotTime() int64

func (*ReqResp) GetEntry

func (m *ReqResp) GetEntry() *Entry

func (*ReqResp) GetID

func (m *ReqResp) GetID() []byte

func (*ReqResp) GetOptions

func (m *ReqResp) GetOptions() *RequestOptions

func (*ReqResp) ProtoMessage

func (*ReqResp) ProtoMessage()

func (*ReqResp) Reset

func (m *ReqResp) Reset()

func (*ReqResp) String

func (m *ReqResp) String() string

type RequestOptions

type RequestOptions struct {
	// Index of the source in the PeerSet.  This is set internally by the log
	SourceIndex int32 `protobuf:"varint,1,opt,name=SourceIndex" json:"SourceIndex,omitempty"`
	// Set of peers for the request.
	PeerSet []*Participant `protobuf:"bytes,2,rep,name=PeerSet" json:"PeerSet,omitempty"`
	// Wait on ballot before returning
	WaitBallot bool `protobuf:"varint,5,opt,name=WaitBallot" json:"WaitBallot,omitempty"`
	// Wait for fsm to apply entry after ballot is closed. This should take
	// effect only if WaitBallot is also true
	WaitApply bool `protobuf:"varint,6,opt,name=WaitApply" json:"WaitApply,omitempty"`
	// Apply timeout in ms.  This only takes effect if WaitApply is also set
	WaitApplyTimeout int32 `protobuf:"varint,7,opt,name=WaitApplyTimeout" json:"WaitApplyTimeout,omitempty"`
}

Hexalog request options

func DefaultRequestOptions

func DefaultRequestOptions() *RequestOptions

DefaultRequestOptions returns sane options for a request. The PeerSet still must be set if needed.

func (*RequestOptions) CloneWithSourceIndex

func (o *RequestOptions) CloneWithSourceIndex(idx int32) *RequestOptions

CloneWithSourceIndex clones RequestOptions assigning it the provided idx as the SourceIndex

func (*RequestOptions) Descriptor

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

func (*RequestOptions) GetPeerSet

func (m *RequestOptions) GetPeerSet() []*Participant

func (*RequestOptions) GetSourceIndex

func (m *RequestOptions) GetSourceIndex() int32

func (*RequestOptions) GetWaitApply

func (m *RequestOptions) GetWaitApply() bool

func (*RequestOptions) GetWaitApplyTimeout

func (m *RequestOptions) GetWaitApplyTimeout() int32

func (*RequestOptions) GetWaitBallot

func (m *RequestOptions) GetWaitBallot() bool

func (*RequestOptions) ProtoMessage

func (*RequestOptions) ProtoMessage()

func (*RequestOptions) Reset

func (m *RequestOptions) Reset()

func (*RequestOptions) SourcePeer

func (o *RequestOptions) SourcePeer() *Participant

SourcePeer returns the peer for the source index

func (*RequestOptions) String

func (m *RequestOptions) String() string

type SafeKeylogIndex

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

SafeKeylogIndex implements an in-memory KeylogIndex interface. It simply wraps the KeylogIndex with a mutex for safety.

func NewSafeKeylogIndex

func NewSafeKeylogIndex(key, marker []byte) *SafeKeylogIndex

NewSafeKeylogIndex instantiates a new in-memory KeylogIndex safe for concurrent access.

func (*SafeKeylogIndex) Append

func (idx *SafeKeylogIndex) Append(id, prev []byte, ltime uint64) error

Append appends the id to the index checking the previous hash.

func (*SafeKeylogIndex) Close

func (idx *SafeKeylogIndex) Close() error

Close is a noop

func (*SafeKeylogIndex) Contains

func (idx *SafeKeylogIndex) Contains(id []byte) bool

Contains safely returns if the entry id is in the index

func (*SafeKeylogIndex) Count

func (idx *SafeKeylogIndex) Count() int

Count returns the number of entries in the index

func (*SafeKeylogIndex) Height

func (idx *SafeKeylogIndex) Height() uint32

Height returns the height of the log in a thread safe way

func (*SafeKeylogIndex) Index

func (idx *SafeKeylogIndex) Index() UnsafeKeylogIndex

Index returns the KeylogIndex index struct. It is meant be used as readonly point in time.

func (*SafeKeylogIndex) Iter

func (idx *SafeKeylogIndex) Iter(seek []byte, cb func(id []byte) error) error

Iter iterates over each entry id in the index

func (*SafeKeylogIndex) Key

func (idx *SafeKeylogIndex) Key() []byte

Key returns the key for the index

func (*SafeKeylogIndex) Last

func (idx *SafeKeylogIndex) Last() []byte

Last safely returns the last entry id

func (*SafeKeylogIndex) Marker

func (idx *SafeKeylogIndex) Marker() []byte

Marker returns the marker value

func (*SafeKeylogIndex) Rollback

func (idx *SafeKeylogIndex) Rollback(ltime uint64) (int, bool)

Rollback safely removes the last entry id

func (*SafeKeylogIndex) SetMarker

func (idx *SafeKeylogIndex) SetMarker(marker []byte) (bool, error)

SetMarker sets the marker for the index. It returns true if the marker is not part of the index and was set. This never returns an error as it is in-memory

type StableStore

type StableStore interface {
	Name() string
	Open() error
	Get(key []byte) ([]byte, error)
	Set(key []byte, value []byte) error
	Iter(cb func([]byte, []byte) error) error
	Close() error
}

StableStore is the interface used to store the FSM state. It contains information about each key and the hash of the last applied entry. This is used when a node is restarted to ensure it is caught up.

type Stats

type Stats struct {
	Keys      int64
	Entries   int64
	Ballots   int
	Proposals int
	Commits   int
	Heals     int
}

Stats contains various pieces of information regarding the current state of the log

type Transport

type Transport interface {
	// New entry from the remote host
	NewEntry(host string, key []byte, opts *RequestOptions) (*Entry, error)

	// Gets an entry from a remote host
	GetEntry(host string, key, id []byte, opts *RequestOptions) (*Entry, error)

	// Get last entry for the key
	LastEntry(host string, key []byte, opts *RequestOptions) (*Entry, error)

	// Proposes an entry on the remote host
	ProposeEntry(ctx context.Context, host string, entry *Entry, opts *RequestOptions) (*ReqResp, error)

	// Commits an entry on the remote host.  This is not directly called by the
	// user
	CommitEntry(ctx context.Context, host string, entry *Entry, opts *RequestOptions) error

	// Sends a complete key log to the remote host based on what the remote
	// has
	PushKeylog(host string, key []byte, opts *RequestOptions) error

	// Gets all entries from the remote host for a key starting at entry
	PullKeylog(host string, entry *Entry, opts *RequestOptions) (*FutureEntry, error)

	// Returns a stream of keys used to seed a new or partial log
	GetSeedKeys(host string) (*KeySeedStream, error)

	// Makes the log available to the transport
	Register(hlog *Hexalog)

	// Shutdown the transport closing outbound connections
	Shutdown()
}

Transport implements a Hexalog network transport

type UnsafeKeylogIndex

type UnsafeKeylogIndex struct {
	// Key for the index
	Key []byte `protobuf:"bytes,1,opt,name=Key,proto3" json:"Key,omitempty"`
	// Current height of the keylog
	Height uint32 `protobuf:"varint,2,opt,name=Height" json:"Height,omitempty"`
	// Used to mark an incomplete log
	Marker []byte `protobuf:"bytes,3,opt,name=Marker,proto3" json:"Marker,omitempty"`
	// LamportClock based on the last write
	LTime uint64 `protobuf:"varint,4,opt,name=LTime" json:"LTime,omitempty"`
	// Entry ids
	Entries [][]byte `protobuf:"bytes,5,rep,name=Entries,proto3" json:"Entries,omitempty"`
}

UnsafeKeylogIndex is an in-memory keylog index. This is the base class for all implementations of KeylogIndex

func NewUnsafeKeylogIndex

func NewUnsafeKeylogIndex(key []byte) *UnsafeKeylogIndex

NewUnsafeKeylogIndex creates a new keylog index

func (*UnsafeKeylogIndex) Append

func (idx *UnsafeKeylogIndex) Append(id, prev []byte, ltime uint64) error

Append appends the id to the index making sure prev matches the id of the current last entry. If this is the first entry, prev should be a zero hash.

func (*UnsafeKeylogIndex) Contains

func (idx *UnsafeKeylogIndex) Contains(id []byte) bool

Contains returns true if the index contains the given entry id

func (*UnsafeKeylogIndex) Count

func (idx *UnsafeKeylogIndex) Count() int

Count returns the number of entries in the index

func (*UnsafeKeylogIndex) Descriptor

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

func (*UnsafeKeylogIndex) GetEntries

func (m *UnsafeKeylogIndex) GetEntries() [][]byte

func (*UnsafeKeylogIndex) GetHeight

func (m *UnsafeKeylogIndex) GetHeight() uint32

func (*UnsafeKeylogIndex) GetKey

func (m *UnsafeKeylogIndex) GetKey() []byte

func (*UnsafeKeylogIndex) GetLTime

func (m *UnsafeKeylogIndex) GetLTime() uint64

func (*UnsafeKeylogIndex) GetMarker

func (m *UnsafeKeylogIndex) GetMarker() []byte

func (*UnsafeKeylogIndex) Iter

func (idx *UnsafeKeylogIndex) Iter(seek []byte, cb func(id []byte) error) (err error)

Iter iterates through each entry id starting fromt he seek position. If seek is nil all entries are traversed. If the callback returns true the function exits immediately

func (*UnsafeKeylogIndex) Last

func (idx *UnsafeKeylogIndex) Last() []byte

Last returns the last entry id or nil if there are no entries.

func (UnsafeKeylogIndex) MarshalJSON

func (idx UnsafeKeylogIndex) MarshalJSON() ([]byte, error)

MarshalJSON is a custom marshaller to handle encoding byte slices to hex. We do not have an unmarshaller as the index is not directly written to.

func (*UnsafeKeylogIndex) ProtoMessage

func (*UnsafeKeylogIndex) ProtoMessage()

func (*UnsafeKeylogIndex) Reset

func (m *UnsafeKeylogIndex) Reset()

func (*UnsafeKeylogIndex) Rollback

func (idx *UnsafeKeylogIndex) Rollback(ltime uint64) (int, bool)

Rollback removes the last entry from the index. It returns the remaining entries and whether a rollback was performed

func (*UnsafeKeylogIndex) SetMarker

func (idx *UnsafeKeylogIndex) SetMarker(marker []byte) bool

SetMarker sets the marker for he index only if it is not currently in the index

func (*UnsafeKeylogIndex) String

func (m *UnsafeKeylogIndex) String() string

Jump to

Keyboard shortcuts

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