/**
  * @param cell
  * @param out
  * @param encodingCtx
  * @return unencoded size added
  * @throws IOException
  */
 protected final int afterEncodingKeyValue(
     Cell cell, DataOutputStream out, HFileBlockDefaultEncodingContext encodingCtx)
     throws IOException {
   int size = 0;
   if (encodingCtx.getHFileContext().isIncludesTags()) {
     int tagsLength = cell.getTagsLength();
     ByteBufferUtils.putCompressedInt(out, tagsLength);
     // There are some tags to be written
     if (tagsLength > 0) {
       TagCompressionContext tagCompressionContext = encodingCtx.getTagCompressionContext();
       // When tag compression is enabled, tagCompressionContext will have a not null value. Write
       // the tags using Dictionary compression in such a case
       if (tagCompressionContext != null) {
         tagCompressionContext.compressTags(
             out, cell.getTagsArray(), cell.getTagsOffset(), tagsLength);
       } else {
         out.write(cell.getTagsArray(), cell.getTagsOffset(), tagsLength);
       }
     }
     size += tagsLength + KeyValue.TAGS_LENGTH_SIZE;
   }
   if (encodingCtx.getHFileContext().isIncludesMvcc()) {
     // Copy memstore timestamp from the byte buffer to the output stream.
     long memstoreTS = cell.getSequenceId();
     WritableUtils.writeVLong(out, memstoreTS);
     // TODO use a writeVLong which returns the #bytes written so that 2 time parsing can be
     // avoided.
     size += WritableUtils.getVIntSize(memstoreTS);
   }
   return size;
 }
Exemplo n.º 2
0
 @Override
 public void postGetOp(
     ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results)
     throws IOException {
   if (results.size() > 0) {
     // Check tag presence in the 1st cell in 1st Result
     if (!results.isEmpty()) {
       Cell cell = results.get(0);
       tags = Tag.asList(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength());
     }
   }
 }
Exemplo n.º 3
0
    @Override
    public void write(Cell cell) throws IOException {
      if (encryptor == null) {
        super.write(cell);
        return;
      }

      byte[] iv = nextIv();
      encryptor.setIv(iv);
      encryptor.reset();

      // TODO: Check if this is a cell for an encrypted CF. If not, we can
      // write a 0 here to signal an unwrapped cell and just dump the KV bytes
      // afterward

      StreamUtils.writeRawVInt32(out, iv.length);
      out.write(iv);

      // TODO: Add support for WAL compression

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      OutputStream cout = encryptor.createEncryptionStream(baos);

      int tlen = cell.getTagsLength();
      // Write the KeyValue infrastructure as VInts.
      StreamUtils.writeRawVInt32(cout, KeyValueUtil.keyLength(cell));
      StreamUtils.writeRawVInt32(cout, cell.getValueLength());
      // To support tags
      StreamUtils.writeRawVInt32(cout, tlen);

      // Write row, qualifier, and family
      StreamUtils.writeRawVInt32(cout, cell.getRowLength());
      cout.write(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
      StreamUtils.writeRawVInt32(cout, cell.getFamilyLength());
      cout.write(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
      StreamUtils.writeRawVInt32(cout, cell.getQualifierLength());
      cout.write(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
      // Write the rest ie. ts, type, value and tags parts
      StreamUtils.writeLong(cout, cell.getTimestamp());
      cout.write(cell.getTypeByte());
      cout.write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
      if (tlen > 0) {
        cout.write(cell.getTagsArray(), cell.getTagsOffset(), tlen);
      }
      cout.close();

      StreamUtils.writeRawVInt32(out, baos.size());
      baos.writeTo(out);

      // Increment IV given the final payload length
      incrementIv(baos.size());
    }
Exemplo n.º 4
0
 @Override
 public void write(Cell cell) throws IOException {
   checkFlushed();
   // Row
   write(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
   // Column family
   write(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
   // Qualifier
   write(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
   // Version
   this.out.write(Bytes.toBytes(cell.getTimestamp()));
   // Type
   this.out.write(cell.getTypeByte());
   // Value
   write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
   // Tags
   write(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength());
   // MvccVersion
   this.out.write(Bytes.toBytes(cell.getMvccVersion()));
 }