triedb/pathdb: optimize history indexing efficiency #33303
+344
−87
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.
This pull request optimizes history indexing by splitting a single large database
batch into multiple smaller chunks.
Originally, the indexer will resolve a batch of state histories and commit all
corresponding index entries atomically together with the indexing marker.
While indexing more state histories in a single batch improves efficiency, excessively
large batches can cause significant memory issues.
To mitigate this, the pull request splits the mega-batch into several smaller batches
and flushes them independently during indexing. However, this introduces a potential
inconsistency that some index entries may be flushed while the indexing marker is not,
and an unclean shutdown may leave the database in a partially updated state.
This can corrupt index data.
To address this, head truncation is introduced. After a restart, any excessive index
entries beyond the expected indexing marker are removed, ensuring the index remains
consistent after an unclean shutdown.