framework

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxScore = 100
	MinScore = 0

	SuccessStatus       StatusCode = "success"
	UnschedulableStatus StatusCode = "Unschedulable"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate added in v0.0.2

type Candidate struct {
	// Node represents the candidate nodeTracker.
	Node api.NodeTracker
	// Only set after scoring.
	Score float32
}

Candidate will be used as the result of Filter extension point and input/output of Score extension point.

type ChunkInfo

type ChunkInfo struct {
	Name         string
	Size         int64
	Path         string
	Revision     string
	NodeSelector map[string]string
}

type DefaultFramework

type DefaultFramework struct {
	// contains filtered or unexported fields
}

func (*DefaultFramework) RegisterPlugins

func (df *DefaultFramework) RegisterPlugins(fns []RegisterFunc) error

func (*DefaultFramework) RunFilterPlugins

func (df *DefaultFramework) RunFilterPlugins(ctx context.Context, chunk ChunkInfo, nodeInfo *NodeInfo, nodeTrackers []api.NodeTracker, cache *cache.Cache) (candidates []Candidate)

func (*DefaultFramework) RunScorePlugins

func (df *DefaultFramework) RunScorePlugins(ctx context.Context, chunk ChunkInfo, nodeInfo *NodeInfo, candidates []Candidate, cache *cache.Cache) []Candidate

type Download

type Download interface {
	Framework
}

Download represents the methods to download a chunk.

type FilterPlugin

type FilterPlugin interface {
	Plugin
	// Filter helps to filter out unrelated nodes.
	// Once NodeInfo is nil, it's a download task, otherwise it's a sync task.
	Filter(context.Context, ChunkInfo, *NodeInfo, api.NodeTracker, *cache.Cache) Status
}

type Framework

type Framework interface {
	// RegisterPlugins will register the plugins to run.
	RegisterPlugins([]RegisterFunc) error
	// RunFilterPlugins will filter out unsatisfied peers.
	// NodeInfo refers to the source node in syncing tasks, it must not be nil in syncing,
	// on the contrary, it must be nil in downloading tasks.
	RunFilterPlugins(context.Context, ChunkInfo, *NodeInfo, []api.NodeTracker, *cache.Cache) []Candidate
	// RunScorePlugins will calculate the scores of all the peers.
	// NodeInfo refers to the source node in syncing tasks, it must not be nil in syncing,
	// on the contrary, it must be nil in downloading tasks.
	RunScorePlugins(context.Context, ChunkInfo, *NodeInfo, []Candidate, *cache.Cache) []Candidate
}

Framework represents the algo about how to pick the candidates among all the peers.

type NodeInfo added in v0.0.2

type NodeInfo struct {
	Name string
}

type Plugin

type Plugin interface {
	Name() string
}

Plugin is the parent type for all the framework plugins. the same time.

type PreFilterPlugin

type PreFilterPlugin interface {
	Plugin
	// PreFilter helps to do some computing before calling Filter plugins.
	PreFilter(context.Context, ChunkInfo, *cache.Cache) Status
}

type RegisterFunc

type RegisterFunc = func() (Plugin, error)

type Registry

type Registry map[string]Plugin

Registry is a collection of all available plugins. The framework uses a registry to enable and initialize configured plugins.

func (Registry) Register

func (r Registry) Register(fn RegisterFunc) error

Register adds a new plugin to the registry. If a plugin with the same name exists, it returns an error.

func (Registry) Unregister

func (r Registry) Unregister(name string) error

Unregister removes an existing plugin from the registry. If no plugin with the provided name exists, it returns an error.

type ScoreCandidate added in v0.0.2

type ScoreCandidate struct {
	// SourceNodeName represents the the source node name in syncing tasks.
	// It's empty once in downloading tasks.
	SourceNodeName string
	// CandidateNodeName represents the target node name.
	CandidateNodeName string
	// Score for candidate node.
	Score float32
}

ScoreCandidate will be used after Score extension point for picking best effort nodes.

type ScorePlugin

type ScorePlugin interface {
	Plugin
	// Score gets the score of the nodeTracker, it should be ranged between
	// 0 and 100.
	// Once NodeInfo is nil, it's a download task, otherwise it's a sync task.
	Score(context.Context, ChunkInfo, *NodeInfo, api.NodeTracker, *cache.Cache) float32
}

type Status

type Status struct {
	Code StatusCode
}

type StatusCode

type StatusCode string

type Sync

type Sync interface {
	Framework
}

Sync represents the methods to sync a chunk.

Jump to

Keyboard shortcuts

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