gmaj

package module
v0.0.0-...-28279fb Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 15 Imported by: 0

README

build status GoDoc

GMaj

Golang implementation of Chord DHT

This is a rewrite of work I did with @asubiotto for our distributed systems course at Brown university.

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

Constants

This section is empty.

Variables

View Source
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.

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 Get

func Get(node *Node, key string) ([]byte, error)

Get a value in the datastore, provided an abitrary node in the ring

func IDToString

func IDToString(id []byte) string

IDToString converts a []byte to a big.Int string, useful for debugging/logging.

func Init

func Init(cfg *gmajcfg.Config) error

Init allows consumers of this package to set the configuration. This has to happen before any other functionality of the package is used. Should only be called once.

func NewID

func NewID(str string) ([]byte, error)

NewID takes a string representing

func Put

func Put(node *Node, key string, val []byte) error

Put a key/value in the datastore, provided an abitrary node in the ring. This is useful for testing.

Types

type Node

type Node struct {
	*gmajpb.Node
	// contains filtered or unexported fields
}

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

func (node *Node) DatastoreString() (str string)

DatastoreString write the contents of a node's data store to stdout.

func (*Node) FindSuccessor

func (node *Node) FindSuccessor(
	ctx context.Context, id *gmajpb.ID,
) (*gmajpb.Node, error)

FindSuccessor finds the successor, error if nil.

func (*Node) FingerTableString

func (node *Node) FingerTableString() string

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) GetKey

func (node *Node) GetKey(ctx context.Context, key *gmajpb.Key) (*gmajpb.Val, error)

GetKey returns the value of the key requested at the node.

func (*Node) GetPredecessor

func (node *Node) GetPredecessor(context.Context, *gmajpb.MT) (*gmajpb.Node, error)

GetPredecessor gets the predecessor on the node.

func (*Node) GetSuccessor

func (node *Node) GetSuccessor(context.Context, *gmajpb.MT) (*gmajpb.Node, error)

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) Notify

func (node *Node) Notify(
	ctx context.Context, remoteNode *gmajpb.Node,
) (*gmajpb.MT, error)

Notify is called when remoteNode thinks it's our predecessor.

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) PutKeyVal

func (node *Node) PutKeyVal(ctx context.Context, kv *gmajpb.KeyVal) (*gmajpb.MT, error)

PutKeyVal stores a key value pair on the node.

func (*Node) SetPredecessor

func (node *Node) SetPredecessor(
	ctx context.Context, pred *gmajpb.Node,
) (*gmajpb.MT, error)

SetPredecessor sets the predecessor on the node.

func (*Node) SetSuccessor

func (node *Node) SetSuccessor(
	ctx context.Context, succ *gmajpb.Node,
) (*gmajpb.MT, error)

SetSuccessor sets the successor on the node.

func (*Node) Shutdown

func (node *Node) Shutdown()

Shutdown shuts down the Chord node (gracefully).

func (*Node) String

func (node *Node) String() string

String takes a Node and generates a short semi-descriptive string.

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.

Directories

Path Synopsis
cmd
examples
Package gmajpb is a generated protocol buffer package.
Package gmajpb is a generated protocol buffer package.
internal
chord
Package chord is a generated protocol buffer package.
Package chord is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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