replica

package
v0.0.0-...-b1bb88e Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: LGPL-2.1 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const Error_Arguments = "arguments_wrong" // arguments are invalid (e.g. wrong number, wrong type)
View Source
const Error_Authorisation = "authorisation_invalid" // error due to wrong authorisation
View Source
const Error_Invalid_Data = "data_invalid" // For all kind of wrong data errors
View Source
const Error_Operation_Invalid = "operation_invalid" // User operation not possible with current application state
View Source
const Error_Process = "process_failed" // For all kind of proccesses or operations
View Source
const Error_Setup = "setup_invalid" // The datastructures are not setup correctly
View Source
const Error_Unavailable = "node_unavailable" // error due to not being able to reach node

Variables

This section is empty.

Functions

func NewLibp2pTransport

func NewLibp2pTransport(h host.Host, dht *kaddht.IpfsDHT, timeout time.Duration, name string) (*raft.NetworkTransport, error)

Types

type Event

type Event struct {
	Peer  peer.ID
	Event Event_Type
}

type Event_Type

type Event_Type int
const (
	EVENT_PEER_ADDED         Event_Type = iota // new peer added to config (for leader only)
	EVENT_PEER_REMOVED                         // peer removed from config (for leader only)
	EVENT_LEADER_CHANGED                       // leader changed
	EVENT_MAJORITY_AVAILABLE                   // Majority of nodes online and reachable
	EVENT_MAJORITY_LOST                        // Cannot reach majority of notes
)

type Observer

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

func (Observer) EventChannel

func (self Observer) EventChannel() chan Event

type Operation

type Operation struct {
	State string
	OpID  string
	Op    []byte
}

a little herlper to ease multi state commands

func NewOperation

func NewOperation(state string, cmd []byte) Operation

func (Operation) ToBytes

func (self Operation) ToBytes() []byte

type Replica

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

func NewReplica

func NewReplica(name string, path string, host p2phost.Host, dht *kaddht.IpfsDHT, logger hclog.Logger) (*Replica, error)

func (*Replica) AddCommand

func (self *Replica) AddCommand(ctx context.Context, op Operation) error

func (*Replica) AddState

func (self *Replica) AddState(name string, state State) error

func (*Replica) Bootstrap

func (self *Replica) Bootstrap() error

setup the replica completely new (to be done after all states are added)

func (*Replica) Close

func (self *Replica) Close(ctx context.Context) error

warning: only close after removing ourself from the cluster!

func (*Replica) CloseObserver

func (self *Replica) CloseObserver(obs Observer)

func (*Replica) CloseResultChan

func (self *Replica) CloseResultChan(opID string)

func (*Replica) ConnectPeer

func (self *Replica) ConnectPeer(ctx context.Context, pid peer.ID, writer bool) error

func (*Replica) ConnectedPeers

func (self *Replica) ConnectedPeers() ([]peer.ID, error)

func (*Replica) CreateResultChannel

func (self *Replica) CreateResultChannel(opID string) (chan interface{}, error)

func (*Replica) DisconnectPeer

func (self *Replica) DisconnectPeer(ctx context.Context, pid peer.ID) error

func (*Replica) GetLeader

func (self *Replica) GetLeader(ctx context.Context) (peer.ID, error)

func (*Replica) HasMajority

func (self *Replica) HasMajority() bool

func (*Replica) IsLastPeer

func (self *Replica) IsLastPeer(pid peer.ID) (bool, error)

func (*Replica) IsRunning

func (self *Replica) IsRunning() bool

func (*Replica) Join

func (self *Replica) Join() error

starts the replica and waits to get added by the leader (to be done after all states are added)

func (*Replica) NewObserver

func (self *Replica) NewObserver(blocking bool) Observer

func (*Replica) PrintConf

func (self *Replica) PrintConf()

func (*Replica) Shutdown

func (self *Replica) Shutdown(ctx context.Context) error

shutdown the cluster. Only use when we are the last peer! otherwise remove ourself from the cluster and call close!

func (*Replica) TransferLeadership

func (self *Replica) TransferLeadership(ctx context.Context) (peer.ID, error)

type State

type State interface {
	Apply([]byte) interface{}
	Snapshot() ([]byte, error)
	LoadSnapshot([]byte) error
}

interface that must be implemented by replica states

Jump to

Keyboard shortcuts

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