コード例 #1
0
ファイル: HFileWriterV2.java プロジェクト: jimmyjin/hbase
  /**
   * Add key/value to file. Keys must be added in an order that agrees with the Comparator passed on
   * construction.
   *
   * @param kv KeyValue to add. Cannot be empty nor null.
   * @throws IOException
   */
  @Override
  public void append(final KeyValue kv) throws IOException {
    byte[] key = kv.getBuffer();
    int koffset = kv.getKeyOffset();
    int klength = kv.getKeyLength();
    byte[] value = kv.getValueArray();
    int voffset = kv.getValueOffset();
    int vlength = kv.getValueLength();
    boolean dupKey = checkKey(key, koffset, klength);
    checkValue(value, voffset, vlength);
    if (!dupKey) {
      checkBlockBoundary();
    }

    if (!fsBlockWriter.isWriting()) newBlock();

    fsBlockWriter.write(kv);

    totalKeyLength += klength;
    totalValueLength += vlength;

    // Are we the first key in this block?
    if (firstKeyInBlock == null) {
      // Copy the key.
      firstKeyInBlock = new byte[klength];
      System.arraycopy(key, koffset, firstKeyInBlock, 0, klength);
    }

    lastKeyBuffer = key;
    lastKeyOffset = koffset;
    lastKeyLength = klength;
    entryCount++;
    this.maxMemstoreTS = Math.max(this.maxMemstoreTS, kv.getMvccVersion());
  }