org.apache.hadoop.hbase.CellScanner Java Examples

The following examples show how to use org.apache.hadoop.hbase.CellScanner. 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 File: QuotaTableUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a multimap for all existing table snapshot entries.
 * @param conn connection to re-use
 */
public static Multimap<TableName, String> getTableSnapshots(Connection conn) throws IOException {
  try (Table quotaTable = conn.getTable(QUOTA_TABLE_NAME);
      ResultScanner rs = quotaTable.getScanner(createScanForSpaceSnapshotSizes())) {
    Multimap<TableName, String> snapshots = HashMultimap.create();
    for (Result r : rs) {
      CellScanner cs = r.cellScanner();
      while (cs.advance()) {
        Cell c = cs.current();

        final String snapshot = extractSnapshotNameFromSizeCell(c);
        snapshots.put(getTableFromRowKey(r.getRow()), snapshot);
      }
    }
    return snapshots;
  }
}
 
Example #2
Source File: TestTags.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public boolean postScannerNext(ObserverContext<RegionCoprocessorEnvironment> e,
    InternalScanner s, List<Result> results, int limit, boolean hasMore) throws IOException {
  if (checkTagPresence) {
    if (results.size() > 0) {
      // Check tag presence in the 1st cell in 1st Result
      Result result = results.get(0);
      CellScanner cellScanner = result.cellScanner();
      if (cellScanner.advance()) {
        Cell cell = cellScanner.current();
        tags = PrivateCellUtil.getTags(cell);
      }
    }
  }
  return hasMore;
}
 
Example #3
Source File: TestVisibilityLabels.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleVisibilityLabels() throws Exception {
  TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL,
      PRIVATE + "|" + CONFIDENTIAL)) {
    Scan s = new Scan();
    s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE));
    ResultScanner scanner = table.getScanner(s);
    Result[] next = scanner.next(3);

    assertTrue(next.length == 2);
    CellScanner cellScanner = next[0].cellScanner();
    cellScanner.advance();
    Cell current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
        current.getRowLength(), row1, 0, row1.length));
    cellScanner = next[1].cellScanner();
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
        current.getRowLength(), row2, 0, row2.length));
  }
}
 
Example #4
Source File: CellBlockBuilder.java    From hbase with Apache License 2.0 6 votes vote down vote up
private boolean buildCellBlock(final Codec codec, final CompressionCodec compressor,
    final CellScanner cellScanner, OutputStreamSupplier supplier) throws IOException {
  if (cellScanner == null) {
    return false;
  }
  if (codec == null) {
    throw new CellScannerButNoCodecException();
  }
  int bufferSize = cellBlockBuildingInitialBufferSize;
  encodeCellsTo(supplier.get(bufferSize), cellScanner, codec, compressor);
  if (LOG.isTraceEnabled() && bufferSize < supplier.size()) {
    LOG.trace("Buffer grew from initial bufferSize=" + bufferSize + " to " + supplier.size()
        + "; up hbase.ipc.cellblock.building.initial.buffersize?");
  }
  return true;
}
 
Example #5
Source File: TableSnapshotInputFormatTestBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected static void verifyRowFromMap(ImmutableBytesWritable key, Result result)
  throws IOException {
  byte[] row = key.get();
  CellScanner scanner = result.cellScanner();
  while (scanner.advance()) {
    Cell cell = scanner.current();

    //assert that all Cells in the Result have the same key
    Assert.assertEquals(0, Bytes.compareTo(row, 0, row.length,
      cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
  }

  for (byte[] family : FAMILIES) {
    byte[] actual = result.getValue(family, family);
    Assert.assertArrayEquals(
      "Row in snapshot does not match, expected:" + Bytes.toString(row) + " ,actual:" + Bytes
        .toString(actual), row, actual);
  }
}
 
Example #6
Source File: AccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void checkForReservedTagPresence(User user, Mutation m) throws IOException {
  // No need to check if we're not going to throw
  if (!authorizationEnabled) {
    m.setAttribute(TAG_CHECK_PASSED, TRUE);
    return;
  }
  // Superusers are allowed to store cells unconditionally.
  if (Superusers.isSuperUser(user)) {
    m.setAttribute(TAG_CHECK_PASSED, TRUE);
    return;
  }
  // We already checked (prePut vs preBatchMutation)
  if (m.getAttribute(TAG_CHECK_PASSED) != null) {
    return;
  }
  for (CellScanner cellScanner = m.cellScanner(); cellScanner.advance();) {
    Iterator<Tag> tagsItr = PrivateCellUtil.tagsIterator(cellScanner.current());
    while (tagsItr.hasNext()) {
      if (tagsItr.next().getType() == PermissionStorage.ACL_TAG_TYPE) {
        throw new AccessDeniedException("Mutation contains cell with reserved type tag");
      }
    }
  }
  m.setAttribute(TAG_CHECK_PASSED, TRUE);
}
 
Example #7
Source File: RSRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static Get toGet(final Mutation mutation) throws IOException {
  if(!(mutation instanceof Increment) && !(mutation instanceof Append)) {
    throw new AssertionError("mutation must be a instance of Increment or Append");
  }
  Get get = new Get(mutation.getRow());
  CellScanner cellScanner = mutation.cellScanner();
  while (!cellScanner.advance()) {
    Cell cell = cellScanner.current();
    get.addColumn(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell));
  }
  if (mutation instanceof Increment) {
    // Increment
    Increment increment = (Increment) mutation;
    get.setTimeRange(increment.getTimeRange().getMin(), increment.getTimeRange().getMax());
  } else {
    // Append
    Append append = (Append) mutation;
    get.setTimeRange(append.getTimeRange().getMin(), append.getTimeRange().getMax());
  }
  for (Entry<String, byte[]> entry : mutation.getAttributesMap().entrySet()) {
    get.setAttribute(entry.getKey(), entry.getValue());
  }
  return get;
}
 
Example #8
Source File: QuotaTableUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of {@code Delete} to remove all entries returned by the passed scanner.
 * @param connection connection to re-use
 * @param scan the scanner to use to generate the list of deletes
 */
static List<Delete> createDeletesForExistingSnapshotsFromScan(Connection connection, Scan scan)
    throws IOException {
  List<Delete> deletes = new ArrayList<>();
  try (Table quotaTable = connection.getTable(QUOTA_TABLE_NAME);
      ResultScanner rs = quotaTable.getScanner(scan)) {
    for (Result r : rs) {
      CellScanner cs = r.cellScanner();
      while (cs.advance()) {
        Cell c = cs.current();
        byte[] family = Bytes.copy(c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength());
        byte[] qual =
            Bytes.copy(c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength());
        Delete d = new Delete(r.getRow());
        d.addColumns(family, qual);
        deletes.add(d);
      }
    }
    return deletes;
  }
}
 
Example #9
Source File: TestUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public static CellCount getCellCount(Table table, boolean isRaw) throws IOException {
    Scan s = new Scan();
    s.setRaw(isRaw);;
    s.setMaxVersions();

    CellCount cellCount = new CellCount();
    try (ResultScanner scanner = table.getScanner(s)) {
        Result result = null;
        while ((result = scanner.next()) != null) {
            CellScanner cellScanner = result.cellScanner();
            Cell current = null;
            while (cellScanner.advance()) {
                current = cellScanner.current();
                cellCount.addCell(Bytes.toString(CellUtil.cloneRow(current)));
            }
        }
    }
    return cellCount;
}
 
Example #10
Source File: RSRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void skipCellsForMutation(Action action, CellScanner cellScanner) {
  if (cellScanner == null) {
    return;
  }
  try {
    if (action.hasMutation()) {
      MutationProto m = action.getMutation();
      if (m.hasAssociatedCellCount()) {
        for (int i = 0; i < m.getAssociatedCellCount(); i++) {
          cellScanner.advance();
        }
      }
    }
  } catch (IOException e) {
    // No need to handle these Individual Muatation level issue. Any way this entire RegionAction
    // marked as failed as we could not see the Region here. At client side the top level
    // RegionAction exception will be considered first.
    LOG.error("Error while skipping Cells in CellScanner for invalid Region Mutations", e);
  }
}
 
Example #11
Source File: RSRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Replicate WAL entries on the region server.
 * @param controller the RPC controller
 * @param request the request
 */
@Override
@QosPriority(priority=HConstants.REPLICATION_QOS)
public ReplicateWALEntryResponse replicateWALEntry(final RpcController controller,
    final ReplicateWALEntryRequest request) throws ServiceException {
  try {
    checkOpen();
    if (regionServer.getReplicationSinkService() != null) {
      requestCount.increment();
      List<WALEntry> entries = request.getEntryList();
      checkShouldRejectReplicationRequest(entries);
      CellScanner cellScanner = ((HBaseRpcController) controller).cellScanner();
      regionServer.getRegionServerCoprocessorHost().preReplicateLogEntries();
      regionServer.getReplicationSinkService().replicateLogEntries(entries, cellScanner,
        request.getReplicationClusterId(), request.getSourceBaseNamespaceDirPath(),
        request.getSourceHFileArchiveDirPath());
      regionServer.getRegionServerCoprocessorHost().postReplicateLogEntries();
      return ReplicateWALEntryResponse.newBuilder().build();
    } else {
      throw new ServiceException("Replication services are not initialized yet");
    }
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
Example #12
Source File: BaseIndexIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void assertNoIndexDeletes(Connection conn, long minTimestamp, String fullIndexName) throws IOException, SQLException {
    if (!this.mutable) {
        PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
        PTable index = pconn.getTable(new PTableKey(null, fullIndexName));
        byte[] physicalIndexTable = index.getPhysicalName().getBytes();
        try (Table hIndex = pconn.getQueryServices().getTable(physicalIndexTable)) {
            Scan scan = new Scan();
            scan.setRaw(true);
            if (this.transactional) {
                minTimestamp = TransactionUtil.convertToNanoseconds(minTimestamp);
            }
            scan.setTimeRange(minTimestamp, HConstants.LATEST_TIMESTAMP);
            ResultScanner scanner = hIndex.getScanner(scan);
            Result result;
            while ((result = scanner.next()) != null) {
                CellScanner cellScanner = result.cellScanner();
                while (cellScanner.advance()) {
                    Cell current = cellScanner.current();
                    assertTrue(CellUtil.isPut(current));
                }
            }
        };
    }
}
 
Example #13
Source File: TestUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public static int getRowCount(Table table, boolean isRaw) throws IOException {
    Scan s = new Scan();
    s.setRaw(isRaw);;
    s.setMaxVersions();
    int rows = 0;
    try (ResultScanner scanner = table.getScanner(s)) {
        Result result = null;
        while ((result = scanner.next()) != null) {
            rows++;
            CellScanner cellScanner = result.cellScanner();
            Cell current = null;
            while (cellScanner.advance()) {
                current = cellScanner.current();
            }
        }
    }
    return rows;
}
 
Example #14
Source File: PhoenixTxIndexMutationGenerator.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private TxTableState(Set<ColumnReference> indexedColumns, long currentTimestamp, Mutation mutation) {
    this.currentTimestamp = currentTimestamp;
    this.indexedColumns = indexedColumns;
    this.mutation = mutation;
    int estimatedSize = indexedColumns.size();
    this.valueMap = Maps.newHashMapWithExpectedSize(estimatedSize);
    this.pendingUpdates = Lists.newArrayListWithExpectedSize(estimatedSize);
    try {
        CellScanner scanner = mutation.cellScanner();
        while (scanner.advance()) {
            Cell cell = scanner.current();
            pendingUpdates.add(PhoenixKeyValueUtil.maybeCopyCell(cell));
        }
    } catch (IOException e) {
        throw new RuntimeException(e); // Impossible
    }
}
 
Example #15
Source File: CellBlockBuilder.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void encodeCellsTo(OutputStream os, CellScanner cellScanner, Codec codec,
    CompressionCodec compressor) throws IOException {
  Compressor poolCompressor = null;
  try {
    if (compressor != null) {
      if (compressor instanceof Configurable) {
        ((Configurable) compressor).setConf(this.conf);
      }
      poolCompressor = CodecPool.getCompressor(compressor);
      os = compressor.createOutputStream(os, poolCompressor);
    }
    Codec.Encoder encoder = codec.getEncoder(os);
    while (cellScanner.advance()) {
      encoder.write(cellScanner.current());
    }
    encoder.flush();
  } catch (BufferOverflowException | IndexOutOfBoundsException e) {
    throw new DoNotRetryIOException(e);
  } finally {
    os.close();
    if (poolCompressor != null) {
      CodecPool.returnCompressor(poolCompressor);
    }
  }
}
 
Example #16
Source File: HbaseSessions.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
/**
 * Just for debug
 */
@SuppressWarnings("unused")
private void dump(String table, Scan scan) throws IOException {
    System.out.println(String.format(">>>> scan table %s with %s",
                                     table, scan));
    RowIterator iterator = this.scan(table, scan);
    while (iterator.hasNext()) {
        Result row = iterator.next();
        System.out.println(StringEncoding.format(row.getRow()));
        CellScanner cellScanner = row.cellScanner();
        while (cellScanner.advance()) {
            Cell cell = cellScanner.current();
            byte[] key = CellUtil.cloneQualifier(cell);
            byte[] val = CellUtil.cloneValue(cell);
            System.out.println(String.format("  %s=%s",
                               StringEncoding.format(key),
                               StringEncoding.format(val)));
        }
    }
}
 
Example #17
Source File: SimpleServerRpcConnection.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public SimpleServerCall createCall(int id, BlockingService service, MethodDescriptor md,
    RequestHeader header, Message param, CellScanner cellScanner, long size,
    InetAddress remoteAddress, int timeout, CallCleanup reqCleanup) {
  return new SimpleServerCall(id, service, md, header, param, cellScanner, this, size,
      remoteAddress, System.currentTimeMillis(), timeout, this.rpcServer.bbAllocator,
      this.rpcServer.cellBlockBuilder, reqCleanup, this.responder);
}
 
Example #18
Source File: SimpleRpcServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Pair<Message, CellScanner> call(BlockingService service, MethodDescriptor md,
    Message param, CellScanner cellScanner, long receiveTime, MonitoredRPCHandler status)
    throws IOException {
  return call(service, md, param, cellScanner, receiveTime, status, System.currentTimeMillis(),
    0);
}
 
Example #19
Source File: TestVisibilityLabelsWithDeletes.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void scanAll(Result[] next) throws IOException {
  CellScanner cellScanner = next[0].cellScanner();
  cellScanner.advance();
  Cell current = cellScanner.current();
  assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
    row1, 0, row1.length));
  assertEquals(127L, current.getTimestamp());
  cellScanner.advance();
  current = cellScanner.current();
  assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
    row1, 0, row1.length));
  assertEquals(126L, current.getTimestamp());
  cellScanner.advance();
  current = cellScanner.current();
  assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
    row1, 0, row1.length));
  assertEquals(125L, current.getTimestamp());
  cellScanner.advance();
  current = cellScanner.current();
  assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
    row1, 0, row1.length));
  assertEquals(124L, current.getTimestamp());
  cellScanner.advance();
  current = cellScanner.current();
  assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
    row1, 0, row1.length));
  assertEquals(123L, current.getTimestamp());
  cellScanner = next[1].cellScanner();
  cellScanner.advance();
  current = cellScanner.current();
  assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
    row2, 0, row2.length));
}
 
Example #20
Source File: NettyRpcServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Pair<Message, CellScanner> call(BlockingService service, MethodDescriptor md,
    Message param, CellScanner cellScanner, long receiveTime, MonitoredRPCHandler status,
    long startTime, int timeout) throws IOException {
  NettyServerCall fakeCall = new NettyServerCall(-1, service, md, null, param, cellScanner, null,
      -1, null, receiveTime, timeout, bbAllocator, cellBlockBuilder, null);
  return call(fakeCall, status);
}
 
Example #21
Source File: TestVisibilityLabels.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleVisibilityLabelsWithUniCodeCharacters() throws Exception {
  TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  try (Table table = createTableAndWriteDataWithLabels(tableName,
      SECRET + "|" + CellVisibility.quote(COPYRIGHT), "(" + CellVisibility.quote(COPYRIGHT)
          + "&"  + CellVisibility.quote(ACCENT) + ")|" + CONFIDENTIAL,
      CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET)) {
    Scan s = new Scan();
    s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, COPYRIGHT, ACCENT,
        UNICODE_VIS_TAG));
    ResultScanner scanner = table.getScanner(s);
    Result[] next = scanner.next(3);
    assertTrue(next.length == 3);
    CellScanner cellScanner = next[0].cellScanner();
    cellScanner.advance();
    Cell current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
        current.getRowLength(), row1, 0, row1.length));
    cellScanner = next[1].cellScanner();
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
        current.getRowLength(), row2, 0, row2.length));
    cellScanner = next[2].cellScanner();
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
        current.getRowLength(), row3, 0, row3.length));
  }
}
 
Example #22
Source File: SimpleServerCall.java    From hbase with Apache License 2.0 5 votes vote down vote up
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_ON_SOME_PATH",
    justification = "Can't figure why this complaint is happening... see below")
SimpleServerCall(int id, final BlockingService service, final MethodDescriptor md,
    RequestHeader header, Message param, CellScanner cellScanner,
    SimpleServerRpcConnection connection, long size, final InetAddress remoteAddress,
    long receiveTime, int timeout, ByteBuffAllocator bbAllocator,
    CellBlockBuilder cellBlockBuilder, CallCleanup reqCleanup,
    SimpleRpcServerResponder responder) {
  super(id, service, md, header, param, cellScanner, connection, size, remoteAddress, receiveTime,
      timeout, bbAllocator, cellBlockBuilder, reqCleanup);
  this.responder = responder;
}
 
Example #23
Source File: RSRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void skipCellsForMutations(List<Action> actions, CellScanner cellScanner) {
  if (cellScanner == null) {
    return;
  }
  for (Action action : actions) {
    skipCellsForMutation(action, cellScanner);
  }
}
 
Example #24
Source File: SimpleRpcServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Pair<Message, CellScanner> call(BlockingService service, MethodDescriptor md,
    Message param, CellScanner cellScanner, long receiveTime, MonitoredRPCHandler status,
    long startTime, int timeout) throws IOException {
  SimpleServerCall fakeCall = new SimpleServerCall(-1, service, md, null, param, cellScanner,
      null, -1, null, receiveTime, timeout, bbAllocator, cellBlockBuilder, null, null);
  return call(fakeCall, status);
}
 
Example #25
Source File: Call.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected Call(int id, final Descriptors.MethodDescriptor md, Message param,
    final CellScanner cells, final Message responseDefaultType, int timeout, int priority,
    RpcCallback<Call> callback, MetricsConnection.CallStats callStats) {
  this.param = param;
  this.md = md;
  this.cells = cells;
  this.callStats = callStats;
  this.callStats.setStartTime(EnvironmentEdgeManager.currentTime());
  this.responseDefaultType = responseDefaultType;
  this.id = id;
  this.timeout = timeout;
  this.priority = priority;
  this.callback = callback;
  this.span = Tracer.getCurrentSpan();
}
 
Example #26
Source File: HBaseRpcControllerImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setDone(CellScanner cellScanner) {
  if (done) {
    return;
  }
  done = true;
  this.cellScanner = cellScanner;
}
 
Example #27
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a protocol buffer Result to a client Result
 *
 * @param proto the protocol buffer Result to convert
 * @param scanner Optional cell scanner.
 * @return the converted client Result
 * @throws IOException
 */
public static Result toResult(final ClientProtos.Result proto, final CellScanner scanner)
throws IOException {
  List<CellProtos.Cell> values = proto.getCellList();

  if (proto.hasExists()) {
    if ((values != null && !values.isEmpty()) ||
        (proto.hasAssociatedCellCount() && proto.getAssociatedCellCount() > 0)) {
      throw new IllegalArgumentException("bad proto: exists with cells is no allowed " + proto);
    }
    if (proto.getStale()) {
      return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE_STALE :EMPTY_RESULT_EXISTS_FALSE_STALE;
    }
    return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE : EMPTY_RESULT_EXISTS_FALSE;
  }

  // TODO: Unit test that has some Cells in scanner and some in the proto.
  List<Cell> cells = null;
  if (proto.hasAssociatedCellCount()) {
    int count = proto.getAssociatedCellCount();
    cells = new ArrayList<>(count + values.size());
    for (int i = 0; i < count; i++) {
      if (!scanner.advance()) throw new IOException("Failed get " + i + " of " + count);
      cells.add(scanner.current());
    }
  }

  if (!values.isEmpty()){
    if (cells == null) cells = new ArrayList<>(values.size());
    ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
    for (CellProtos.Cell c: values) {
      cells.add(toCell(builder, c));
    }
  }

  return (cells == null || cells.isEmpty())
      ? (proto.getStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT)
      : Result.create(cells, null, proto.getStale());
}
 
Example #28
Source File: CellBlockBuilder.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @param codec to use for cellblock
 * @param cellBlock ByteBuffer containing the cells written by the Codec. The buffer should be
 *          position()'ed at the start of the cell block and limit()'ed at the end.
 * @return CellScanner to work against the content of <code>cellBlock</code>. All cells created
 *         out of the CellScanner will share the same ByteBuffer being passed.
 * @throws IOException if cell encoding fails
 */
public CellScanner createCellScannerReusingBuffers(final Codec codec,
    final CompressionCodec compressor, ByteBuff cellBlock) throws IOException {
  // Use this method from HRS to create the CellScanner
  // If compressed, decompress it first before passing it on else we will leak compression
  // resources if the stream is not closed properly after we let it out.
  if (compressor != null) {
    cellBlock = decompress(compressor, cellBlock);
  }
  return codec.getDecoder(cellBlock);
}
 
Example #29
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a protocol buffer Mutate to an Increment
 *
 * @param proto the protocol buffer Mutate to convert
 * @return the converted client Increment
 * @throws IOException
 */
public static Increment toIncrement(final MutationProto proto, final CellScanner cellScanner)
        throws IOException {
  MutationType type = proto.getMutateType();
  assert type == MutationType.INCREMENT : type.name();
  Increment increment = toDelta((Bytes row) -> new Increment(row.get(), row.getOffset(), row.getLength()),
          Increment::add, proto, cellScanner);
  if (proto.hasTimeRange()) {
    TimeRange timeRange = toTimeRange(proto.getTimeRange());
    increment.setTimeRange(timeRange.getMin(), timeRange.getMax());
  }
  return increment;
}
 
Example #30
Source File: AbstractTestIPC.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * It is hard to verify the compression is actually happening under the wraps. Hope that if
 * unsupported, we'll get an exception out of some time (meantime, have to trace it manually to
 * confirm that compression is happening down in the client and server).
 */
@Test
public void testCompressCellBlock() throws IOException, ServiceException {
  Configuration conf = new Configuration(HBaseConfiguration.create());
  conf.set("hbase.client.rpc.compressor", GzipCodec.class.getCanonicalName());
  List<Cell> cells = new ArrayList<>();
  int count = 3;
  for (int i = 0; i < count; i++) {
    cells.add(CELL);
  }
  RpcServer rpcServer = createRpcServer(null, "testRpcServer",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(
          SERVICE, null)), new InetSocketAddress("localhost", 0), CONF,
      new FifoRpcScheduler(CONF, 1));

  try (AbstractRpcClient<?> client = createRpcClient(conf)) {
    rpcServer.start();
    BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
    HBaseRpcController pcrc = new HBaseRpcControllerImpl(CellUtil.createCellScanner(cells));
    String message = "hello";
    assertEquals(message,
      stub.echo(pcrc, EchoRequestProto.newBuilder().setMessage(message).build()).getMessage());
    int index = 0;
    CellScanner cellScanner = pcrc.cellScanner();
    assertNotNull(cellScanner);
    while (cellScanner.advance()) {
      assertEquals(CELL, cellScanner.current());
      index++;
    }
    assertEquals(count, index);
  } finally {
    rpcServer.stop();
  }
}