private int getNumberOfReplicasFromMeta(Connection connection, int regionReplicaCount, List<RegionInfo> regionsOfTable) throws IOException { Result r = getRegionFromMeta(connection, regionsOfTable); int replicasFound = 0; for (int i = 1; i < regionReplicaCount; i++) { // Since we have already added the entries to the META we will be getting only that here List<Cell> columnCells = r.getColumnCells(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(i)); if (!columnCells.isEmpty()) { replicasFound++; } } return replicasFound; }
public static long[] getReplicationBarriers(Result result) { return result.getColumnCells(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER) .stream().mapToLong(MetaTableAccessor::getReplicationBarrier).sorted().distinct().toArray(); }
@Override protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { long longRk = Bytes.toLong(value.getRow()); for (Map.Entry<byte[], byte[]> entry : value.getFamilyMap(CHAIN_FAM).entrySet()) { long chainId = Bytes.toLong(entry.getKey()); long next = Bytes.toLong(entry.getValue()); Cell c = value.getColumnCells(SORT_FAM, entry.getKey()).get(0); long order = Bytes.toLong(CellUtil.cloneValue(c)); context.write(new LinkKey(chainId, order), new LinkChain(longRk, next)); } } }
private void checkResult(Result r, byte[] col, byte[] ... vals) { assertEquals(r.size(), vals.length); List<Cell> kvs = r.getColumnCells(col, col); assertEquals(kvs.size(), vals.length); for (int i=0;i<vals.length;i++) { assertTrue(CellUtil.matchingValue(kvs.get(i), vals[i])); } }
private void checkResult(Result r, byte[] fam, byte[] col, byte[] ... vals) { assertEquals(r.size(), vals.length); List<Cell> kvs = r.getColumnCells(fam, col); assertEquals(kvs.size(), vals.length); for (int i=0;i<vals.length;i++) { assertArrayEquals(CellUtil.cloneValue(kvs.get(i)), vals[i]); } }
public void testBasicGetColumn() throws Exception { KeyValue [] kvs = genKVs(row, family, value, 1, 100); Arrays.sort(kvs, CellComparator.getInstance()); Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); List<Cell> ks = r.getColumnCells(family, qf); assertEquals(1, ks.size()); assertTrue(CellUtil.matchingQualifier(ks.get(0), qf)); assertEquals(ks.get(0), r.getColumnLatestCell(family, qf)); } }
private Table init(Admin admin, long l, Scan scan, TableName tableName) throws Exception { Table table = TEST_UTIL.getConnection().getTable(tableName); Put put0 = new Put(Bytes.toBytes("row1")); put0.add(new KeyValue(Bytes.toBytes("row1"), Bytes.toBytes("col"), Bytes.toBytes("q"), l, Bytes.toBytes("version0"))); table.put(put0); admin.flush(tableName); Put put1 = new Put(Bytes.toBytes("row2")); put1.add(new KeyValue(Bytes.toBytes("row2"), Bytes.toBytes("col"), Bytes.toBytes("q"), l, Bytes .toBytes("version0"))); table.put(put1); admin.flush(tableName); put0 = new Put(Bytes.toBytes("row1")); put0.add(new KeyValue(Bytes.toBytes("row1"), Bytes.toBytes("col"), Bytes.toBytes("q"), l, Bytes .toBytes("version1"))); table.put(put0); admin.flush(tableName); admin.compact(tableName); ResultScanner scanner = table.getScanner(scan); Result result = scanner.next(); List<Cell> cells = result.getColumnCells(Bytes.toBytes("col"), Bytes.toBytes("q")); Assert.assertEquals(1, cells.size()); Cell _c = cells.get(0); Assert.assertEquals("version1", Bytes.toString(_c.getValueArray(), _c.getValueOffset(), _c.getValueLength())); scanner.close(); return table; }
public void testMultiVersionGetColumn() throws Exception { KeyValue [] kvs1 = genKVs(row, family, value, 1, 100); KeyValue [] kvs2 = genKVs(row, family, value, 200, 100); KeyValue [] kvs = new KeyValue[kvs1.length+kvs2.length]; System.arraycopy(kvs1, 0, kvs, 0, kvs1.length); System.arraycopy(kvs2, 0, kvs, kvs1.length, kvs2.length); Arrays.sort(kvs, CellComparator.getInstance()); Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); List<Cell> ks = r.getColumnCells(family, qf); assertEquals(2, ks.size()); assertTrue(CellUtil.matchingQualifier(ks.get(0), qf)); assertEquals(200, ks.get(0).getTimestamp()); assertEquals(ks.get(0), r.getColumnLatestCell(family, qf)); } }
private void migrateNamespaceTable() throws IOException { try (Table nsTable = masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME); ResultScanner scanner = nsTable.getScanner( new Scan().addFamily(TableDescriptorBuilder.NAMESPACE_FAMILY_INFO_BYTES).readAllVersions()); BufferedMutator mutator = masterServices.getConnection().getBufferedMutator(TableName.META_TABLE_NAME)) { for (Result result;;) { result = scanner.next(); if (result == null) { break; } Put put = new Put(result.getRow()); result .getColumnCells(TableDescriptorBuilder.NAMESPACE_FAMILY_INFO_BYTES, TableDescriptorBuilder.NAMESPACE_COL_DESC_BYTES) .forEach(c -> put.addColumn(HConstants.NAMESPACE_FAMILY, HConstants.NAMESPACE_COL_DESC_QUALIFIER, c.getTimestamp(), CellUtil.cloneValue(c))); mutator.mutate(put); } } // schedule a disable procedure instead of block waiting here, as when disabling a table we will // wait until master is initialized, but we are part of the initialization... masterServices.getMasterProcedureExecutor().submitProcedure( new DisableTableProcedure(masterServices.getMasterProcedureExecutor().getEnvironment(), TableName.NAMESPACE_TABLE_NAME, false)); }
private Result scanAfterBulkLoad(ResultScanner scanner, Result result, String expctedVal) throws IOException { while (result != null) { List<Cell> cells = result.getColumnCells(Bytes.toBytes("col"), Bytes.toBytes("q")); for (Cell _c : cells) { if (Bytes.toString(_c.getRowArray(), _c.getRowOffset(), _c.getRowLength()) .equals("row1")) { System.out .println(Bytes.toString(_c.getRowArray(), _c.getRowOffset(), _c.getRowLength())); System.out.println(Bytes.toString(_c.getQualifierArray(), _c.getQualifierOffset(), _c.getQualifierLength())); System.out.println( Bytes.toString(_c.getValueArray(), _c.getValueOffset(), _c.getValueLength())); Assert.assertEquals(expctedVal, Bytes.toString(_c.getValueArray(), _c.getValueOffset(), _c.getValueLength())); } } result = scanner.next(); } return result; }
get.setMaxVersions(1); Result res = this.region.get(get); List<Cell> kvs = res.getColumnCells(Appender.family, Appender.qualifier);
get.setMaxVersions(1); Result res = this.region.get(get); List<Cell> kvs = res.getColumnCells(Incrementer.family, Incrementer.qualifier);
get.setMaxVersions(); res = this.region.get(get); kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertArrayEquals(Bytes.toBytes("value0"), CellUtil.cloneValue(kvs.get(0))); get.setMaxVersions(); res = this.region.get(get); kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertArrayEquals(Bytes.toBytes("value0"), CellUtil.cloneValue(kvs.get(0))); get.setMaxVersions(); res = this.region.get(get); kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertArrayEquals(Bytes.toBytes("value1"), CellUtil.cloneValue(kvs.get(0))); get.setMaxVersions(); res = this.region.get(get); kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertArrayEquals(Bytes.toBytes("value1"), CellUtil.cloneValue(kvs.get(0)));
public void verifyNumericRows(Table table, final byte[] f, int startRow, int endRow, int replicaId) throws IOException { for (int i = startRow; i < endRow; i++) { String failMsg = "Failed verification of row :" + i; byte[] data = Bytes.toBytes(String.valueOf(i)); Get get = new Get(data); get.setReplicaId(replicaId); get.setConsistency(Consistency.TIMELINE); Result result = table.get(get); assertTrue(failMsg, result.containsColumn(f, null)); assertEquals(failMsg, 1, result.getColumnCells(f, null).size()); Cell cell = result.getColumnLatestCell(f, null); assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } }
public void verifyNumericRows(HRegion region, final byte[] f, int startRow, int endRow, final boolean present) throws IOException { for (int i = startRow; i < endRow; i++) { String failMsg = "Failed verification of row :" + i; byte[] data = Bytes.toBytes(String.valueOf(i)); Result result = region.get(new Get(data)); boolean hasResult = result != null && !result.isEmpty(); assertEquals(failMsg + result, present, hasResult); if (!present) continue; assertTrue(failMsg, result.containsColumn(f, null)); assertEquals(failMsg, 1, result.getColumnCells(f, null).size()); Cell cell = result.getColumnLatestCell(f, null); assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } }
assertEquals(3, res1[0].getColumnCells(famName, qualifierName).size()); Thread.sleep(SLEEP_TIME); } else { int cellNumber = res1[0].getColumnCells(famName, Bytes.toBytes("f1")).size(); if (cellNumber != 3) { LOG.info("Only got " + cellNumber + " cells"); assertEquals(5, res1[0].getColumnCells(famName, qualifierName).size());
result = scanner.next(); while (result != null) { List<Cell> cells = result.getColumnCells(Bytes.toBytes("col"), Bytes.toBytes("q")); for (Cell _c : cells) { if (Bytes.toString(_c.getRowArray(), _c.getRowOffset(), _c.getRowLength())
result = scanner.next(); while (result != null) { List<Cell> cells = result.getColumnCells(Bytes.toBytes("col"), Bytes.toBytes("q")); for (Cell _c : cells) { if (Bytes.toString(_c.getRowArray(), _c.getRowOffset(), _c.getRowLength())
Result result = region.get(get); for (long i = minSeqId; i <= maxSeqId; i += 10) { List<Cell> kvs = result.getColumnCells(family, Bytes.toBytes(i)); assertEquals(1, kvs.size()); assertArrayEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0)));
for (Result result: scanner) { size++; List<Cell> cells = result.getColumnCells(family, qf1);