Skip to content

Reduce duplicate Couchbase cache lookups - #3769

Open
songgaoye wants to merge 1 commit into
apache:masterfrom
songgaoye:refactor/couchbase-cache-lookups
Open

songgaoye wants to merge 1 commit into
apache:masterfrom
songgaoye:refactor/couchbase-cache-lookups

Conversation

@songgaoye

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

Couchbase manifest-cache paths sometimes look up the same key multiple times.
Collection ID lookup calls find() and then operator[] for both the scope
and collection. The local manifest update path similarly repeats bucket
lookups.

What is changed and the side effects?

Changed:

  • Reuse the iterators returned by find() in the collection ID lookup and
    local manifest update paths.
  • Use emplace() to add a missing local manifest.
  • Add a test covering collection cache hits, misses, and unchanged cache state
    after a miss.

Side effects:

  • Performance effects: Successful collection ID lookups avoid two repeated map
    lookups. The performance impact has not been benchmarked.

  • Breaking backward compatibility: None. Cache lookup and update behavior
    remains unchanged.


Check List:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The cache lookup refactor preserves existing behavior while adding coverage for local cache hits, misses, invalid inputs, and unchanged state.

No open issues 🎉

What changed in this PR

This pull request reduces redundant lookups in Couchbase collection-manifest caches while preserving existing behavior and adds unit coverage for local collection cache hits and misses.

Changes:

  • Reuses bucket, scope, and collection iterators returned by find().
  • Uses emplace() when adding missing local manifests.
  • Adds tests for cache hits, misses, invalid inputs, and unchanged cache state.
File Description
test/​brpc_couchbase_unittest.cpp Adds unit tests covering local collection cache hits, misses, invalid inputs, and unchanged state after misses.
src/​brpc/​couchbase.cpp Reuses cache iterators and avoids repeated map lookups during local manifest updates and collection ID lookups.

Review effort: Lite

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.

2 participants