Search in sources :

Example 71 with ResultScanner

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

the class TestVisibilityLabels method testVisibilityLabelsOnKillingOfRSContainingLabelsTable.

@Test
public void testVisibilityLabelsOnKillingOfRSContainingLabelsTable() throws Exception {
    List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
    int liveRS = 0;
    for (RegionServerThread rsThreads : regionServerThreads) {
        if (!rsThreads.getRegionServer().isAborted()) {
            liveRS++;
        }
    }
    if (liveRS == 1) {
        TEST_UTIL.getHBaseCluster().startRegionServer();
    }
    Thread t1 = new Thread() {

        public void run() {
            List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
            for (RegionServerThread rsThread : regionServerThreads) {
                List<Region> onlineRegions = rsThread.getRegionServer().getOnlineRegions(LABELS_TABLE_NAME);
                if (onlineRegions.size() > 0) {
                    rsThread.getRegionServer().abort("Aborting ");
                    killedRS = true;
                    break;
                }
            }
        }
    };
    t1.start();
    final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
    Thread t = new Thread() {

        public void run() {
            try {
                while (!killedRS) {
                    Thread.sleep(1);
                }
                createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE);
            } catch (Exception e) {
            }
        }
    };
    t.start();
    regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
    while (!killedRS) {
        Thread.sleep(10);
    }
    regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
    for (RegionServerThread rsThread : regionServerThreads) {
        while (true) {
            if (!rsThread.getRegionServer().isAborted()) {
                List<Region> onlineRegions = rsThread.getRegionServer().getOnlineRegions(LABELS_TABLE_NAME);
                if (onlineRegions.size() > 0) {
                    break;
                } else {
                    Thread.sleep(10);
                }
            } else {
                break;
            }
        }
    }
    TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
    t.join();
    try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
        Scan s = new Scan();
        s.setAuthorizations(new Authorizations(SECRET));
        ResultScanner scanner = table.getScanner(s);
        Result[] next = scanner.next(3);
        assertTrue(next.length == 1);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) IOException(java.io.IOException) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) RegionActionResult(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionActionResult) Result(org.apache.hadoop.hbase.client.Result) TableName(org.apache.hadoop.hbase.TableName) Region(org.apache.hadoop.hbase.regionserver.Region) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Scan(org.apache.hadoop.hbase.client.Scan) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Test(org.junit.Test)

Example 72 with ResultScanner

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

the class ThriftHBaseServiceHandler method openScanner.

@Override
public int openScanner(ByteBuffer table, TScan scan) throws TIOError, TException {
    Table htable = getTable(table);
    ResultScanner resultScanner = null;
    try {
        resultScanner = htable.getScanner(scanFromThrift(scan));
    } catch (IOException e) {
        throw getTIOError(e);
    } finally {
        closeTable(htable);
    }
    return addScanner(resultScanner);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) IOException(java.io.IOException)

Example 73 with ResultScanner

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

the class ThriftHBaseServiceHandler method getScannerResults.

@Override
public List<TResult> getScannerResults(ByteBuffer table, TScan scan, int numRows) throws TIOError, TException {
    Table htable = getTable(table);
    List<TResult> results = null;
    ResultScanner scanner = null;
    try {
        scanner = htable.getScanner(scanFromThrift(scan));
        results = resultsFromHBase(scanner.next(numRows));
    } catch (IOException e) {
        throw getTIOError(e);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
        closeTable(htable);
    }
    return results;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) IOException(java.io.IOException) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult)

Example 74 with ResultScanner

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

the class ThriftHBaseServiceHandler method getScannerRows.

@Override
public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError, TIllegalArgument, TException {
    ResultScanner scanner = getScanner(scannerId);
    if (scanner == null) {
        TIllegalArgument ex = new TIllegalArgument();
        ex.setMessage("Invalid scanner Id");
        throw ex;
    }
    try {
        connectionCache.updateConnectionAccessTime();
        return resultsFromHBase(scanner.next(numRows));
    } catch (IOException e) {
        throw getTIOError(e);
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument) IOException(java.io.IOException)

Example 75 with ResultScanner

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

the class TestHRegionOnCluster method putDataAndVerify.

private void putDataAndVerify(Table table, String row, byte[] family, String value, int verifyNum) throws IOException {
    System.out.println("=========Putting data :" + row);
    Put put = new Put(Bytes.toBytes(row));
    put.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes(value));
    table.put(put);
    ResultScanner resultScanner = table.getScanner(new Scan());
    List<Result> results = new ArrayList<>();
    while (true) {
        Result r = resultScanner.next();
        if (r == null)
            break;
        results.add(r);
    }
    resultScanner.close();
    if (results.size() != verifyNum) {
        System.out.println(results);
    }
    assertEquals(verifyNum, results.size());
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)342 Scan (org.apache.hadoop.hbase.client.Scan)303 Result (org.apache.hadoop.hbase.client.Result)302 Table (org.apache.hadoop.hbase.client.Table)164 Test (org.junit.Test)152 Cell (org.apache.hadoop.hbase.Cell)106 IOException (java.io.IOException)102 TableName (org.apache.hadoop.hbase.TableName)89 Delete (org.apache.hadoop.hbase.client.Delete)79 Connection (org.apache.hadoop.hbase.client.Connection)77 Put (org.apache.hadoop.hbase.client.Put)75 ArrayList (java.util.ArrayList)71 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 Admin (org.apache.hadoop.hbase.client.Admin)24 Get (org.apache.hadoop.hbase.client.Get)23