Documentation
¶
Index ¶
- Constants
- Variables
- type BaseProperties
- type CDNPattern
- type Config
- func (c *Config) GetSuperCID(taskID string) string
- func (c *Config) GetSuperPID() string
- func (c *Config) IsSuperCID(clientID string) bool
- func (c *Config) IsSuperPID(peerID string) bool
- func (c *Config) Load(path string) error
- func (c *Config) SetCIDPrefix(ip string)
- func (c *Config) SetSuperPID(pid string)
- func (c *Config) String() string
- type PluginProperties
- type PluginType
Constants ¶
const ( CDNPatternLocal = "local" CDNPatternSource = "source" )
const ( // DefaultListenPort is the default port supernode server listens on. DefaultListenPort = 8002 // DefaultDownloadPort is the default port for download files from supernode. DefaultDownloadPort = 8001 // DefaultSchedulerCorePoolSize is the default core pool size of ScheduledExecutorService. DefaultSchedulerCorePoolSize = 10 )
const ( // DefaultSupernodeConfigFilePath the default supernode config path. DefaultSupernodeConfigFilePath = "/etc/dragonfly/supernode.yml" // SuperNodeCIdPrefix is a string as the prefix of the supernode. SuperNodeCIdPrefix = "cdnnode:" )
const ( PieceSEMISUC = -3 PieceWAITING = -1 PieceRUNNING = 0 PieceSUCCESS = 1 PieceFAILED = 2 )
PieceStatus code
const ( // DefaultFailureCountLimit indicates the default limit of failure count as a client. DefaultFailureCountLimit = 5 // DefaultEliminationLimit indicates the default limit of failure count as a server. DefaultEliminationLimit = 5 // DefaultPeerUpLimit indicates the default limit of the load count as a server. DefaultPeerUpLimit = 5 // DefaultPeerDownLimit indicates the default limit of the download task count as a client. DefaultPeerDownLimit = 4 )
const ( // DefaultPieceSize 4M DefaultPieceSize = 4 * 1024 * 1024 // DefaultPieceSizeLimit 15M DefaultPieceSizeLimit = 15 * 1024 * 1024 // PieceHeadSize 4 bytes PieceHeadSize = 4 // PieceWrapSize 4 bytes head and 1 byte tail PieceWrapSize = PieceHeadSize + 1 // PieceTailChar the value of piece tail PieceTailChar = byte(0x7f) )
const ( // SubsystemSupernode represents metrics from supernode. SubsystemSupernode = "supernode" // SubsystemDfget represents metrics from dfget. SubsystemDfget = "dfget" )
const ( // DefaultFailAccessInterval is the interval time after failed to access the URL. DefaultFailAccessInterval = 3 * time.Minute // DefaultGCInitialDelay is the delay time from the start to the first GC execution. DefaultGCInitialDelay = 6 * time.Second // DefaultGCMetaInterval is the interval time to execute the GC meta. DefaultGCMetaInterval = 2 * time.Minute // DefaultTaskExpireTime when a task is not accessed within the taskExpireTime, // and it will be treated to be expired. DefaultTaskExpireTime = 3 * time.Minute // DefaultPeerGCDelay is the delay time to execute the GC after the peer has reported the offline. DefaultPeerGCDelay = 3 * time.Minute )
const ( DefaultYoungGCThreshold = 100 * fileutils.GB DefaultFullGCThreshold = 5 * fileutils.GB DefaultIntervalThreshold = 2 * time.Hour DefaultGCDiskInterval = 15 * time.Second DefaultCleanRatio = 1 )
Default config value for gc disk
const ( // DefaultLinkLimit is the default network speed limit for each piece. // unit: MB/s DefaultLinkLimit = 20 * rate.MB // DefaultSystemReservedBandwidth is the default network bandwidth reserved for system software. // unit: MB/s DefaultSystemReservedBandwidth = 20 * rate.MB // DefaultMaxBandwidth is the default network bandwidth that supernode can use. // unit: MB/s DefaultMaxBandwidth = 200 * rate.MB )
const ( // StoragePlugin the storage plugin type. StoragePlugin = PluginType("storage") // SchedulerPlugin the scheduler plugin type. SchedulerPlugin = PluginType("scheduler") )
const (
// CDNWriterRoutineLimit 4
CDNWriterRoutineLimit = 4
)
Variables ¶
var ( // DownloadHome is the parent directory where the downloaded files are stored // which is a relative path. DownloadHome = "download" )
var PluginTypes = []PluginType{ StoragePlugin, SchedulerPlugin, }
PluginTypes explicitly stores all available plugin types.
Functions ¶
This section is empty.
Types ¶
type BaseProperties ¶ added in v0.4.0
type BaseProperties struct {
// CDNPattern cdn pattern which must be in ["local", "source"].
// default: CDNPatternLocal
CDNPattern CDNPattern `yaml:"cdnPattern"`
// ListenPort is the port supernode server listens on.
// default: 8002
ListenPort int `yaml:"listenPort"`
// DownloadPort is the port for download files from supernode.
// default: 8001
DownloadPort int `yaml:"downloadPort"`
// HomeDir is working directory of supernode.
// default: /home/admin/supernode
HomeDir string `yaml:"homeDir"`
// the core pool size of ScheduledExecutorService.
// When a request to start a download task, supernode will construct a thread concurrent pool
// to download pieces of source file and write to specified storage.
// Note: source file downloading is into pieces via range attribute set in HTTP header.
// default: 10
SchedulerCorePoolSize int `yaml:"schedulerCorePoolSize"`
// DownloadPath specifies the path where to store downloaded files from source address.
DownloadPath string
// PeerUpLimit is the upload limit of a peer. When dfget starts to play a role of peer,
// it can only stand PeerUpLimit upload tasks from other peers.
// default: 5
PeerUpLimit int `yaml:"peerUpLimit"`
// PeerDownLimit is the download limit of a peer. When a peer starts to download a file/image,
// it will download file/image in the form of pieces. PeerDownLimit mean that a peer can only
// stand starting PeerDownLimit concurrent downloading tasks.
// default: 4
PeerDownLimit int `yaml:"peerDownLimit"`
// When dfget node starts to play a role of peer, it will provide services for other peers
// to pull pieces. If it runs into an issue when providing services for a peer, its self failure
// increases by 1. When the failure limit reaches EliminationLimit, the peer will isolate itself
// as a unhealthy state. Then this dfget will be no longer called by other peers.
// default: 5
EliminationLimit int `yaml:"eliminationLimit"`
// FailureCountLimit is the failure count limit set in supernode for dfget client.
// When a dfget client takes part in the peer network constructed by supernode,
// supernode will command the peer to start distribution task.
// When dfget client fails to finish distribution task, the failure count of client
// increases by 1. When failure count of client reaches to FailureCountLimit(default 5),
// dfget client will be moved to blacklist of supernode to stop playing as a peer.
// default: 5
FailureCountLimit int `yaml:"failureCountLimit"`
// LinkLimit is set for supernode to limit every piece download network speed.
// default: 20 MB, in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will also be parsed as Byte.
LinkLimit rate.Rate `yaml:"linkLimit"`
// SystemReservedBandwidth is the network bandwidth reserved for system software.
// default: 20 MB, in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will also be parsed as Byte.
SystemReservedBandwidth rate.Rate `yaml:"systemReservedBandwidth"`
// MaxBandwidth is the network bandwidth that supernode can use.
// default: 200 MB, in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will also be parsed as Byte.
MaxBandwidth rate.Rate `yaml:"maxBandwidth"`
// Whether to enable profiler
// default: false
EnableProfiler bool `yaml:"enableProfiler"`
// Whether to open DEBUG level
// default: false
Debug bool `yaml:"debug"`
// AdvertiseIP is used to set the ip that we advertise to other peer in the p2p-network.
// By default, the first non-loop address is advertised.
AdvertiseIP string `yaml:"advertiseIP"`
// FailAccessInterval is the interval time after failed to access the URL.
// unit: minutes
// default: 3
FailAccessInterval time.Duration `yaml:"failAccessInterval"`
// GCInitialDelay is the delay time from the start to the first GC execution.
// default: 6s
GCInitialDelay time.Duration `yaml:"gcInitialDelay"`
// GCMetaInterval is the interval time to execute GC meta.
// default: 2min
GCMetaInterval time.Duration `yaml:"gcMetaInterval"`
// TaskExpireTime when a task is not accessed within the taskExpireTime,
// and it will be treated to be expired.
// default: 3min
TaskExpireTime time.Duration `yaml:"taskExpireTime"`
// PeerGCDelay is the delay time to execute the GC after the peer has reported the offline.
// default: 3min
PeerGCDelay time.Duration `yaml:"peerGCDelay"`
// GCDiskInterval is the interval time to execute GC disk.
// default: 15s
GCDiskInterval time.Duration `yaml:"gcDiskInterval"`
// YoungGCThreshold if the available disk space is more than YoungGCThreshold
// and there is no need to GC disk.
//
// default: 100GB
YoungGCThreshold fileutils.Fsize `yaml:"youngGCThreshold"`
// FullGCThreshold if the available disk space is less than FullGCThreshold
// and the supernode should gc all task files which are not being used.
//
// default: 5GB
FullGCThreshold fileutils.Fsize `yaml:"fullGCThreshold"`
// IntervalThreshold is the threshold of the interval at which the task file is accessed.
// default: 2h
IntervalThreshold time.Duration `yaml:"IntervalThreshold"`
// CleanRatio is the ratio to clean the disk and it is based on 10.
// It means the value of CleanRatio should be [1-10].
//
// default: 1
CleanRatio int
LogConfig dflog.LogConfig `yaml:"logConfig" json:"logConfig"`
// contains filtered or unexported fields
}
BaseProperties contains all basic properties of supernode.
func NewBaseProperties ¶ added in v0.4.0
func NewBaseProperties() *BaseProperties
NewBaseProperties creates an instant with default values.
type CDNPattern ¶ added in v1.0.1
type CDNPattern string
type Config ¶
type Config struct {
*BaseProperties `yaml:"base"`
Plugins map[PluginType][]*PluginProperties `yaml:"plugins"`
Storages map[string]interface{} `yaml:"storages"`
}
Config contains all configuration of supernode.
func NewConfig ¶ added in v0.4.0
func NewConfig() *Config
NewConfig creates an instant with default values.
func (*Config) GetSuperCID ¶ added in v0.4.0
GetSuperCID returns the cid string for taskID.
func (*Config) GetSuperPID ¶ added in v0.4.0
GetSuperPID returns the pid string for supernode.
func (*Config) IsSuperCID ¶ added in v0.4.0
IsSuperCID returns whether the clientID represents supernode.
func (*Config) IsSuperPID ¶ added in v0.4.0
IsSuperPID returns whether the peerID represents supernode.
func (*Config) SetCIDPrefix ¶ added in v0.4.0
SetCIDPrefix sets a string as the prefix for supernode CID which used to distinguish from the other peer nodes.
func (*Config) SetSuperPID ¶ added in v0.4.0
SetSuperPID sets the value of supernode PID.
type PluginProperties ¶ added in v0.4.0
type PluginProperties struct {
Name string `yaml:"name"`
Enabled bool `yaml:"enabled"`
Config string `yaml:"config"`
}
PluginProperties the properties of a plugin.