HBase源码分析之WALEdit

客户端发送的每一个修改都会被封装到一个WALEdit。它通过日志级别来管理原子性。
这里写图片描述

VERSION_2:新旧版本标记
replay:boolean类型,表示这个WALEdit是否正常写入,WAL生成了一个(新版)Log,一个Log占有许多的KeyValue;
cells:ArrayList类型,表示一个或多个对Cell写入操作,实际存的是KeyValue,
这里写图片描述

  /**
   * Create a bulk loader WALEdit
   *
   * @param hri                The HRegionInfo for the region in which we are bulk loading
   * @param bulkLoadDescriptor The descriptor for the Bulk Loader
   * @return The WALEdit for the BulkLoad
   */
  public static WALEdit createBulkLoadEvent(HRegionInfo hri,
                                            WALProtos.BulkLoadDescriptor bulkLoadDescriptor) {
    KeyValue kv = new KeyValue(getRowForRegion(hri),
        METAFAMILY,
        BULK_LOAD,
        EnvironmentEdgeManager.currentTime(),
        bulkLoadDescriptor.toByteArray());
    return new WALEdit().add(kv);
  }

这里写图片描述

@Override
  public void write(DataOutput out) throws IOException {
    LOG.warn("WALEdit is being serialized to writable - only expected in test code");
    out.writeInt(VERSION_2);
    out.writeInt(cells.size());
    // We interleave the two lists for code simplicity
    for (Cell cell : cells) {
      // This is not used in any of the core code flows so it is just fine to convert to KV
      KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
      if (compressionContext != null) {
        KeyValueCompression.writeKV(out, kv, compressionContext);
      } else{
        KeyValue.write(kv, out);
      }
    }
    if (scopes == null) {
      out.writeInt(0);
    } else {
      out.writeInt(scopes.size());
      for (byte[] key : scopes.keySet()) {
        Bytes.writeByteArray(out, key);
        out.writeInt(scopes.get(key));
      }
    }
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值