Skip to content
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

[filebeat][azure-blob-storage] - Simplified state checkpoint calculation #40936

Merged
merged 13 commits into from
Oct 2, 2024
Prev Previous commit
Next Next commit
updated with PR suggestions
  • Loading branch information
ShourieG committed Sep 25, 2024
commit 92d6344dc38949b68c7ce1981a0a9c2bceba47de
30 changes: 12 additions & 18 deletions x-pack/filebeat/input/azureblobstorage/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package azureblobstorage
import (
"context"
"fmt"
"slices"
"sort"
"sync"

azruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
Expand Down Expand Up @@ -190,26 +192,18 @@ func (s *scheduler) fetchBlobPager(batchSize int32) *azruntime.Pager[azblob.List
// moveToLastSeenJob, moves to the latest job position past the last seen job
// Jobs are stored in lexicographical order always, hence the latest position can be found either on the basis of job name or timestamp
func (s *scheduler) moveToLastSeenJob(jobs []*job) []*job {
latestJobs := make([]*job, 0, len(jobs))
jobsToReturn := make([]*job, 0, len(jobs))

for _, job := range jobs {
switch {
case job.timestamp().After(s.state.checkpoint().LatestEntryTime):
latestJobs = append(latestJobs, job)
case job.name() > s.state.checkpoint().BlobName:
jobsToReturn = append(jobsToReturn, job)
}
}
cp := s.state.checkpoint()
jobs = slices.DeleteFunc(jobs, func(j *job) bool {
return !(j.timestamp().After(cp.LatestEntryTime) || j.name() > cp.BlobName)
})

// in a senario where there are some jobs which have a greater timestamp
// but lesser alphanumeric order and some jobs have greater alphanumeric order
// than the current checkpoint blob name, we then append to the latest jobs
if len(latestJobs) > 0 {
jobsToReturn = append(latestJobs, jobsToReturn...)
}

return jobsToReturn
// but lesser lexicographic order and some jobs have greater lexicographic order
// than the current checkpoint blob name, we then sort around the pivot checkpoint timestamp
sort.Slice(jobs, func(i, _ int) bool {
ShourieG marked this conversation as resolved.
Show resolved Hide resolved
return jobs[i].timestamp().After(cp.LatestEntryTime)
})
return jobs
}

func (s *scheduler) isFileSelected(name string) bool {
Expand Down
Loading