fix: prevent retention service from hanging #25121
Merged
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.
Fix issue that can cause the retention service to hang waiting on a
Shard.Close
call. When this occurs, no other shards will be deleted by the retention service. This is usually noticed as an increase in disk usage because old shards are not cleaned up.The fix adds to new methods to
Store
,SetShardNewReadersBlocked
andInUse
.InUse
can be used to poll if a shard has active readers, which the retention service uses to skip over in-use shards to prevent the service from hanging.SetShardNewReadersBlocked
determines if new read access may be granted to a shard. This is required to prevent race conditions around the use ofInUse
and the deletion of shards.If the retention service skips over a shard because it is in-use, the shard will be checked again the next time the retention service is run. It can be deleted on subsequent checks if it is no longer in-use. If the shards is stuck in-use, the retention service will not be able to delete the shards, which can be observed in the logs for manual intervention. Other shards can still be deleted by the retention service even if a shard is stuck with readers.
This is a port of ad68ec8 from master-1.x to main-2.x, then backported to 2.7 with a clean cherry-pick.
closes: #25118
(cherry picked from commit b4bd607) (cherry picked from commit cb8cfe3)