storage

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GCName = "StorageManager"
)

Variables

View Source
var (
	ErrTaskNotFound     = errors.New("task not found")
	ErrPieceNotFound    = errors.New("piece not found")
	ErrPieceCountNotSet = errors.New("total piece count not set")
	ErrDigestNotSet     = errors.New("piece digest not set")
	ErrInvalidDigest    = errors.New("invalid digest")
)
View Source
var (
	ErrShortRead = errors.New("short read")
)

Functions

func WithStorageOption

func WithStorageOption(opt *config.StorageOption) func(*storageManager) error

Types

type CommonTaskRequest

type CommonTaskRequest struct {
	PeerID      string `json:"peerID,omitempty"`
	TaskID      string `json:"taskID,omitempty"`
	Destination string
}

type GCCallback

type GCCallback func(request CommonTaskRequest)

type Manager

type Manager interface {
	TaskStorageDriver
	// KeepAlive tests if storage is used in given time duration
	clientutil.KeepAlive
	// RegisterTask registers a task in storage driver
	RegisterTask(ctx context.Context, req RegisterTaskRequest) error
	// FindCompletedTask try to find a completed task for fast path
	FindCompletedTask(taskID string) *ReusePeerTask
	// CleanUp cleans all storage data
	CleanUp()
}

func NewStorageManager

func NewStorageManager(storeStrategy config.StoreStrategy, opt *config.StorageOption, gcCallback GCCallback, moreOpts ...func(*storageManager) error) (Manager, error)

type PeerTaskMetaData

type PeerTaskMetaData struct {
	PeerID string `json:"peerID,omitempty"`
	TaskID string `json:"taskID,omitempty"`
}

type PieceMetaData

type PieceMetaData struct {
	Num    int32            `json:"num,omitempty"`
	Md5    string           `json:"md5,omitempty"`
	Offset uint64           `json:"offset,omitempty"`
	Range  clientutil.Range `json:"range,omitempty"`
	Style  base.PieceStyle  `json:"style,omitempty"`
}

type ReadPieceRequest

type ReadPieceRequest struct {
	PeerTaskMetaData
	PieceMetaData
}

type Reclaimer

type Reclaimer interface {
	// CanReclaim indicates whether the storage can be reclaimed
	CanReclaim() bool

	// MarkReclaim marks the storage which will be reclaimed
	MarkReclaim()

	// Reclaim reclaims the storage
	Reclaim() error
}

Reclaimer stands storage reclaimer

type RegisterTaskRequest

type RegisterTaskRequest struct {
	CommonTaskRequest
	ContentLength int64
	TotalPieces   int32
	PieceMd5Sign  string
}

type ReusePeerTask

type ReusePeerTask = UpdateTaskRequest

type StoreRequest

type StoreRequest struct {
	CommonTaskRequest
	MetadataOnly bool
	StoreOnly    bool
	TotalPieces  int32
}

type TaskStorageDriver

type TaskStorageDriver interface {
	// WritePiece put a piece of a task to storage
	WritePiece(ctx context.Context, req *WritePieceRequest) (int64, error)

	// ReadPiece get a piece data reader of a task from storage
	// return a Reader and a Closer from task data with seeked, caller should read bytes and close it.
	// If req.Num is equal to -1, range has a fixed value.
	ReadPiece(ctx context.Context, req *ReadPieceRequest) (io.Reader, io.Closer, error)

	ReadAllPieces(ctx context.Context, req *PeerTaskMetaData) (io.ReadCloser, error)

	GetPieces(ctx context.Context, req *base.PieceTaskRequest) (*base.PiecePacket, error)

	UpdateTask(ctx context.Context, req *UpdateTaskRequest) error

	// Store stores task data to the target path
	Store(ctx context.Context, req *StoreRequest) error

	ValidateDigest(req *PeerTaskMetaData) error

	IsInvalid(req *PeerTaskMetaData) (bool, error)
}

type UpdateTaskRequest

type UpdateTaskRequest struct {
	PeerTaskMetaData
	ContentLength int64
	TotalPieces   int32
	PieceMd5Sign  string
	// GenPieceDigest is used when back source
	GenPieceDigest bool
}

type WritePieceRequest

type WritePieceRequest struct {
	PeerTaskMetaData
	PieceMetaData
	UnknownLength bool
	Reader        io.Reader
}

Jump to

Keyboard shortcuts

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