Java Code Examples for org.apache.hadoop.hbase.CellScanner#advance()
The following examples show how to use
org.apache.hadoop.hbase.CellScanner#advance() .
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: TestProtobufRpcServiceImpl.java From hbase with Apache License 2.0 | 6 votes |
@Override public EchoResponseProto echo(RpcController controller, EchoRequestProto request) throws ServiceException { if (controller instanceof HBaseRpcController) { HBaseRpcController pcrc = (HBaseRpcController) controller; // If cells, scan them to check we are able to iterate what we were given and since this is an // echo, just put them back on the controller creating a new block. Tests our block building. CellScanner cellScanner = pcrc.cellScanner(); List<Cell> list = null; if (cellScanner != null) { list = new ArrayList<>(); try { while (cellScanner.advance()) { list.add(cellScanner.current()); } } catch (IOException e) { throw new ServiceException(e); } } cellScanner = CellUtil.createCellScanner(list); pcrc.setCellScanner(cellScanner); } return EchoResponseProto.newBuilder().setMessage(request.getMessage()).build(); }
Example 2
Source File: TestUtil.java From phoenix with Apache License 2.0 | 6 votes |
public static void dumpTable(Table table) throws IOException { System.out.println("************ dumping " + table + " **************"); Scan s = new Scan(); s.setRaw(true);; s.setMaxVersions(); 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(); System.out.println(current); } } } System.out.println("-----------------------------------------------"); }
Example 3
Source File: TestUtil.java From phoenix with Apache License 2.0 | 6 votes |
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 4
Source File: TestHBaseRpcControllerImpl.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testListOfCellScannerables() throws IOException { final int count = 10; List<CellScannable> cells = new ArrayList<>(count); for (int i = 0; i < count; i++) { cells.add(createCell(i)); } HBaseRpcController controller = new HBaseRpcControllerImpl(cells); CellScanner cellScanner = controller.cellScanner(); int index = 0; for (; cellScanner.advance(); index++) { Cell cell = cellScanner.current(); byte[] indexBytes = Bytes.toBytes(index); assertTrue("" + index, Bytes.equals(indexBytes, 0, indexBytes.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } assertEquals(count, index); }
Example 5
Source File: RSRpcServices.java From hbase with Apache License 2.0 | 6 votes |
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 6
Source File: TableSnapshotInputFormatTestBase.java From hbase with Apache License 2.0 | 6 votes |
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 7
Source File: CellBlockBuilder.java From hbase with Apache License 2.0 | 6 votes |
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 8
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 6 votes |
/** * 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 9
Source File: TestVisibilityLabelsWithDeletes.java From hbase with Apache License 2.0 | 5 votes |
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 10
Source File: TestVisibilityLabelReplicationWithExpAsString.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void verifyGet(final byte[] row, final String visString, final int expected, final boolean nullExpected, final String... auths) throws IOException, InterruptedException { PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf1); Table table2 = connection.getTable(TABLE_NAME)) { CellScanner cellScanner; Cell current; Get get = new Get(row); get.setAuthorizations(new Authorizations(auths)); Result result = table2.get(get); cellScanner = result.cellScanner(); boolean advance = cellScanner.advance(); if (nullExpected) { assertTrue(!advance); return null; } current = cellScanner.current(); assertArrayEquals(CellUtil.cloneRow(current), row); assertEquals(expected, TestCoprocessorForTagsAtSink.tags.size()); boolean foundNonVisTag = false; for(Tag t : TestCoprocessorForTagsAtSink.tags) { if(t.getType() == NON_VIS_TAG_TYPE) { assertEquals(TEMP, Bytes.toString(Tag.cloneValue(t))); foundNonVisTag = true; break; } } doAssert(row, visString); assertTrue(foundNonVisTag); return null; } } }; USER1.runAs(scanAction); }
Example 11
Source File: CodecPerformance.java From hbase with Apache License 2.0 | 5 votes |
static Cell [] runDecoderTest(final int index, final int count, final CellScanner decoder) throws IOException { Cell [] cells = new Cell[count]; long startTime = System.currentTimeMillis(); for (int i = 0; decoder.advance(); i++) { cells[i] = decoder.current(); } LOG.info("" + index + " decoded count=" + cells.length + " in " + (System.currentTimeMillis() - startTime) + "ms for decoder " + decoder); // Ensure we did not have to grow the backing buffer. assertTrue(cells.length == count); return cells; }
Example 12
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 5 votes |
/** * Returns a set of the names of all namespaces containing snapshot entries. * @param conn connection to re-use */ public static Set<String> getNamespaceSnapshots(Connection conn) throws IOException { try (Table quotaTable = conn.getTable(QUOTA_TABLE_NAME); ResultScanner rs = quotaTable.getScanner(createScanForNamespaceSnapshotSizes())) { Set<String> snapshots = new HashSet<>(); for (Result r : rs) { CellScanner cs = r.cellScanner(); while (cs.advance()) { cs.current(); snapshots.add(getNamespaceFromRowKey(r.getRow())); } } return snapshots; } }
Example 13
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 5 votes |
/** * 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 14
Source File: TestVisibilityLabelsWithDeletes.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testVisibilityLabelsWithDeleteFamilyNoMatchingVisExpWithMultipleVersionsNoTimestamp() throws Exception { setAuths(); final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { Delete d1 = new Delete(row1); d1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d1.addFamily(fam); Delete d2 = new Delete(row1); d2.setCellVisibility(new CellVisibility(SECRET)); d2.addFamily(fam); Delete d3 = new Delete(row1); d3.setCellVisibility(new CellVisibility( "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d3.addFamily(fam); try (Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(tableName)) { table.delete(createList(d1, d2, d3)); } catch (Throwable t) { throw new IOException(t); } return null; } }; SUPERUSER.runAs(actiona); Scan s = new Scan(); s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); 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)); scanner.close(); } }
Example 15
Source File: StatisticsUtil.java From phoenix with Apache License 2.0 | 4 votes |
public static GuidePostsInfo readStatistics(Table statsHTable, GuidePostsKey key, long clientTimeStamp) throws IOException { ImmutableBytesWritable ptr = new ImmutableBytesWritable(); ptr.set(key.getColumnFamily()); byte[] tableNameBytes = key.getPhysicalName(); byte[] startKey = getStartKey(tableNameBytes, ptr); byte[] endKey = getEndKey(tableNameBytes, ptr); Scan s = MetaDataUtil.newTableRowsScan(startKey, endKey, MetaDataProtocol.MIN_TABLE_TIMESTAMP, clientTimeStamp); s.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES); s.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES); s.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES); GuidePostsInfoBuilder guidePostsInfoBuilder = new GuidePostsInfoBuilder(); Cell current = null; GuidePostsInfo emptyGuidePost = null; try (ResultScanner scanner = statsHTable.getScanner(s)) { Result result = null; while ((result = scanner.next()) != null) { CellScanner cellScanner = result.cellScanner(); long rowCount = 0; long byteCount = 0; while (cellScanner.advance()) { current = cellScanner.current(); if (Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), current.getQualifierLength(), PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES, 0, PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES.length)) { rowCount = PLong.INSTANCE.getCodec().decodeLong(current.getValueArray(), current.getValueOffset(), SortOrder.getDefault()); } else if (Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), current.getQualifierLength(), PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES, 0, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES.length)) { byteCount = PLong.INSTANCE.getCodec().decodeLong(current.getValueArray(), current.getValueOffset(), SortOrder.getDefault()); } } if (current != null) { int tableNameLength = tableNameBytes.length + 1; int cfOffset = current.getRowOffset() + tableNameLength; int cfLength = getVarCharLength(current.getRowArray(), cfOffset, current.getRowLength() - tableNameLength); ptr.set(current.getRowArray(), cfOffset, cfLength); byte[] cfName = ByteUtil.copyKeyBytesIfNecessary(ptr); byte[] newGPStartKey = getGuidePostsInfoFromRowKey(tableNameBytes, cfName, result.getRow()); boolean isEmptyGuidePost = GuidePostsInfo.isEmptyGpsKey(newGPStartKey); // Use the timestamp of the cell as the time at which guidepost was // created/updated long guidePostUpdateTime = current.getTimestamp(); if (isEmptyGuidePost) { emptyGuidePost = GuidePostsInfo.createEmptyGuidePost(byteCount, guidePostUpdateTime); } else { guidePostsInfoBuilder.trackGuidePost( new ImmutableBytesWritable(newGPStartKey), byteCount, rowCount, guidePostUpdateTime); } } } } // We write a row with an empty KeyValue in the case that stats were generated but without enough data // for any guideposts. If we have no rows, it means stats were never generated. return current == null ? GuidePostsInfo.NO_GUIDEPOST : guidePostsInfoBuilder.isEmpty() ? emptyGuidePost : guidePostsInfoBuilder.build(); }
Example 16
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 4 votes |
private static <T extends Mutation> T toDelta(Function<Bytes, T> supplier, ConsumerWithException<T, Cell> consumer, final MutationProto proto, final CellScanner cellScanner) throws IOException { byte[] row = proto.hasRow() ? proto.getRow().toByteArray() : null; T mutation = row == null ? null : supplier.apply(new Bytes(row)); int cellCount = proto.hasAssociatedCellCount() ? proto.getAssociatedCellCount() : 0; if (cellCount > 0) { // The proto has metadata only and the data is separate to be found in the cellScanner. if (cellScanner == null) { throw new DoNotRetryIOException("Cell count of " + cellCount + " but no cellScanner: " + toShortString(proto)); } for (int i = 0; i < cellCount; i++) { if (!cellScanner.advance()) { throw new DoNotRetryIOException("Cell count of " + cellCount + " but at index " + i + " no cell returned: " + toShortString(proto)); } Cell cell = cellScanner.current(); if (mutation == null) { mutation = supplier.apply(new Bytes(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())); } consumer.accept(mutation, cell); } } else { if (mutation == null) { throw new IllegalArgumentException("row cannot be null"); } for (ColumnValue column : proto.getColumnValueList()) { byte[] family = column.getFamily().toByteArray(); for (QualifierValue qv : column.getQualifierValueList()) { byte[] qualifier = qv.getQualifier().toByteArray(); if (!qv.hasValue()) { throw new DoNotRetryIOException( "Missing required field: qualifier value"); } byte[] value = qv.getValue().toByteArray(); byte[] tags = null; if (qv.hasTags()) { tags = qv.getTags().toByteArray(); } consumer.accept(mutation, ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(mutation.getRow()) .setFamily(family) .setQualifier(qualifier) .setTimestamp(qv.getTimestamp()) .setType(KeyValue.Type.Put.getCode()) .setValue(value) .setTags(tags) .build()); } } } mutation.setDurability(toDurability(proto.getDurability())); for (NameBytesPair attribute : proto.getAttributeList()) { mutation.setAttribute(attribute.getName(), attribute.getValue().toByteArray()); } return mutation; }
Example 17
Source File: TestVisibilityLabelsWithDeletes.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDeleteColumnWithLatestTimeStampUsingMultipleVersions() throws Exception { setAuths(); final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumn(fam, qual); table.delete(d); } catch (Throwable t) { throw new IOException(t); } return null; } }; SUPERUSER.runAs(actiona); TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); 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)); 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(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 18
Source File: ResponseConverter.java From hbase with Apache License 2.0 | 4 votes |
/** * Create Results from the cells using the cells meta data. * @param cellScanner * @param response * @return results */ public static Result[] getResults(CellScanner cellScanner, ScanResponse response) throws IOException { if (response == null) return null; // If cellscanner, then the number of Results to return is the count of elements in the // cellsPerResult list. Otherwise, it is how many results are embedded inside the response. int noOfResults = cellScanner != null? response.getCellsPerResultCount(): response.getResultsCount(); Result[] results = new Result[noOfResults]; for (int i = 0; i < noOfResults; i++) { if (cellScanner != null) { // Cells are out in cellblocks. Group them up again as Results. How many to read at a // time will be found in getCellsLength -- length here is how many Cells in the i'th Result int noOfCells = response.getCellsPerResult(i); boolean isPartial = response.getPartialFlagPerResultCount() > i ? response.getPartialFlagPerResult(i) : false; List<Cell> cells = new ArrayList<>(noOfCells); for (int j = 0; j < noOfCells; j++) { try { if (cellScanner.advance() == false) { // We are not able to retrieve the exact number of cells which ResultCellMeta says us. // We have to scan for the same results again. Throwing DNRIOE as a client retry on the // same scanner will result in OutOfOrderScannerNextException String msg = "Results sent from server=" + noOfResults + ". But only got " + i + " results completely at client. Resetting the scanner to scan again."; LOG.error(msg); throw new DoNotRetryIOException(msg); } } catch (IOException ioe) { // We are getting IOE while retrieving the cells for Results. // We have to scan for the same results again. Throwing DNRIOE as a client retry on the // same scanner will result in OutOfOrderScannerNextException LOG.error("Exception while reading cells from result." + "Resetting the scanner to scan again.", ioe); throw new DoNotRetryIOException("Resetting the scanner.", ioe); } cells.add(cellScanner.current()); } results[i] = Result.create(cells, null, response.getStale(), isPartial); } else { // Result is pure pb. results[i] = ProtobufUtil.toResult(response.getResults(i)); } } return results; }
Example 19
Source File: TestVisibilityLabelsWithDeletes.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDeleteFamilyLatestTimeStampWithMulipleVersions() throws Exception { setAuths(); final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addFamily(fam); table.delete(d); } catch (Throwable t) { throw new IOException(t); } return null; } }; SUPERUSER.runAs(actiona); TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); 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)); 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 = 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: TestVisibilityLabelsWithDeletes.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testDeleteColumnswithMultipleColumnsWithMultipleVersions() throws Exception { setAuths(); final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPutsWithDiffCols(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumns(fam, qual, 125L); try (Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(tableName)) { table.delete(d); } catch (Throwable t) { throw new IOException(t); } return null; } }; SUPERUSER.runAs(actiona); TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 1); 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(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.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length)); assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), current.getQualifierLength(), qual1, 0, qual1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), current.getQualifierLength(), qual2, 0, qual2.length)); } }