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: fix catchpoint pending hashes locking #5534

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion ledger/catchupaccessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ func (c *catchpointCatchupAccessorImpl) BuildMerkleTrie(ctx context.Context, pro
defer wg.Done()
defer close(writerQueue)

dbErr := dbs.Transaction(func(transactionCtx context.Context, tx trackerdb.TransactionScope) (err error) {
// Note: this needs to be accessed on a snapshot to guarantee a concurrent read-only access to the sqlite db
dbErr := dbs.Snapshot(func(transactionCtx context.Context, tx trackerdb.SnapshotScope) (err error) {
it := tx.MakeCatchpointPendingHashesIterator(trieRebuildAccountChunkSize)
var hashes [][]byte
for {
Expand Down
10 changes: 5 additions & 5 deletions ledger/store/trackerdb/sqlitedriver/sqlitedriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
return makeStateProofVerificationReader(r.q)
}

// MakeCatchpointPendingHashesIterator implements trackerdb.Reader
func (r *sqlReader) MakeCatchpointPendingHashesIterator(hashCount int) trackerdb.CatchpointPendingHashesIter {
return MakeCatchpointPendingHashesIterator(hashCount, r.q)

Check warning on line 183 in ledger/store/trackerdb/sqlitedriver/sqlitedriver.go

View check run for this annotation

Codecov / codecov/patch

ledger/store/trackerdb/sqlitedriver/sqlitedriver.go#L182-L183

Added lines #L182 - L183 were not covered by tests
}

type sqlWriter struct {
e db.Executable
}
Expand Down Expand Up @@ -231,11 +236,6 @@
e db.Executable
}

// MakeCatchpointPendingHashesIterator implements trackerdb.Catchpoint
func (c *sqlCatchpoint) MakeCatchpointPendingHashesIterator(hashCount int) trackerdb.CatchpointPendingHashesIter {
return MakeCatchpointPendingHashesIterator(hashCount, c.e)
}

// MakeCatchpointReader implements trackerdb.Catchpoint
func (c *sqlCatchpoint) MakeCatchpointReader() (trackerdb.CatchpointReader, error) {
return NewCatchpointSQLReaderWriter(c.e), nil
Expand Down
4 changes: 3 additions & 1 deletion ledger/store/trackerdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type Reader interface {
MakeAccountsOptimizedReader() (AccountsReader, error)
MakeOnlineAccountsOptimizedReader() (OnlineAccountsReader, error)
MakeSpVerificationCtxReader() SpVerificationCtxReader
// catchpoint
// Note: BuildMerkleTrie() needs this on the reader handle in sqlite to not get locked by write txns
MakeCatchpointPendingHashesIterator(hashCount int) CatchpointPendingHashesIter
}

// Writer is the interface for the trackerdb write operations.
Expand All @@ -80,7 +83,6 @@ type Writer interface {
type Catchpoint interface {
// reader
MakeCatchpointReader() (CatchpointReader, error)
MakeCatchpointPendingHashesIterator(hashCount int) CatchpointPendingHashesIter
MakeOrderedAccountsIter(accountCount int) OrderedAccountsIter
MakeKVsIter(ctx context.Context) (KVsIter, error)
MakeEncodedAccoutsBatchIter() EncodedAccountsBatchIter
Expand Down