Skip to content

[kv] Batch old-value lookups in the KV write path #4063

Description

@platinumhamburg

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

When processing a KV write batch, KvTablet may need to read the existing value of each key to generate the correct merged value and CDC records.

Currently, the write path checks the pre-write buffer first and then performs an individual RocksDB point lookup for every missing key. For a batch containing N distinct keys whose values are stored in RocksDB, this can result in N RocksDB JNI calls.

These lookups are executed while the tablet write lock is held. The repeated JNI crossings and serialized point lookups therefore increase the lock-holding time and limit write throughput, especially for large partial-update batches and tables using the FULL changelog image.

Solution

atch the RocksDB old-value lookups performed while processing one KV write batch:

  • Decode the incoming records and identify the keys that require an old value.
  • Check the pre-write buffer first because it contains values newer than RocksDB.
  • Preserve pre-write tombstones without falling back to RocksDB.
  • Deduplicate the remaining keys and load them with one RocksDB multiGet.
  • Continue processing records in their original order.
  • Recheck the pre-write buffer before using a prefetched RocksDB value so that repeated keys in the same batch observe earlier mutations from that batch.
  • Keep the existing fast path for WAL changelog writes that do not require old values.

This optimization should reduce RocksDB JNI crossings for old-value lookup from up to N point-get calls to at most one multi-get call per KV record batch.

The change must not alter:

  • KV tablet locking semantics.
  • Pre-write buffer visibility.
  • Record processing order.
  • WAL and CDC ordering.
  • Partial-update, aggregation, versioned, first-row, or auto-increment semantics.
  • Duplicate batch detection and rollback behavior.
  • Flush, snapshot, recovery, or lifecycle behavior.

Anything else?

No response

Willingness to contribute

  • I'm willing to submit a PR!

Activity

  1. Anurag15v commented on Oct 4, 2026

    @Anurag15v
    Contributor

    Hi @platinumhamburg
    Can you assign this to me ?

  2. platinumhamburg commented on Oct 8, 2026

    @platinumhamburg
    ContributorAuthor

    Hi @platinumhamburg Can you assign this to me ?

    @Anurag15v Thanks for your interest; assigned.

  3. platinumhamburg commented on Oct 20, 2026

    @platinumhamburg
    ContributorAuthor

    Hi @Anurag15v , this issue has become a high priority, so I’ve reopened my earlier PR #4065 and completed the tests and performance benchmarks. Given the urgency, I’ll take the issue back and move the PR forward to avoid putting you under time pressure. Thanks for offering to help—your review and feedback would be very welcome!

  4. Anurag15v commented on Oct 20, 2026

    @Anurag15v
    Contributor

    Hi @platinumhamburg
    There is no concern; you may proceed. At present, I am delayed by other open issues. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions