types

package
Version: v0.0.0-...-f617e85 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2016 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FileInQueue = FileStatus(0)
	FileWriting = FileStatus(1)
	FileSync    = FileStatus(2)
	FileOK      = FileStatus(3)
	FileDelete  = FileStatus(4)
)
View Source
var (
	Healthy   = NodeStatus(0)
	Unhealthy = NodeStatus(1)
)

Functions

This section is empty.

Types

type Blob

type Blob struct {
	FileID  FileID
	Length  int64
	Content []byte
	Name    string
}

type Block

type Block struct {
	ID     BlockID
	Header *BlockHeader // metadata
	Data   []byte       // contents of this block
}

Block is storage unit of each file

func NewBlock

func NewBlock(filename string, data []byte, size int64, chunk NodeID) *Block

func (*Block) Reader

func (b *Block) Reader() io.Reader

type BlockHeader

type BlockHeader struct {
	BlockID  BlockID `json:"block_id"`
	FileID   FileID  `json:"file_id"`
	Chunk    NodeID  `json:"chunk"`
	Checksum string  `json:"checksum"`
	Filename string  `json:"filenam"`
	Size     int64   `json:"size"`
}

BlockHeaders holds Block metadata

type BlockID

type BlockID string

type File

type File struct {
	ID           FileID
	Name         string
	Length       int64
	Replications int
	Createtime   time.Time
	Status       FileStatus
	Blocks       map[BlockID]*BlockHeader
}

func NewFile

func NewFile(name string, length int64) *File

type FileID

type FileID string

type FileStatus

type FileStatus int

type Node

type Node struct {
	ID   NodeID
	Addr string

	Blocks          []BlockID
	Connections     int
	Heath           NodeStatus
	LastHeartbeat   time.Time
	LastUtilization int64
}

func NewInitialNode

func NewInitialNode(addr string, id NodeID) *Node

NewInitialNode return a whole new node with initial information.

func (*Node) HeartbeatDuration

func (node *Node) HeartbeatDuration() time.Duration

HeartbeatDuration compute the duration between last heartbeat and now.

func (*Node) IsHealthy

func (node *Node) IsHealthy() bool

IsHealthy check if a node is healthy or not.

type NodeID

type NodeID string

type NodeStatus

type NodeStatus int

type SyncBlock

type SyncBlock struct {
	BlockID BlockID
	Addr    string
	NodeID  NodeID
}

func NewSyncBlock

func NewSyncBlock(blockID BlockID, addr string, nodeID NodeID) *SyncBlock

type UUID

type UUID [16]byte

UUID type.

func FromStr

func FromStr(s string) (id UUID, err error)

FromStr returns a UUID based on a string. The string could be in the following format:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

If the string is not in one of these formats, it'll return an error.

func MustFromStr

func MustFromStr(s string) UUID

MustFromStr behaves similarly to FromStr except that it'll panic instead of returning an error.

func RandUUID

func RandUUID() UUID

Rand generates a new version 4 UUID.

func (UUID) Hex

func (this UUID) Hex() string

Hex returns a hex string representation of the UUID in xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL