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: refactor store module interfaces before kv impl merge #5451

Merged
merged 4 commits into from
Jun 16, 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
20 changes: 14 additions & 6 deletions ledger/acctdeltas.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
if len(a.misses) == 0 {
return nil
}
arw, err := tx.MakeAccountsReaderWriter()
ar, err := tx.MakeAccountsReader()
if err != nil {
return err
}
Expand All @@ -317,9 +317,9 @@
if delta.oldResource.AcctRef != nil {
acctRef = delta.oldResource.AcctRef
} else if acctRef, ok = knownAddresses[addr]; !ok {
acctRef, err = arw.LookupAccountRowID(addr)
acctRef, err = ar.LookupAccountRowID(addr)

Check warning on line 320 in ledger/acctdeltas.go

View check run for this annotation

Codecov / codecov/patch

ledger/acctdeltas.go#L320

Added line #L320 was not covered by tests
if err != nil {
if err != sql.ErrNoRows {
if err != sql.ErrNoRows || err != trackerdb.ErrNotFound {

Check warning on line 322 in ledger/acctdeltas.go

View check run for this annotation

Codecov / codecov/patch

ledger/acctdeltas.go#L322

Added line #L322 was not covered by tests
err = fmt.Errorf("base account cannot be read while processing resource for addr=%s, aidx=%d: %w", addr.String(), aidx, err)
return err

Expand All @@ -330,7 +330,7 @@
continue
}
}
resDataBuf, err = arw.LookupResourceDataByAddrID(acctRef, aidx)
resDataBuf, err = ar.LookupResourceDataByAddrID(acctRef, aidx)
switch err {
case nil:
if len(resDataBuf) > 0 {
Expand All @@ -344,6 +344,10 @@
err = fmt.Errorf("empty resource record: addrid=%d, aidx=%d", acctRef, aidx)
return err
}
case trackerdb.ErrNotFound:
// we don't have that account, just return an empty record.
a.updateOld(missIdx, trackerdb.PersistedResourcesData{AcctRef: acctRef, Aidx: aidx})
err = nil
Comment on lines +347 to +350
Copy link
Contributor

Choose a reason for hiding this comment

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

since theese appear identical, you could make this a fallthrough

Copy link
Contributor

Choose a reason for hiding this comment

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

You can also do case trackerdb.ErrNotFound, sql.ErrNoRows: which is like fallthrough but shorter

case sql.ErrNoRows:
// we don't have that account, just return an empty record.
a.updateOld(missIdx, trackerdb.PersistedResourcesData{AcctRef: acctRef, Aidx: aidx})
Expand Down Expand Up @@ -591,7 +595,7 @@
if len(a.misses) == 0 {
return nil
}
arw, err := tx.MakeAccountsReaderWriter()
ar, err := tx.MakeAccountsReader()
if err != nil {
return err
}
Expand All @@ -600,7 +604,7 @@
}()
for _, idx := range a.misses {
addr := a.deltas[idx].address
ref, acctDataBuf, err := arw.LookupOnlineAccountDataByAddress(addr)
ref, acctDataBuf, err := ar.LookupOnlineAccountDataByAddress(addr)
switch err {
case nil:
if len(acctDataBuf) > 0 {
Expand All @@ -614,6 +618,10 @@
// empty data means offline account
a.updateOld(idx, trackerdb.PersistedOnlineAccountData{Addr: addr, Ref: ref})
}
case trackerdb.ErrNotFound:
// we don't have that account, just return an empty record.
a.updateOld(idx, trackerdb.PersistedOnlineAccountData{Addr: addr})
// TODO: phase out sql.ErrNoRows
case sql.ErrNoRows:
// we don't have that account, just return an empty record.
a.updateOld(idx, trackerdb.PersistedOnlineAccountData{Addr: addr})
Expand Down