Skip to content

Commit

Permalink
downloader: add timestamp for stable heap order
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Mar 3, 2024
1 parent 2ed1429 commit 42095cc
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions renterd/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ type (
b []byte
err error

key string
priority int
index int
key string
priority int
index int
timestamp time.Time
}

priorityQueue []*blockResponse
Expand All @@ -60,7 +61,10 @@ type (
func (h priorityQueue) Len() int { return len(h) }

func (h priorityQueue) Less(i, j int) bool {
return h[i].priority < h[j].priority
if h[i].priority != h[j].priority {
return h[i].priority < h[j].priority
}
return h[i].timestamp.Before(h[j].timestamp)
}

func (h priorityQueue) Swap(i, j int) {
Expand Down Expand Up @@ -156,9 +160,10 @@ func (bd *BlockDownloader) getResponse(c cid.Cid, priority int) *blockResponse {
return task
}
task := &blockResponse{
key: key,
priority: priority,
ch: make(chan struct{}),
key: key,
priority: priority,
timestamp: time.Now(),
ch: make(chan struct{}),
}
bd.cache.Add(key, task)
heap.Push(bd.queue, task)
Expand Down

0 comments on commit 42095cc

Please sign in to comment.