HBase数据达到Memstore的过程

本文详细介绍了HBase RegionServer启动时的初始化工作以及数据put操作的流程,特别是Chunk的分配和Cell数据如何写入到Memstore的过程。在put操作中,首先分配Chunk,接着从Chunk中申请内存空间用于Cell数据存储,最后将新Cell对象加入到Memostore。整个流程涉及内存管理、对象创建以及数据写入等关键步骤。
摘要由CSDN通过智能技术生成

往HBase表中写入数据的主要流程。

1 RegionServer启动的初始化工作

启动RegionServer进程的入口类是HRegionServer,通过执行该类的main方法开始。

其简单流程如下:

//通过main方法的执行流程
//main()
new HRegionServerCommandLine(regionServerClass).doMain(args);

//doMain
int ret = ToolRunner.run(HBaseConfiguration.create(), this, args);

//ToolRunner.run, 启动的tool就是HRegionServerCommandLine对象
run(tool.getConf);

//HRegionServerCommandLine.run  HRegionServerCommandLine.start
//构造一个HRegionServer线程对象,并启动
HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf);
hrs.start();
handleReportForDutyResponse(w);
startServices();
initializeMemStoreChunkCreator();

//这里定义chunksize的默认大小为2M
int chunkSize = conf.getInt(MemStoreLAB.CHUNK_SIZE_KEY, MemStoreLAB.CHUNK_SIZE_DEFAULT);
// init the chunkCreator
ChunkCreator.initialize(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,
                        initialCountPercentage, this.hMemManager);

//initialize
instance = new ChunkCreator(chunkSize, offheap, globalMemStoreSize, poolSizePercentage,
            initialCountPercentage, heapMemoryManager,
            MemStoreLABImpl.INDEX_CHUNK_PERCENTAGE_DEFAULT);

//ChunkCreator构造方法
this.chunkSize = chunkSize; // in case pools are not allocated
initializePools(chunkSize, globalMemStoreSize, poolSizePercentage, indexChunkSizePercentage,
                initialCountPercentage, heapMemoryManager);

//initializePools
//在这里定义了dataChunk、indexChunk的size大小,默认为2M
this.dataChunksPool = initializePool("data", globalMemStoreSize,
            (1 - indexChunkSizePercentage) * poolSizePercentage,
            initialCountPercentage, chunkSize, heapMemoryManager);
// The index chunks pool is needed only when the index type is CCM.
// Since the pools are not created at all when the index type isn't CCM,
// we don't need to check it here.
this.indexChunksPool = initializePool("index", globalMemStoreSize,
                                      indexChunkSizePercentage * poolSizePercentage,
                                      initialCountPercentage, (int) (indexChunkSizePercentage * chunkSize),
                                      heapMemoryManager);
2 put操作的流程

当往HBase表中put数据时,最终会调用HRgion中的doMiniBatchMutate方法,接下来的调用流程如下所示。

//doMiniBatchMutate
//在此方法内,会先将修改写入到WAl中
// STEP 3. Build WAL edit
List<Pair<NonceKey, WALEdit>> walEdits = batchOp.buildWALEdits(miniBatchOp);

// STEP 4. Append the WALEdits to WAL and sync.
for(Iterator<Pair<NonceKey, WALEdit>> it = walEdits.iterator(); it.hasNext();) {
   
    Pair<NonceKey, WALEdit> nonceKeyWALEditPair = it.next();
    walEdit = nonceKeyWALEditPair.getSecond();
    NonceKey nonceKey = nonceKeyWALEditPair.getFirst();

    if (walEdit != null && !walEdit.isEmpty()) {
   
        writeEntry = doWALAppend(walEdit, batchOp.durability, batchOp.getClusterIds<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值