Search in sources :

Example 26 with TraceScope

use of org.apache.htrace.TraceScope 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 27 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class MemStoreFlusher method reclaimMemStoreMemory.

/**
   * Check if the regionserver's memstore memory usage is greater than the
   * limit. If so, flush regions with the biggest memstores until we're down
   * to the lower limit. This method blocks callers until we're down to a safe
   * amount of memstore consumption.
   */
public void reclaimMemStoreMemory() {
    TraceScope scope = Trace.startSpan("MemStoreFluser.reclaimMemStoreMemory");
    FlushType flushType = isAboveHighWaterMark();
    if (flushType != FlushType.NORMAL) {
        if (Trace.isTracing()) {
            scope.getSpan().addTimelineAnnotation("Force Flush. We're above high water mark.");
        }
        long start = EnvironmentEdgeManager.currentTime();
        synchronized (this.blockSignal) {
            boolean blocked = false;
            long startTime = 0;
            boolean interrupted = false;
            try {
                flushType = isAboveHighWaterMark();
                while (flushType != FlushType.NORMAL && !server.isStopped()) {
                    if (!blocked) {
                        startTime = EnvironmentEdgeManager.currentTime();
                        if (!server.getRegionServerAccounting().isOffheap()) {
                            logMsg("global memstore heapsize", server.getRegionServerAccounting().getGlobalMemstoreHeapSize(), server.getRegionServerAccounting().getGlobalMemstoreLimit());
                        } else {
                            switch(flushType) {
                                case ABOVE_OFFHEAP_HIGHER_MARK:
                                    logMsg("the global offheap memstore datasize", server.getRegionServerAccounting().getGlobalMemstoreDataSize(), server.getRegionServerAccounting().getGlobalMemstoreLimit());
                                    break;
                                case ABOVE_ONHEAP_HIGHER_MARK:
                                    logMsg("global memstore heapsize", server.getRegionServerAccounting().getGlobalMemstoreHeapSize(), server.getRegionServerAccounting().getGlobalOnHeapMemstoreLimit());
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    blocked = true;
                    wakeupFlushThread();
                    try {
                        // we should be able to wait forever, but we've seen a bug where
                        // we miss a notify, so put a 5 second bound on it at least.
                        blockSignal.wait(5 * 1000);
                    } catch (InterruptedException ie) {
                        LOG.warn("Interrupted while waiting");
                        interrupted = true;
                    }
                    long took = EnvironmentEdgeManager.currentTime() - start;
                    LOG.warn("Memstore is above high water mark and block " + took + "ms");
                    flushType = isAboveHighWaterMark();
                }
            } finally {
                if (interrupted) {
                    Thread.currentThread().interrupt();
                }
            }
            if (blocked) {
                final long totalTime = EnvironmentEdgeManager.currentTime() - startTime;
                if (totalTime > 0) {
                    this.updatesBlockedMsHighWater.add(totalTime);
                }
                LOG.info("Unblocking updates for server " + server.toString());
            }
        }
    } else if (isAboveLowWaterMark() != FlushType.NORMAL) {
        wakeupFlushThread();
    }
    scope.close();
}
Also used : TraceScope(org.apache.htrace.TraceScope)

Example 28 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class TestHTraceHooks method testTraceCreateTable.

@Test
public void testTraceCreateTable() throws Exception {
    TraceScope tableCreationSpan = Trace.startSpan("creating table", Sampler.ALWAYS);
    Table table;
    try {
        table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY_BYTES);
    } finally {
        tableCreationSpan.close();
    }
    // Some table creation is async.  Need to make sure that everything is full in before
    // checking to see if the spans are there.
    TEST_UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return rcvr.getSpans().size() >= 5;
        }
    });
    Collection<Span> spans = rcvr.getSpans();
    TraceTree traceTree = new TraceTree(spans);
    Collection<Span> roots = traceTree.getSpansByParent().find(ROOT_SPAN_ID);
    assertEquals(1, roots.size());
    Span createTableRoot = roots.iterator().next();
    assertEquals("creating table", createTableRoot.getDescription());
    int createTableCount = 0;
    for (Span s : traceTree.getSpansByParent().find(createTableRoot.getSpanId())) {
        if (s.getDescription().startsWith("MasterService.CreateTable")) {
            createTableCount++;
        }
    }
    assertTrue(createTableCount >= 1);
    assertTrue(traceTree.getSpansByParent().find(createTableRoot.getSpanId()).size() > 3);
    assertTrue(spans.size() > 5);
    Put put = new Put("row".getBytes());
    put.addColumn(FAMILY_BYTES, "col".getBytes(), "value".getBytes());
    TraceScope putSpan = Trace.startSpan("doing put", Sampler.ALWAYS);
    try {
        table.put(put);
    } finally {
        putSpan.close();
    }
    spans = rcvr.getSpans();
    traceTree = new TraceTree(spans);
    roots = traceTree.getSpansByParent().find(ROOT_SPAN_ID);
    assertEquals(2, roots.size());
    Span putRoot = null;
    for (Span root : roots) {
        if (root.getDescription().equals("doing put")) {
            putRoot = root;
        }
    }
    assertNotNull(putRoot);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) TraceScope(org.apache.htrace.TraceScope) Waiter(org.apache.hadoop.hbase.Waiter) Span(org.apache.htrace.Span) TraceTree(org.apache.htrace.TraceTree) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 29 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class IntegrationTestSendTraceRequests method doGets.

private void doGets(ExecutorService service, final LinkedBlockingQueue<Long> rowKeys) throws IOException {
    for (int i = 0; i < 100; i++) {
        Runnable runnable = new Runnable() {

            private TraceScope innerScope = null;

            private final LinkedBlockingQueue<Long> rowKeyQueue = rowKeys;

            @Override
            public void run() {
                Table ht = null;
                try {
                    ht = util.getConnection().getTable(tableName);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                long accum = 0;
                for (int x = 0; x < 5; x++) {
                    try {
                        innerScope = Trace.startSpan("gets", Sampler.ALWAYS);
                        long rk = rowKeyQueue.take();
                        Result r1 = ht.get(new Get(Bytes.toBytes(rk)));
                        if (r1 != null) {
                            accum |= Bytes.toLong(r1.getRow());
                        }
                        Result r2 = ht.get(new Get(Bytes.toBytes(rk)));
                        if (r2 != null) {
                            accum |= Bytes.toLong(r2.getRow());
                        }
                        innerScope.getSpan().addTimelineAnnotation("Accum = " + accum);
                    } catch (IOException e) {
                    // IGNORED
                    } catch (InterruptedException ie) {
                    // IGNORED
                    } finally {
                        if (innerScope != null)
                            innerScope.close();
                    }
                }
            }
        };
        service.submit(runnable);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) TraceScope(org.apache.htrace.TraceScope) IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Result(org.apache.hadoop.hbase.client.Result)

Example 30 with TraceScope

use of org.apache.htrace.TraceScope in project hbase by apache.

the class IntegrationTestSendTraceRequests method doScans.

private void doScans(ExecutorService service, final LinkedBlockingQueue<Long> rks) {
    for (int i = 0; i < 100; i++) {
        Runnable runnable = new Runnable() {

            private TraceScope innerScope = null;

            private final LinkedBlockingQueue<Long> rowKeyQueue = rks;

            @Override
            public void run() {
                ResultScanner rs = null;
                try {
                    innerScope = Trace.startSpan("Scan", Sampler.ALWAYS);
                    Table ht = util.getConnection().getTable(tableName);
                    Scan s = new Scan();
                    s.setStartRow(Bytes.toBytes(rowKeyQueue.take()));
                    s.setBatch(7);
                    rs = ht.getScanner(s);
                    // Something to keep the jvm from removing the loop.
                    long accum = 0;
                    for (int x = 0; x < 1000; x++) {
                        Result r = rs.next();
                        accum |= Bytes.toLong(r.getRow());
                    }
                    innerScope.getSpan().addTimelineAnnotation("Accum result = " + accum);
                    ht.close();
                    ht = null;
                } catch (IOException e) {
                    e.printStackTrace();
                    innerScope.getSpan().addKVAnnotation(Bytes.toBytes("exception"), Bytes.toBytes(e.getClass().getSimpleName()));
                } catch (Exception e) {
                } finally {
                    if (innerScope != null)
                        innerScope.close();
                    if (rs != null)
                        rs.close();
                }
            }
        };
        service.submit(runnable);
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Table(org.apache.hadoop.hbase.client.Table) TraceScope(org.apache.htrace.TraceScope) Scan(org.apache.hadoop.hbase.client.Scan) IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

TraceScope (org.apache.htrace.TraceScope)38 RetryCounter (org.apache.hadoop.hbase.util.RetryCounter)11 KeeperException (org.apache.zookeeper.KeeperException)11 IOException (java.io.IOException)9 Span (org.apache.htrace.Span)7 Pair (org.apache.hadoop.hbase.util.Pair)4 InterruptedIOException (java.io.InterruptedIOException)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 Mutation (org.apache.hadoop.hbase.client.Mutation)3 Table (org.apache.hadoop.hbase.client.Table)3 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Path (org.apache.hadoop.fs.Path)2 Put (org.apache.hadoop.hbase.client.Put)2 Result (org.apache.hadoop.hbase.client.Result)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)2 ResultIterator (org.apache.phoenix.iterate.ResultIterator)2 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)2