Skip to content

HBASE-30550 Make cache admission decisions tier-aware - #8903

Open
VladRodionov wants to merge 2 commits into
apache:HBASE-30018from
VladRodionov:HBASE-30550-tier-aware-cache-admission
Open

VladRodionov wants to merge 2 commits into
apache:HBASE-30018from
VladRodionov:HBASE-30550-tier-aware-cache-admission

Conversation

@VladRodionov

Copy link
Copy Markdown
Contributor

Summary

This PR makes cache admission decisions tier-aware.

Previously, CachePlacementAdmissionPolicy.shouldAdmit() made a cache-wide admission decision before tier placement was evaluated. This does not work correctly for tiered topologies where a block may be rejected by one tier but still be admissible to another.

The change separates placement from admission:

  • selectTier() determines the target cache tier or tiers.
  • shouldAdmit() evaluates admission independently for each selected tier.
  • CacheTier is now passed to shouldAdmit().
  • TopologyBackedCacheAccessService performs placement first and then checks admission for each selected tier before insertion.

AdaptiveLRU

AdaptiveLruCachePlacementAdmissionPolicy previously implemented first-level admission by modifying the result of selectTier() and removing L1 when a data block was rejected.

With tier-aware admission, this is no longer necessary. AdaptiveLRU now preserves the default placement decision and performs adaptive filtering through shouldAdmit() for SINGLE and L1. L2 admission is not affected by the AdaptiveLRU first-level admission policy.

For an inclusive topology this means, for example, that a data block may be rejected from L1 while still being admitted to L2.

Tests

Updated the affected cache policy and topology-backed cache service tests to reflect the new ordering and per-tier admission semantics.

The changes cover:

  • single-tier admission
  • tiered-exclusive admission
  • tiered-inclusive admission
  • rejection of a selected tier without suppressing placement decisions
  • AdaptiveLRU first-level admission behavior

Scope

This PR contains the cache admission API and insertion-flow refactoring only.

The IndexOnlyLRU migration that motivated the need for per-tier admission is handled separately under HBASE-30362.

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.

🟡 Changes recommended

The rejection test selects an unsupported tier and bypasses admission checks, while no service-level test verifies that rejecting one tier still allows another selected tier to cache the block.

2 open issues
What changed in this PR

This PR separates cache placement from admission in HBase’s topology-backed cache service, allowing a block rejected by one tier to remain eligible for another.

Changes:

  • Adds CacheTier to admission decisions and selects placement before checking each tier.
  • Moves AdaptiveLRU filtering into admission for SINGLE and L1, leaving L2 unaffected.
  • Updates policy tests and service mocks for the per-tier API and insertion flow.
File Description
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TestTopologyBackedCacheAccessServiceWithBlockCacheBackedEngines.java Updates admission mocks and rejection placement.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TestTopologyBackedCacheAccessService.java Updates assertions and mocks for per-tier admission.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TestSingleTierTopologyBackedCacheAccessService.java Adapts single-tier policy helpers to the new flow.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TestInclusiveCombinedBlockCacheCompatibleTopologyBackedCacheAccessService.java Updates inclusive-topology admission mocks.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TestCombinedBlockCacheCompatibleTopologyBackedCacheAccessService.java Updates exclusive-topology policy helpers.
hbase-server/​src/​test/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TestAdaptiveLruCachePlacementAdmissionPolicy.java Tests placement separately from tier-specific admission.
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​TopologyBackedCacheAccessService.java Unifies insertion around placement followed by per-tier admission.
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​DefaultHBaseCachePlacementAdmissionPolicy.java Accepts the admission tier and classifies blocks through Cacheable.
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​CachePlacementAdmissionPolicy.java Adds the target tier to the admission contract.
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​AdmissionDecision.java Adds a reusable null-block-type rejection decision.
hbase-server/​src/​main/​java/​org/​apache/​hadoop/​hbase/​io/​hfile/​cache/​AdaptiveLruCachePlacementAdmissionPolicy.java Preserves default placement and filters first-level admission.

Review effort: Balanced

Comment on lines +290 to +291
if (!admission.isAdmitted()) {
continue;
CachePlacementAdmissionPolicy policy = mock(CachePlacementAdmissionPolicy.class);
when(policy.shouldAdmit(any(), any(), any(), any(), any()))
when(policy.selectTier(any(), any(), any(), any()))
.thenReturn(TierDecision.single(CacheTier.L1));

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.

can you check this ?

@taklwu taklwu 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.

claude found another possible problem, please verify it.

Single-tier caching now depends on the policy returning SINGLE, and fails silently otherwise. Before, a single-tier topology always wrote admitted blocks to topology.getEngine(CacheTier.SINGLE). Now it only caches if selectTier returns SINGLE. A single-tier topology has no L1 or L2 engine:

TestSingleTierTopologyBackedCacheAccessService.java
Ln 86–88

assertSame(engine, topology.getEngine(CacheTier.SINGLE).orElseThrow());
assertFalse(topology.getEngine(CacheTier.L1).isPresent());
assertFalse(topology.getEngine(CacheTier.L2).isPresent());

So a policy that returns L1 or L2 there makes cacheBlock skip every tier with continue. Nothing gets cached, with no log line or metric. Both shipped policies return SINGLE correctly, so nothing breaks today. But the safety net is gone, and the next policy added would fail silently. Suggestions:

  1. Map L1/L2 to SINGLE in the service when the topology is single-tier, or keep the old single-tier fast path.
  2. At minimum, log at debug level or count a metric when a selected tier has no engine.


if (
topologyView.getType() == CacheTopologyType.SINGLE_TIER
(tier == CacheTier.SINGLE || tier == CacheTier.L1)

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.

nit: does that mean SINGLE or L1 mean this is one tier cache ?


assertTrue(admission.isAdmitted());
assertEquals(List.of(CacheTier.L2), placement.getTiers());
assertTrue(admission.isAdmitted());

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.

nit: why do we need to move this line down ?

CachePlacementAdmissionPolicy policy = mock(CachePlacementAdmissionPolicy.class);
when(policy.shouldAdmit(any(), any(), any(), any(), any()))
when(policy.selectTier(any(), any(), any(), any()))
.thenReturn(TierDecision.single(CacheTier.L1));

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.

can you check this ?

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.

3 participants