-
Notifications
You must be signed in to change notification settings - Fork 21.4k
triedb/pathdb: add history index config #32875
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
Closed
+143
−62
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,8 @@ import ( | |
) | ||
|
||
const ( | ||
indexBlockDescSize = 14 // The size of index block descriptor | ||
indexBlockEntriesCap = 4096 // The maximum number of entries can be grouped in a block | ||
indexBlockRestartLen = 256 // The restart interval length of index block | ||
historyIndexBatch = 1_000_000 // The number of state history indexes for constructing or deleting as batch | ||
indexBlockDescSize = 14 // The size of index block descriptor | ||
indexBlockRestartLen = 256 // The restart interval length of index block | ||
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. While in theory, the restart size can also be configured, it's not moved into the config in this pull request yet |
||
) | ||
|
||
// indexBlockDesc represents a descriptor for an index block, which contains a | ||
|
@@ -51,8 +49,8 @@ func (d *indexBlockDesc) empty() bool { | |
|
||
// full indicates whether the number of elements in the block exceeds the | ||
// preconfigured limit. | ||
func (d *indexBlockDesc) full() bool { | ||
return d.entries >= indexBlockEntriesCap | ||
func (d *indexBlockDesc) full(capacity uint16) bool { | ||
return d.entries >= capacity | ||
} | ||
|
||
// encode packs index block descriptor into byte stream. | ||
|
@@ -222,13 +220,15 @@ type blockWriter struct { | |
desc *indexBlockDesc // Descriptor of the block | ||
restarts []uint16 // Offsets into the data slice, marking the start of each section | ||
data []byte // Aggregated encoded data slice | ||
capacity uint16 // Maximum number of entries grouped into a single block | ||
} | ||
|
||
func newBlockWriter(blob []byte, desc *indexBlockDesc) (*blockWriter, error) { | ||
func newBlockWriter(blob []byte, desc *indexBlockDesc, capacity uint16) (*blockWriter, error) { | ||
if len(blob) == 0 { | ||
return &blockWriter{ | ||
desc: desc, | ||
data: make([]byte, 0, 1024), | ||
desc: desc, | ||
data: make([]byte, 0, 1024), | ||
capacity: capacity, | ||
}, nil | ||
} | ||
restarts, data, err := parseIndexBlock(blob) | ||
|
@@ -239,6 +239,7 @@ func newBlockWriter(blob []byte, desc *indexBlockDesc) (*blockWriter, error) { | |
desc: desc, | ||
restarts: restarts, | ||
data: data, // safe to own the slice | ||
capacity: capacity, | ||
}, nil | ||
} | ||
|
||
|
@@ -372,7 +373,7 @@ func (b *blockWriter) empty() bool { | |
} | ||
|
||
func (b *blockWriter) full() bool { | ||
return b.desc.full() | ||
return b.desc.full(b.capacity) | ||
} | ||
|
||
// finish finalizes the index block encoding by appending the encoded restart points | ||
|
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
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.
In theory, if the last resolved reader is full, it's unnecessary to reload it for refreshing.
In practice, it's very rare that the last reader is full. In order to avoid passing the block capacity from the top down to the indexReader only for this purpose, this condition is removed.
The correctness shouldn't be affected.