View Javadoc

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    }
30  
31    @Override
32    public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching,
33                              boolean repeat, boolean updateCacheMetrics) {
34      // On all external cache set ups the lru should have the l2 cache set as the victimHandler
35      // Because of that all requests that miss inside of the lru block cache will be
36      // tried in the l2 block cache.
37      return lruCache.getBlock(cacheKey, caching, repeat, updateCacheMetrics);
38    }
39  
40    /**
41     *
42     * @param cacheKey The block's cache key.
43     * @param buf The block contents wrapped in a ByteBuffer.
44     * @param inMemory Whether block should be treated as in-memory. This parameter is only useful for
45     *                 the L1 lru cache.
46     * @param cacheDataInL1 This is totally ignored.
47     */
48    @Override
49    public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory,
50                           final boolean cacheDataInL1) {
51      // This is the inclusive part of the combined block cache.
52      // Every block is placed into both block caches.
53      lruCache.cacheBlock(cacheKey, buf, inMemory, true);
54  
55      // This assumes that insertion into the L2 block cache is either async or very fast.
56      l2Cache.cacheBlock(cacheKey, buf, inMemory, true);
57    }
58  }