-
Notifications
You must be signed in to change notification settings - Fork 493
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
LRU Cache for Boxes/KVs #4275
Merged
algoidurovic
merged 23 commits into
algorand:feature/avm-box
from
algoidurovic:box_cache
Aug 18, 2022
Merged
LRU Cache for Boxes/KVs #4275
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
dd82278
basic box read db perf test
algoidurovic 55c114a
improve test and add sub benchmark to gauge sqlite caching performanc…
algoidurovic 6707b91
test
algoidurovic 3d4e105
benchmark across different dimensions: boxSize, boxCount, and lookback
algoidurovic 68c66cb
improve cache performance
algoidurovic e64f659
comments
algoidurovic ffe1585
implement box cache and corresponding unit tests
algoidurovic bcbdb1a
resolve merge conflicts
algoidurovic fcfd075
resolve todos
algoidurovic abaf6ca
remove todo
algoidurovic e15b6da
fill in missing pieces of cache implementation
algoidurovic 3bbee10
exercise box cache and enforce invariants through acctupdates test
algoidurovic f9f50b0
typo
algoidurovic 6d7aca5
update old test
algoidurovic f40283e
rename threshold variable and reduce cache size
algoidurovic 4fb59f5
unsaved changes
algoidurovic 25946b4
rename boxes to KV
algoidurovic 856b59c
rename updatedBoxes
algoidurovic fda8d5f
Merge branch 'feature/avm-box' of https://github.com/algorand/go-algo…
algoidurovic fb0cb6c
fix compile error
algoidurovic 6458d41
rename and minor refactor for error handling
algoidurovic 2b3a0ae
fix compile error
algoidurovic 24ff56e
explicit nil error
algoidurovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,15 @@ func (prd *persistedResourcesData) AccountResource() ledgercore.AccountResource | |
return ret | ||
} | ||
|
||
//msgp:ignore persistedKVData | ||
type persistedKVData struct { | ||
// kv value | ||
value *string | ||
// the round number that is associated with the kv value. This field is the corresponding one to the round field | ||
// in persistedAccountData, and serves the same purpose. | ||
round basics.Round | ||
} | ||
|
||
// resourceDelta is used as part of the compactResourcesDeltas to describe a change to a single resource. | ||
type resourceDelta struct { | ||
oldResource persistedResourcesData | ||
|
@@ -2567,12 +2576,7 @@ func (qs *accountsDbQueries) listCreatables(maxIdx basics.CreatableIndex, maxRes | |
return | ||
} | ||
|
||
type persistedValue struct { | ||
value *string | ||
round basics.Round | ||
} | ||
|
||
jannotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (qs *accountsDbQueries) lookupKeyValue(key string) (pv persistedValue, err error) { | ||
func (qs *accountsDbQueries) lookupKeyValue(key string) (pv persistedKVData, err error) { | ||
err = db.Retry(func() error { | ||
var v sql.NullString | ||
// Cast to []byte to avoid interpretation as character string, see note in upsertKvPair | ||
|
@@ -3397,7 +3401,7 @@ func accountsNewRound( | |
tx *sql.Tx, | ||
updates compactAccountDeltas, resources compactResourcesDeltas, kvPairs map[string]modifiedValue, creatables map[basics.CreatableIndex]ledgercore.ModifiedCreatable, | ||
proto config.ConsensusParams, lastUpdateRound basics.Round, | ||
) (updatedAccounts []persistedAccountData, updatedResources map[basics.Address][]persistedResourcesData, err error) { | ||
) (updatedAccounts []persistedAccountData, updatedResources map[basics.Address][]persistedResourcesData, updatedKVs map[string]persistedKVData, err error) { | ||
hasAccounts := updates.len() > 0 | ||
hasResources := resources.len() > 0 | ||
hasKvPairs := len(kvPairs) > 0 | ||
|
@@ -3435,7 +3439,7 @@ func accountsNewRoundImpl( | |
writer accountsWriter, | ||
updates compactAccountDeltas, resources compactResourcesDeltas, kvPairs map[string]modifiedValue, creatables map[basics.CreatableIndex]ledgercore.ModifiedCreatable, | ||
proto config.ConsensusParams, lastUpdateRound basics.Round, | ||
) (updatedAccounts []persistedAccountData, updatedResources map[basics.Address][]persistedResourcesData, err error) { | ||
) (updatedAccounts []persistedAccountData, updatedResources map[basics.Address][]persistedResourcesData, updatedKVs map[string]persistedKVData, err error) { | ||
updatedAccounts = make([]persistedAccountData, updates.len()) | ||
updatedAccountIdx := 0 | ||
newAddressesRowIDs := make(map[basics.Address]int64) | ||
|
@@ -3633,11 +3637,14 @@ func accountsNewRoundImpl( | |
} | ||
} | ||
|
||
updatedKVs = make(map[string]persistedKVData, len(kvPairs)) | ||
for key, value := range kvPairs { | ||
if value.data != nil { | ||
err = writer.upsertKvPair(key, *value.data) | ||
updatedKVs[key] = persistedKVData{value: value.data, round: lastUpdateRound} | ||
} else { | ||
err = writer.deleteKvPair(key) | ||
updatedKVs[key] = persistedKVData{value: nil, round: lastUpdateRound} | ||
} | ||
if err != nil { | ||
return | ||
|
@@ -4762,6 +4769,12 @@ func (prd *persistedResourcesData) before(other *persistedResourcesData) bool { | |
return prd.round < other.round | ||
} | ||
|
||
// before compares the round numbers of two persistedKVData and determines if the current persistedKVData | ||
// happened before the other. | ||
func (prd *persistedKVData) before(other *persistedKVData) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since they are small objects, I might not use pointers for the receiver or the arg. |
||
return prd.round < other.round | ||
} | ||
|
||
// before compares the round numbers of two persistedAccountData and determines if the current persistedAccountData | ||
// happened before the other. | ||
func (pac *persistedOnlineAccountData) before(other *persistedOnlineAccountData) bool { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just renamed and moved this but I don't mind undoing it if there's an objection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@algoidurovic I think the rename touches on a central question: What is box-specific about the cache?
I realize the question prompts a potentially large renaming exercise, but I'm wondering if the cache ought to be kv themed rather than box themed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think it should. Anything below the ledger tries to talk about kv rather than about boxes. But I don't think it changes much code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@algoidurovic From my perspective, based on renames to KV, the thread is now resolved. Since I didn't open it, I'm leaving it open for you to resolve.