1 /** 2 * Copyright 2009 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package org.apache.hadoop.hbase.io.hfile; 21 22 import java.io.IOException; 23 import java.util.List; 24 25 import org.apache.hadoop.conf.Configuration; 26 27 /** 28 * Block cache interface. Anything that implements the {@link Cacheable} 29 * interface can be put in the cache. 30 */ 31 public interface BlockCache { 32 /** 33 * Add block to cache. 34 * @param cacheKey The block's cache key. 35 * @param buf The block contents wrapped in a ByteBuffer. 36 * @param inMemory Whether block should be treated as in-memory 37 */ 38 public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory); 39 40 /** 41 * Add block to cache (defaults to not in-memory). 42 * @param cacheKey The block's cache key. 43 * @param buf The object to cache. 44 */ 45 public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf); 46 47 /** 48 * Fetch block from cache. 49 * @param cacheKey Block to fetch. 50 * @param caching Whether this request has caching enabled (used for stats) 51 * @param repeat Whether this is a repeat lookup for the same block 52 * (used to avoid double counting cache misses when doing double-check locking) 53 * {@see HFileReaderV2#readBlock(long, long, boolean, boolean, boolean, BlockType)} 54 * @return Block or null if block is not in 2 cache. 55 */ 56 public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat); 57 58 /** 59 * Evict block from cache. 60 * @param cacheKey Block to evict 61 * @return true if block existed and was evicted, false if not 62 */ 63 public boolean evictBlock(BlockCacheKey cacheKey); 64 65 /** 66 * Evicts all blocks for the given HFile. 67 * 68 * @return the number of blocks evicted 69 */ 70 public int evictBlocksByHfileName(String hfileName); 71 72 /** 73 * Get the statistics for this block cache. 74 * @return Stats 75 */ 76 public CacheStats getStats(); 77 78 /** 79 * Shutdown the cache. 80 */ 81 public void shutdown(); 82 83 /** 84 * Returns the total size of the block cache, in bytes. 85 * @return size of cache, in bytes 86 */ 87 public long size(); 88 89 /** 90 * Returns the free size of the block cache, in bytes. 91 * @return free space in cache, in bytes 92 */ 93 public long getFreeSize(); 94 95 /** 96 * Returns the occupied size of the block cache, in bytes. 97 * @return occupied space in cache, in bytes 98 */ 99 public long getCurrentSize(); 100 101 /** 102 * Returns the number of evictions that have occurred. 103 * @return number of evictions 104 */ 105 public long getEvictedCount(); 106 107 /** 108 * Returns the number of blocks currently cached in the block cache. 109 * @return number of blocks in the cache 110 */ 111 public long getBlockCount(); 112 113 /** 114 * Performs a BlockCache summary and returns a List of BlockCacheColumnFamilySummary objects. 115 * This method could be fairly heavyweight in that it evaluates the entire HBase file-system 116 * against what is in the RegionServer BlockCache. 117 * <br><br> 118 * The contract of this interface is to return the List in sorted order by Table name, then 119 * ColumnFamily. 120 * 121 * @param conf HBaseConfiguration 122 * @return List of BlockCacheColumnFamilySummary 123 * @throws IOException exception 124 */ 125 public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries(Configuration conf) throws IOException; 126 }