storage

package
v2.0.2-beta.6 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: Apache-2.0 Imports: 24 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("digest not set")
	ErrInvalidDigest    = errors.New("invalid digest")
)
View Source
var (
	ErrShortRead = errors.New("short read")
)

Functions

func WithGCInterval added in v2.0.2

func WithGCInterval(gcInterval time.Duration) func(*storageManager) error

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) (TaskStorageDriver, 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 added in v2.0.2

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

type PieceMetadata added in v2.0.2

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 sought, 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
}

type WritePieceRequest

type WritePieceRequest struct {
	PeerTaskMetadata
	PieceMetadata
	UnknownLength bool
	Reader        io.Reader
	// GenPieceDigest is used after the last piece in back source case
	GenPieceDigest func(n int64) (total int32, gen bool)
}

Jump to

Keyboard shortcuts

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