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: convert FC unmarshalled nil value to empty byte slice on DB write KVs #5225

Merged
merged 16 commits into from Mar 30, 2023

Conversation

ahangsu
Copy link
Contributor

@ahangsu ahangsu commented Mar 22, 2023

Summary

This is an improvement for DB on write, though it does not have effect on current sqlite3, it might matter if we take new DB backend (some Key-value based DB).

Since encoded.KVRecordV6 is codec:,omitempty,omitemptyarray, when we have an instance of encoded.KVRecordV6, WLOG we talk about empty box, then an empty byte slice []byte{} would be unmarshalled to nil, and written to DB.

The current status is, writing to DB with a nil value tied to a key doesn't really matter, for sqlite3 takes nil and []byte{} as same empty BLOB. But for the sake of consistency, we should convert the value to []byte{}.

Also, when we recheck with the logic of a round-by-round catchup, a box deletion would incur kvmod.val = nil, and accountsNewRoundImpl in acctdelta.go would treat this as a KV pair deletion in DB.

Thus, I think it would be good to convert a nil value unmarshal result to an empty byte slice []byte{}.

Test Plan

Consider the following test:

  1. bring up a tracker DB instance of version 9
  2. jam a bunch of keys with nil values into table kvstore
  3. ensure that the DB read for nil values gets all the keys
  4. start tracker DB migration from version 9 to version 10
  5. ensure that the DB read for nil values gets 0 keys, i.e., all the nil values are converted to empty byte slices.

@codecov
Copy link

codecov bot commented Mar 23, 2023

Codecov Report

Merging #5225 (586ecbf) into master (14ce659) will decrease coverage by 0.03%.
The diff coverage is 44.44%.

@@            Coverage Diff             @@
##           master    #5225      +/-   ##
==========================================
- Coverage   53.73%   53.71%   -0.03%     
==========================================
  Files         444      444              
  Lines       55671    55680       +9     
==========================================
- Hits        29913    29906       -7     
- Misses      23426    23440      +14     
- Partials     2332     2334       +2     
Impacted Files Coverage Δ
ledger/catchupaccessor.go 62.94% <0.00%> (-0.21%) ⬇️
ledger/store/trackerdb/sqlitedriver/trackerdbV2.go 0.00% <0.00%> (ø)
ledger/store/trackerdb/sqlitedriver/schema.go 47.54% <100.00%> (+0.23%) ⬆️
ledger/store/trackerdb/sqlitedriver/testing.go 51.02% <100.00%> (+2.08%) ⬆️

... and 6 files with indirect coverage changes

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

@cce cce requested a review from algorandskiy March 24, 2023 20:50
@cce
Copy link
Contributor

cce commented Mar 24, 2023

Do we want to do the migration? I guess it is probably cheap to do because there aren't a lot of KVs out in the wild yet?

@ahangsu
Copy link
Contributor Author

ahangsu commented Mar 24, 2023

I am not really sure, for I am unaware of how many nil values out there. But the migration should be cheap, for I guess the nil values in the table caused by FC should be sparse. (just guessing)

ledger/catchupaccessor.go Outdated Show resolved Hide resolved
jannotti
jannotti previously approved these changes Mar 29, 2023
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

jannotti
jannotti previously approved these changes Mar 29, 2023
@jannotti jannotti merged commit 36ffb59 into algorand:master Mar 30, 2023
9 checks passed
@ahangsu ahangsu deleted the empty-value-nil-to-bytes branch March 30, 2023 18:13
@ahangsu ahangsu restored the empty-value-nil-to-bytes branch March 30, 2023 18:13
@ahangsu ahangsu deleted the empty-value-nil-to-bytes branch March 30, 2023 18:13
@ahangsu ahangsu restored the empty-value-nil-to-bytes branch March 30, 2023 18:14
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

4 participants