Java Code Examples for org.apache.hadoop.hbase.Cell#getSerializedSize()

The following examples show how to use org.apache.hadoop.hbase.Cell#getSerializedSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hbase   File: QuotaUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static long calculateMutationSize(final Mutation mutation) {
  long size = 0;
  for (Map.Entry<byte[], List<Cell>> entry : mutation.getFamilyCellMap().entrySet()) {
    for (Cell cell : entry.getValue()) {
      size += cell.getSerializedSize();
    }
  }
  return size;
}
 
Example 2
Source Project: hbase   File: QuotaUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static long calculateResultSize(final Result result) {
  long size = 0;
  for (Cell cell : result.rawCells()) {
    size += cell.getSerializedSize();
  }
  return size;
}
 
Example 3
Source Project: hbase   File: QuotaUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static long calculateResultSize(final List<Result> results) {
  long size = 0;
  for (Result result: results) {
    for (Cell cell : result.rawCells()) {
      size += cell.getSerializedSize();
    }
  }
  return size;
}
 
Example 4
Source Project: hbase   File: HFilePrettyPrinter.java    License: Apache License 2.0 5 votes vote down vote up
public void collect(Cell cell) {
  valLen.update(cell.getValueLength());
  if (prevCell != null &&
      CellComparator.getInstance().compareRows(prevCell, cell) != 0) {
    // new row
    collectRow();
  }
  curRowBytes += cell.getSerializedSize();
  curRowKeyLength = KeyValueUtil.keyLength(cell);
  curRowCols++;
  prevCell = cell;
}
 
Example 5
Source Project: hbase   File: ConnectionUtils.java    License: Apache License 2.0 5 votes vote down vote up
static void validatePut(Put put, int maxKeyValueSize) throws IllegalArgumentException {
  if (put.isEmpty()) {
    throw new IllegalArgumentException("No columns to insert");
  }
  if (maxKeyValueSize > 0) {
    for (List<Cell> list : put.getFamilyCellMap().values()) {
      for (Cell cell : list) {
        if (cell.getSerializedSize() > maxKeyValueSize) {
          throw new IllegalArgumentException("KeyValue size too large");
        }
      }
    }
  }
}
 
Example 6
Source Project: hbase   File: Segment.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Get cell length after serialized in {@link KeyValue}
 */
@VisibleForTesting
static int getCellLength(Cell cell) {
  return cell.getSerializedSize();
}
 
Example 7
Source Project: hbase   File: TestCellFlatSet.java    License: Apache License 2.0 4 votes vote down vote up
private CellChunkMap setUpCellChunkMap(boolean asc) {

    // allocate new chunks and use the data chunk to hold the full data of the cells
    // and the index chunk to hold the cell-representations
    Chunk dataChunk = chunkCreator.getChunk(CompactingMemStore.IndexType.CHUNK_MAP);
    Chunk idxChunk  = chunkCreator.getChunk(CompactingMemStore.IndexType.CHUNK_MAP);
    // the array of index chunks to be used as a basis for CellChunkMap
    Chunk chunkArray[] = new Chunk[8];  // according to test currently written 8 is way enough
    int chunkArrayIdx = 0;
    chunkArray[chunkArrayIdx++] = idxChunk;

    ByteBuffer idxBuffer = idxChunk.getData();  // the buffers of the chunks
    ByteBuffer dataBuffer = dataChunk.getData();
    int dataOffset = ChunkCreator.SIZEOF_CHUNK_HEADER;        // offset inside data buffer
    int idxOffset = ChunkCreator.SIZEOF_CHUNK_HEADER;         // skip the space for chunk ID

    Cell[] cellArray = asc ? ascCells : descCells;

    for (Cell kv: cellArray) {
      // do we have enough space to write the cell data on the data chunk?
      if (dataOffset + kv.getSerializedSize() > chunkCreator.getChunkSize()) {
        // allocate more data chunks if needed
        dataChunk = chunkCreator.getChunk(CompactingMemStore.IndexType.CHUNK_MAP);
        dataBuffer = dataChunk.getData();
        dataOffset = ChunkCreator.SIZEOF_CHUNK_HEADER;
      }
      int dataStartOfset = dataOffset;
      dataOffset = KeyValueUtil.appendTo(kv, dataBuffer, dataOffset, false); // write deep cell data

      // do we have enough space to write the cell-representation on the index chunk?
      if (idxOffset + ClassSize.CELL_CHUNK_MAP_ENTRY > chunkCreator.getChunkSize()) {
        // allocate more index chunks if needed
        idxChunk = chunkCreator.getChunk(CompactingMemStore.IndexType.CHUNK_MAP);
        idxBuffer = idxChunk.getData();
        idxOffset = ChunkCreator.SIZEOF_CHUNK_HEADER;
        chunkArray[chunkArrayIdx++] = idxChunk;
      }
      idxOffset = ByteBufferUtils.putInt(idxBuffer, idxOffset, dataChunk.getId()); // write data chunk id
      idxOffset = ByteBufferUtils.putInt(idxBuffer, idxOffset, dataStartOfset);          // offset
      idxOffset = ByteBufferUtils.putInt(idxBuffer, idxOffset, kv.getSerializedSize()); // length
      idxOffset = ByteBufferUtils.putLong(idxBuffer, idxOffset, kv.getSequenceId());     // seqId
    }

    return new CellChunkMap(CellComparator.getInstance(),chunkArray,0,NUM_OF_CELLS,!asc);
  }
 
Example 8
Source Project: phoenix   File: CompatUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static int getCellSerializedSize(Cell cell) {
    return cell.getSerializedSize();
}