HBase-1.2.4LruBlockCache实现分析(二)
来源:互联网 发布:乃木坂网络直播电视剧 编辑:程序博客网 时间:2024/05/17 06:19
本文介绍LruBlockCache如何获取缓存数据。
缓存数据的获取是在方法getBlock()中实现的,代码如下:
/** * Get the buffer of the block with the specified name. * @param cacheKey block's cache key * @param caching true if the caller caches blocks on cache misses * @param repeat Whether this is a repeat lookup for the same block * (used to avoid double counting cache misses when doing double-check locking) * @param updateCacheMetrics Whether to update cache metrics or not * @return buffer of specified cache key, or null if not in cache */ @Override public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) { LruCachedBlock cb = map.get(cacheKey); if (cb == null) { if (!repeat && updateCacheMetrics) stats.miss(caching, cacheKey.isPrimary()); // If there is another block cache then try and read there. // However if this is a retry ( second time in double checked locking ) // And it's already a miss then the l2 will also be a miss. if (victimHandler != null && !repeat) { Cacheable result = victimHandler.getBlock(cacheKey, caching, repeat, updateCacheMetrics); // Promote this to L1. if (result != null && caching) { cacheBlock(cacheKey, result, /* inMemory = */ false, /* cacheData = */ true); } return result; } return null; } if (updateCacheMetrics) stats.hit(caching, cacheKey.isPrimary()); cb.access(count.incrementAndGet()); return cb.getBuffer(); }实现逻辑如下:
1、首先,从LruBlockCache的map中直接获取;
2、如果map中没有,则在victimHandler存在且!repeat的情况下,通过victimHandler的getBlock()方法获取并缓存到LruBlockCache中,即综合考虑第二种缓存模式,并同步到第一种缓存中;
3、如果1或2能够获取到数据,更新统计数据,且通过缓存块的access方法,更新访问时间accessTime,将可能的BlockPriority.SINGLE升级为BlockPriority.MULTI;
4、返回。
1 0
- HBase-1.2.4LruBlockCache实现分析(二)
- [转] HBase-1.2.4LruBlockCache实现分析
- HBase-1.2.4LruBlockCache实现分析(一)
- HBase-1.2.4LruBlockCache实现分析(一)
- HBase源码分析之BlockCache一:综述及LruBlockCache的实现
- HBase架构深入分析(二)
- HBase基本代码实现(二)
- [HBase] HBase Block Cache实现机制分析
- HBase分析之Get、Scan(二)RegionScanner
- Hadoop学习笔记(一)HBase脚本分析(二)hbase-daemon.sh
- Hadoop学习笔记(一)HBase脚本分析(二)hbase-daemon.sh
- HBase的Nonce实现分析
- HBase StoreFile的实现分析
- HBase系列(二)
- HBase(二)
- hadoop学习-海量日志分析(二) HBase
- HBase源码分析之BlockCache二:BucketCache
- hbase总结(二)-hbase安装
- 产品新人撰写需求文档须知的几个要点
- HDU 5945 (线性dp+单调队列优化)
- 正则手机号验证
- vivado与modelsim的联合仿真(一)
- 封装的概述
- HBase-1.2.4LruBlockCache实现分析(二)
- 多线程采集的核心代码
- 瞬态变量
- [微信小程序]知识总结及案例汇总
- OKVIS 代码框架
- vivado与modelsim的联合仿真(二)
- android apk编译时间获取
- 51NOD 序列求和 V5题解
- python的制表工具包Matplotlib