HBase源码分析之WALEdit

版权声明:本文为博主原创文章,欢迎转载,请注明出处。 https://blog.csdn.net/plgy_Y/article/details/75946607

客户端发送的每一个修改都会被封装到一个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));
      }
    }
  }

猜你喜欢

转载自blog.csdn.net/plgy_Y/article/details/75946607
今日推荐