Skip to content

Commit

Permalink
fix: lock on last_scraped_time update
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Nov 11, 2024
1 parent 5db9c51 commit dba5d63
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"

"github.com/aws/smithy-go/ptr"
Expand Down Expand Up @@ -742,11 +743,22 @@ func saveResults(ctx api.ScrapeContext, results []v1.ScrapeResult) (v1.ScrapeSum
return summary, nil
}

var lastScrapedTimeMutex sync.Map

func updateLastScrapedTime(ctx api.ScrapeContext, ids []string) error {
if len(ids) == 0 {
return nil
}

{
// an incremental scraper might be trying to update last_scraped_time at the same time.
l, _ := lastScrapedTimeMutex.LoadOrStore(ctx.ScraperID(), &sync.Mutex{})
mu := l.(*sync.Mutex)

mu.Lock()
defer mu.Unlock()
}

for i := 0; i < len(ids); i = i + 5000 {
end := i + 5000
if end > len(ids) {
Expand Down

0 comments on commit dba5d63

Please sign in to comment.