Skip to content

Conversation

@nugaon
Copy link
Member

@nugaon nugaon commented Sep 22, 2025

The changes implemented comprehensive pin protection for chunk eviction by addressing a critical bug in the EvictBatchBin method.

The fix modified the EvictBatchBin method to properly check each chunk against all pin collections using the newly created pinstore.IsChunkPinnedInCollection function. When a pinned chunk is found, the eviction only removes reserve related records of that chunk. This ensures that non-pinned chunks can still be evicted while maintaining the integrity of pinned content.

Reserve capacity eviction is directly protected through the EvictBatchBin method.
Batch expiry eviction is automatically protected because the entire flow from EvictBatch ultimately calls EvictBatchBin.
Cache eviction was determined to not require pin protection because pinned chunks are stored in the main ChunkStore layer.

Closes #5215

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

@nugaon nugaon force-pushed the fix/pin-eviction-guard branch from c54b4b2 to b22264a Compare September 22, 2025 12:58
@nugaon
Copy link
Member Author

nugaon commented Sep 22, 2025

This change may affect other parts of the system and the followings were considered:

if pinned chunks remain in the reserve when they should have been evicted then:

  1. the reserve sample may include chunks that shouldn't be there, leading to different commitment hashes.
  2. storage radius calculation may deviate from the expected value

because of these points, during the eviction, pinned chunks are protected by retaining the chunk in the chunkstore but it removes all reserve related records.
This should be taken into account when designing migration processes.

@nugaon nugaon marked this pull request as ready for review September 22, 2025 16:23
func(item *BatchRadiusItem) {
eg.Go(func() error {
err := r.st.Run(ctx, func(s transaction.Store) error {
return RemoveChunkMetaData(ctx, s, item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to remove the Pinned Chunks metadata, would this affect retrieval of those pinned chunks if storage pressure eviction or manual eviction?

@gacevicljubisa
Copy link
Member

This should be taken into account when designing migration processes.

Can we add this as a note in migration?

Comment on lines +342 to +343
evictedItems []*BatchRadiusItem
pinnedEvictedItems []*BatchRadiusItem
Copy link
Member

@gacevicljubisa gacevicljubisa Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think to change names of this 2 collections and add some comment, something like:

    nonPinnedItems []*BatchRadiusItem  // Fully evicted from reserve + chunkstore
    pinnedItems    []*BatchRadiusItem  // Only evicted from reserve, kept in chunkstore

@gacevicljubisa
Copy link
Member

I have tested it with expired batch and seems good. @nugaon if you can, please address other comments. I will approve it now

@gacevicljubisa gacevicljubisa requested a review from janos October 2, 2025 12:08

// Check if the chunk is pinned in any collection
pinned := false
for _, uuid := range pinUuids {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will slow down batch eviction linearly with the number of collections. Is there a possibility to have collection uuid as a field in BatchRadiusItem so that all of these lookups (Has method calls) are not done? From what I see, it would need some complexity to manage the synchronisations between BatchRadiusItem and pinChunkItem keys, but if the performance degradation is significant, it may be necessary. It is ok to try with this simpler solution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is information redundant approach but faster one for sure.
IMO this is still a good enough approach because if you don't use pinning feature you won't notice any performance difference. It is questionable how much this feature is used to worth modifying the underlying DB structure to be redundant.

@nugaon nugaon merged commit 0856b6a into master Oct 3, 2025
15 checks passed
@nugaon nugaon deleted the fix/pin-eviction-guard branch October 3, 2025 14:02
@bcsorvasi bcsorvasi added this to the v2.7.0 milestone Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Pinned chunks can be evicted from storage despite pin protection

6 participants