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 ¶
- func RegisterHexalogRPCServer(s *grpc.Server, srv HexalogRPCServer)
- type Ballot
- type Config
- type EchoFSM
- type Entry
- func (entry *Entry) Clone() *Entry
- func (*Entry) Descriptor() ([]byte, []int)
- func (m *Entry) GetData() []byte
- func (m *Entry) GetHeight() uint32
- func (m *Entry) GetKey() []byte
- func (m *Entry) GetLTime() uint64
- func (m *Entry) GetPrevious() []byte
- func (m *Entry) GetTimestamp() uint64
- func (entry *Entry) Hash(hashFunc hash.Hash) []byte
- func (entry Entry) MarshalJSON() ([]byte, error)
- func (*Entry) ProtoMessage()
- func (m *Entry) Reset()
- func (m *Entry) String() string
- type EntryStore
- type FSM
- type FutureEntry
- type Hexalog
- func (hlog *Hexalog) Commit(entry *Entry, opts *RequestOptions) (*Ballot, error)
- func (hlog *Hexalog) Get(key, id []byte) (*Entry, error)
- func (hlog *Hexalog) Heal(key []byte, opts *RequestOptions) error
- func (hlog *Hexalog) Leader(key []byte, locs []*Participant) (*KeyLeader, error)
- func (hlog *Hexalog) New(key []byte) *Entry
- func (hlog *Hexalog) Propose(entry *Entry, opts *RequestOptions) (*Ballot, error)
- func (hlog *Hexalog) Seed(existing string, bufsize, parallel int) error
- func (hlog *Hexalog) Shutdown()
- func (hlog *Hexalog) Stats() *Stats
- type HexalogRPCClient
- type HexalogRPCServer
- type HexalogRPC_PullKeylogRPCClient
- type HexalogRPC_PullKeylogRPCServer
- type HexalogRPC_PushKeylogRPCClient
- type HexalogRPC_PushKeylogRPCServer
- type HexalogRPC_SeedKeysRPCClient
- type HexalogRPC_SeedKeysRPCServer
- type InMemEntryStore
- func (store *InMemEntryStore) Close() error
- func (store *InMemEntryStore) Count() int64
- func (store *InMemEntryStore) Delete(id []byte) error
- func (store *InMemEntryStore) Get(id []byte) (*Entry, error)
- func (store *InMemEntryStore) Name() string
- func (store *InMemEntryStore) Set(id []byte, entry *Entry) error
- type InMemIndexStore
- func (store *InMemIndexStore) Close() error
- func (store *InMemIndexStore) Count() int64
- func (store *InMemIndexStore) GetKey(key []byte) (KeylogIndex, error)
- func (store *InMemIndexStore) Iter(cb func([]byte, KeylogIndex) error) error
- func (store *InMemIndexStore) MarkKey(key, marker []byte) (KeylogIndex, error)
- func (store *InMemIndexStore) Name() string
- func (store *InMemIndexStore) NewKey(key []byte) (KeylogIndex, error)
- func (store *InMemIndexStore) RemoveKey(key []byte) error
- type InMemStableStore
- func (store *InMemStableStore) Close() error
- func (store *InMemStableStore) Get(key []byte) ([]byte, error)
- func (store *InMemStableStore) Iter(cb func([]byte, []byte) error) error
- func (store *InMemStableStore) Name() string
- func (store *InMemStableStore) Open() error
- func (store *InMemStableStore) Set(key, value []byte) error
- type IndexStore
- type KeyLeader
- func (l *KeyLeader) Entries() []*Entry
- func (l *KeyLeader) IsConsistent() (bool, *Participant)
- func (l *KeyLeader) Key() []byte
- func (l *KeyLeader) LastEntry() *Entry
- func (l *KeyLeader) Location() *Participant
- func (l *KeyLeader) LocationSet() []*Participant
- func (l KeyLeader) MarshalJSON() ([]byte, error)
- type KeySeed
- type KeySeedStream
- type Keylog
- func (keylog *Keylog) AppendEntry(entry *Entry) (err error)
- func (keylog *Keylog) Close() error
- func (keylog *Keylog) GetEntry(id []byte) (*Entry, error)
- func (keylog *Keylog) GetIndex() UnsafeKeylogIndex
- func (keylog *Keylog) Iter(seek []byte, cb func(id []byte, entry *Entry) error) error
- func (keylog *Keylog) LastEntry() *Entry
- func (keylog *Keylog) RollbackEntry(entry *Entry) (int, error)
- type KeylogIndex
- type LogStore
- func (hlog *LogStore) AppendEntry(entry *Entry) error
- func (hlog *LogStore) GetEntry(key, id []byte) (*Entry, error)
- func (hlog *LogStore) GetKey(key []byte) (keylog *Keylog, err error)
- func (hlog *LogStore) IterKeySeed(f func(*KeySeed) error) error
- func (hlog *LogStore) LastEntry(key []byte) *Entry
- func (hlog *LogStore) NewEntry(key []byte) *Entry
- func (hlog *LogStore) NewKey(key []byte) (keylog *Keylog, err error)
- func (hlog *LogStore) RemoveKey(key []byte) error
- func (hlog *LogStore) RollbackEntry(entry *Entry) error
- func (hlog *LogStore) Stats() *Stats
- type NetTransport
- func (trans *NetTransport) CommitEntry(ctx context.Context, host string, entry *Entry, opts *RequestOptions) error
- func (trans *NetTransport) CommitRPC(ctx context.Context, req *ReqResp) (*ReqResp, error)
- func (trans *NetTransport) GetEntry(host string, key, id []byte, opts *RequestOptions) (*Entry, error)
- func (trans *NetTransport) GetRPC(ctx context.Context, req *ReqResp) (resp *ReqResp, err error)
- func (trans *NetTransport) GetSeedKeys(host string) (*KeySeedStream, error)
- func (trans *NetTransport) LastEntry(host string, key []byte, opts *RequestOptions) (*Entry, error)
- func (trans *NetTransport) LastRPC(ctx context.Context, req *ReqResp) (resp *ReqResp, err error)
- func (trans *NetTransport) NewEntry(host string, key []byte, opts *RequestOptions) (*Entry, error)
- func (trans *NetTransport) NewRPC(ctx context.Context, req *ReqResp) (*ReqResp, error)
- func (trans *NetTransport) ProposeEntry(ctx context.Context, host string, entry *Entry, opts *RequestOptions) (*ReqResp, error)
- func (trans *NetTransport) ProposeRPC(ctx context.Context, req *ReqResp) (*ReqResp, error)
- func (trans *NetTransport) PullKeylog(host string, entry *Entry, opts *RequestOptions) (*FutureEntry, error)
- func (trans *NetTransport) PullKeylogRPC(stream HexalogRPC_PullKeylogRPCServer) error
- func (trans *NetTransport) PushKeylog(host string, key []byte, opts *RequestOptions) error
- func (trans *NetTransport) PushKeylogRPC(stream HexalogRPC_PushKeylogRPCServer) error
- func (trans *NetTransport) Register(hlog *Hexalog)
- func (trans *NetTransport) SeedKeysRPC(req *ReqResp, stream HexalogRPC_SeedKeysRPCServer) error
- func (trans *NetTransport) Shutdown()
- type Participant
- func (*Participant) Descriptor() ([]byte, []int)
- func (m *Participant) GetHost() string
- func (m *Participant) GetID() []byte
- func (m *Participant) GetIndex() int32
- func (m *Participant) GetPriority() int32
- func (part Participant) MarshalJSON() ([]byte, error)
- func (*Participant) ProtoMessage()
- func (m *Participant) Reset()
- func (m *Participant) String() string
- type ReqResp
- func (*ReqResp) Descriptor() ([]byte, []int)
- func (m *ReqResp) GetApplyTime() int64
- func (m *ReqResp) GetBallotTime() int64
- func (m *ReqResp) GetEntry() *Entry
- func (m *ReqResp) GetID() []byte
- func (m *ReqResp) GetOptions() *RequestOptions
- func (*ReqResp) ProtoMessage()
- func (m *ReqResp) Reset()
- func (m *ReqResp) String() string
- type RequestOptions
- func (o *RequestOptions) CloneWithSourceIndex(idx int32) *RequestOptions
- func (*RequestOptions) Descriptor() ([]byte, []int)
- func (m *RequestOptions) GetPeerSet() []*Participant
- func (m *RequestOptions) GetSourceIndex() int32
- func (m *RequestOptions) GetWaitApply() bool
- func (m *RequestOptions) GetWaitApplyTimeout() int32
- func (m *RequestOptions) GetWaitBallot() bool
- func (*RequestOptions) ProtoMessage()
- func (m *RequestOptions) Reset()
- func (o *RequestOptions) SourcePeer() *Participant
- func (m *RequestOptions) String() string
- type SafeKeylogIndex
- func (idx *SafeKeylogIndex) Append(id, prev []byte, ltime uint64) error
- func (idx *SafeKeylogIndex) Close() error
- func (idx *SafeKeylogIndex) Contains(id []byte) bool
- func (idx *SafeKeylogIndex) Count() int
- func (idx *SafeKeylogIndex) Height() uint32
- func (idx *SafeKeylogIndex) Index() UnsafeKeylogIndex
- func (idx *SafeKeylogIndex) Iter(seek []byte, cb func(id []byte) error) error
- func (idx *SafeKeylogIndex) Key() []byte
- func (idx *SafeKeylogIndex) Last() []byte
- func (idx *SafeKeylogIndex) Marker() []byte
- func (idx *SafeKeylogIndex) Rollback(ltime uint64) (int, bool)
- func (idx *SafeKeylogIndex) SetMarker(marker []byte) (bool, error)
- type StableStore
- type Stats
- type Transport
- type UnsafeKeylogIndex
- func (idx *UnsafeKeylogIndex) Append(id, prev []byte, ltime uint64) error
- func (idx *UnsafeKeylogIndex) Contains(id []byte) bool
- func (idx *UnsafeKeylogIndex) Count() int
- func (*UnsafeKeylogIndex) Descriptor() ([]byte, []int)
- func (m *UnsafeKeylogIndex) GetEntries() [][]byte
- func (m *UnsafeKeylogIndex) GetHeight() uint32
- func (m *UnsafeKeylogIndex) GetKey() []byte
- func (m *UnsafeKeylogIndex) GetLTime() uint64
- func (m *UnsafeKeylogIndex) GetMarker() []byte
- func (idx *UnsafeKeylogIndex) Iter(seek []byte, cb func(id []byte) error) (err error)
- func (idx *UnsafeKeylogIndex) Last() []byte
- func (idx UnsafeKeylogIndex) MarshalJSON() ([]byte, error)
- func (*UnsafeKeylogIndex) ProtoMessage()
- func (m *UnsafeKeylogIndex) Reset()
- func (idx *UnsafeKeylogIndex) Rollback(ltime uint64) (int, bool)
- func (idx *UnsafeKeylogIndex) SetMarker(marker []byte) bool
- func (m *UnsafeKeylogIndex) String() string
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) 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.
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 ¶
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.
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) Descriptor ¶
func (*Entry) GetPrevious ¶
func (*Entry) GetTimestamp ¶
func (Entry) MarshalJSON ¶
MarshalJSON is a custom JSON marshaler for Entry
func (*Entry) ProtoMessage ¶
func (*Entry) ProtoMessage()
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 ¶
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
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) 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) 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 ¶
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
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_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
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) 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) 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) 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 ¶
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) ProtoMessage ¶
func (*KeySeed) ProtoMessage()
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 ¶
AppendEntry appends an entry to the log. It returns an error if there is a previous hash mismatch
func (*Keylog) GetIndex ¶
func (keylog *Keylog) GetIndex() UnsafeKeylogIndex
GetIndex returns a KeylogIndex struct
func (*Keylog) Iter ¶
Iter iterates over entries starting from the seek position. It iterates over all entries if seek is nil
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 ¶
AppendEntry appends an entry to a KeyLog. If the key does not exist it returns an error
func (*LogStore) IterKeySeed ¶
IterKeySeed iterates of KeySeed objects
func (*LogStore) NewEntry ¶
NewEntry sets the previous hash and height for a new Entry and returns it
func (*LogStore) NewKey ¶
NewKey creates a new keylog for a key. It returns an error if the key already exists
func (*LogStore) RemoveKey ¶
RemoveKey marks a key log to be removed. It is actually removed during compaction
func (*LogStore) RollbackEntry ¶
RollbackEntry rolls the log back to the given entry. The entry must be the last entry in the log
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 ¶
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 ¶
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 ¶
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) 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 ¶
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) GetApplyTime ¶
func (*ReqResp) GetBallotTime ¶
func (*ReqResp) GetOptions ¶
func (m *ReqResp) GetOptions() *RequestOptions
func (*ReqResp) ProtoMessage ¶
func (*ReqResp) ProtoMessage()
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) 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
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 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