HBase-1.2.4 CombinedBlockCache和InclusiveCombinedBlockCache

一、综述

        在《HBase-1.2.4 Allow block cache to be external分析》一文的最后,讲解了如何实例化外部缓存MemcachedBlockCache。本文将对上文中提到的几种缓存中的InclusiveCombinedBlockCache和CombinedBlockCache做个综述。

        上文中提到的缓存实现,有以下几种:

        1、单独LruBlockCache

        2、启用外部缓存:InclusiveCombinedBlockCache

        3、启用混合缓存CombinedBlockCache

二、CombinedBlockCache

        CombinedBlockCache是一个混合缓存,它是由LruBlockCache和另外一种BlockCache实现的。它的cacheBlock()方法,会根据参数inMemory和cacheDataInL1来确定缓存的地址是LruBlockCache还是另外一种BlockCache,如下:

  @Override
  public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory,
      final boolean cacheDataInL1) {
    boolean isMetaBlock = buf.getBlockType().getCategory() != BlockCategory.DATA;
    if (isMetaBlock || cacheDataInL1) {
      lruCache.cacheBlock(cacheKey, buf, inMemory, cacheDataInL1);
    } else {
      l2Cache.cacheBlock(cacheKey, buf, inMemory, false);
    }
  }
       而获取缓存时,则是先从LruBlockCache中获取,获取不到时再从另外一种BlockCache中获取,如下:

  @Override
  public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching,
      boolean repeat, boolean updateCacheMetrics) {
    // TODO: is there a hole here, or just awkwardness since in the lruCache getBlock
    // we end up calling l2Cache.getBlock.
    if (lruCache.containsBlock(cacheKey)) {
      return lruCache.getBlock(cacheKey, caching, repeat, updateCacheMetrics);
    }
    Cacheable result = l2Cache.getBlock(cacheKey, caching, repeat, updateCacheMetrics);

    return result;
  }
        回收缓存亦是如此,如下:

  @Override
  public boolean evictBlock(BlockCacheKey cacheKey) {
    return lruCache.evictBlock(cacheKey) || l2Cache.evictBlock(cacheKey);
  }

三、InclusiveCombinedBlockCache

        InclusiveCombinedBlockCache是外部缓存的集中体现,它继承自CombinedBlockCache,但是对于缓存及其获取做了特别的声明,如下:

        1、获取缓存时从lruCache中获取,因为启用外部缓存时会同时写入lru和外部缓存,并且,lru有一种机制,即存在victimHandler且!repeat的情况下,会尝试从另外一种缓存中获取;

        2、缓存时则是lruCache和l2Cache同时缓存。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值