Documentation ¶
Overview ¶
Package grasure is an Universal Erasure Coding Architecture in Go
For usage and examples, see https://github.com/DurantVivado/Grasure
Index ¶
- Constants
- Variables
- func Accept(lis net.Listener)
- func DiskUsage(path string) (uint64, uint64)
- func HandleHTTP()
- func Heartbeat(ctx context.Context, registry, addr string, duration time.Duration)
- func Register(rcvr interface{}) error
- func RegistryHandleHTTP()
- type ACL
- type BlockReadRequest
- type BlockReadResponse
- type Call
- type Client
- func Dial(network, address string, opts ...*Option) (*Client, error)
- func DialHTTP(network, address string, opts ...*Option) (*Client, error)
- func NewClient(conn net.Conn, opt *Option) (*Client, error)
- func NewHTTPClient(conn net.Conn, opt *Option) (*Client, error)
- func XDial(rpcAddr string, opts ...*Option) (*Client, error)
- type Cluster
- func (c *Cluster) AddErasurePools(pool ...*ErasurePool)
- func (c *Cluster) AddNode(id int, node *Node)
- func (c *Cluster) CheckIfExistPool(pattern string) (*ErasurePool, bool)
- func (c *Cluster) DelNode(id int)
- func (c *Cluster) GetIPsFromRole(role string) (addrs []string)
- func (c *Cluster) GetLocalNode() (ret *Node)
- func (c *Cluster) GetNodesFromRole(role string) (nodes []*Node)
- func (c *Cluster) ReadNodesAddr()
- func (c *Cluster) SetNodeStatus(duration time.Duration)
- func (c *Cluster) SetOuput(level LogLevel, filename string)
- func (c *Cluster) StartDFSServer(port string)
- func (c *Cluster) StartHeartbeatServer(port string)
- type ClusterOption
- type ClusterStatus
- type Context
- type Discovery
- type DiskArray
- type DiskInfo
- type DiskState
- type ErasurePool
- type Hash
- type Int64Arr
- type IntSet
- type Layout
- type LogLevel
- type Mode
- type MultiServersDiscovery
- type Node
- type NodeStat
- type NodeStatus
- type NodeType
- type NodeWriter
- type Option
- type Output
- type ParallelReader
- type ParallelWriter
- type Pattern
- type Redundancy
- type Registry
- type RegistryDiscovery
- type SelectMode
- type Server
- type ServerItem
- type SimOptions
- type StorageAPI
- type Version
- type Volume
- type XClient
Constants ¶
const ( DATA = "DATA" CLIENT = "CLIENT" SERVER = "SERVER" COMPUTING = "COMPUTING" GATEWAY = "GATEWAY" NAME = "NAME" )
const ( DEFAULT_MAGIC_NUMBER = 0x7fffffff READ_MAGIC_NUMBER = 0xaaaaaaaa WRITE_MAGIC_NUMBER = 0xbbbbbbbb )
Variables ¶
var DefaultOption = &Option{ MagicNumber: DEFAULT_MAGIC_NUMBER, CodecType: codec.GobType, ConnectTimeout: defaultConnectionTimeout, HandleTimeout: defaultHandleTimeout, }
var DefaultRegister = NewRegistry(defaultRegistryTimeout)
var DefaultServer = NewServer()
var ErrShutdown = errors.New("connection is shut down")
Functions ¶
func Accept ¶
Accept accepts connections on the listener and serves requests for each incoming connection.
func HandleHTTP ¶
func HandleHTTP()
HandleHTTP is a convenient approach for default server to register HTTP handlers
func Heartbeat ¶
Heartbeat send a heartbeat message every once in a while it's a helper function for a server to register or send heartbeat
func Register ¶
func Register(rcvr interface{}) error
Register publishes the receiver's methods in the DefaultServer.
func RegistryHandleHTTP ¶
func RegistryHandleHTTP()
Types ¶
type BlockReadRequest ¶
type BlockReadResponse ¶
type Call ¶
type Call struct { Seq uint64 ServiceMethod string // format "<service>.<method>" Args interface{} // arguments to the function Reply interface{} // reply from the function Error error // if error occurs, it will be set Done chan *Call // Strobes when call is complete. }
Call represents an active RPC.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an RPC Client. There may be multiple outstanding Calls associated with a single Client, and a Client may be used by multiple goroutines simultaneously.
func DialHTTP ¶
DialHTTP connects to an HTTP RPC server at the specified network address listening on the default HTTP RPC path.
func NewHTTPClient ¶
NewHTTPClient new a Client instance via HTTP as transport protocol
func XDial ¶
XDial calls different functions to connect to a RPC server according the first parameter rpcAddr. rpcAddr is a general format (protocol@addr) to represent a rpc server eg, http@10.0.0.1:7001, tcp@10.0.0.1:9999, unix@/tmp/geerpc.sock
func (*Client) Call ¶
Call invokes the named function, waits for it to complete, and returns its error status.
func (*Client) Go ¶
Go invokes the function asynchronously. It returns the Call structure representing the invocation.
func (*Client) IsAvailable ¶
IsAvailable return true if the client does work
type Cluster ¶
type Cluster struct { //UUID is the global unique id of a cluster UUID int64 `json:"UUID"` //InfoFilePath is the path of a textual file storing basic information of the cluster InfoFilePath string //NodeFilePath is the path of file includes all nodes address, provided by user NodeFilePath string // contains filtered or unexported fields }
Cluster is an instance that is only created once at each node
func NewCluster ¶
NewCluster initializes a Cluster with customized ataShards, parityShards, usedNodeNum, replicateFactor and blockSize
func (*Cluster) AddErasurePools ¶
func (c *Cluster) AddErasurePools(pool ...*ErasurePool)
AddErasurePool adds an erasure-pool to the cluster's poolMap whose key should be like "RS-10-4-1024k", namely policy.
func (*Cluster) CheckIfExistPool ¶
func (c *Cluster) CheckIfExistPool(pattern string) (*ErasurePool, bool)
CheckIfExistPool checks if there exists pool of certain pattern, e.g. "RS-4-2-4096"
func (*Cluster) GetIPsFromRole ¶
GetIPsFromRole returns IP address according to given role
func (*Cluster) GetLocalNode ¶
GetLocalNode returns the local node if exists in the cluster
func (*Cluster) GetNodesFromRole ¶
GetNodesFromRole returns Node slice according to given role
func (*Cluster) ReadNodesAddr ¶
func (c *Cluster) ReadNodesAddr()
ReadNodesAddr reads the node information from file
func (*Cluster) SetNodeStatus ¶
SetNodeStatus reset nodes' status every duration
func (*Cluster) StartDFSServer ¶
StartDFSServer starts the server to handle HTTP requests
func (*Cluster) StartHeartbeatServer ¶
StartServer starts the server to handle HTTP requests
type ClusterOption ¶
type ClusterOption struct {
// contains filtered or unexported fields
}
type ClusterStatus ¶
type ClusterStatus struct { UUID string // contains filtered or unexported fields }
ClusterStatus is delpoyed on certain port of the server to inform the user of real-time status of the cluster
type DiskArray ¶
type DiskArray struct {
// contains filtered or unexported fields
}
DiskArray contains the low-level disk information
func NewDiskArray ¶
func (*DiskArray) ReadDiskPath ¶
func (d *DiskArray) ReadDiskPath()
ReadDiskPath reads the disk paths from diskFilePath. There should be exactly ONE disk path at each line.
This func can NOT be called concurrently.
type DiskInfo ¶
type DiskInfo struct {
// contains filtered or unexported fields
}
func NewDiskInfo ¶
NewDiskInfo news a disk with basic information
type ErasurePool ¶
type ErasurePool struct { //the redun is how the files are encoded in this pool Redun Redundancy `json:"redundancy"` // the number of data blocks in a stripe K int `json:"dataShards"` // the number of parity blocks in a stripe M int `json:"parityShards"` //the used node number for the pool NodeNum int `json:"nodeNum"` // the block size. default to 4KiB BlockSize int64 `json:"blockSize"` // contains filtered or unexported fields }
func NewErasurePool ¶
func NewErasurePool(redun Redundancy, dataShards, parityShards, nodeNum int, blockSize int64, dataNodes []int, layout Pattern) *ErasurePool
NewErasurePool news an erasurePool with designated dataShards, parityShards, nodeNum and blockSize, When set dataNodes as nil by default, the pool uses the first nodeNum nodes, you can specify the nodes in the order of their ids (indexed from 0).
func (*ErasurePool) Write ¶
func (ep *ErasurePool) Write(src io.ReadCloser, addr string) error
Write writes a file or byte flow into certain node.
type Layout ¶
type Layout struct {
// contains filtered or unexported fields
}
Layout determines the block location relative to the nodes, usually stored on name node
type MultiServersDiscovery ¶
type MultiServersDiscovery struct {
// contains filtered or unexported fields
}
MultiServersDiscovery is a discovery for multi servers without a registry center user provides the server addresses explicitly instead
func NewMultiServerDiscovery ¶
func NewMultiServerDiscovery(servers []string) *MultiServersDiscovery
NewMultiServerDiscovery creates a MultiServersDiscovery instance
func (*MultiServersDiscovery) Get ¶
func (d *MultiServersDiscovery) Get(mode SelectMode) (string, error)
Get a server according to mode
func (*MultiServersDiscovery) GetAll ¶
func (d *MultiServersDiscovery) GetAll() ([]string, error)
GetAll returns all servers in discovery
func (*MultiServersDiscovery) Refresh ¶
func (d *MultiServersDiscovery) Refresh() error
Refresh doesn't make sense for MultiServersDiscovery, so ignore it
func (*MultiServersDiscovery) Update ¶
func (d *MultiServersDiscovery) Update(servers []string) error
Update the servers of discovery dynamically if needed
type Node ¶
type NodeStatus ¶
type NodeStatus struct {
// contains filtered or unexported fields
}
type NodeWriter ¶
type NodeWriter struct {
// contains filtered or unexported fields
}
type ParallelReader ¶
type ParallelReader struct {
// contains filtered or unexported fields
}
ParallelReader is a reader that handles parallel disk reads
func NewParallelReader ¶
func NewParallelReader(pool *ErasurePool, offset, size uint64, degrade bool) *ParallelReader
func (*ParallelReader) ReadBlock ¶
func (pr *ParallelReader) ReadBlock(offset, size uint64)
type ParallelWriter ¶
type ParallelWriter struct {
// contains filtered or unexported fields
}
ParallelReader is a writer that write data bytes to multiple nodes
type Pattern ¶
type Pattern int
const ( Random Pattern = iota // see http://www.accs.com/p_and_p/RAID/LinuxRAID.html for more infos LeftSymmetric LeftAsymmetric RightSymmetric RightAsymmetric )
type Redundancy ¶
type Redundancy string
const ( Erasure_RS Redundancy = "Erasure_RS" Erasure_XOR Redundancy = "Erasure_XOR" Erasure_LRC Redundancy = "Erasure_LRC" Replication Redundancy = "Replication" None Redundancy = "None" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a simple register center, provide following functions. add a server and receive heartbeat to keep it alive. returns all alive servers and delete dead servers sync simultaneously.
func NewRegistry ¶
NewRegistry create a registry instance with timeout setting
func (*Registry) HandleHTTP ¶
HandleHTTP registers an HTTP handler for Registry messages on registryPath
type RegistryDiscovery ¶
type RegistryDiscovery struct { *MultiServersDiscovery // contains filtered or unexported fields }
func NewRegistryDiscovery ¶
func NewRegistryDiscovery(registerAddr string, timeout time.Duration) *RegistryDiscovery
func (*RegistryDiscovery) Get ¶
func (d *RegistryDiscovery) Get(mode SelectMode) (string, error)
func (*RegistryDiscovery) GetAll ¶
func (d *RegistryDiscovery) GetAll() ([]string, error)
func (*RegistryDiscovery) Refresh ¶
func (d *RegistryDiscovery) Refresh() error
func (*RegistryDiscovery) Update ¶
func (d *RegistryDiscovery) Update(servers []string) error
type SelectMode ¶
type SelectMode int
const ( RandomSelect SelectMode = iota // select randomly RoundRobinSelect // select using Robbin algorithm )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an RPC server.
func (*Server) Accept ¶
Accept accepts connections on the listener and serves requests for each incoming connection.
func (*Server) HandleHTTP ¶
func (s *Server) HandleHTTP()
HandleHTTP registers an HTTP handler for RPC messages on rpcPath. It is still necessary to invoke http.Serve(), typically in a go statement.
func (*Server) ServeConn ¶
func (s *Server) ServeConn(conn io.ReadWriteCloser)
type ServerItem ¶
type ServerItem struct { Addr string // contains filtered or unexported fields }
type SimOptions ¶
type SimOptions struct { //switch between "diskFail" and "bitRot" Mode string // specify which disks to fail FailDisk string // specify number of disks to fail FailNum int //specify the fileName, used only for "bitRot" mode FileName string }
SimOptions defines the parameters for simulation
type StorageAPI ¶
type StorageAPI interface { ListDir(ctx context.Context, dirPath string, level int) ([]string, error) ReadFile(ctx context.Context, path string, offset, size int64, buf []byte) (n int64, err error) ReadFileStream(ctx context.Context, path string, offset, length int64) (io.ReadCloser, error) WriteFile(ctx context.Context, path string, size int64, buf []byte) error WriteFileStream(ctx context.Context, path string, size int64, reader io.Reader) error RenameFile(ctx context.Context, srcPath, dstPath string) error Delete(ctx context.Context, path string, recursive bool) (err error) }
Customer APIs
type XClient ¶
type XClient struct {
// contains filtered or unexported fields
}
func NewXClient ¶
func NewXClient(d Discovery, mode SelectMode, opt *Option) *XClient
func (*XClient) Broadcast ¶
func (xc *XClient) Broadcast(ctx context.Context, serviceMethod string, args, reply interface{}) error
Broadcast invokes the named function for every server registered in discovery Once a server returns response, the function quickly quits by a cancelled context
Source Files ¶
- erasure-cluster.go
- erasure-disk.go
- erasure-encode.go
- erasure-errors.go
- erasure-file.go
- erasure-handlers.go
- erasure-layout.go
- erasure-node.go
- erasure-pool.go
- erasure-read.go
- erasure-recover.go
- erasure-remove.go
- erasure-scale.go
- erasure-simulator.go
- erasure-transfer.go
- erasure-update.go
- erasure-utils.go
- frontend-ACL.go
- restful-api.go
- rpc-client.go
- rpc-debug.go
- rpc-discovery.go
- rpc-registry.go
- rpc-server.go
- rpc-service.go
- rpc-xclient.go