Repository navigation
fix(storage): count real orphan blob deletions, own orphan cursors and surface lost blob locks - #422
Merged
Merged
Conversation
…d surface lost blob locks - WithBlobLocks returns ErrBlobLockLost when the lock transaction cannot be committed (its session died while fn ran) instead of logging and reporting success. The lock transactions (WithBlobLocks, DeleteBlobIfUnreferenced, the batched delete, FlipBlobPlacement) switch off idle_in_transaction_session_timeout for themselves so a server setting cannot drop the lock. - The orphan collector counts a blob only when it was handed to deletion: one a row references again is kept and no longer counted. What a batch committed before an error is kept in the count; the orphan chunk now equals the database's lock chunk, so one batch call is one transaction. - The process-wide orphan cursor is replaced by an OrphanCursor owned by each caller (cleanup worker, trash purge worker, repository and trash handlers), so one caller's passes no longer move another's position past unexamined blobs. A window cut short by shutdown is redone instead of skipped. - Document the no-nesting rule for blob lock slots on WithBlobLocks, FlipBlobPlacement, SafeDeleteBlob and core.lockSlots.
Coverage
Go by area
Web by area (lines)
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the blob refcount / blob lock findings of the code audit.
Fixed
WithBlobLockslogged a failedtx.Commitand returned nil, so a holder whose lock session died (idle_in_transaction_session_timeout, failover,pg_terminate_backend) believed it had run exclusively. It now returnsdatabase.ErrBlobLockLost(wrapping the commit error). In addition every lock transaction (WithBlobLocks,DeleteBlobIfUnreferenced, the batched delete,FlipBlobPlacement, which runsverifyagainst the object store) executesset_config('idle_in_transaction_session_timeout','0',true)with its first lock statement, so a server-wide timeout can no longer kill an idle lock transaction in the first place. All callers go throughstorage.WithBlobLock(s)/CommitBlobsand already return the error.removed++wheneverSafeDeleteBlobreturned nil, even whenDeleteBlobIfUnreferencedreturned false (a row references the blob again). The bool now flows through an unexportedsafeDeleteBloband only real deletions are counted. The exportedSafeDeleteBlobkeeps its error-only signature: ~60 call sites ignore the outcome and none needs it.removed += nis now done before the batch error is looked at, andorphanDeleteChunkis tied todatabase.BlobBatchLockChunkso oneDeleteBlobsIfUnreferencedcall is one transaction (commits all or nothing); this also guarantees the per-blob fallback cannot count a blob twice. Todaynis 0 on error, so this is defensive rather than a visible change.orphanCursor. Replaced bystorage.OrphanCursor, owned by each caller:CleanupWorker,TrashPurgeWorker,RepositoriesHandlerandTrashHandler. A cursor is mutex-protected, held for a whole window (concurrent passes on one cursor take consecutive windows) and advanced only when the window was worked through (a pass cut short by shutdown redoes the window instead of skipping it).lockSlotsnesting rule. Documented oncore.lockSlots,acquireLockSlot,WithBlobLocks,FlipBlobPlacement,SafeDeleteBlobandstorage.WithBlobLock. No runtime assertion: a marker in the context would break production code that nests today (see below).Skipped
ReclaimMetadataBlobvs a same-shablobsrow. Not a bug.blobRefCountcounts FK references when the row exists, andBlobDeletionSweeper.bytesNeededre-checks under the blob lock: for scope All it keeps the bytes and drops the queue entry ifBlobReferenceCount > 0or ablobsrow exists (GetBlobPlacementfound). A dangling row or lost bytes is impossible; an unreferenced same-sha row is later removed by the orphan collector, which re-queues the bytes. Pinned by a new integration test (TestReclaimMetadataBlobLeavesAnUnreferencedBlobsRowIntact).Tests
fnyieldsErrBlobLockLost; a lock held 3x longer than a 200 msidle_in_transaction_session_timeoutsurvives (the test fails with theset_configremoved, with a control transaction proving the timeout is in effect).Notes / not changed
fncommitted, the caller sees an error although its rows exist (e.g. gomodhandleUploadreleases its quota reservation; the periodic quota reconcile corrects it).SafeDeleteBlobcleanup after such a failure is refcount-guarded, so no referenced bytes are lost.internal/format/docker/attach.goAttachReferrerrunsstorage.WithBlobLockand inside itattachLockedcallsstorage.CommitBlob(nestedWithBlobLocks) andSafeDeleteBlob. That violates the no-nesting rule and can deadlock onceMaxOpenConns/2concurrent attaches fill the slots.