Skip to content

Commit

Permalink
fix: catchpoint pending hashes locking
Browse files Browse the repository at this point in the history
  • Loading branch information
icorderi committed Jul 10, 2023
1 parent e215f6d commit 3a254c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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 @@ func (r *sqlReader) MakeSpVerificationCtxReader() trackerdb.SpVerificationCtxRea
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 @@ type sqlCatchpoint struct {
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

0 comments on commit 3a254c3

Please sign in to comment.