Search in sources :

Example 21 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class ReplicationTableBase method getQueuesBelongingToServer.

/**
   * Get the queue id's and meta data (Owner and History) for the queues belonging to the named
   * server
   *
   * @param server name of the server
   * @return a ResultScanner over the QueueIds belonging to the server
   * @throws IOException
   */
protected ResultScanner getQueuesBelongingToServer(String server) throws IOException {
    Scan scan = new Scan();
    SingleColumnValueFilter filterMyQueues = new SingleColumnValueFilter(CF_QUEUE, COL_QUEUE_OWNER, CompareFilter.CompareOp.EQUAL, Bytes.toBytes(server));
    scan.setFilter(filterMyQueues);
    scan.addColumn(CF_QUEUE, COL_QUEUE_OWNER);
    scan.addColumn(CF_QUEUE, COL_QUEUE_OWNER_HISTORY);
    try (Table replicationTable = getOrBlockOnReplicationTable()) {
        ResultScanner results = replicationTable.getScanner(scan);
        return results;
    }
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan)

Example 22 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class TableBasedReplicationQueuesImpl method getResultIfOwner.

/**
   * Attempts to run a Get on some queue. Will only return a non-null result if we currently own
   * the queue.
   *
   * @param get The Get that we want to query
   * @return The result of the Get if this server is the owner of the queue. Else it returns null.
   * @throws IOException
   */
private Result getResultIfOwner(Get get) throws IOException {
    Scan scan = new Scan(get);
    // Check if the Get currently contains all columns or only specific columns
    if (scan.getFamilyMap().size() > 0) {
        // Add the OWNER column if the scan is already only over specific columns
        scan.addColumn(CF_QUEUE, COL_QUEUE_OWNER);
    }
    scan.setMaxResultSize(1);
    SingleColumnValueFilter checkOwner = new SingleColumnValueFilter(CF_QUEUE, COL_QUEUE_OWNER, CompareFilter.CompareOp.EQUAL, serverNameBytes);
    scan.setFilter(checkOwner);
    ResultScanner scanner = null;
    try (Table replicationTable = getOrBlockOnReplicationTable()) {
        scanner = replicationTable.getScanner(scan);
        Result result = scanner.next();
        return (result == null || result.isEmpty()) ? null : result;
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Table(org.apache.hadoop.hbase.client.Table) Scan(org.apache.hadoop.hbase.client.Scan) Result(org.apache.hadoop.hbase.client.Result)

Example 23 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class BackupSystemTable method hasBackupSessions.

/**
   * Checks if we have at least one backup session in backup system table This API is used by
   * BackupLogCleaner
   * @return true, if - at least one session exists in backup system table table
   * @throws IOException exception
   */
public boolean hasBackupSessions() throws IOException {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Has backup sessions from backup system table");
    }
    boolean result = false;
    Scan scan = createScanForBackupHistory();
    scan.setCaching(1);
    try (Table table = connection.getTable(tableName);
        ResultScanner scanner = table.getScanner(scan)) {
        if (scanner.next() != null) {
            result = true;
        }
        return result;
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan)

Example 24 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class BackupSystemTable method readRegionServerLastLogRollResult.

/**
   * 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 {
    if (LOG.isTraceEnabled()) {
        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 = null;
        HashMap<String, Long> rsTimestampMap = new HashMap<String, Long>();
        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;
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HashMap(java.util.HashMap) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Example 25 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class BackupSystemTable method listBackupSets.

/**
   * BACKUP SETS
   */
/**
   * Get backup set list
   * @return backup set list
   * @throws IOException
   */
public List<String> listBackupSets() throws IOException {
    if (LOG.isTraceEnabled()) {
        LOG.trace(" Backup set list");
    }
    List<String> list = new ArrayList<String>();
    Table table = null;
    ResultScanner scanner = null;
    try {
        table = connection.getTable(tableName);
        Scan scan = createScanForBackupSetList();
        scan.setMaxVersions(1);
        scanner = table.getScanner(scan);
        Result res = null;
        while ((res = scanner.next()) != null) {
            res.advance();
            list.add(cellKeyToBackupSetName(res.current()));
        }
        return list;
    } finally {
        if (scanner != null) {
            scanner.close();
        }
        if (table != null) {
            table.close();
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)326 Scan (org.apache.hadoop.hbase.client.Scan)295 Result (org.apache.hadoop.hbase.client.Result)286 Table (org.apache.hadoop.hbase.client.Table)160 Test (org.junit.Test)143 Cell (org.apache.hadoop.hbase.Cell)104 IOException (java.io.IOException)102 TableName (org.apache.hadoop.hbase.TableName)88 Connection (org.apache.hadoop.hbase.client.Connection)75 Put (org.apache.hadoop.hbase.client.Put)75 Delete (org.apache.hadoop.hbase.client.Delete)70 ArrayList (java.util.ArrayList)61 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)47 InterruptedIOException (java.io.InterruptedIOException)46 CellScanner (org.apache.hadoop.hbase.CellScanner)42 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 HTable (org.apache.hadoop.hbase.client.HTable)29 Get (org.apache.hadoop.hbase.client.Get)23 Admin (org.apache.hadoop.hbase.client.Admin)22