mgr

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

PieceStatusMap maintains the mapping relationship between PieceUpdateRequestResult and PieceStatus code.

Functions

This section is empty.

Types

type CDNMgr

type CDNMgr interface {
	// TriggerCDN will trigger CDN to download the file from sourceUrl.
	// It includes the following steps:
	// 1). download the source file
	// 2). write the file to disk
	//
	// In fact, it's a very time consuming operation.
	// So if not necessary, it should usually be executed concurrently.
	// In addition, it's not thread-safe.
	TriggerCDN(ctx context.Context, taskInfo *types.TaskInfo) (*types.TaskInfo, error)

	// GetHTTPPath returns the http download path of taskID.
	GetHTTPPath(ctx context.Context, taskID string) (path string, err error)

	// GetStatus get the status of the file.
	GetStatus(ctx context.Context, taskID string) (cdnStatus string, err error)

	// Delete the file from disk with specified taskID.
	Delete(ctx context.Context, taskID string) error
}

CDNMgr as an interface defines all operations against CDN and operates on the underlying files stored on the local disk, etc.

type DfgetTaskMgr

type DfgetTaskMgr interface {
	// Add a new dfgetTask, we use clientID and taskID to identify a dfgetTask uniquely.
	// ClientID should be generated by dfget, supernode will use it directly.
	// NOTE: We should create a new dfgetTask for each download process,
	//       even if the downloads initiated by the same machine.
	Add(ctx context.Context, dfgetTask *types.DfGetTask) error

	// Get a dfgetTask info with specified clientID and taskID.
	Get(ctx context.Context, clientID, taskID string) (dfgetTask *types.DfGetTask, err error)

	// GetCIDByPeerIDAndTaskID returns cid with specified peerID and taskID.
	GetCIDByPeerIDAndTaskID(ctx context.Context, peerID, taskID string) (string, error)

	// List returns the list of dfgetTask.
	List(ctx context.Context, filter map[string]string) (dfgetTaskList []*types.DfGetTask, err error)

	// Delete a dfgetTask with clientID and taskID.
	Delete(ctx context.Context, clientID, taskID string) error

	// UpdateStatus update the status of dfgetTask with specified clientID and taskID.
	// Supernode will update the status of dfgetTask in the following situations:
	// 1. after init the dfgetTask
	// 2. when success/fail to download some pieces
	// 3. when the entire download process ends in success or failure
	UpdateStatus(ctx context.Context, clientID, taskID, status string) error
}

DfgetTaskMgr as an interface defines all operations against DfgetTask. A DfgetTask represents a download process initiated by dfget or other clients.

type PeerMgr

type PeerMgr interface {
	// Register a peer with specified peerInfo.
	// Supernode will generate a unique peerID for every Peer with PeerInfo provided.
	Register(ctx context.Context, peerCreateRequest *types.PeerCreateRequest) (peerCreateResponse *types.PeerCreateResponse, err error)

	// DeRegister offline a peer service and
	// NOTE: update the info related for scheduler.
	DeRegister(ctx context.Context, peerID string) error

	// Get the peer Info with specified peerID.
	Get(ctx context.Context, peerID string) (*types.PeerInfo, error)

	// List return a list of peers info with filter.
	List(ctx context.Context, filter *util.PageFilter) (peerList []*types.PeerInfo, err error)
}

PeerMgr as an interface defines all operations against Peer. A Peer represents a web server that provides file downloads for others.

type PeerState added in v0.4.0

type PeerState struct {
	// PeerID identifies a peer uniquely.
	PeerID string

	// ProducerLoad is the load of download services provided by the current node.
	ProducerLoad *cutil.AtomicInt

	// ClientErrorCount maintains the number of times that PeerID failed to downloaded from the other peer nodes.
	ClientErrorCount *cutil.AtomicInt

	// ServiceErrorCount maintains the number of times that the other peer nodes failed to downloaded from the PeerID.
	ServiceErrorCount *cutil.AtomicInt

	// ServiceDownTime the down time of the peer service.
	ServiceDownTime *int64
}

PeerState maintains peer related information.

type PieceResult added in v0.4.0

type PieceResult struct {
	TaskID   string
	PieceNum int
	DstPID   string
}

PieceResult contains the information about which piece to download from which node.

type ProgressMgr

type ProgressMgr interface {
	// InitProgress inits the correlation information between peers and pieces, etc.
	InitProgress(ctx context.Context, taskID, peerID, clientID string) error

	// UpdateProgress updates the correlation information between peers and pieces.
	// 1. update the info about srcCID to tell the scheduler that corresponding peer has the piece now.
	// 2. update the info about dstPID to tell the scheduler that someone has downloaded the piece form here.
	// Scheduler will calculate the load and times of error/success for every peer to make better decisions.
	UpdateProgress(ctx context.Context, taskID, srcCID, srcPID, dstPID string, pieceNum, pieceStatus int) error

	// UpdateClientProgress updates the info when success to schedule peer srcCID to download from dstPID.
	UpdateClientProgress(ctx context.Context, taskID, srcCID, dstPID string, pieceNum, pieceStatus int) error

	// GetPieceProgressByCID gets all pieces progress with specified clientID.
	// The filter parameter depends on the specific implementation.
	GetPieceProgressByCID(ctx context.Context, taskID, clientID, filter string) (pieceNums []int, err error)

	// DeletePieceProgressByCID deletes the pieces progress with specified clientID.
	DeletePieceProgressByCID(ctx context.Context, taskID, clientID string) (err error)

	// GetPeerIDsByPieceNum gets all peerIDs with specified taskID and pieceNum.
	GetPeerIDsByPieceNum(ctx context.Context, taskID string, pieceNum int) (peerIDs []string, err error)

	// DeletePeerIDByPieceNum deletes the peerID which means that
	// the peer no longer provides the service for the pieceNum of taskID.
	DeletePeerIDByPieceNum(ctx context.Context, taskID string, pieceNum int, peerID string) error

	// GetPeerStateByPeerID gets peer state with specified peerID.
	GetPeerStateByPeerID(ctx context.Context, peerID string) (peerState *PeerState, err error)

	// DeletePeerStateByPeerID deletes the peerState by PeerID.
	DeletePeerStateByPeerID(ctx context.Context, peerID string) error

	// GetPeersByTaskID gets all peers info with specified taskID.
	GetPeersByTaskID(ctx context.Context, taskID string) (peersInfo []*types.PeerInfo, err error)

	// GetBlackInfoByPeerID gets black info with specified peerID.
	GetBlackInfoByPeerID(ctx context.Context, peerID string) (dstPIDMap *cutil.SyncMap, err error)
}

ProgressMgr is responsible for maintaining the correspondence between peer and pieces.

type SchedulerMgr

type SchedulerMgr interface {
	// Schedule gets scheduler result with specified taskID, clientID and peerID through some rules.
	Schedule(ctx context.Context, taskID, clientID, peerID string) ([]*PieceResult, error)
}

SchedulerMgr is responsible for calculating scheduling results according to certain rules.

type TaskMgr

type TaskMgr interface {
	// Register a task represents that someone wants to download a file.
	// Supernode will get the task file meta and return taskID.
	// NOTE: If supernode cannot find the task file, the CDN download will be triggered.
	Register(ctx context.Context, taskCreateRequest *types.TaskCreateRequest) (taskCreateResponse *types.TaskCreateResponse, err error)

	// Get the task Info with specified taskID.
	Get(ctx context.Context, taskID string) (*types.TaskInfo, error)

	// List returns the list tasks with filter.
	List(ctx context.Context, filter map[string]string) ([]*types.TaskInfo, error)

	// CheckTaskStatus check whether the taskID corresponding file exists.
	CheckTaskStatus(ctx context.Context, taskID string) (bool, error)

	// Delete deletes a task
	// NOTE: delete the related peers and dfgetTask info is necessary.
	Delete(ctx context.Context, taskID string) error

	// Update updates the task info with specified info.
	// In common, there are several situations that we will use this method:
	// 1. when finished to download, update task status.
	// 2. for operation usage.
	// TODO: define a struct of TaskUpdateRequest?
	Update(ctx context.Context, taskID string, taskInfo *types.TaskInfo) error

	// GetPieces get the pieces to be downloaded based on the scheduling result,
	// just like this: which pieces can be downloaded from which peers.
	GetPieces(ctx context.Context, taskID, clientID string, piecePullRequest *types.PiecePullRequest) (isFinished bool, data interface{}, err error)

	// UpdatePieceStatus update the piece status with specified parameters.
	// A task file is divided into several pieces logically.
	// We use a sting called pieceRange to identify a piece.
	// A pieceRange separated by a dash, like this: 0-45565, etc.
	UpdatePieceStatus(ctx context.Context, taskID, pieceRange string, pieceUpdateRequest *types.PieceUpdateRequest) error
}

TaskMgr as an interface defines all operations against Task. A Task will store some meta info about the taskFile, pieces and something else. A Task has a one-to-one correspondence with a file on the disk which is identified by taskID.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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