-
Notifications
You must be signed in to change notification settings - Fork 820
Implementing Bucket index sync status file #5446
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
alvinlin123
merged 4 commits into
cortexproject:master
from
alanprot:bucket-index-sync-status
Jul 11, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,6 +206,11 @@ func (c *BlocksCleaner) deleteUserMarkedForDeletion(ctx context.Context, userID | |
if err := bucketindex.DeleteIndex(ctx, c.bucketClient, userID, c.cfgProvider); err != nil { | ||
return err | ||
} | ||
|
||
// Delete the bucket sync status | ||
if err := bucketindex.DeleteIndexSyncStatus(ctx, c.bucketClient, userID); err != nil { | ||
return err | ||
} | ||
c.tenantBucketIndexLastUpdate.DeleteLabelValues(userID) | ||
|
||
var deletedBlocks, failed int | ||
|
@@ -321,15 +326,40 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userID string, firstRun b | |
} | ||
} | ||
|
||
// Reading bucket index sync stats | ||
idxs, err := bucketindex.ReadSyncStatus(ctx, c.bucketClient, userID, userLogger) | ||
|
||
if err != nil { | ||
level.Warn(userLogger).Log("msg", "error reading the bucket index status", "err", err) | ||
idxs = bucketindex.Status{Version: bucketindex.SyncStatusFileVersion, NonQueryableReason: bucketindex.Unknown} | ||
} | ||
|
||
idxs.Status = bucketindex.Ok | ||
idxs.SyncTime = time.Now().Unix() | ||
|
||
// Read the bucket index. | ||
idx, err := bucketindex.ReadIndex(ctx, c.bucketClient, userID, c.cfgProvider, c.logger) | ||
|
||
defer func() { | ||
bucketindex.WriteSyncStatus(ctx, c.bucketClient, userID, idxs, userLogger) | ||
alanprot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}() | ||
|
||
if errors.Is(err, bucketindex.ErrIndexCorrupted) { | ||
level.Warn(userLogger).Log("msg", "found a corrupted bucket index, recreating it") | ||
} else if errors.Is(err, bucket.ErrCustomerManagedKeyAccessDenied) { | ||
// Give up cleaning if we get access denied | ||
level.Warn(userLogger).Log("msg", err.Error()) | ||
level.Warn(userLogger).Log("msg", "customer manager key access denied", "err", err) | ||
idxs.Status = bucketindex.CustomerManagedKeyError | ||
// Making the tenant non queryable until 3x the cleanup interval to give time to compactors and storegateways | ||
// to reload the bucket index in case the key access is re-granted | ||
idxs.NonQueryableUntil = time.Now().Add(3 * c.cfg.CleanupInterval).Unix() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can we extract the magic number 3 to some meaningfully name constant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
idxs.NonQueryableReason = bucketindex.CustomerManagedKeyError | ||
|
||
// Update the bucket index update time | ||
c.tenantBucketIndexLastUpdate.WithLabelValues(userID).SetToCurrentTime() | ||
return nil | ||
} else if err != nil && !errors.Is(err, bucketindex.ErrIndexNotFound) { | ||
idxs.Status = bucketindex.GenericError | ||
return err | ||
} | ||
|
||
|
@@ -348,6 +378,7 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userID string, firstRun b | |
w := bucketindex.NewUpdater(c.bucketClient, userID, c.cfgProvider, c.logger) | ||
idx, partials, totalBlocksBlocksMarkedForNoCompaction, err := w.UpdateIndex(ctx, idx) | ||
if err != nil { | ||
idxs.Status = bucketindex.GenericError | ||
return err | ||
} | ||
|
||
|
@@ -398,7 +429,6 @@ func (c *BlocksCleaner) cleanUser(ctx context.Context, userID string, firstRun b | |
c.tenantBlocksMarkedForNoCompaction.WithLabelValues(userID).Set(float64(totalBlocksBlocksMarkedForNoCompaction)) | ||
c.tenantBucketIndexLastUpdate.WithLabelValues(userID).SetToCurrentTime() | ||
c.tenantPartialBlocks.WithLabelValues(userID).Set(float64(len(partials))) | ||
|
||
return nil | ||
} | ||
|
||
|
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
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.