Skip to content

core: warm key TransactionIndexTail by writing#3196

Merged
zzzckck merged 1 commit intobnb-chain:masterfrom
buddh0:master-with-txindex-fixed
Jun 24, 2025
Merged

core: warm key TransactionIndexTail by writing#3196
zzzckck merged 1 commit intobnb-chain:masterfrom
buddh0:master-with-txindex-fixed

Conversation

@buddh0
Copy link
Contributor

@buddh0 buddh0 commented Jun 24, 2025

Description

core: warm key TransactionIndexTail by writing

Rationale

tell us why we need these changes...

Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

@MatusKysel MatusKysel requested a review from Copilot June 24, 2025 07:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a warm-up mechanism for the TransactionIndexTail key by performing a dummy write if the key exists in cold SST files, thereby optimizing future read performance.

  • Removed the previous inline assignment for lastTail.
  • Added a new code block to perform a dummy write using a batch operation if lastTail is non-nil.

Comment on lines +137 to +151
lastTail := rawdb.ReadTxIndexTail(indexer.db)
if lastTail != nil {
// NOTE: The "TransactionIndexTail" key may exist only in cold SST files.
// Without a recent write, the key won't be in the memtable or block cache,
// causing every Get to trigger expensive readBlock + CRC checks.
//
// This dummy write forces the key into the memtable (and later SST),
// ensuring future reads are fast (from memory or block cache).
batch := indexer.db.NewBatch()
rawdb.WriteTxIndexTail(batch, *lastTail)

if err := batch.Write(); err != nil {
log.Crit("Failed to write TransactionIndexTail warm-up", "error", err)
return
}
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting the warm-up write logic into a separate function for improved readability and maintainability in case this behavior needs to be reused or extended.

Suggested change
lastTail := rawdb.ReadTxIndexTail(indexer.db)
if lastTail != nil {
// NOTE: The "TransactionIndexTail" key may exist only in cold SST files.
// Without a recent write, the key won't be in the memtable or block cache,
// causing every Get to trigger expensive readBlock + CRC checks.
//
// This dummy write forces the key into the memtable (and later SST),
// ensuring future reads are fast (from memory or block cache).
batch := indexer.db.NewBatch()
rawdb.WriteTxIndexTail(batch, *lastTail)
if err := batch.Write(); err != nil {
log.Crit("Failed to write TransactionIndexTail warm-up", "error", err)
return
}
lastTail := indexer.warmUpTxIndexTail()
if lastTail == nil {
return

Copilot uses AI. Check for mistakes.
@zzzckck zzzckck merged commit d689f3b into bnb-chain:master Jun 24, 2025
6 of 7 checks passed
Copy link

@octavio12345300 octavio12345300 left a comment

Choose a reason for hiding this comment

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

List

flywukong pushed a commit to flywukong/bsc that referenced this pull request Sep 9, 2025
flywukong pushed a commit to flywukong/bsc that referenced this pull request Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants