Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ledger: move MakeCatchpointReader back to the Reader interface #5583

Merged
merged 2 commits into from Jul 21, 2023

Conversation

icorderi
Copy link
Contributor

Summary

#5451 introduced a bug, catchpoint reads need to be kept on a separate readonly connection for the node to make forward progress.

This PR adds the required method to the Reader interface for the store, so it becomes available via the Snapshot scope.
There is an implicit contract that the snapshot is going through a separate read-only handle to the sqlite db.
If this were ever to change, this will break again.

Test Plan

@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #5583 (9e2d6fe) into master (d316914) will increase coverage by 0.00%.
The diff coverage is 20.00%.

@@           Coverage Diff           @@
##           master    #5583   +/-   ##
=======================================
  Coverage   55.79%   55.79%           
=======================================
  Files         446      446           
  Lines       63418    63422    +4     
=======================================
+ Hits        35381    35388    +7     
  Misses      25668    25668           
+ Partials     2369     2366    -3     
Impacted Files Coverage Δ
ledger/store/trackerdb/sqlitedriver/catchpoint.go 21.23% <0.00%> (-0.13%) ⬇️
...edger/store/trackerdb/sqlitedriver/sqlitedriver.go 0.00% <0.00%> (ø)
ledger/catchpointtracker.go 60.40% <100.00%> (+0.70%) ⬆️
ledger/catchpointwriter.go 62.34% <100.00%> (ø)

... and 11 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@algorandskiy algorandskiy requested a review from cce July 19, 2023 18:12
@algorandskiy
Copy link
Contributor

Now discussing should we keep DB reading for snapshot in commitSyncer in write connection or accept reading in read connection.

@@ -1126,7 +1126,7 @@ func (ct *catchpointTracker) generateCatchpointData(ctx context.Context, account

start := time.Now()
ledgerGeneratecatchpointCount.Inc(nil)
err = ct.dbs.TransactionContext(ctx, func(dbCtx context.Context, tx trackerdb.TransactionScope) (err error) {
err = ct.dbs.SnapshotContext(ctx, func(dbCtx context.Context, tx trackerdb.SnapshotScope) (err error) {
Copy link
Contributor

@cce cce Jul 21, 2023

Choose a reason for hiding this comment

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

I got kind of lost trying to figure out how things "originally" were implemented and the history of changes, tracking down when things switched from Rdb/Wdb to Snapshot/Transaction — just for reference, jotting down my notes —

this was changed from Rdb to BatchContext (now called TransactionContext) in #5021 in https://github.com/algorand/go-algorand/pull/5021/files#diff-9ca6833a989d244ce6b95aaddf4f2f0889203f7e3e6918b0c9ace37c62f21320R1090

@@ -1316,7 +1316,7 @@ func (ct *catchpointTracker) GetCatchpointStream(round basics.Round) (ReadCloseS
ledgerGetcatchpointCount.Inc(nil)
// TODO: we need to generalize this, check @cce PoC PR, he has something
// somewhat broken for some KVs..
err := ct.dbs.Transaction(func(ctx context.Context, tx trackerdb.TransactionScope) (err error) {
err := ct.dbs.Snapshot(func(ctx context.Context, tx trackerdb.SnapshotScope) (err error) {
Copy link
Contributor

@cce cce Jul 21, 2023

Choose a reason for hiding this comment

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

This was changed from Rdb to Snapshot in #5021 (which preserved old dbpair behavior) and then from Snapshot to Transaction in #5451 in https://github.com/algorand/go-algorand/pull/5451/files#diff-9ca6833a989d244ce6b95aaddf4f2f0889203f7e3e6918b0c9ace37c62f21320R1319

@@ -107,7 +107,7 @@ func (data catchpointStateProofVerificationContext) ToBeHashed() (protocol.HashI
return protocol.StateProofVerCtx, protocol.Encode(&data)
}

func makeCatchpointWriter(ctx context.Context, filePath string, tx trackerdb.TransactionScope, maxResourcesPerChunk int) (*catchpointWriter, error) {
func makeCatchpointWriter(ctx context.Context, filePath string, tx trackerdb.SnapshotScope, maxResourcesPerChunk int) (*catchpointWriter, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This (and the struct field tx) was changed from sql.Tx to TransactionScope in #5080 in https://github.com/algorand/go-algorand/pull/5080/files#diff-ea28f4f1f6d1a703b59a0a03c2f71be0614487d17ab17a3da7183beef0e49ae8R94 — we should give catchpointWriter a better name like catchpointFileDumper or catchpointReadDBToFile to make it sound more read-only

@@ -82,10 +86,7 @@ type Writer interface {
// we should split these two sets of methods into two separate interfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it makes sense to do this now, and split CatchpointReader and CatchpointWriter interfaces? or are there still a few places that mix them both to record the FirstStageInfo and stuff like that and we should do it later

Copy link
Contributor

@cce cce Jul 21, 2023

Choose a reason for hiding this comment

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

I guess moving the MakeCatchpointReader & the other two methods into Reader is the first step of that, you could add the three methods into a CatchpointReader interface that is embedded into Reader as a tiny step further towards that

Copy link
Contributor

@cce cce left a comment

Choose a reason for hiding this comment

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

LGTM but we could also have these methods hang off of CatchpointReader and be split from Reader.. but maybe you already have that in a different PR

@algorandskiy algorandskiy changed the title fix: move MakeCatchpointReader back to the Reader interface ledger: move MakeCatchpointReader back to the Reader interface Jul 21, 2023
@algorandskiy algorandskiy changed the title ledger: move MakeCatchpointReader back to the Reader interface ledger: move MakeCatchpointReader back to the Reader interface Jul 21, 2023
@algorandskiy algorandskiy merged commit 197bfb6 into algorand:master Jul 21, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants