Skip to content

feat: add option to cancel idle peer task #3810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/config/peerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ type DownloadOption struct {
Concurrent *ConcurrentOption `mapstructure:"concurrent" yaml:"concurrent"`
SyncPieceViaHTTPS bool `mapstructure:"syncPieceViaHTTPS" yaml:"syncPieceViaHTTPS"`
SplitRunningTasks bool `mapstructure:"splitRunningTasks" yaml:"splitRunningTasks"`
CancelIdlePeerTask bool `mapstructure:"cancelIdlePeerTask" yaml:"cancelIdlePeerTask"`
// resource clients option
ResourceClients ResourceClientsOption `mapstructure:"resourceClients" yaml:"resourceClients"`

Expand Down
17 changes: 9 additions & 8 deletions client/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,15 @@ func New(opt *config.DaemonOption, d dfpath.Dfpath) (Daemon, error) {

peerTaskManagerOption := &peer.TaskManagerOption{
TaskOption: peer.TaskOption{
PeerHost: host,
SchedulerOption: opt.Scheduler,
PieceManager: pieceManager,
StorageManager: storageManager,
WatchdogTimeout: opt.Download.WatchdogTimeout,
CalculateDigest: opt.Download.CalculateDigest,
GRPCCredentials: rpc.NewInsecureCredentials(),
GRPCDialTimeout: opt.Download.GRPCDialTimeout,
PeerHost: host,
SchedulerOption: opt.Scheduler,
PieceManager: pieceManager,
StorageManager: storageManager,
WatchdogTimeout: opt.Download.WatchdogTimeout,
CalculateDigest: opt.Download.CalculateDigest,
GRPCCredentials: rpc.NewInsecureCredentials(),
GRPCDialTimeout: opt.Download.GRPCDialTimeout,
CancelIdlePeerTask: opt.Download.CancelIdlePeerTask,
},
SchedulerClient: schedulerClient,
PerPeerRateLimit: opt.Download.PerPeerRateLimit.Limit,
Expand Down
12 changes: 8 additions & 4 deletions client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ type TaskOption struct {
GRPCCredentials credentials.TransportCredentials
GRPCDialTimeout time.Duration
// WatchdogTimeout > 0 indicates to start watch dog for every single peer task
WatchdogTimeout time.Duration
WatchdogTimeout time.Duration
CancelIdlePeerTask bool
}

func (ptm *peerTaskManager) newPeerTaskConductor(
Expand All @@ -183,9 +184,12 @@ func (ptm *peerTaskManager) newPeerTaskConductor(
parent *peerTaskConductor,
rg *nethttp.Range,
seed bool) *peerTaskConductor {
// use a new context with span info
ctx = trace.ContextWithSpan(context.Background(), trace.SpanFromContext(ctx))
ctx, span := tracer.Start(ctx, config.SpanPeerTask, trace.WithSpanKind(trace.SpanKindClient))
var span trace.Span
if !ptm.TaskOption.CancelIdlePeerTask {
// use a new context to avoid cancel idle peer task
ctx = trace.ContextWithSpan(context.Background(), trace.SpanFromContext(ctx))
}
ctx, span = tracer.Start(ctx, config.SpanPeerTask, trace.WithSpanKind(trace.SpanKindClient))
span.SetAttributes(config.AttributePeerHost.String(ptm.PeerHost.Id))
span.SetAttributes(semconv.NetHostIPKey.String(ptm.PeerHost.Ip))
span.SetAttributes(config.AttributePeerID.String(request.PeerId))
Expand Down