Documentation ¶
Overview ¶
Package gmaj implements the Chord distributed hash table.
TODO ¶
1. Port over tests from original code
2. Timeout connections and make an RPC function for disconnecting nodes to remove themselves from the connMap of other nodes
3. Make sure nil values in RPC methods are handled properly
4. Logging
5. Dockerize
6. Easy deployment
7. Write example app that just uses client
Index ¶
- Variables
- func Dial(addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
- func Get(node *Node, key string) ([]byte, error)
- func IDToString(id []byte) string
- func Init(cfg *gmajcfg.Config) error
- func NewID(str string) ([]byte, error)
- func Put(node *Node, key string, val []byte) error
- type Node
- func (node *Node) ClosestPrecedingFinger(ctx context.Context, id *gmajpb.ID) (*gmajpb.Node, error)
- func (node *Node) DatastoreString() (str string)
- func (node *Node) FindSuccessor(ctx context.Context, id *gmajpb.ID) (*gmajpb.Node, error)
- func (node *Node) FingerTableString() string
- func (node *Node) Get(ctx context.Context, req *gmajpb.GetRequest) (*gmajpb.GetResponse, error)
- func (node *Node) GetID(ctx context.Context, _ *gmajpb.GetIDRequest) (*gmajpb.GetIDResponse, error)
- func (node *Node) GetKey(ctx context.Context, key *gmajpb.Key) (*gmajpb.Val, error)
- func (node *Node) GetPredecessor(context.Context, *gmajpb.MT) (*gmajpb.Node, error)
- func (node *Node) GetSuccessor(context.Context, *gmajpb.MT) (*gmajpb.Node, error)
- func (node *Node) Locate(ctx context.Context, req *gmajpb.LocateRequest) (*gmajpb.LocateResponse, error)
- func (node *Node) Notify(ctx context.Context, remoteNode *gmajpb.Node) (*gmajpb.MT, error)
- func (node *Node) Put(ctx context.Context, req *gmajpb.PutRequest) (*gmajpb.PutResponse, error)
- func (node *Node) PutKeyVal(ctx context.Context, kv *gmajpb.KeyVal) (*gmajpb.MT, error)
- func (node *Node) SetPredecessor(ctx context.Context, pred *gmajpb.Node) (*gmajpb.MT, error)
- func (node *Node) SetSuccessor(ctx context.Context, succ *gmajpb.Node) (*gmajpb.MT, error)
- func (node *Node) Shutdown()
- func (node *Node) String() string
- func (node *Node) TransferKeys(ctx context.Context, tmsg *gmajpb.TransferKeysReq) (*gmajpb.MT, error)
- type NodeOption
Constants ¶
This section is empty.
Variables ¶
var ErrBadIDLen = errors.New("gmaj: ID length does not match length in configuration")
ErrBadIDLen indicates that the passed in ID is of the wrong length.
var Log grpclog.Logger
Log allows clients to log with logger in configuration.
Functions ¶
func Dial ¶
func Dial(addr string, opts ...grpc.DialOption) (*grpc.ClientConn, error)
Dial wraps grpc's dial function with settings that facilitate the functionality of gmaj.
func IDToString ¶
IDToString converts a []byte to a big.Int string, useful for debugging/logging.
Types ¶
type Node ¶
Node represents a node in the Chord mesh.
func NewNode ¶
func NewNode(parent *gmajpb.Node, opts ...NodeOption) (*Node, error)
NewNode creates a Chord node with a pre-defined ID (useful for testing) if a non-nil id is provided.
func (*Node) ClosestPrecedingFinger ¶
func (node *Node) ClosestPrecedingFinger( ctx context.Context, id *gmajpb.ID, ) (*gmajpb.Node, error)
ClosestPrecedingFinger will find the closest preceding entry in the finger table based on the id.
func (*Node) DatastoreString ¶
DatastoreString write the contents of a node's data store to stdout.
func (*Node) FindSuccessor ¶
FindSuccessor finds the successor, error if nil.
func (*Node) FingerTableString ¶
FingerTableString takes a node and converts it's finger table into a string.
func (*Node) Get ¶
func (node *Node) Get(ctx context.Context, req *gmajpb.GetRequest) (*gmajpb.GetResponse, error)
Get a value in the datastore, provided an abitrary node in the ring
func (*Node) GetID ¶
func (node *Node) GetID(ctx context.Context, _ *gmajpb.GetIDRequest) (*gmajpb.GetIDResponse, error)
GetID returns the ID of the node.
func (*Node) GetPredecessor ¶
GetPredecessor gets the predecessor on the node.
func (*Node) GetSuccessor ¶
GetSuccessor gets the successor on the node..
func (*Node) Locate ¶
func (node *Node) Locate(ctx context.Context, req *gmajpb.LocateRequest) (*gmajpb.LocateResponse, error)
Locate finds where a key belongs.
func (*Node) Put ¶
func (node *Node) Put(ctx context.Context, req *gmajpb.PutRequest) (*gmajpb.PutResponse, error)
Put a key/value in the datastore, provided an abitrary node in the ring. This is useful for testing.
func (*Node) SetPredecessor ¶
SetPredecessor sets the predecessor on the node.
func (*Node) SetSuccessor ¶
SetSuccessor sets the successor on the node.
func (*Node) Shutdown ¶
func (node *Node) Shutdown()
Shutdown shuts down the Chord node (gracefully).
func (*Node) TransferKeys ¶
func (node *Node) TransferKeys( ctx context.Context, tmsg *gmajpb.TransferKeysReq, ) (*gmajpb.MT, error)
TransferKeys transfers the appropriate keys on this node to the remote node specified in the request.
type NodeOption ¶
type NodeOption func(o *nodeOptions)
NodeOption is a function that customizes a Node.
func WithAddress ¶
func WithAddress(addr string) NodeOption
WithAddress sets the address on which the node should listen.
func WithGRPCDialOptions ¶
func WithGRPCDialOptions(opts ...grpc.DialOption) NodeOption
WithGRPCDialOptions makes the node dial other nodes with the specified gRPC dial options.
func WithGRPCServerOptions ¶
func WithGRPCServerOptions(opts ...grpc.ServerOption) NodeOption
WithGRPCServerOptions instantiates the gRPC server with the specified options.
func WithID ¶
func WithID(id []byte) NodeOption
WithID sets a custom ID on the nodee. Useful for testing.