Skip to content

Read concurrency#437

Open
Alrighttt wants to merge 12 commits into
masterfrom
matt/read-concurrency
Open

Read concurrency#437
Alrighttt wants to merge 12 commits into
masterfrom
matt/read-concurrency

Conversation

@Alrighttt

@Alrighttt Alrighttt commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Changes Manager.mu to sync.RWMutex to enable reads to run in parallel.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-project-automation github-project-automation Bot moved this to In Progress in Sia Jun 5, 2026
@Alrighttt

Copy link
Copy Markdown
Contributor Author

As discussed with Nate and Luke, I will be redesigning or removing the peer cancellation logic. Don't bother with review for now.

Comment thread syncer/peer.go Outdated
@Alrighttt Alrighttt force-pushed the matt/read-concurrency branch from eaf7c4c to db7a3a3 Compare June 9, 2026 12:23
@Alrighttt Alrighttt changed the title Read concurrency and peer cancellation Read concurrency Jun 9, 2026
@Alrighttt

Copy link
Copy Markdown
Contributor Author

I removed all code related to the peer cancellation mechanism.

@Alrighttt Alrighttt requested a review from n8mgr June 9, 2026 14:42
Comment thread chain/db.go Outdated
// calls. Buckets obtained via the DB inside fn must not be used
// after fn returns. Writes via the DB inside fn are not durable
// and may panic.
View(fn func(DB) error) error

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.

this makes me sad

maybe we could add a writeable flag on Bucket() instead?

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.

Not sure you'd like that more but if you want to be able to do multiple operations within a single View we could also do something like

snap := m.store.Snapshot()
defer snap.Close()
for range 10 {
  _, _ = snap.Block(...)
}

Where Snapshot starts a readonly transaction which returns a ReadonlyDB interface only containing a subset of the DB interface. So it's impossible to call CreateBucket in the first place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented Chris's suggestion

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.

I do like the idea of making it impossible to call mutating methods, but to make it airtight, we need a read-only DBBucket as well that has no Put or Delete methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added this in 38d9717

Comment thread chain/db.go Outdated
@Alrighttt Alrighttt requested a review from ChrisSchinnerl June 16, 2026 14:55
ChrisSchinnerl
ChrisSchinnerl previously approved these changes Jun 16, 2026
@@ -0,0 +1,5 @@
---
default: patch

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.

This should probably be minor considering we're extending the exported Store and DB interfaces? Anyone implementing those will have to add Snapshot for it to compile.

Comment thread chain/concurrency_test.go
}
}

func runConcurrentReadsWrites(t *testing.T, db chain.DB) {

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.

Should we add a reader that calls AddV2PoolTransactions alongside the existing readers? Isn't that the most interesting one because we temporarily release the lock there to notify the listeners?

@chris124567 chris124567 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.

LGTM besides PJ's comments

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.

6 participants