accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [5/5] accumulo git commit: Merge branch '1.6'
Date Fri, 21 Nov 2014 04:04:21 GMT
Merge branch '1.6'

Conflicts:
	server/tracer/src/main/java/org/apache/accumulo/tracer/TraceDump.java


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9e2867d4
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9e2867d4
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9e2867d4

Branch: refs/heads/master
Commit: 9e2867d46969c595dbafff2f59165159da551fcb
Parents: 4062b34 0934298
Author: Josh Elser <elserj@apache.org>
Authored: Thu Nov 20 23:04:05 2014 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Thu Nov 20 23:04:05 2014 -0500

----------------------------------------------------------------------
 .../org/apache/accumulo/tracer/TraceDump.java   |  24 ++--
 .../org/apache/accumulo/tracer/TraceServer.java |   5 +
 .../accumulo/test/ConditionalWriterIT.java      |   1 -
 .../test/TracerRecoversAfterOfflineTableIT.java | 127 +++++++++++++++++++
 4 files changed, 146 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/9e2867d4/server/tracer/src/main/java/org/apache/accumulo/tracer/TraceDump.java
----------------------------------------------------------------------
diff --cc server/tracer/src/main/java/org/apache/accumulo/tracer/TraceDump.java
index c109fd8,0000000..4468866
mode 100644,000000..100644
--- a/server/tracer/src/main/java/org/apache/accumulo/tracer/TraceDump.java
+++ b/server/tracer/src/main/java/org/apache/accumulo/tracer/TraceDump.java
@@@ -1,162 -1,0 +1,166 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.tracer;
 +
 +import static java.lang.Math.min;
 +
 +import java.io.PrintStream;
 +import java.util.ArrayList;
 +import java.util.Collection;
 +import java.util.Collections;
 +import java.util.Comparator;
 +import java.util.Date;
 +import java.util.List;
 +import java.util.Map.Entry;
 +import java.util.Set;
 +
- import org.apache.accumulo.tracer.thrift.RemoteSpan;
 +import org.apache.accumulo.core.cli.ClientOnDefaultTable;
 +import org.apache.accumulo.core.cli.ScannerOpts;
 +import org.apache.accumulo.core.client.Connector;
 +import org.apache.accumulo.core.client.Scanner;
 +import org.apache.accumulo.core.data.Key;
 +import org.apache.accumulo.core.data.Range;
 +import org.apache.accumulo.core.data.Value;
++import org.apache.accumulo.tracer.thrift.RemoteSpan;
 +import org.apache.hadoop.io.Text;
 +import org.htrace.Span;
 +
 +import com.beust.jcommander.Parameter;
 +
 +
 +public class TraceDump {
 +  static final long DEFAULT_TIME_IN_MILLIS = 10 * 60 * 1000l;
-   
++
 +  static class Opts extends ClientOnDefaultTable {
 +    @Parameter(names={"-l", "--list"}, description="List recent traces")
 +    boolean list = false;
 +    @Parameter(names={"-s", "--start"}, description="The start time of traces to display")
 +    String start;
 +    @Parameter(names={"-e", "--end"}, description="The end time of traces to display")
 +    String end;
 +    @Parameter(names={"-d", "--dump"}, description="Dump the traces")
 +    boolean dump = false;
 +    @Parameter(names={"-i", "--instance"}, description="URL to point to accumulo.")
 +    String instance;
 +    @Parameter(description=" <trace id> { <trace id> ... }")
 +    List<String> traceIds = new ArrayList<String>();
 +    Opts() { super("trace");}
 +  }
-   
++
 +  public static void main(String[] args) throws Exception {
 +    Opts opts = new Opts();
 +    ScannerOpts scanOpts = new ScannerOpts();
 +    opts.parseArgs(TraceDump.class.getName(), args, scanOpts);
 +    int code = 0;
 +    if (opts.list) {
 +      code = listSpans(opts, scanOpts);
 +    }
 +    if (code == 0 && opts.dump) {
 +      code = dumpTrace(opts, scanOpts);
 +    }
 +    System.exit(code);
 +  }
-   
++
 +  public static List<RemoteSpan> sortByStart(Collection<RemoteSpan> spans) {
 +    List<RemoteSpan> spanList = new ArrayList<RemoteSpan>(spans);
 +    Collections.sort(spanList, new Comparator<RemoteSpan>() {
 +      @Override
 +      public int compare(RemoteSpan o1, RemoteSpan o2) {
 +        return (int) (o1.start - o2.start);
 +      }
 +    });
 +    return spanList;
 +  }
-   
++
 +  private static int listSpans(Opts opts, ScannerOpts scanOpts) throws Exception {
 +    PrintStream out = System.out;
 +    long endTime = System.currentTimeMillis();
 +    long startTime = endTime - DEFAULT_TIME_IN_MILLIS;
 +    Connector conn = opts.getConnector();
 +    Scanner scanner = conn.createScanner(opts.getTableName(), opts.auths);
 +    scanner.setBatchSize(scanOpts.scanBatchSize);
 +    Range range = new Range(new Text("start:" + Long.toHexString(startTime)), new Text("start:"
+ Long.toHexString(endTime)));
 +    scanner.setRange(range);
 +    out.println("Trace            Day/Time                 (ms)  Start");
 +    for (Entry<Key,Value> entry : scanner) {
 +      RemoteSpan span = TraceFormatter.getRemoteSpan(entry);
 +      out.println(String.format("%016x %s %5d %s", span.traceId, TraceFormatter.formatDate(new
Date(span.getStart())), span.stop - span.start, span.description));
 +    }
 +    return 0;
 +  }
-   
++
 +  public interface Printer {
 +    void print(String line);
 +  }
-   
++
 +  private static int dumpTrace(Opts opts, ScannerOpts scanOpts) throws Exception {
 +    final PrintStream out = System.out;
 +    Connector conn = opts.getConnector();
-     
++
 +    int count = 0;
 +    for (String traceId : opts.traceIds) {
 +      Scanner scanner = conn.createScanner(opts.getTableName(), opts.auths);
 +      scanner.setBatchSize(scanOpts.scanBatchSize);
 +      Range range = new Range(new Text(traceId.toString()));
 +      scanner.setRange(range);
 +      count = printTrace(scanner, new Printer() {
 +        @Override
 +        public void print(String line) {
 +          out.println(line);
 +        }
 +      });
 +    }
 +    return count > 0 ? 0 : 1;
 +  }
-   
++
 +  public static int printTrace(Scanner scanner, final Printer out) {
 +    int count = 0;
 +    SpanTree tree = new SpanTree();
 +    long start = Long.MAX_VALUE;
 +    for (Entry<Key,Value> entry : scanner) {
 +      RemoteSpan span = TraceFormatter.getRemoteSpan(entry);
 +      tree.addNode(span);
 +      start = min(start, span.start);
 +      if (span.parentId == Span.ROOT_SPAN_ID)
 +        count++;
 +    }
++    if (Long.MAX_VALUE == start) {
++      out.print("Did not find any traces!");
++      return 0;
++    }
 +    out.print(String.format("Trace started at %s", TraceFormatter.formatDate(new Date(start))));
 +    out.print("Time  Start  Service@Location       Name");
-     
++
 +    final long finalStart = start;
 +    Set<Long> visited = tree.visit(new SpanTreeVisitor() {
 +      @Override
 +      public void visit(int level, RemoteSpan parent, RemoteSpan node, Collection<RemoteSpan>
children) {
 +        String fmt = "%5d+%-5d %" + (level * 2 + 1) + "s%s@%s %s";
 +        out.print(String.format(fmt, node.stop - node.start, node.start - finalStart, "",
node.svc, node.sender, node.description));
 +      }
 +    });
 +    tree.nodes.keySet().removeAll(visited);
 +    if (!tree.nodes.isEmpty()) {
 +      out.print("Warning: the following spans are not rooted!");
 +      for (RemoteSpan span : sortByStart(tree.nodes.values())) {
 +        out.print(String.format("%s %s %s", Long.toHexString(span.spanId), Long.toHexString(span.parentId),
span.description));
 +      }
 +      return -1;
 +    }
 +    return count;
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/9e2867d4/server/tracer/src/main/java/org/apache/accumulo/tracer/TraceServer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/accumulo/blob/9e2867d4/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
----------------------------------------------------------------------
diff --cc test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
index 72db704,8406570..0810fb2
--- a/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/ConditionalWriterIT.java
@@@ -1231,9 -1232,8 +1231,8 @@@ public class ConditionalWriterIT extend
  
      String tableName = getUniqueNames(1)[0];
      conn.tableOperations().create(tableName);
-     conn.tableOperations().deleteRows("trace", null, null);
  
 -    DistributedTrace.enable(conn.getInstance(), new ZooReader(conn.getInstance().getZooKeepers(),
30*1000), "testTrace", "localhost");
 +    DistributedTrace.enable("localhost", "testTrace", getClientConfig());
      Span root = Trace.on("traceTest");
      ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig());
  

http://git-wip-us.apache.org/repos/asf/accumulo/blob/9e2867d4/test/src/test/java/org/apache/accumulo/test/TracerRecoversAfterOfflineTableIT.java
----------------------------------------------------------------------
diff --cc test/src/test/java/org/apache/accumulo/test/TracerRecoversAfterOfflineTableIT.java
index 0000000,bd186a9..e32ec16
mode 000000,100644..100644
--- a/test/src/test/java/org/apache/accumulo/test/TracerRecoversAfterOfflineTableIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/TracerRecoversAfterOfflineTableIT.java
@@@ -1,0 -1,127 +1,127 @@@
+ /*
+  * Licensed to the Apache Software Foundation (ASF) under one or more
+  * contributor license agreements.  See the NOTICE file distributed with
+  * this work for additional information regarding copyright ownership.
+  * The ASF licenses this file to You under the Apache License, Version 2.0
+  * (the "License"); you may not use this file except in compliance with
+  * the License.  You may obtain a copy of the License at
+  *
+  *     http://www.apache.org/licenses/LICENSE-2.0
+  *
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  */
+ package org.apache.accumulo.test;
+ 
+ import static org.junit.Assert.assertTrue;
+ 
+ import org.apache.accumulo.core.client.BatchWriter;
+ import org.apache.accumulo.core.client.Connector;
+ import org.apache.accumulo.core.client.Scanner;
+ import org.apache.accumulo.core.data.Mutation;
+ import org.apache.accumulo.core.data.Range;
+ import org.apache.accumulo.core.security.Authorizations;
+ import org.apache.accumulo.core.trace.DistributedTrace;
 -import org.apache.accumulo.core.trace.TraceDump;
 -import org.apache.accumulo.core.trace.TraceDump.Printer;
+ import org.apache.accumulo.core.util.UtilWaitThread;
+ import org.apache.accumulo.fate.zookeeper.ZooReader;
+ import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl;
+ import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
+ import org.apache.accumulo.test.functional.ConfigurableMacIT;
+ import org.apache.accumulo.trace.instrument.Span;
+ import org.apache.accumulo.trace.instrument.Trace;
++import org.apache.accumulo.tracer.TraceDump;
++import org.apache.accumulo.tracer.TraceDump.Printer;
+ import org.apache.accumulo.tracer.TraceServer;
+ import org.apache.hadoop.conf.Configuration;
+ import org.apache.hadoop.io.Text;
+ import org.junit.Test;
+ 
+ /**
+  *
+  */
+ public class TracerRecoversAfterOfflineTableIT extends ConfigurableMacIT {
+ 
+   @Override
+   public void configure(MiniAccumuloConfigImpl cfg, Configuration coreSite) {
+     cfg.setNumTservers(1);
+   }
+ 
+   @Override
+   public int defaultTimeoutSeconds() {
+     return 60;
+   }
+ 
+   @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")) {
+         UtilWaitThread.sleep(1000);
+       }
+     }
+ 
+     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(conn.getInstance(), new ZooReader(conn.getInstance().getZooKeepers(),
30 * 1000), "testTrace", "localhost");
+     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");
+ 
+     final Scanner scanner = conn.createScanner("trace", Authorizations.EMPTY);
+     scanner.setRange(new Range(new Text(Long.toHexString(root.traceId()))));
+     while (true) {
+       final StringBuffer finalBuffer = new StringBuffer();
+       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();
+     }
+   }
+ 
+ }


Mime
View raw message