fred

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Addr string
	IsIP bool
}

Address is an IP address or a hostname of a FReD node.

type Client

type Client interface {
	SendCreateKeygroup(host string, kgname KeygroupName, expiry int) error
	SendDeleteKeygroup(host string, kgname KeygroupName) error
	SendUpdate(host string, kgname KeygroupName, id string, value string) error
	SendAppend(host string, kgname KeygroupName, id string, value string) error
	SendDelete(host string, kgname KeygroupName, id string) error
	SendAddReplica(host string, kgname KeygroupName, node Node, expiry int) error
	SendRemoveReplica(host string, kgname KeygroupName, node Node) error
	SendGetItem(host string, kgname KeygroupName, id string) (Item, error)
	SendGetAllItems(host string, kgname KeygroupName) ([]Item, error)
}

Client is an interface to send replication messages across nodes.

type Config

type Config struct {
	Store             Store
	Client            Client
	NaSe              NameService
	PeeringHost       string
	PeeringHostProxy  string
	ExternalHost      string
	ExternalHostProxy string
	NodeID            string
	TriggerCert       string
	TriggerKey        string
	TriggerCA         []string
}

Config holds configuration parameters for an instance of FReD.

type ExtHandler

type ExtHandler interface {
	HandleCreateKeygroup(user string, k Keygroup) error
	HandleDeleteKeygroup(user string, k Keygroup) error
	HandleRead(user string, i Item) (Item, error)
	HandleScan(user string, i Item, count uint64) ([]Item, error)
	HandleUpdate(user string, i Item) error
	HandleDelete(user string, i Item) error
	HandleAppend(user string, i Item) (Item, error)
	HandleAddReplica(user string, k Keygroup, n Node) error
	HandleGetKeygroupReplica(user string, k Keygroup) ([]Node, map[NodeID]int, error)
	HandleRemoveReplica(user string, k Keygroup, n Node) error
	HandleGetReplica(user string, n Node) (Node, error)
	HandleGetAllReplica(user string) ([]Node, error)
	HandleGetKeygroupTriggers(user string, keygroup Keygroup) ([]Trigger, error)
	HandleAddTrigger(user string, keygroup Keygroup, t Trigger) error
	HandleRemoveTrigger(user string, keygroup Keygroup, t Trigger) error
	HandleAddUser(user string, newuser string, keygroup Keygroup, role Role) error
	HandleRemoveUser(user string, newuser string, keygroup Keygroup, role Role) error
}

ExtHandler is an interface that abstracts the methods of the handler that handles client requests.

type Fred

type Fred struct {
	E ExtHandler
	I IntHandler
}

Fred is an instance of FReD.

func New

func New(config *Config) (f Fred)

New creates a new FReD instance.

type IntHandler

type IntHandler interface {
	HandleCreateKeygroup(k Keygroup) error
	HandleDeleteKeygroup(k Keygroup) error
	HandleUpdate(i Item) error
	HandleAppend(i Item) error
	HandleDelete(i Item) error
	HandleAddReplica(k Keygroup, n Node) error
	HandleRemoveReplica(k Keygroup, n Node) error
	HandleGet(i Item) (Item, error)
	HandleGetAllItems(k Keygroup) ([]Item, error)
}

IntHandler is an interface that abstracts the methods of the handler that handles internal requests.

type Item

type Item struct {
	Keygroup KeygroupName
	ID       string
	Val      string
}

Item is an item in the key-value store.

type Keygroup

type Keygroup struct {
	Name    KeygroupName
	Mutable bool
	Expiry  int
}

Keygroup has a name and a list of replica nodes and trigger nodes.

type KeygroupName

type KeygroupName string

KeygroupName is a name of a keygroup.

type Method

type Method string

Method is a representation of all methods a client could perform on a keygroup.

const (
	CreateKeygroup Method = "CreateKeygroup"
	DeleteKeygroup Method = "DeleteKeygroup"
	Read           Method = "Read"
	Update         Method = "Update"
	Delete         Method = "Delete"
	AddReplica     Method = "AddReplica"
	GetReplica     Method = "GetReplica"
	RemoveReplica  Method = "RemoveReplica"
	GetAllReplica  Method = "GetAllReplica"
	GetTrigger     Method = "GetTrigger"
	AddTrigger     Method = "AddTrigger"
	RemoveTrigger  Method = "RemoveTrigger"
	AddUser        Method = "AddUser"
	RemoveUser     Method = "RemoveUser"
)

These are all methods that clients can perform on FReD, implemented as constants for easier use.

type NameService

type NameService interface {
	// manage information about this node
	GetNodeID() NodeID
	RegisterSelf(host string, externalHost string) error

	// manage permissions
	AddUserPermissions(user string, method Method, keygroup KeygroupName) error
	RevokeUserPermissions(user string, method Method, keygroup KeygroupName) error
	GetUserPermissions(user string, keygroup KeygroupName) (map[Method]struct{}, error)

	// get information about a keygroup
	IsMutable(kg KeygroupName) (bool, error)
	GetExpiry(kg KeygroupName) (int, error)

	// manage information about another node
	GetNodeAddress(nodeID NodeID) (addr string, err error)
	GetNodeAddressExternal(nodeID NodeID) (addr string, err error)
	GetAllNodes() (nodes []Node, err error)
	GetAllNodesExternal() (nodes []Node, err error)

	// manage keygroups
	ExistsKeygroup(kg KeygroupName) (bool, error)
	JoinNodeIntoKeygroup(kg KeygroupName, nodeID NodeID, expiry int) error
	ExitOtherNodeFromKeygroup(kg KeygroupName, nodeID NodeID) error
	CreateKeygroup(kg KeygroupName, mutable bool, expiry int) error
	DeleteKeygroup(kg KeygroupName) error
	GetKeygroupMembers(kg KeygroupName, excludeSelf bool) (ids map[NodeID]int, err error)

	// handle node failures
	ReportFailedNode(nodeID NodeID, kg KeygroupName, id string) error
	RequestNodeStatus(nodeID NodeID) []Item
	GetNodeWithBiggerExpiry(kg KeygroupName) (nodeID NodeID, addr string)
}

NameService interface abstracts from the features of the nameservice, whether that is etcd or a distributed implementation.

type Node

type Node struct {
	ID   NodeID
	Host string
}

Node is a replica node.

type NodeID

type NodeID string

NodeID is an identifier of a replica node.

type Role

type Role string

Role is a wrapper for a set of permissions/methods.

const (
	ReadKeygroup       Role = "R"
	WriteKeygroup      Role = "W"
	ConfigureReplica   Role = "C"
	ConfigureTrigger   Role = "T"
	ConfigureKeygroups Role = "K"
)

These are all roles that we have in FReD.

type Store

type Store interface {
	// Needs: keygroup, id, val
	Update(kg, id, val string, append bool, expiry int) error
	// Needs: keygroup, id
	Delete(kg, id string) error
	// Needs: keygroup, val, Returns: key
	Append(kg, val string, expiry int) (string, error)
	// Needs: keygroup, id; Returns: val
	Read(kg, id string) (string, error)
	// Needs: keygroup, id, range; Returns: ids and values
	ReadSome(kg, id string, count uint64) (map[string]string, error)
	// Needs: keygroup; Returns: ids and values
	ReadAll(kg string) (map[string]string, error)
	// Needs: keygroup, Returns:[] keygroup, id
	IDs(kg string) ([]string, error)
	// Needs: keygroup, id
	Exists(kg, id string) bool
	// Needs: keygroup, Returns: err
	// Doesnt really need to store the KG itself, that is keygroup/store.go's job.
	// But might be useful for databases using it
	CreateKeygroup(kg string) error
	// Same as with CreateKeygroup
	DeleteKeygroup(kg string) error
	// Needs: keygroup
	ExistsKeygroup(kg string) bool
	// Needs: keygroup, trigger node id, trigger node host
	AddKeygroupTrigger(kg string, id string, host string) error
	// Needs: keygroup, trigger node id
	DeleteKeygroupTrigger(kg string, id string) error
	// Needs: keygroup; Returns map: trigger node id -> trigger node host
	GetKeygroupTrigger(kg string) (map[string]string, error)
	// Close indicates that the underlying store should be closed as it is no longer needed.
	Close() error
}

Store is an interface for the storage medium that the key-value val items are persisted on.

type Trigger

type Trigger struct {
	ID   string
	Host string
}

Trigger is one trigger node with an ID and a host address.

Jump to

Keyboard shortcuts

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