Copilot commented on code in PR #8903:
URL: https://github.com/apache/hbase/pull/8903#discussion_r4672067958


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/cache/TestSingleTierTopologyBackedCacheAccessService.java:
##########
@@ -401,7 +401,9 @@ private static CachePlacementAdmissionPolicy 
admitToTiersPolicy(CacheTier... tie
    */
   private static CachePlacementAdmissionPolicy rejectPolicy() {
     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));

Review Comment:
   `SingleTierTopology` exposes only `CacheTier.SINGLE`, so selecting `L1` 
makes `cacheBlock()` skip the tier before calling `shouldAdmit()`. 
Consequently, `testRejectedBlockIsNotCached()` now passes without exercising 
rejection at all. Select `SINGLE` here so the test actually checks that an 
admission rejection prevents insertion.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/cache/TopologyBackedCacheAccessService.java:
##########
@@ -277,77 +277,21 @@ public void cacheBlock(BlockCacheKey cacheKey, Cacheable 
block, CacheWriteContex
     Objects.requireNonNull(block, "block must not be null");
     Objects.requireNonNull(context, "context must not be null");
 
-    if (topology.getType() == CacheTopologyType.SINGLE_TIER) {
-      cacheBlockToSingleTier(cacheKey, block, context);
-      return;
-    }
-
-    cacheBlockToSelectedTiers(cacheKey, block, context);
-  }
-
-  /**
-   * Caches a block into the only engine in a single-tier topology.
-   * <p>
-   * This method preserves the behavior of the legacy {@link 
BlockCacheBackedCacheAccessService}
-   * path. A single-tier topology has no placement decision to make: admitted 
blocks are written to
-   * the only available engine, which is exposed as {@link CacheTier#SINGLE}.
-   * </p>
-   * @param cacheKey cache key identifying the block
-   * @param block    block to cache
-   * @param context  cache write context
-   * @throws NullPointerException if {@code cacheKey}, {@code block}, or 
{@code context} is
-   *                              {@code null}
-   */
-  private void cacheBlockToSingleTier(BlockCacheKey cacheKey, Cacheable block,
-    CacheWriteContext context) {
-    Objects.requireNonNull(cacheKey, "cacheKey must not be null");
-    Objects.requireNonNull(block, "block must not be null");
-    Objects.requireNonNull(context, "context must not be null");
-
-    AdmissionDecision admission =
-      policy.shouldAdmit(cacheKey, block, context, AdmissionPriority.NORMAL, 
topologyView);
-    if (!admission.isAdmitted()) {
-      return;
-    }
-
-    Optional<CacheEngine> engine = topology.getEngine(CacheTier.SINGLE);
-    if (!engine.isPresent()) {
-      return;
-    }
-
-    engine.get().cacheBlock(cacheKey, block, context.isInMemory(), 
context.isWaitWhenCache());
-  }
-
-  /**
-   * Caches a block into the tiers selected by the placement policy.
-   * <p>
-   * This method is used for tiered topologies where the placement policy 
decides whether the block
-   * belongs in L1, L2, or multiple tiers.
-   * </p>
-   * @param cacheKey cache key identifying the block
-   * @param block    block to cache
-   * @param context  cache write context
-   * @throws NullPointerException if {@code cacheKey}, {@code block}, or 
{@code context} is
-   *                              {@code null}
-   */
-  private void cacheBlockToSelectedTiers(BlockCacheKey cacheKey, Cacheable 
block,
-    CacheWriteContext context) {
-    Objects.requireNonNull(cacheKey, "cacheKey must not be null");
-    Objects.requireNonNull(block, "block must not be null");
-    Objects.requireNonNull(context, "context must not be null");
-
-    AdmissionDecision admission =
-      policy.shouldAdmit(cacheKey, block, context, AdmissionPriority.NORMAL, 
topologyView);
-    if (!admission.isAdmitted()) {
-      return;
-    }
-
     TierDecision tierDecision = policy.selectTier(cacheKey, block, context, 
topologyView);
+
     for (CacheTier tier : tierDecision.getTiers()) {
       Optional<CacheEngine> engine = topology.getEngine(tier);
-      if (engine.isPresent()) {
-        engine.get().cacheBlock(cacheKey, block, context.isInMemory(), 
context.isWaitWhenCache());
+      if (!engine.isPresent()) {
+        continue;
+      }
+
+      AdmissionDecision admission =
+        policy.shouldAdmit(cacheKey, block, context, AdmissionPriority.NORMAL, 
tier, topologyView);
+      if (!admission.isAdmitted()) {
+        continue;

Review Comment:
   The service tests do not exercise rejection of one selected tier while 
another admits, so replacing this `continue` with `return` would leave the 
central per-tier behavior untested. Add a service-level test selecting L1 and 
L2, rejecting L1 and admitting L2, and verify that admission is checked for 
both tiers but only L2 receives the block.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to