Skip to content

Ensure that pruning slabs/sectors in parallel doesn't leave orphaned slabs/sectors#1010

Open
chris124567 wants to merge 5 commits into
masterfrom
christopher/concurrency-issue
Open

Ensure that pruning slabs/sectors in parallel doesn't leave orphaned slabs/sectors#1010
chris124567 wants to merge 5 commits into
masterfrom
christopher/concurrency-issue

Conversation

@chris124567

@chris124567 chris124567 commented Jun 12, 2026

Copy link
Copy Markdown
Member

Close #1009

Test fails on master and passes on this branch

Copilot AI review requested due to automatic review settings June 12, 2026 17:11
@github-project-automation github-project-automation Bot moved this to In Progress in Sia Jun 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses #1009 by hardening Postgres slab/sector pruning against concurrency races that could leave orphaned slabs or sectors, and adds a regression test to reproduce/guard against those scenarios.

Changes:

  • Add row-level locking in unpinSlabs to serialize concurrent unpin/prune operations on the same slabs and their sectors.
  • Make slab stat decrements rely on the actual number of deleted slab rows (via RowsAffected) to keep counters accurate under concurrency.
  • Add TestSlabPruningConcurrent to exercise concurrent pruning across shared slabs, shared sectors, and account-pruning interactions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
persist/postgres/slabs_test.go Adds a multi-scenario concurrency test to detect orphaned slabs/sectors and verify stats return to zero after concurrent pruning.
persist/postgres/sectors.go Adds explicit FOR UPDATE locking around slab and sector deletion checks and adjusts slab stat decrementing to use actual deletions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread persist/postgres/slabs_test.go Outdated
Comment thread persist/postgres/sectors.go Outdated
@chris124567 chris124567 self-assigned this Jun 12, 2026
@chris124567 chris124567 force-pushed the christopher/concurrency-issue branch from 3b00a57 to 2092763 Compare June 12, 2026 21:02
peterjan
peterjan previously approved these changes Jun 15, 2026

@peterjan peterjan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified test fails on master and there's no noticeable regression in BenchmarkUnpinSlab

Comment thread persist/postgres/sectors.go Outdated
// slabs. The deletion checks below rely on committed account_slabs rows, so
// two transactions each removing one of the final references must not run
// their checks at the same time.
if _, err := tx.Exec(ctx, `

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As discussed in the meeting today we want to move unpinning slabs and sectors out of the hot path. So when a user prunes their account we limit the deletion to the account_slabs table and prune slabs and sectors in a background loop which should then avoid the concurrency issue.

@chris124567 chris124567 Jun 25, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I missed that meeting but is what I just pushed roughly what we wanted to do?

@ChrisSchinnerl

Copy link
Copy Markdown
Member

@chris124567 reminder to update this

@chris124567

Copy link
Copy Markdown
Member Author

Ok I will do this on Wednesday got tied up with s3d stuff

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread persist/postgres/accounts.go
Comment thread persist/postgres/slabs_test.go
Comment thread persist/postgres/sectors.go Outdated
Comment thread persist/postgres/sectors.go Outdated
Comment thread persist/postgres/init.sql Outdated
Comment thread persist/postgres/accounts.go Outdated

@ChrisSchinnerl ChrisSchinnerl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One last nit

Comment thread persist/postgres/accounts.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Test that pruning slabs/sectors in parallel doesn't leave orphaned slabs/sectors

4 participants