-
Notifications
You must be signed in to change notification settings - Fork 833
Introduce cleaner visit marker #6113
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f754a94
Introduce cleaner visit marker to make sure cleaning cycle for one te…
alexqyle 2742aeb
update CHANGELOG
alexqyle a745e07
update CHANGELOG and fix lint
alexqyle 6590605
removed unused function
alexqyle cc55af0
fix lint
alexqyle f8e91d2
Merge branch 'master' into cleaner-visit-marker
alexqyle 509427e
fixed test
alexqyle 10762a6
refactor
alexqyle 3d202f1
refactor
alexqyle 76d08f8
refactor
alexqyle 249da68
rename metric
alexqyle e3c0c6e
use mutex to lock all write operations
alexqyle 1dfd81c
Removed problemic function only used by test
alexqyle 1e17396
update test order
alexqyle bce6824
fix test
alexqyle e1e6881
fix lint
alexqyle 37f2458
refactor
alexqyle c1b4e8a
update doc and remove visit marker metrics
alexqyle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package compactor | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"time" | ||
|
||
"github.com/cortexproject/cortex/pkg/storage/tsdb/bucketindex" | ||
) | ||
|
||
const ( | ||
// CleanerVisitMarkerName is the name of cleaner visit marker file. | ||
CleanerVisitMarkerName = "cleaner-visit-marker.json" | ||
// CleanerVisitMarkerVersion1 is the current supported version of cleaner visit mark file. | ||
CleanerVisitMarkerVersion1 = 1 | ||
) | ||
|
||
type CleanerVisitMarker struct { | ||
CompactorID string `json:"compactorID"` | ||
Status VisitStatus `json:"status"` | ||
// VisitTime is a unix timestamp of when the partition was visited (mark updated). | ||
VisitTime int64 `json:"visitTime"` | ||
// Version of the file. | ||
Version int `json:"version"` | ||
} | ||
|
||
func NewCleanerVisitMarker(compactorID string) *CleanerVisitMarker { | ||
return &CleanerVisitMarker{ | ||
CompactorID: compactorID, | ||
Version: CleanerVisitMarkerVersion1, | ||
} | ||
} | ||
|
||
func (b *CleanerVisitMarker) IsExpired(cleanerVisitMarkerTimeout time.Duration) bool { | ||
return !time.Now().Before(time.Unix(b.VisitTime, 0).Add(cleanerVisitMarkerTimeout)) | ||
} | ||
|
||
func (b *CleanerVisitMarker) IsVisited(cleanerVisitMarkerTimeout time.Duration) bool { | ||
return !(b.GetStatus() == Completed) && !(b.GetStatus() == Failed) && !b.IsExpired(cleanerVisitMarkerTimeout) | ||
} | ||
|
||
func (b *CleanerVisitMarker) GetStatus() VisitStatus { | ||
return b.Status | ||
} | ||
|
||
func (b *CleanerVisitMarker) GetVisitMarkerFilePath() string { | ||
return GetCleanerVisitMarkerFilePath() | ||
} | ||
|
||
func (b *CleanerVisitMarker) UpdateStatus(ownerIdentifier string, status VisitStatus) { | ||
b.CompactorID = ownerIdentifier | ||
b.Status = status | ||
b.VisitTime = time.Now().Unix() | ||
} | ||
|
||
func (b *CleanerVisitMarker) String() string { | ||
return fmt.Sprintf("compactor_id=%s status=%s visit_time=%s", | ||
b.CompactorID, | ||
b.Status, | ||
time.Unix(b.VisitTime, 0).String(), | ||
) | ||
} | ||
|
||
func GetCleanerVisitMarkerFilePath() string { | ||
return path.Join(bucketindex.MarkersPathname, CleanerVisitMarkerName) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.