Search in sources :

Example 1 with Printer

use of org.apache.accumulo.tracer.TraceDump.Printer in project accumulo by apache.

the class TracerRecoversAfterOfflineTableIT method test.

@Test
public void test() throws Exception {
    Process tracer = null;
    Connector conn = getConnector();
    if (!conn.tableOperations().exists("trace")) {
        MiniAccumuloClusterImpl mac = cluster;
        tracer = mac.exec(TraceServer.class);
        while (!conn.tableOperations().exists("trace")) {
            sleepUninterruptibly(1, TimeUnit.SECONDS);
        }
        sleepUninterruptibly(5, TimeUnit.SECONDS);
    }
    log.info("Taking table offline");
    conn.tableOperations().offline("trace", true);
    String tableName = getUniqueNames(1)[0];
    conn.tableOperations().create(tableName);
    log.info("Start a distributed trace span");
    DistributedTrace.enable("localhost", "testTrace", getClientConfig());
    Span root = Trace.on("traceTest");
    BatchWriter bw = conn.createBatchWriter(tableName, null);
    Mutation m = new Mutation("m");
    m.put("a", "b", "c");
    bw.addMutation(m);
    bw.close();
    root.stop();
    log.info("Bringing trace table back online");
    conn.tableOperations().online("trace", true);
    log.info("Trace table is online, should be able to find trace");
    try (Scanner scanner = conn.createScanner("trace", Authorizations.EMPTY)) {
        scanner.setRange(new Range(new Text(Long.toHexString(root.traceId()))));
        while (true) {
            final StringBuilder finalBuffer = new StringBuilder();
            int traceCount = TraceDump.printTrace(scanner, new Printer() {

                @Override
                public void print(final String line) {
                    try {
                        finalBuffer.append(line).append("\n");
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                }
            });
            String traceOutput = finalBuffer.toString();
            log.info("Trace output:{}", traceOutput);
            if (traceCount > 0) {
                int lastPos = 0;
                for (String part : "traceTest,close,binMutations".split(",")) {
                    log.info("Looking in trace output for '{}'", part);
                    int pos = traceOutput.indexOf(part);
                    assertTrue("Did not find '" + part + "' in output", pos > 0);
                    assertTrue("'" + part + "' occurred earlier than the previous element unexpectedly", pos > lastPos);
                    lastPos = pos;
                }
                break;
            } else {
                log.info("Ignoring trace output as traceCount not greater than zero: {}", traceCount);
                Thread.sleep(1000);
            }
        }
        if (tracer != null) {
            tracer.destroy();
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Printer(org.apache.accumulo.tracer.TraceDump.Printer) Span(org.apache.accumulo.core.trace.Span) TraceServer(org.apache.accumulo.tracer.TraceServer) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) Test(org.junit.Test)

Example 2 with Printer

use of org.apache.accumulo.tracer.TraceDump.Printer in project accumulo by apache.

the class ConditionalWriterIT method testTrace.

@Test
public void testTrace() throws Exception {
    // Need to add a getClientConfig() to AccumuloCluster
    Assume.assumeTrue(getClusterType() == ClusterType.MINI);
    Process tracer = null;
    Connector conn = getConnector();
    AccumuloCluster cluster = getCluster();
    MiniAccumuloClusterImpl mac = (MiniAccumuloClusterImpl) cluster;
    if (!conn.tableOperations().exists("trace")) {
        tracer = mac.exec(TraceServer.class);
        while (!conn.tableOperations().exists("trace")) {
            sleepUninterruptibly(1, TimeUnit.SECONDS);
        }
    }
    String tableName = getUniqueNames(1)[0];
    conn.tableOperations().create(tableName);
    DistributedTrace.enable("localhost", "testTrace", mac.getClientConfig());
    sleepUninterruptibly(1, TimeUnit.SECONDS);
    Span root = Trace.on("traceTest");
    try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig())) {
        // mutation conditional on column tx:seq not exiting
        ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq"));
        cm0.put("name", "last", "doe");
        cm0.put("name", "first", "john");
        cm0.put("tx", "seq", "1");
        Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
        root.stop();
    }
    try (Scanner scanner = conn.createScanner("trace", Authorizations.EMPTY)) {
        scanner.setRange(new Range(new Text(Long.toHexString(root.traceId()))));
        loop: while (true) {
            final StringBuilder finalBuffer = new StringBuilder();
            int traceCount = TraceDump.printTrace(scanner, new Printer() {

                @Override
                public void print(final String line) {
                    try {
                        finalBuffer.append(line).append("\n");
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                }
            });
            String traceOutput = finalBuffer.toString();
            log.info("Trace output:" + traceOutput);
            if (traceCount > 0) {
                int lastPos = 0;
                for (String part : "traceTest, startScan,startConditionalUpdate,conditionalUpdate,Check conditions,apply conditional mutations".split(",")) {
                    log.info("Looking in trace output for '" + part + "'");
                    int pos = traceOutput.indexOf(part);
                    if (-1 == pos) {
                        log.info("Trace output doesn't contain '" + part + "'");
                        Thread.sleep(1000);
                        break loop;
                    }
                    assertTrue("Did not find '" + part + "' in output", pos > 0);
                    assertTrue("'" + part + "' occurred earlier than the previous element unexpectedly", pos > lastPos);
                    lastPos = pos;
                }
                break;
            } else {
                log.info("Ignoring trace output as traceCount not greater than zero: " + traceCount);
                Thread.sleep(1000);
            }
        }
        if (tracer != null) {
            tracer.destroy();
        }
    }
}
Also used : Condition(org.apache.accumulo.core.data.Condition) Connector(org.apache.accumulo.core.client.Connector) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) AccumuloCluster(org.apache.accumulo.cluster.AccumuloCluster) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Printer(org.apache.accumulo.tracer.TraceDump.Printer) Span(org.apache.accumulo.core.trace.Span) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) TraceServer(org.apache.accumulo.tracer.TraceServer) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) Test(org.junit.Test)

Example 3 with Printer

use of org.apache.accumulo.tracer.TraceDump.Printer in project accumulo-examples by apache.

the class TraceDumpExample method dump.

public void dump(Opts opts) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
    if (opts.traceId.isEmpty()) {
        throw new IllegalArgumentException("--traceid option is required");
    }
    final Connector conn = opts.getConnector();
    final String principal = opts.getPrincipal();
    final String table = opts.getTableName();
    if (!conn.securityOperations().hasTablePermission(principal, table, TablePermission.READ)) {
        conn.securityOperations().grantTablePermission(principal, table, TablePermission.READ);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
        while (!conn.securityOperations().hasTablePermission(principal, table, TablePermission.READ)) {
            log.info("{} didn't propagate read permission on {}", principal, table);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new RuntimeException(e);
            }
        }
    }
    Scanner scanner = conn.createScanner(table, opts.auths);
    scanner.setRange(new Range(new Text(opts.traceId)));
    TraceDump.printTrace(scanner, new Printer() {

        @Override
        public void print(String line) {
            System.out.println(line);
        }
    });
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Printer(org.apache.accumulo.tracer.TraceDump.Printer)

Aggregations

Connector (org.apache.accumulo.core.client.Connector)3 Scanner (org.apache.accumulo.core.client.Scanner)3 Range (org.apache.accumulo.core.data.Range)3 Printer (org.apache.accumulo.tracer.TraceDump.Printer)3 Text (org.apache.hadoop.io.Text)3 Span (org.apache.accumulo.core.trace.Span)2 MiniAccumuloClusterImpl (org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl)2 TraceServer (org.apache.accumulo.tracer.TraceServer)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 AccumuloCluster (org.apache.accumulo.cluster.AccumuloCluster)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 BatchWriter (org.apache.accumulo.core.client.BatchWriter)1 ConditionalWriter (org.apache.accumulo.core.client.ConditionalWriter)1 ConditionalWriterConfig (org.apache.accumulo.core.client.ConditionalWriterConfig)1 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)1 TableDeletedException (org.apache.accumulo.core.client.TableDeletedException)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1