Documentation ¶
Index ¶
- Variables
- type AliveStabilizer
- type Finger
- type FingerTableStabilizer
- type LocalNode
- func (l *LocalNode) CreateRing()
- func (l *LocalNode) DeleteValue(ctx context.Context, key *string) (bool, error)
- func (l *LocalNode) FindClosestPrecedingNode(_ context.Context, id model.HashID) (RingNode, error)
- func (l *LocalNode) FindSuccessorByList(ctx context.Context, id model.HashID) (RingNode, error)
- func (l *LocalNode) FindSuccessorByTable(ctx context.Context, id model.HashID) (RingNode, error)
- func (l *LocalNode) GetPredecessor(_ context.Context) (RingNode, error)
- func (l *LocalNode) GetSuccessors(_ context.Context) ([]RingNode, error)
- func (l *LocalNode) GetValue(ctx context.Context, key *string) (*string, bool, error)
- func (l *LocalNode) JoinRing(ctx context.Context, existNode RingNode) error
- func (l *LocalNode) JoinSuccessors(offset int, successors []RingNode)
- func (l *LocalNode) Notify(_ context.Context, node RingNode) error
- func (l *LocalNode) Ping(_ context.Context) error
- func (l *LocalNode) PutSuccessor(suc RingNode)
- func (l *LocalNode) PutValue(_ context.Context, key *string, value *string) (bool, error)
- func (l *LocalNode) Reference() *model.NodeRef
- func (l *LocalNode) Shutdown()
- type MockTransport
- func (m *MockTransport) DeleteValueInnerRPC(ctx context.Context, to *model.NodeRef, key *string) (bool, error)
- func (m *MockTransport) FindClosestPrecedingNodeRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error)
- func (m *MockTransport) FindSuccessorByListRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error)
- func (m *MockTransport) FindSuccessorByTableRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error)
- func (m *MockTransport) GetValueInnerRPC(ctx context.Context, to *model.NodeRef, key *string) (*string, bool, error)
- func (m *MockTransport) NotifyRPC(ctx context.Context, to *model.NodeRef, node *model.NodeRef) error
- func (m *MockTransport) PingRPC(ctx context.Context, to *model.NodeRef) error
- func (m *MockTransport) PredecessorRPC(ctx context.Context, to *model.NodeRef) (RingNode, error)
- func (m *MockTransport) PutValueInnerRPC(ctx context.Context, to *model.NodeRef, key *string, value *string) (bool, error)
- func (m *MockTransport) Shutdown()
- func (m *MockTransport) SuccessorsRPC(ctx context.Context, to *model.NodeRef) ([]RingNode, error)
- type Process
- type ProcessOptionFunc
- type RemoteNode
- func (r *RemoteNode) DeleteValue(ctx context.Context, key *string) (bool, error)
- func (r *RemoteNode) FindClosestPrecedingNode(ctx context.Context, id model.HashID) (RingNode, error)
- func (r *RemoteNode) FindSuccessorByList(ctx context.Context, id model.HashID) (RingNode, error)
- func (r *RemoteNode) FindSuccessorByTable(ctx context.Context, id model.HashID) (RingNode, error)
- func (r *RemoteNode) GetPredecessor(ctx context.Context) (RingNode, error)
- func (r *RemoteNode) GetSuccessors(ctx context.Context) ([]RingNode, error)
- func (r *RemoteNode) GetValue(ctx context.Context, key *string) (*string, bool, error)
- func (r *RemoteNode) Notify(ctx context.Context, node RingNode) error
- func (r *RemoteNode) Ping(ctx context.Context) error
- func (r *RemoteNode) PutValue(ctx context.Context, key *string, value *string) (bool, error)
- func (r *RemoteNode) Reference() *model.NodeRef
- type RingNode
- type Stabilizer
- type SuccessorStabilizer
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound represents node not found error ErrNotFound = errors.New("NotFound") // ErrStabilizeNotCompleted represents stabilize process not completed error ErrStabilizeNotCompleted = errors.New("StabilizeNotCompleted") ErrNodeUnavailable = errors.New("NodeUnavailable") // ErrNoSuccessorAlive represents no successor available error ErrNoSuccessorAlive = errors.New("ErrNoSuccessorAlive") )
Functions ¶
This section is empty.
Types ¶
type AliveStabilizer ¶
type AliveStabilizer struct {
Node *LocalNode
}
AliveStabilizer checks successor status. If this stabilizer detects successors dead, remove them from a successor list of a local node.
func NewAliveStabilizer ¶
func NewAliveStabilizer(node *LocalNode) AliveStabilizer
NewAliveStabilizer creates an alive stabilizer
func (AliveStabilizer) Stabilize ¶
func (a AliveStabilizer) Stabilize(ctx context.Context)
Stabilize is implemented for Stabilizer interface.
type Finger ¶
Finger represents an element of routing table
func NewFinger ¶
NewFinger creates a finger. index is an order of finger table. node is this finger table's owner.
func NewFingerTable ¶
NewFingerTable creates a finger table.
type FingerTableStabilizer ¶
type FingerTableStabilizer struct { Node *LocalNode // contains filtered or unexported fields }
FingerTableStabilizer maintains a finger table of a local node.
func NewFingerTableStabilizer ¶
func NewFingerTableStabilizer(node *LocalNode) *FingerTableStabilizer
NewFingerTableStabilizer creates a finger table stabilizer.
func (*FingerTableStabilizer) Stabilize ¶
func (s *FingerTableStabilizer) Stabilize(ctx context.Context)
Stabilize is implemented for Stabilizer interface.
type LocalNode ¶
LocalNode represents local host node.
func NewLocalNode ¶
NewLocalNode creates a local node.
func (*LocalNode) CreateRing ¶
func (l *LocalNode) CreateRing()
func (*LocalNode) DeleteValue ¶
func (*LocalNode) FindClosestPrecedingNode ¶
func (*LocalNode) FindSuccessorByList ¶
func (*LocalNode) FindSuccessorByTable ¶
func (*LocalNode) GetPredecessor ¶
func (*LocalNode) GetSuccessors ¶
func (*LocalNode) JoinSuccessors ¶
func (*LocalNode) PutSuccessor ¶
type MockTransport ¶
type MockTransport struct{}
MockTransport does nothing
func (*MockTransport) DeleteValueInnerRPC ¶
func (*MockTransport) FindClosestPrecedingNodeRPC ¶
func (m *MockTransport) FindClosestPrecedingNodeRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error)
FindClosestPrecedingNodeRPC does nothing
func (*MockTransport) FindSuccessorByListRPC ¶
func (m *MockTransport) FindSuccessorByListRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error)
FindSuccessorByListRPC does nothing
func (*MockTransport) FindSuccessorByTableRPC ¶
func (m *MockTransport) FindSuccessorByTableRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error)
FindSuccessorByTableRPC does nothing
func (*MockTransport) GetValueInnerRPC ¶
func (*MockTransport) NotifyRPC ¶
func (m *MockTransport) NotifyRPC(ctx context.Context, to *model.NodeRef, node *model.NodeRef) error
NotifyRPC does nothing
func (*MockTransport) PredecessorRPC ¶
PredecessorRPC does nothing
func (*MockTransport) PutValueInnerRPC ¶
func (*MockTransport) SuccessorsRPC ¶
SuccessorsRPC does nothing
type Process ¶
type Process struct { *LocalNode AliveStabilizer Stabilizer SuccessorStabilizer Stabilizer FingerTableStabilizer Stabilizer Transport Transport IsShutdown bool // contains filtered or unexported fields }
Process represents chord process. Process manages a local node and some stabilizers.
func NewProcess ¶
NewProcess creates a process.
type ProcessOptionFunc ¶
type ProcessOptionFunc func(option *processOption)
ProcessOptionFunc is function to apply options to a process
func WithExistNode ¶
func WithExistNode(node RingNode) ProcessOptionFunc
func WithStabilizeInterval ¶
func WithStabilizeInterval(duration time.Duration) ProcessOptionFunc
type RemoteNode ¶
RemoteNode represents remote nodes. To communicate with remote nodes, need to call rpc.
func (*RemoteNode) DeleteValue ¶
func (*RemoteNode) FindClosestPrecedingNode ¶
func (*RemoteNode) FindSuccessorByList ¶
func (*RemoteNode) FindSuccessorByTable ¶
func (*RemoteNode) GetPredecessor ¶
func (r *RemoteNode) GetPredecessor(ctx context.Context) (RingNode, error)
func (*RemoteNode) GetSuccessors ¶
func (r *RemoteNode) GetSuccessors(ctx context.Context) ([]RingNode, error)
func (*RemoteNode) Reference ¶
func (r *RemoteNode) Reference() *model.NodeRef
type RingNode ¶
type RingNode interface { Ping(ctx context.Context) error Reference() *model.NodeRef GetSuccessors(ctx context.Context) ([]RingNode, error) GetPredecessor(ctx context.Context) (RingNode, error) FindSuccessorByTable(ctx context.Context, id model.HashID) (RingNode, error) FindSuccessorByList(ctx context.Context, id model.HashID) (RingNode, error) FindClosestPrecedingNode(ctx context.Context, id model.HashID) (RingNode, error) Notify(ctx context.Context, node RingNode) error PutValue(ctx context.Context, key *string, value *string) (bool, error) GetValue(ctx context.Context, key *string) (*string, bool, error) DeleteValue(ctx context.Context, key *string) (bool, error) }
RingNode represents a node of Chord Ring
func NewRemoteNode ¶
type Stabilizer ¶
Stabilizer is a process that runs asynchronously in a single goroutine
type SuccessorStabilizer ¶
type SuccessorStabilizer struct {
Node *LocalNode
}
SuccessorStabilizer checks new successors. If this stabilizer finds new successor, adds a new one to a successor list of a local node. In addition, this notify a successor to check its predecessor.
func NewSuccessorStabilizer ¶
func NewSuccessorStabilizer(node *LocalNode) SuccessorStabilizer
NewSuccessorStabilizer creates a successor stabilizer.
func (SuccessorStabilizer) Stabilize ¶
func (s SuccessorStabilizer) Stabilize(ctx context.Context)
Stabilize is implemented for Stabilizer interface.
type Transport ¶
type Transport interface { PingRPC(ctx context.Context, to *model.NodeRef) error SuccessorsRPC(ctx context.Context, to *model.NodeRef) ([]RingNode, error) PredecessorRPC(ctx context.Context, to *model.NodeRef) (RingNode, error) FindSuccessorByTableRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error) FindSuccessorByListRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error) FindClosestPrecedingNodeRPC(ctx context.Context, to *model.NodeRef, id model.HashID) (RingNode, error) NotifyRPC(ctx context.Context, to *model.NodeRef, node *model.NodeRef) error Shutdown() PutValueInnerRPC(ctx context.Context, to *model.NodeRef, key *string, value *string) (bool, error) GetValueInnerRPC(ctx context.Context, to *model.NodeRef, key *string) (*string, bool, error) DeleteValueInnerRPC(ctx context.Context, to *model.NodeRef, key *string) (bool, error) }
Transport represents rpc to remote node