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


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/cache/IndexOnlyCachePlacementAdmissionPolicy.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.io.hfile.cache;
+
+import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
+import org.apache.hadoop.hbase.io.hfile.BlockType;
+import org.apache.hadoop.hbase.io.hfile.Cacheable;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Cache placement and admission policy that preserves the admission behavior 
of the legacy
+ * {@code IndexOnlyLruBlockCache}.
+ * <p>
+ * Despite its historical name, {@code IndexOnlyLruBlockCache} admits all 
non-data blocks. This
+ * policy preserves that behavior while delegating placement, representation, 
and promotion
+ * decisions to {@link DefaultHBaseCachePlacementAdmissionPolicy}.
+ * </p>
+ */
[email protected]
+public class IndexOnlyCachePlacementAdmissionPolicy
+  extends DefaultHBaseCachePlacementAdmissionPolicy {
+
+  public static final IndexOnlyCachePlacementAdmissionPolicy INSTANCE =
+    new IndexOnlyCachePlacementAdmissionPolicy();
+
+  /**
+   * Admits non-data blocks and rejects data blocks.
+   * @param cacheKey     block cache key
+   * @param block        block to cache
+   * @param context      write context describing insertion source and hints
+   * @param priority     admission priority hint
+   * @param topologyView read-only topology view
+   * @return admission decision
+   */
+  @Override
+  public AdmissionDecision shouldAdmit(BlockCacheKey cacheKey, Cacheable block,
+    CacheWriteContext context, AdmissionPriority priority, CacheTopologyView 
topologyView) {
+    super.shouldAdmit(cacheKey, block, context, priority, topologyView);
+
+    BlockType blockType = block.getBlockType();
+    return blockType != null && blockType.getCategory() != 
BlockType.BlockCategory.DATA
+      ? AdmissionDecision.admit()

Review Comment:
   The override calls `super.shouldAdmit(...)` but discards its returned 
`AdmissionDecision`, then returns a new `AdmissionDecision` via 
`admit()`/`reject()`. This likely drops placement/representation/promotion 
details that `DefaultHBaseCachePlacementAdmissionPolicy` computes 
(contradicting the class Javadoc about delegating those decisions). Capture and 
return the superclass decision for the admitted case (or wrap/modify it) and 
only override the admission predicate for DATA vs non-DATA.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/cache/IndexOnlyCachePlacementAdmissionPolicy.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.io.hfile.cache;
+
+import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
+import org.apache.hadoop.hbase.io.hfile.BlockType;
+import org.apache.hadoop.hbase.io.hfile.Cacheable;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Cache placement and admission policy that preserves the admission behavior 
of the legacy
+ * {@code IndexOnlyLruBlockCache}.
+ * <p>
+ * Despite its historical name, {@code IndexOnlyLruBlockCache} admits all 
non-data blocks. This
+ * policy preserves that behavior while delegating placement, representation, 
and promotion
+ * decisions to {@link DefaultHBaseCachePlacementAdmissionPolicy}.
+ * </p>
+ */
[email protected]
+public class IndexOnlyCachePlacementAdmissionPolicy
+  extends DefaultHBaseCachePlacementAdmissionPolicy {
+
+  public static final IndexOnlyCachePlacementAdmissionPolicy INSTANCE =
+    new IndexOnlyCachePlacementAdmissionPolicy();
+
+  /**
+   * Admits non-data blocks and rejects data blocks.
+   * @param cacheKey     block cache key
+   * @param block        block to cache
+   * @param context      write context describing insertion source and hints
+   * @param priority     admission priority hint
+   * @param topologyView read-only topology view
+   * @return admission decision
+   */
+  @Override
+  public AdmissionDecision shouldAdmit(BlockCacheKey cacheKey, Cacheable block,
+    CacheWriteContext context, AdmissionPriority priority, CacheTopologyView 
topologyView) {
+    super.shouldAdmit(cacheKey, block, context, priority, topologyView);
+
+    BlockType blockType = block.getBlockType();
+    return blockType != null && blockType.getCategory() != 
BlockType.BlockCategory.DATA
+      ? AdmissionDecision.admit()
+      : AdmissionDecision.reject("IndexOnlyLRU admits only non-data blocks");

Review Comment:
   The rejection reason is misleading when `blockType == null` (it’s not being 
rejected because it’s a DATA block). Consider returning a distinct message for 
the null block-type case (e.g., \"BlockType is null\"), and keep the current 
message specifically for DATA-category rejections.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/cache/IndexOnlyCachePlacementAdmissionPolicy.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.io.hfile.cache;
+
+import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
+import org.apache.hadoop.hbase.io.hfile.BlockType;
+import org.apache.hadoop.hbase.io.hfile.Cacheable;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Cache placement and admission policy that preserves the admission behavior 
of the legacy
+ * {@code IndexOnlyLruBlockCache}.
+ * <p>
+ * Despite its historical name, {@code IndexOnlyLruBlockCache} admits all 
non-data blocks. This
+ * policy preserves that behavior while delegating placement, representation, 
and promotion
+ * decisions to {@link DefaultHBaseCachePlacementAdmissionPolicy}.
+ * </p>
+ */
[email protected]
+public class IndexOnlyCachePlacementAdmissionPolicy
+  extends DefaultHBaseCachePlacementAdmissionPolicy {
+
+  public static final IndexOnlyCachePlacementAdmissionPolicy INSTANCE =
+    new IndexOnlyCachePlacementAdmissionPolicy();
+

Review Comment:
   The class exposes a singleton `INSTANCE` but does not prevent additional 
instantiation. To enforce singleton usage (and avoid accidental extra 
instances), make the constructor `private` (or at least package-private) and 
document that `INSTANCE` should be used.



-- 
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