VladRodionov commented on code in PR #8231: URL: https://github.com/apache/hbase/pull/8231#discussion_r3236417944
########## hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/cache/NoOpCacheAccessService.java: ########## @@ -0,0 +1,216 @@ +/* + * 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 java.util.Objects; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.io.hfile.BlockCacheKey; +import org.apache.hadoop.hbase.io.hfile.CacheStats; +import org.apache.hadoop.hbase.io.hfile.Cacheable; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * Disabled-cache implementation of {@link CacheAccessService}. + * <p> + * {@code NoOpCacheAccessService} is useful when block cache access is disabled but callers still + * want to depend on a non-null {@link CacheAccessService}. It never stores blocks, never returns + * cached blocks, reports zero capacity and occupancy, and treats all invalidation requests as + * no-ops. + * </p> + * <p> + * This implementation should not be used to hide configuration mistakes. It represents an explicit + * disabled-cache state and should be selected only when the caller has determined that no block + * cache is available or desired. + * </p> + */ [email protected] +public final class NoOpCacheAccessService implements CacheAccessService { Review Comment: The intent is to have a null-object implementation for the disabled-cache case. Once read/write path callers start depending on CacheAccessService, having a disabled implementation lets the runtime wire a non-null service even when block cache is disabled or unavailable. That keeps future call sites simpler because they can call the service uniformly instead of carrying repeated null checks around BlockCache. So instead of patterns like: ```java if (blockCache != null) { blockCache.getBlock(...); } ``` the wiring can select either: ```java CacheAccessServices.fromBlockCache(blockCache) ``` or: ```java CacheAccessServices.disabled() ``` and callers can use CacheAccessService consistently. It is not strictly required for the first adapter PR. If you think it adds unnecessary surface area before we wire CacheAccessService into runtime code, I can remove NoOpCacheAccessService and the disabled() helper from this PR and add it later when the first disabled-cache wiring needs it. -- 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]
