Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.hadoop.hbase.io.hfile.cache.BlockCacheBackedCacheAccessService;
import org.apache.hadoop.hbase.io.hfile.cache.CacheAccessService;
import org.apache.hadoop.hbase.io.hfile.cache.CacheAccessServices;
import org.apache.hadoop.hbase.io.hfile.cache.CacheTopologyType;
import org.apache.hadoop.hbase.io.hfile.cache.TopologyBackedCacheAccessService;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -527,7 +529,20 @@ public CacheAccessService getCacheAccessService() {
}

public boolean isCombinedBlockCache() {
return blockCache instanceof CombinedBlockCache;
if (blockCache instanceof CombinedBlockCache) {
return true;
}
return isCombinedBlockCacheCompatible(cacheAccessService);
}

private static boolean isCombinedBlockCacheCompatible(CacheAccessService cacheAccessService) {
if (!(cacheAccessService instanceof TopologyBackedCacheAccessService)) {
return false;
}

TopologyBackedCacheAccessService service =
(TopologyBackedCacheAccessService) cacheAccessService;
return service.getTopology().getType() == CacheTopologyType.TIERED_EXCLUSIVE;
}

public ByteBuffAllocator getByteBuffAllocator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.io.hfile.cache;

import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -30,6 +31,7 @@
import org.apache.hadoop.hbase.io.hfile.CachedBlock;
import org.apache.hadoop.hbase.io.hfile.HFileBlock;
import org.apache.hadoop.hbase.io.hfile.HFileInfo;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand Down Expand Up @@ -310,6 +312,11 @@ public void notifyFileCachingCompleted(Path fileName, int totalBlockCount, int d
blockCache.notifyFileCachingCompleted(fileName, totalBlockCount, dataBlockCount, size);
}

@Override
public Optional<Map<String, Pair<String, Long>>> getFullyCachedFiles() {
return blockCache.getFullyCachedFiles();
}

@Override
public Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, Configuration conf) {
Objects.requireNonNull(hFileInfo, "hFileInfo must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.io.hfile.cache;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -26,7 +27,10 @@
import org.apache.hadoop.hbase.io.hfile.BlockType;
import org.apache.hadoop.hbase.io.hfile.CacheStats;
import org.apache.hadoop.hbase.io.hfile.Cacheable;
import org.apache.hadoop.hbase.io.hfile.FirstLevelBlockCache;
import org.apache.hadoop.hbase.io.hfile.HFileBlock;
import org.apache.hadoop.hbase.io.hfile.HFileInfo;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand Down Expand Up @@ -184,9 +188,13 @@ public Optional<Boolean> blockFitsIntoTheCache(HFileBlock block) {
}

@Override
public Optional<Boolean> isAlreadyCached(BlockCacheKey key) {
Objects.requireNonNull(key, "key must not be null");
return blockCache.isAlreadyCached(key);
public Optional<Boolean> isAlreadyCached(BlockCacheKey cacheKey) {
Objects.requireNonNull(cacheKey, "cacheKey must not be null");
if (blockCache instanceof FirstLevelBlockCache) {
FirstLevelBlockCache firstLevelBlockCache = (FirstLevelBlockCache) blockCache;
return Optional.of(firstLevelBlockCache.containsBlock(cacheKey));
}
return blockCache.isAlreadyCached(cacheKey);
}

@Override
Expand Down Expand Up @@ -217,4 +225,24 @@ public void notifyFileCachingCompleted(Path fileName, int totalBlockCount, int d
Objects.requireNonNull(fileName, "fileName must not be null");
blockCache.notifyFileCachingCompleted(fileName, totalBlockCount, dataBlockCount, size);
}

@Override
public Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, Configuration conf) {
Objects.requireNonNull(hFileInfo, "hFileInfo must not be null");
Objects.requireNonNull(conf, "conf must not be null");
return blockCache.shouldCacheFile(hFileInfo, conf);
}

@Override
public Optional<Boolean> shouldCacheBlock(BlockCacheKey key, long maxTimeStamp,
Configuration conf) {
Objects.requireNonNull(key, "key must not be null");
Objects.requireNonNull(conf, "conf must not be null");
return blockCache.shouldCacheBlock(key, maxTimeStamp, conf);
}

@Override
public Optional<Map<String, Pair<String, Long>>> getFullyCachedFiles() {
return blockCache.getFullyCachedFiles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.io.hfile.cache;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
Expand All @@ -29,6 +30,7 @@
import org.apache.hadoop.hbase.io.hfile.Cacheable;
import org.apache.hadoop.hbase.io.hfile.HFileBlock;
import org.apache.hadoop.hbase.io.hfile.HFileInfo;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand Down Expand Up @@ -123,6 +125,7 @@ public interface CacheAccessService extends ConfigurationObserver {
*/
default Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat,
boolean updateCacheMetrics) {
Objects.requireNonNull(cacheKey, "cacheKey must not be null");
CacheRequestContext context = CacheRequestContext.newBuilder().withCaching(caching)
.withRepeat(repeat).withUpdateCacheMetrics(updateCacheMetrics).build();
return getBlock(cacheKey, context);
Expand All @@ -144,6 +147,7 @@ default Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repe
*/
default Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat,
boolean updateCacheMetrics, BlockType blockType) {
Objects.requireNonNull(cacheKey, "cacheKey must not be null");
CacheRequestContext context =
CacheRequestContext.newBuilder().withCaching(caching).withRepeat(repeat)
.withUpdateCacheMetrics(updateCacheMetrics).withBlockType(blockType).build();
Expand Down Expand Up @@ -183,7 +187,10 @@ default Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repe
* @param inMemory whether the block should be treated as in-memory
*/
default void cacheBlock(BlockCacheKey cacheKey, Cacheable block, boolean inMemory) {
CacheWriteContext context = CacheWriteContext.newBuilder().withInMemory(inMemory).build();
Objects.requireNonNull(cacheKey, "cacheKey must not be null");
Objects.requireNonNull(block, "block must not be null");
CacheWriteContext context = CacheWriteContext.newBuilder().withInMemory(inMemory)
.withBlockCategory(block.getBlockType().getCategory()).build();
cacheBlock(cacheKey, block, context);
}

Expand All @@ -199,10 +206,14 @@ default void cacheBlock(BlockCacheKey cacheKey, Cacheable block, boolean inMemor
* @param inMemory whether the block should be treated as in-memory
* @param waitWhenCache whether to wait for the cache operation to be accepted/flushed
*/

default void cacheBlock(BlockCacheKey cacheKey, Cacheable block, boolean inMemory,
boolean waitWhenCache) {
CacheWriteContext context = CacheWriteContext.newBuilder().withInMemory(inMemory)
.withWaitWhenCache(waitWhenCache).build();
Objects.requireNonNull(cacheKey, "cacheKey must not be null");
Objects.requireNonNull(block, "block must not be null");
CacheWriteContext context =
CacheWriteContext.newBuilder().withInMemory(inMemory).withWaitWhenCache(waitWhenCache)
.withBlockCategory(block.getBlockType().getCategory()).build();
cacheBlock(cacheKey, block, context);
}

Expand All @@ -215,7 +226,11 @@ default void cacheBlock(BlockCacheKey cacheKey, Cacheable block, boolean inMemor
* @param block block contents
*/
default void cacheBlock(BlockCacheKey cacheKey, Cacheable block) {
cacheBlock(cacheKey, block, CacheWriteContext.newBuilder().build());
Objects.requireNonNull(cacheKey, "cacheKey must not be null");
Objects.requireNonNull(block, "block must not be null");
CacheWriteContext context =
CacheWriteContext.newBuilder().withBlockCategory(block.getBlockType().getCategory()).build();
cacheBlock(cacheKey, block, context);
}

/**
Expand Down Expand Up @@ -524,4 +539,19 @@ default Optional<Boolean> shouldCacheBlock(BlockCacheKey key, long maxTimestamp,
Configuration conf) {
return Optional.empty();
}

/**
* Returns the files that are fully cached by this cache implementation.
* <p>
* A file is considered fully cached when all of its cacheable blocks are present in the cache.
* Not all cache implementations track this information. Implementations that do not support this
* capability should return {@link Optional#empty()}.
* </p>
* @return an {@link Optional} containing a map of fully cached files when this capability is
* supported; otherwise {@link Optional#empty()}
*/
default Optional<Map<String, Pair<String, Long>>> getFullyCachedFiles() {
return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.hadoop.hbase.io.hfile.BlockCache;
import org.apache.hadoop.hbase.io.hfile.BlockCacheFactory;
import org.apache.hadoop.hbase.io.hfile.CachedBlock;
import org.apache.hadoop.hbase.io.hfile.CombinedBlockCache;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand All @@ -46,18 +47,26 @@ private CacheAccessServices() {
}

/**
* Creates a {@link CacheAccessService} backed by an existing {@link BlockCache}.
* Creates a cache access service backed by an existing block cache.
* <p>
* This is the default compatibility path during migration from {@code BlockCache} to
* {@code CacheAccessService}. The returned service delegates to the supplied block cache and
* should preserve existing behavior.
* For regular {@link BlockCache} implementations, this returns a legacy
* {@link BlockCacheBackedCacheAccessService}. For {@link CombinedBlockCache}, this returns a
* topology-backed service using {@link TieredExclusiveTopology}. This moves combined L1/L2
* orchestration to the new topology layer while keeping the existing combined block cache object
* available for legacy {@link BlockCache}-facing APIs.
* </p>
* @param blockCache block cache to wrap
* @return cache access service backed by {@code blockCache}
* @param blockCache block cache to expose through {@link CacheAccessService}
* @return cache access service
*/

public static CacheAccessService fromBlockCache(BlockCache blockCache) {
return new BlockCacheBackedCacheAccessService(
Objects.requireNonNull(blockCache, "blockCache must not be null"));
Objects.requireNonNull(blockCache, "blockCache must not be null");
if (blockCache instanceof CombinedBlockCache) {
return TopologyBackedCacheAccessServices
.fromCombinedBlockCache((CombinedBlockCache) blockCache);
}
return new BlockCacheBackedCacheAccessService(blockCache);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.io.hfile.cache;

import java.util.Map;
import java.util.Optional;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
Expand All @@ -25,6 +26,8 @@
import org.apache.hadoop.hbase.io.hfile.CacheStats;
import org.apache.hadoop.hbase.io.hfile.Cacheable;
import org.apache.hadoop.hbase.io.hfile.HFileBlock;
import org.apache.hadoop.hbase.io.hfile.HFileInfo;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand Down Expand Up @@ -302,4 +305,17 @@ default void notifyFileCachingCompleted(Path fileName, int totalBlockCount, int
long size) {
// noop
}

default Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, Configuration conf) {
return Optional.empty();
}

default Optional<Boolean> shouldCacheBlock(BlockCacheKey key, long maxTimeStamp,
Configuration conf) {
return Optional.empty();
}

default Optional<Map<String, Pair<String, Long>>> getFullyCachedFiles() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ public List<CacheTier> getTiers() {
public boolean isEmpty() {
return tiers.isEmpty();
}

@Override
public String toString() {
return "TierDecision{" + "tiers=" + tiers + '}';
}
}
Loading
Loading