/** * Converts Result to BackupInfo * @param res HBase result * @return backup info instance * @throws IOException exception */ private BackupInfo resultToBackupInfo(Result res) throws IOException { res.advance(); Cell cell = res.current(); return cellToBackupInfo(cell); }
/** * Get backup set description (list of tables) * @param name set's name * @return list of tables in a backup set * @throws IOException if a table operation fails */ public List<TableName> describeBackupSet(String name) throws IOException { if (LOG.isTraceEnabled()) { LOG.trace(" Backup set describe: " + name); } try (Table table = connection.getTable(tableName)) { Get get = createGetForBackupSet(name); Result res = table.get(get); if (res.isEmpty()) { return null; } res.advance(); String[] tables = cellValueToBackupSet(res.current()); return Arrays.asList(tables).stream().map(item -> TableName.valueOf(item)) .collect(Collectors.toList()); } }
private long count(Table t) throws IOException { try (ResultScanner rs = t.getScanner(new Scan())) { long sum = 0; for (Result r : rs) { while (r.advance()) { sum++; } } return sum; } }
/** * Extracts the size component from a serialized {@link SpaceQuotaSnapshot} protobuf. * * @param r A Result containing one cell with a SpaceQuotaSnapshot protobuf * @return The size in bytes of the snapshot. */ long getSnapshotSizeFromResult(Result r) throws InvalidProtocolBufferException { // Per javadoc, Result should only be null if an exception was thrown. So, if we're here, // we should be non-null. If we can't advance to the first cell, same as "no cell". if (!r.isEmpty() && r.advance()) { return QuotaTableUtil.parseSnapshotSize(r.current()); } return 0L; }
/** * Count the number of rows and the number of entries from a scanner * * @param scanner * The Scanner * @return An entry where the first item is rows observed and the second is entries observed. */ private Entry<Long,Long> sumTable(ResultScanner scanner) { long rowsObserved = 0L; long entriesObserved = 0L; // Read all the records in the table for (Result result : scanner) { rowsObserved++; while (result.advance()) { entriesObserved++; } } return Maps.immutableEntry(rowsObserved,entriesObserved); } }
/** * Get backup set list * @return backup set list * @throws IOException if a table or scanner operation fails */ public List<String> listBackupSets() throws IOException { LOG.trace("Backup set list"); List<String> list = new ArrayList<>(); try (Table table = connection.getTable(tableName)) { Scan scan = createScanForBackupSetList(); scan.setMaxVersions(1); try (ResultScanner scanner = table.getScanner(scan)) { Result res; while ((res = scanner.next()) != null) { res.advance(); list.add(cellKeyToBackupSetName(res.current())); } return list; } } }
Result res = null; while ((res = scanner.next()) != null) { res.advance(); String fam = null; String path = null;
Result res = null; while ((res = scanner.next()) != null) { res.advance(); TableName tbl = null; byte[] fam = null;
Map<byte[], String> readBulkLoadedFiles(String backupId) throws IOException { Scan scan = BackupSystemTable.createScanForBulkLoadedFiles(backupId); try (Table table = connection.getTable(bulkLoadTableName); ResultScanner scanner = table.getScanner(scan)) { Result res = null; Map<byte[], String> map = new TreeMap<>(Bytes.BYTES_COMPARATOR); while ((res = scanner.next()) != null) { res.advance(); byte[] row = CellUtil.cloneRow(res.listCells().get(0)); for (Cell cell : res.listCells()) { if (CellUtil.compareQualifiers(cell, BackupSystemTable.PATH_COL, 0, BackupSystemTable.PATH_COL.length) == 0) { map.put(row, Bytes.toString(CellUtil.cloneValue(cell))); } } } return map; } }
/** * Get all backup sessions with a given state (in descending order by time) * @param state backup session state * @return history info of backup info objects * @throws IOException exception */ public ArrayList<BackupInfo> getBackupInfos(BackupState state) throws IOException { LOG.trace("get backup infos from backup system table"); Scan scan = createScanForBackupHistory(); ArrayList<BackupInfo> list = new ArrayList<>(); try (Table table = connection.getTable(tableName); ResultScanner scanner = table.getScanner(scan)) { Result res; while ((res = scanner.next()) != null) { res.advance(); BackupInfo context = cellToBackupInfo(res.current()); if (state != BackupState.ANY && context.getState() != state) { continue; } list.add(context); } return list; } }
return; } else { res.advance(); tables = cellValueToBackupSet(res.current()); disjoint = disjoin(tables, toRemove);
while (r.advance()) { final Cell c = r.current(); result.put(Bytes.toString(CellUtil.cloneQualifier(c)),
/** * Fetches the computed size of all snapshots against tables in a namespace for space quotas. */ static long getNamespaceSnapshotSize( Connection conn, String namespace) throws IOException { try (Table quotaTable = conn.getTable(QuotaTableUtil.QUOTA_TABLE_NAME)) { Result r = quotaTable.get(createGetNamespaceSnapshotSize(namespace)); if (r.isEmpty()) { return 0L; } r.advance(); return parseSnapshotSize(r.current()); } catch (InvalidProtocolBufferException e) { throw new IOException("Could not parse snapshot size value for namespace " + namespace, e); } }
Result res; while ((res = scanner.next()) != null) { res.advance(); Cell cell = res.current(); byte[] row = CellUtil.cloneRow(cell);
/** * Get the Region Servers log information after the last log roll from backup system table. * @param backupRoot root directory path to backup * @return RS log info * @throws IOException exception */ public HashMap<String, Long> readRegionServerLastLogRollResult(String backupRoot) throws IOException { LOG.trace("read region server last roll log result to backup system table"); Scan scan = createScanForReadRegionServerLastLogRollResult(backupRoot); try (Table table = connection.getTable(tableName); ResultScanner scanner = table.getScanner(scan)) { Result res; HashMap<String, Long> rsTimestampMap = new HashMap<>(); while ((res = scanner.next()) != null) { res.advance(); Cell cell = res.current(); byte[] row = CellUtil.cloneRow(cell); String server = getServerNameForReadRegionServerLastLogRollResult(row); byte[] data = CellUtil.cloneValue(cell); rsTimestampMap.put(server, Bytes.toLong(data)); } return rsTimestampMap; } }
/** * Add backup set (list of tables) * @param name set name * @param newTables list of tables, comma-separated * @throws IOException if a table operation fails */ public void addToBackupSet(String name, String[] newTables) throws IOException { if (LOG.isTraceEnabled()) { LOG.trace("Backup set add: " + name + " tables [" + StringUtils.join(newTables, " ") + "]"); } String[] union = null; try (Table table = connection.getTable(tableName)) { Get get = createGetForBackupSet(name); Result res = table.get(get); if (res.isEmpty()) { union = newTables; } else { res.advance(); String[] tables = cellValueToBackupSet(res.current()); union = merge(tables, newTables); } Put put = createPutForBackupSet(name, union); table.put(put); } }
public void testCurrentOnEmptyCell() throws IOException { Result r = Result.create(new Cell[0]); assertFalse(r.advance()); assertNull(r.current()); }
result.advance();
Result r = quotaTable.get(QuotaTableUtil.makeGetForSnapshotSize(tn, snapshot1)); assertTrue("Expected a non-null, non-empty Result", r != null && !r.isEmpty()); assertTrue(r.advance()); assertEquals("The snapshot's size should be the same as the origin store file", storeFileSize, QuotaTableUtil.parseSnapshotSize(r.current())); assertTrue(r.advance()); assertEquals("The snapshot's size should be the same as the origin store file", storeFileSize, QuotaTableUtil.parseSnapshotSize(r.current()));