1 /**
2 * Copyright The Apache Software Foundation
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with this
6 * work for additional information regarding copyright ownership. The ASF
7 * licenses this file to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 * License for the specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.hadoop.hbase.io.hfile;
21
22 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24
25 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
26 public class InclusiveCombinedBlockCache extends CombinedBlockCache implements BlockCache {
27 public InclusiveCombinedBlockCache(LruBlockCache l1, BlockCache l2) {
28 super(l1,l2);
29 l1.setVictimCache(l2);
30 }
31
32 @Override
33 public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching,
34 boolean repeat, boolean updateCacheMetrics) {
35 // On all external cache set ups the lru should have the l2 cache set as the victimHandler
36 // Because of that all requests that miss inside of the lru block cache will be
37 // tried in the l2 block cache.
38 return lruCache.getBlock(cacheKey, caching, repeat, updateCacheMetrics);
39 }
40
41 /**
42 *
43 * @param cacheKey The block's cache key.
44 * @param buf The block contents wrapped in a ByteBuffer.
45 * @param inMemory Whether block should be treated as in-memory. This parameter is only useful for
46 * the L1 lru cache.
47 * @param cacheDataInL1 This is totally ignored.
48 */
49 @Override
50 public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory,
51 final boolean cacheDataInL1) {
52 // This is the inclusive part of the combined block cache.
53 // Every block is placed into both block caches.
54 lruCache.cacheBlock(cacheKey, buf, inMemory, true);
55
56 // This assumes that insertion into the L2 block cache is either async or very fast.
57 l2Cache.cacheBlock(cacheKey, buf, inMemory, true);
58 }
59 }