-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(iavl): add KV data reader & writer, and mmap wrapper #25645
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
Open
aaronc
wants to merge
42
commits into
main
Choose a base branch
from
aaronc/iavlx-part6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
b27e5d3
feat(iavl): initialize disk layout
aaronc 3599010
change package
aaronc e581282
switch size to uint40, update docs and tests
aaronc abf0976
update docs
aaronc 7fcba13
Merge branch 'main' into aaronc/iavlx-init
aaronc a716e2f
reorder code
aaronc ca25571
Merge remote-tracking branch 'origin/aaronc/iavlx-init' into aaronc/i…
aaronc cccd14b
documented Uint40 endianness and added fmt.Stringer
aaronc 07d0d5e
feat(iavl): add Node, MemNode, and NodePointer
aaronc a65f1c6
switch table tests to key: value struct init
aaronc 66d3dee
Merge branch 'aaronc/iavlx-init' into aaronc/iavlx-init2
aaronc b212f96
add basic mem node getter tests
aaronc e6ccd8d
adding mutation, hash, verification code, basic tests
aaronc fab53dc
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/iavlx…
aaronc d19f0e7
add tests
aaronc 95318bb
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/iavlx…
aaronc 90bad56
reduce PR size
aaronc e37410b
add get tests and update docs
aaronc 0564bdb
add more test explanations
aaronc f4607bf
update doc, add missing test
aaronc 78faae5
feat(iavl): define KV data format
aaronc e8cfa93
WIP on kv data design
aaronc 3ff4da5
WIP on kv data design
aaronc c75dde0
WIP on kv data writer
aaronc aea0c86
WIP on kv data writer
aaronc 6d28292
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/iavlx…
aaronc 8a74b7a
update leaf size, add missing ChangesetInfo size check
aaronc 9b4a396
add Mmap
aaronc b6b140d
implement KVDataReader
aaronc 8f72673
fixes to KVDataReader
aaronc 647f932
fixes to KVDataReader
aaronc b0efee3
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/iavlx…
aaronc b0b1dd1
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/iavlx…
aaronc f42a7af
add tests, update go.mod's
aaronc 4156068
WIP on tests, add WAL mode checks
aaronc b76da6b
WIP on tests
aaronc a34a174
WIP on tests
aaronc db113dc
document FileWriter
aaronc 493430b
add empty key/value test cases
aaronc 9db9564
add mmap tests, fix empty close bug, minor cleanups
aaronc 951c767
lint fix
aaronc 938c3c3
fix lint
aaronc 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| ) | ||
|
|
||
| type FileWriter struct { | ||
| writer *bufio.Writer | ||
| written int | ||
| } | ||
|
|
||
| func NewFileWriter(file *os.File) *FileWriter { | ||
| return &FileWriter{ | ||
| writer: bufio.NewWriterSize(file, 512*1024 /* 512kb */), // TODO: maybe we can have this as a config option? | ||
| } | ||
| } | ||
|
|
||
| func (f *FileWriter) Write(p []byte) (n int, err error) { | ||
| n, err = f.writer.Write(p) | ||
| f.written += n | ||
| return n, err | ||
| } | ||
|
|
||
| func (f *FileWriter) Flush() error { | ||
| if err := f.writer.Flush(); err != nil { | ||
| return fmt.Errorf("failed to flush writer: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (f *FileWriter) Size() int { | ||
| return f.written | ||
| } | ||
|
|
||
| var _ io.Writer = (*FileWriter)(nil) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package internal | ||
|
|
||
| // KVEntryType represents the type of entry in the KV data file. | ||
| type KVEntryType byte | ||
|
|
||
| const ( | ||
| // KVEntryWALStart is the first entry in an uncompacted KV data file which indicates that this KV data file | ||
| // can be used for WAL replay restoration. It must immediately be followed by the varint-encoded version number | ||
| // corresponding to the first version in this changeset. | ||
| KVEntryWALStart KVEntryType = 0x0 | ||
|
|
||
| // KVEntryWALSet indicates a set operation for a key-value pair. | ||
| // This should be followed by: | ||
| // - varint key length + key bytes, OR if KVFlagCachedKey is set, a 32-bit LE offset to a cached key | ||
| // - varint value length + value bytes | ||
| // Offsets point to the start of the varint length field, not the type byte. | ||
| KVEntryWALSet KVEntryType = 0x1 | ||
|
|
||
| // KVEntryWALDelete indicates a delete operation for a key. | ||
| // This should be followed by: | ||
| // - varint key length + key bytes, OR if KVFlagCachedKey is set, a 32-bit LE offset to a cached key | ||
| // Offsets point to the start of the varint length field, not the type byte. | ||
| KVEntryWALDelete KVEntryType = 0x2 | ||
|
|
||
| // KVEntryWALCommit indicates the commit operation for a version. | ||
| // This must be followed by a varint-encoded version number. | ||
| KVEntryWALCommit KVEntryType = 0x3 | ||
|
|
||
| // KVEntryKeyBlob indicates a standalone key data entry. | ||
| // This should be followed by varint length + raw bytes. | ||
| // Used for compacted (non-WAL) leaf or branch keys not already cached. | ||
| KVEntryKeyBlob KVEntryType = 0x4 | ||
|
|
||
| // KVEntryValueBlob indicates a standalone value data entry. | ||
| // This should be followed by varint length + raw bytes. | ||
| // Used for compacted (non-WAL) leaf values. | ||
| // The main difference between KVEntryKeyBlob and KVEntryValueBlob is that key | ||
| // entries may be cached for faster access, while value entries are not cached. | ||
| KVEntryValueBlob KVEntryType = 0x5 | ||
|
|
||
| // KVFlagCachedKey indicates that the key for this entry is cached and should be referenced by | ||
| // a 32-bit little-endian offset instead of being stored inline. | ||
| KVFlagCachedKey KVEntryType = 0x80 | ||
| ) |
Oops, something went wrong.
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.
This was missing in the previous PR