Search in sources :

Example 66 with CellScanner

use of org.apache.hadoop.hbase.CellScanner in project hbase by apache.

the class TestVisibilityLabelsWithDeletes method scanAll.

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(current.getTimestamp(), 127l);
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
    assertEquals(current.getTimestamp(), 126l);
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
    assertEquals(current.getTimestamp(), 125l);
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
    assertEquals(current.getTimestamp(), 124l);
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
    assertEquals(current.getTimestamp(), 123l);
    cellScanner = next[1].cellScanner();
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length));
}
Also used : CellScanner(org.apache.hadoop.hbase.CellScanner) Cell(org.apache.hadoop.hbase.Cell)

Example 67 with CellScanner

use of org.apache.hadoop.hbase.CellScanner in project hbase by apache.

the class TestVisibilityLabelsWithDeletes method testDeleteFamilySpecificTimeStampWithMulipleVersionsDoneTwice.

@Test
public void testDeleteFamilySpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception {
    setAuths();
    final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
    // Do not flush here.
    try (Table table = doPuts(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("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + TOPSECRET + "&" + SECRET + ")"));
                    d.addFamily(fam, 125l);
                    table.delete(d);
                } catch (Throwable t) {
                    throw new IOException(t);
                }
                return null;
            }
        };
        SUPERUSER.runAs(actiona);
        Scan s = new Scan();
        s.setMaxVersions(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(current.getTimestamp(), 127l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 126l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 125l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 123l);
        cellScanner = next[1].cellScanner();
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length));
        // Issue 2nd delete
        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("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")"));
                    d.addFamily(fam, 127l);
                    table.delete(d);
                } catch (Throwable t) {
                    throw new IOException(t);
                }
                return null;
            }
        };
        SUPERUSER.runAs(actiona);
        s = new Scan();
        s.setMaxVersions(5);
        s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
        scanner = table.getScanner(s);
        next = scanner.next(3);
        assertTrue(next.length == 2);
        cellScanner = next[0].cellScanner();
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 125l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 123l);
        cellScanner = next[1].cellScanner();
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length));
        assertEquals(current.getTimestamp(), 127l);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Connection(org.apache.hadoop.hbase.client.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CellScanner(org.apache.hadoop.hbase.CellScanner) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) Result(org.apache.hadoop.hbase.client.Result) TableName(org.apache.hadoop.hbase.TableName) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 68 with CellScanner

use of org.apache.hadoop.hbase.CellScanner in project hbase by apache.

the class TestVisibilityLabelsWithDeletes method testDeleteColumnWithLatestTimeStampWhenNoVersionMatches.

@Test(timeout = 180000)
public void testDeleteColumnWithLatestTimeStampWhenNoVersionMatches() throws Exception {
    setAuths();
    final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
    try (Table table = doPuts(tableName)) {
        TEST_UTIL.getAdmin().flush(tableName);
        Put put = new Put(Bytes.toBytes("row1"));
        put.addColumn(fam, qual, 128l, value);
        put.setCellVisibility(new CellVisibility(TOPSECRET));
        table.put(put);
        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));
                    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.setMaxVersions(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(current.getTimestamp(), 128l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 127l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 126l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 125l);
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 124l);
        cellScanner = next[1].cellScanner();
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length));
        put = new Put(Bytes.toBytes("row1"));
        put.addColumn(fam, qual, 129l, value);
        put.setCellVisibility(new CellVisibility(SECRET));
        table.put(put);
        TEST_UTIL.getAdmin().flush(tableName);
        s = new Scan();
        s.setMaxVersions(5);
        s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
        scanner = table.getScanner(s);
        next = scanner.next(3);
        assertTrue(next.length == 2);
        cellScanner = next[0].cellScanner();
        cellScanner.advance();
        current = cellScanner.current();
        assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
        assertEquals(current.getTimestamp(), 129l);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Connection(org.apache.hadoop.hbase.client.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CellScanner(org.apache.hadoop.hbase.CellScanner) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) TableName(org.apache.hadoop.hbase.TableName) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 69 with CellScanner

use of org.apache.hadoop.hbase.CellScanner in project hbase by apache.

the class CallRunner method run.

public void run() {
    try {
        if (call.disconnectSince() >= 0) {
            if (RpcServer.LOG.isDebugEnabled()) {
                RpcServer.LOG.debug(Thread.currentThread().getName() + ": skipped " + call);
            }
            return;
        }
        call.setStartTime(System.currentTimeMillis());
        if (call.getStartTime() > call.getDeadline()) {
            RpcServer.LOG.warn("Dropping timed out call: " + call);
            return;
        }
        this.status.setStatus("Setting up call");
        this.status.setConnection(call.getRemoteAddress().getHostAddress(), call.getRemotePort());
        if (RpcServer.LOG.isTraceEnabled()) {
            User remoteUser = call.getRequestUser();
            RpcServer.LOG.trace(call.toShortString() + " executing as " + ((remoteUser == null) ? "NULL principal" : remoteUser.getName()));
        }
        Throwable errorThrowable = null;
        String error = null;
        Pair<Message, CellScanner> resultPair = null;
        RpcServer.CurCall.set(call);
        TraceScope traceScope = null;
        try {
            if (!this.rpcServer.isStarted()) {
                InetSocketAddress address = rpcServer.getListenerAddress();
                throw new ServerNotRunningYetException("Server " + (address != null ? address : "(channel closed)") + " is not running yet");
            }
            if (call.getTraceInfo() != null) {
                String serviceName = call.getService() != null ? call.getService().getDescriptorForType().getName() : "";
                String methodName = (call.getMethod() != null) ? call.getMethod().getName() : "";
                String traceString = serviceName + "." + methodName;
                traceScope = Trace.startSpan(traceString, call.getTraceInfo());
            }
            // make the call
            resultPair = this.rpcServer.call(call, this.status);
        } catch (TimeoutIOException e) {
            RpcServer.LOG.warn("Can not complete this request in time, drop it: " + call);
            return;
        } catch (Throwable e) {
            RpcServer.LOG.debug(Thread.currentThread().getName() + ": " + call.toShortString(), e);
            errorThrowable = e;
            error = StringUtils.stringifyException(e);
            if (e instanceof Error) {
                throw (Error) e;
            }
        } finally {
            if (traceScope != null) {
                traceScope.close();
            }
            RpcServer.CurCall.set(null);
            if (resultPair != null) {
                this.rpcServer.addCallSize(call.getSize() * -1);
                sucessful = true;
            }
        }
        // return back the RPC request read BB we can do here. It is done by now.
        call.cleanup();
        // Set the response
        Message param = resultPair != null ? resultPair.getFirst() : null;
        CellScanner cells = resultPair != null ? resultPair.getSecond() : null;
        call.setResponse(param, cells, errorThrowable, error);
        call.sendResponseIfReady();
        this.status.markComplete("Sent response");
        this.status.pause("Waiting for a call");
    } catch (OutOfMemoryError e) {
        if (this.rpcServer.getErrorHandler() != null) {
            if (this.rpcServer.getErrorHandler().checkOOME(e)) {
                RpcServer.LOG.info(Thread.currentThread().getName() + ": exiting on OutOfMemoryError");
                return;
            }
        } else {
            // rethrow if no handler
            throw e;
        }
    } catch (ClosedChannelException cce) {
        InetSocketAddress address = rpcServer.getListenerAddress();
        RpcServer.LOG.warn(Thread.currentThread().getName() + ": caught a ClosedChannelException, " + "this means that the server " + (address != null ? address : "(channel closed)") + " was processing a request but the client went away. The error message was: " + cce.getMessage());
    } catch (Exception e) {
        RpcServer.LOG.warn(Thread.currentThread().getName() + ": caught: " + StringUtils.stringifyException(e));
    } finally {
        if (!sucessful) {
            this.rpcServer.addCallSize(call.getSize() * -1);
        }
        cleanup();
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) User(org.apache.hadoop.hbase.security.User) Message(org.apache.hadoop.hbase.shaded.com.google.protobuf.Message) InetSocketAddress(java.net.InetSocketAddress) TraceScope(org.apache.htrace.TraceScope) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) CellScanner(org.apache.hadoop.hbase.CellScanner) ClosedChannelException(java.nio.channels.ClosedChannelException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) CallDroppedException(org.apache.hadoop.hbase.CallDroppedException)

Example 70 with CellScanner

use of org.apache.hadoop.hbase.CellScanner in project hbase by apache.

the class RSRpcServices method replicateWALEntry.

/**
   * Replicate WAL entries on the region server.
   *
   * @param controller the RPC controller
   * @param request the request
   * @throws ServiceException
   */
@Override
@QosPriority(priority = HConstants.REPLICATION_QOS)
public ReplicateWALEntryResponse replicateWALEntry(final RpcController controller, final ReplicateWALEntryRequest request) throws ServiceException {
    try {
        checkOpen();
        if (regionServer.replicationSinkHandler != null) {
            requestCount.increment();
            List<WALEntry> entries = request.getEntryList();
            CellScanner cellScanner = ((HBaseRpcController) controller).cellScanner();
            regionServer.getRegionServerCoprocessorHost().preReplicateLogEntries(entries, cellScanner);
            regionServer.replicationSinkHandler.replicateLogEntries(entries, cellScanner, request.getReplicationClusterId(), request.getSourceBaseNamespaceDirPath(), request.getSourceHFileArchiveDirPath());
            regionServer.getRegionServerCoprocessorHost().postReplicateLogEntries(entries, cellScanner);
            return ReplicateWALEntryResponse.newBuilder().build();
        } else {
            throw new ServiceException("Replication services are not initialized yet");
        }
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) WALEntry(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) CellScanner(org.apache.hadoop.hbase.CellScanner) QosPriority(org.apache.hadoop.hbase.ipc.QosPriority)

Aggregations

CellScanner (org.apache.hadoop.hbase.CellScanner)82 Cell (org.apache.hadoop.hbase.Cell)69 Test (org.junit.Test)58 Result (org.apache.hadoop.hbase.client.Result)47 Scan (org.apache.hadoop.hbase.client.Scan)43 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)42 Table (org.apache.hadoop.hbase.client.Table)41 IOException (java.io.IOException)40 TableName (org.apache.hadoop.hbase.TableName)40 InterruptedIOException (java.io.InterruptedIOException)35 Connection (org.apache.hadoop.hbase.client.Connection)34 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)32 Delete (org.apache.hadoop.hbase.client.Delete)32 Put (org.apache.hadoop.hbase.client.Put)15 KeyValue (org.apache.hadoop.hbase.KeyValue)14 ArrayList (java.util.ArrayList)10 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)7 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)5