Skip to content

HBASE-30362 Migrate IndexOnlyLRU to cache admission policy - #8876

Open
VladRodionov wants to merge 1 commit into
apache:HBASE-30018from
VladRodionov:HBASE-30362-index-lru-cache-engine
Open

VladRodionov wants to merge 1 commit into
apache:HBASE-30018from
VladRodionov:HBASE-30362-index-lru-cache-engine

Conversation

@VladRodionov

Copy link
Copy Markdown
Contributor

Summary

Migrate IndexOnlyLRU to the pluggable cache architecture.

The legacy IndexOnlyLruBlockCache specializes LruBlockCache only by filtering cache
admission: data blocks are rejected while non-data blocks are admitted. Rather than introducing
another specialized CacheEngine, this change represents that behavior using the existing cache
architecture:

  • LruCacheEngine for cache storage and LRU eviction
  • SingleTierTopology for the standalone cache topology
  • IndexOnlyCachePlacementAdmissionPolicy for block admission

This keeps admission policy separate from cache-engine implementation.

Changes

  • Add IndexOnlyCachePlacementAdmissionPolicy.
  • Preserve the existing IndexOnlyLruBlockCache admission semantics:
    • reject blocks in the DATA category
    • admit non-data blocks
  • Select the new admission policy when hbase.blockcache.policy=IndexOnlyLRU.
  • Use the native LruCacheEngine for the IndexOnlyLRU configuration.
  • Update TestCacheConfig to verify the new engine/policy architecture and preserved admission
    behavior.
  • Update TestClientSideRegionScanner to verify that its cache uses:
    • LruCacheEngine
    • CacheTier.SINGLE
    • IndexOnlyCachePlacementAdmissionPolicy
  • Add focused unit coverage for IndexOnlyCachePlacementAdmissionPolicy.

Architecture

Before:

IndexOnlyLRU
    -> IndexOnlyLruBlockCache
    -> BlockCacheBackedCacheEngine

After:

IndexOnlyLRU
    -> TopologyBackedCacheAccessService
    -> SingleTierTopology
    -> LruCacheEngine
    -> IndexOnlyCachePlacementAdmissionPolicy

The legacy IndexOnlyLruBlockCache remains available for the transitional BlockCache path and
can be removed together with the remaining BlockCache implementation during the final migration.

Behavior

No user-visible behavior change is intended.

Despite its historical name, IndexOnlyLruBlockCache admits all non-data blocks rather than only
literal index blocks. The new admission policy intentionally preserves that behavior.

AI-assisted development

This change was developed in collaboration with ChatGPT 5.6 Sol. ChatGPT was used as a
development and review assistant for architecture discussion, code migration, and test adaptation.
All resulting code and design decisions were reviewed and validated by the author.

@taklwu
taklwu requested a balanced review from Copilot November 13, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Migrates the legacy IndexOnlyLRU behavior to the pluggable cache architecture by expressing “index-only” behavior as a cache admission policy while using the native LruCacheEngine.

Changes:

  • Add IndexOnlyCachePlacementAdmissionPolicy and select it when hbase.blockcache.policy=IndexOnlyLRU.
  • Switch IndexOnlyLRU to use LruCacheEngine (instead of wrapping IndexOnlyLruBlockCache) while preserving “reject DATA, admit non-DATA” semantics.
  • Update/add unit tests to validate the new engine/policy wiring and preserved admission behavior.
File Description
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​IndexOnlyCachePlacementAdmissionPolicy.java Introduces admission policy intended to replicate legacy IndexOnlyLRU admission behavior.
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​CacheAccessServices.java Wires IndexOnlyLRU policy name to the new admission policy.
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​BlockCacheFactory.java Routes IndexOnlyLRU to use LruCacheEngine directly.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TestIndexOnlyCachePlacementAdmissionPolicy.java Adds focused unit tests for the new admission policy.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​TestCacheConfig.java Updates cache config test to assert engine/policy wiring and admission behavior.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​client/​TestClientSideRegionScanner.java Updates client-side scanner test to assert engine/tier/policy under IndexOnlyLRU.

Review effort: Lite

Comment on lines +56 to +58
return blockType != null && blockType.getCategory() != BlockType.BlockCategory.DATA
? AdmissionDecision.admit()
: AdmissionDecision.reject("IndexOnlyLRU admits only non-data blocks");

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.

this one is right, please check and add tests for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it possible at all for blockType being null?

Comment on lines +37 to +40

public static final IndexOnlyCachePlacementAdmissionPolicy INSTANCE =
new IndexOnlyCachePlacementAdmissionPolicy();

Comment on lines +56 to +58
return blockType != null && blockType.getCategory() != BlockType.BlockCategory.DATA
? AdmissionDecision.admit()
: AdmissionDecision.reject("IndexOnlyLRU admits only non-data blocks");

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.

this one is right, please check and add tests for it.


if (policy.equalsIgnoreCase("LRU")) {
if (
policy.equalsIgnoreCase("LRU") || policy.equalsIgnoreCase("AdaptiveLRU")

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.

for all these type of policy, we should start using ENUM for it.

@anmolnar

Copy link
Copy Markdown
Contributor

🤖 AI-assisted review: drafted by Claude on behalf of @anmolnar

Thanks @VladRodionov. The single-tier path looks equivalent to the legacy IndexOnlyLruBlockCache: the predicate matches isMetaBlock exactly, and TestCacheConfig is stronger than before now that it asserts the data block is rejected. One behaviour change needs addressing before merge; the rest is minor.

1. Tiered topologies no longer cache data blocks in L2

CacheAccessServices.createPlacementAdmissionPolicy applies the policy to every topology, and TopologyBackedCacheAccessService.cacheBlockToSelectedTiers calls shouldAdmit before selectTier. A rejected DATA block is therefore rejected for the whole service. Previously IndexOnlyLruBlockCache was only the L1:

  • L1 + BucketCache (exclusive): data blocks went to L2. Now they are not cached at all.
  • L1 + external cache (inclusive): L1 rejected, L2 cached. Now they are not cached at all.

ClientSideRegionScanner unsets the bucket IO engine but not hbase.blockcache.use.external, so the inclusive case is reachable from the scanner itself, and hfile.block.cache.policy=IndexOnlyLRU can be set alongside a bucket cache.

Could we mirror AdaptiveLruCachePlacementAdmissionPolicy: reject in shouldAdmit only for SINGLE_TIER, and otherwise drop L1 from the selectTier result for data blocks? A test with a tiered topology would be good too; the current ones only cover single tier.

2. Discarded super.shouldAdmit(...) result

Agree with @taklwu that this is harmless today, since the parent only null-checks and admits. It would silently ignore a rejection if the default policy ever starts returning one, though. Suggest capturing the decision and returning early when it is not admitted, as the Adaptive policy does.

3. Allocation per rejected data block

AdmissionDecision.reject(String) allocates a new object per call, and this path rejects every data block read in a client-side scan. A private static final decision would avoid that. A second constant for the blockType == null case would also fix the misleading reason text, and the existing null-type test could assert on it.

4. Leftovers

  • The comment in ClientSideRegionScanner (around line 75) still says it uses IndexOnlyLruBlockCache.
  • IndexOnlyLruBlockCache is now only referenced from the legacy createFirstLevelCache. Is removing it planned for a follow-up?
  • +1 to @taklwu's enum suggestion, now that the policy name literals live in both BlockCacheFactory and CacheAccessServices. Fine as a follow-up.

Note: this review is from reading the code; I did not build or run the tests locally.

@VladRodionov

Copy link
Copy Markdown
Contributor Author

on 2. DefaultHBaseCachePlacementAdmissionPolicy always admits by definition.

@VladRodionov

VladRodionov commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

It turned out that fixing Tiered topologies no longer cache data blocks in L2 issue requires some code refactoring in CachePlacementAdmissionPolicy - changing signature of shouldAdmit. Now it requires Cache tier and decision is per cache tier. This is definitely better. This was done but now PR became mostly refactoring existing code + some addition for IndexOnlyLruBlockCache work. I am going to close this PR and create new JIRA then resubmit my only refactored part of code code.

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.

4 participants