seed

package
v0.0.0-...-7d98ad5 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBlockSize int64 = 4 * 1024 * 1024
)

Functions

This section is empty.

Types

type Block

type Block struct {
	Size        int64              `json:"size"`
	StartFile   int                `json:"startFile"`
	StartOffset int64              `json:"startOffset"`
	Done        bool               `json:"-"`
	CheckSum    []byte             `json:"checkSum"`
	Hosts       map[Host]time.Time `json:"-"`
}

type File

type File struct {
	Mode os.FileMode `json:"mode"`
	//Size of file, -1 for dir, -2 for symbol link
	Size int64 `json:"size"`
	//SymPath if symbol link target path
	SymPath   string `json:"symPath"`
	Path      string `json:"path"`
	LocalPath string `json:"-"`
	CheckSum  []byte `json:"checkSum"`
	// contains filtered or unexported fields
}

type Host

type Host struct {
	IP   [4]byte `json:"ip"` // IPv4 only
	Port uint16  `json:"port"`
}

func ParseHost

func ParseHost(hStr string) (Host, error)

ParseHost parses "IPv4:Port"

func SortDeDup

func SortDeDup(l []Host) []Host

func (Host) Hash

func (h Host) Hash(vIndex byte) uint32

Hash uses HashCrc which has better uniformity

func (Host) HashCrc

func (h Host) HashCrc(vIndex byte) uint32

func (Host) HashFnv

func (h Host) HashFnv(vIndex byte) uint32

func (Host) HashSha

func (h Host) HashSha(vIndex byte) uint32

func (Host) String

func (h Host) String() string

type HostPath

type HostPath struct {
	Host string `json:"host" form:"host" query:"host"`
	Path string `json:"path" form:"path" query:"path"`
}

type Seed

type Seed struct {
	sync.RWMutex
	Path       string   `json:"path"`
	FileCount  int      `json:"fileCount"`
	Files      []*File  `json:"files"`
	Blocks     []*Block `json:"blocks"`
	BlockSize  int64    `json:"blockSize"`
	VNodeCount uint8    `json:"vnodeCount"`
	// Hosts are only updated before Marshal
	Hosts []Host `json:"hosts"`
	//InitFileIdx   int      `json:"initFileIdx"`
	//InitBlockIdx  int      `json:"initBlockIdx"`
	TotalSize    int64 `json:"totalSize"`
	TotalWritten int64 `json:"-"`
}

func MakeSeed

func MakeSeed(path string, blockSize int64) (*Seed, error)

func (*Seed) Add

func (sd *Seed) Add(host Host)

func (*Seed) GetAllHosts

func (sd *Seed) GetAllHosts() []Host

func (*Seed) GetBlockIndex

func (sd *Seed) GetBlockIndex(host Host) []uint32

func (*Seed) Localize

func (sd *Seed) Localize(cmdSrcPath string, cmdDestPath string) (err error)

func (*Seed) LocateBlock

func (sd *Seed) LocateBlock(blockId int64, n int) []Host

LocateBlock tries to find maximum `n` different hosts for `blockId`. As the golang map is not deterministic on iteration, when multiple hosts hashed onto the same block the LocateBlock returned hosts are also not deterministic which is good for load balancing.

func (*Seed) Remove

func (sd *Seed) Remove(host Host)

func (*Seed) TouchAll

func (sd *Seed) TouchAll() (err error)

TouchAll make all directory and all files including symbol links and empty files. THIS Must be called after Localize

Jump to

Keyboard shortcuts

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