[2/3] PHOENIX-177: Collect usage and performance metrics

2014-07-28 Thread jyates
http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7f46c10/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
index e24591d..b3bec6e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
@@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.regionserver.ScanType;
 import org.apache.hadoop.hbase.regionserver.Store;
 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.hbase.index.builder.IndexBuildManager;
 import org.apache.phoenix.hbase.index.builder.IndexBuilder;
@@ -64,6 +65,11 @@ import org.apache.phoenix.hbase.index.write.IndexWriter;
 import org.apache.phoenix.hbase.index.write.recovery.PerRegionIndexWriteCache;
 import 
org.apache.phoenix.hbase.index.write.recovery.StoreFailuresInCachePolicy;
 import 
org.apache.phoenix.hbase.index.write.recovery.TrackingParallelWriterIndexCommitter;
+import org.apache.phoenix.trace.TracingCompat;
+import org.apache.phoenix.trace.util.NullSpan;
+import org.apache.phoenix.trace.util.Tracing;
+import org.cloudera.htrace.Span;
+import org.cloudera.htrace.Trace;
 
 import com.google.common.collect.Multimap;
 
@@ -134,10 +140,18 @@ public class Indexer extends BaseRegionObserver {
 private static final int INDEX_WAL_COMPRESSION_MINIMUM_SUPPORTED_VERSION = 
VersionUtil
 .encodeVersion(0.94.9);
 
+/**
+ * Raw configuration, for tracing. Coprocessors generally will get a 
subset configuration (if
+ * they are on a per-table basis), so we need the raw one from the server, 
so we can get the
+ * actual configuration keys
+ */
+private Configuration rawConf;
+
   @Override
   public void start(CoprocessorEnvironment e) throws IOException {
   try {
 final RegionCoprocessorEnvironment env = 
(RegionCoprocessorEnvironment) e;
+this.rawConf = env.getRegionServerServices().getConfiguration();
 String serverName = 
env.getRegionServerServices().getServerName().getServerName();
 if (env.getConfiguration().getBoolean(CHECK_VERSION_CONF_KEY, true)) {
   // make sure the right version - combinations are allowed.
@@ -312,12 +326,24 @@ public class Indexer extends BaseRegionObserver {
 // don't worry which one we get
 WALEdit edit = miniBatchOp.getWalEdit(0);
 
+// get the current span, or just use a null-span to avoid a bunch of 
if statements
+Span current = Trace.startSpan(Starting to build index 
updates).getSpan();
+if (current == null) {
+current = NullSpan.INSTANCE;
+}
+
 // get the index updates for all elements in this batch
 CollectionPairMutation, byte[] indexUpdates =
 this.builder.getIndexUpdate(miniBatchOp, mutations.values());
 
+current.addTimelineAnnotation(Built index updates, doing preStep);
+TracingCompat.addAnnotation(current, index update count, 
indexUpdates.size());
+
 // write them, either to WAL or the index tables
 doPre(indexUpdates, edit, durability);
+
+// close the span
+current.stop();
   }
 
   private class MultiMutation extends Mutation {
@@ -458,16 +484,24 @@ public class Indexer extends BaseRegionObserver {
   return;
 }
 
+// get the current span, or just use a null-span to avoid a bunch of 
if statements
+Span current = Trace.startSpan(Completing index writes).getSpan();
+if (current == null) {
+current = NullSpan.INSTANCE;
+}
+
 // there is a little bit of excess here- we iterate all the non-indexed 
kvs for this check first
 // and then do it again later when getting out the index updates. This 
should be pretty minor
 // though, compared to the rest of the runtime
 IndexedKeyValue ikv = getFirstIndexedKeyValue(edit);
+
 /*
  * early exit - we have nothing to write, so we don't need to do anything 
else. NOTE: we don't
  * release the WAL Rolling lock (INDEX_UPDATE_LOCK) since we never take it 
in doPre if there are
  * no index updates.
  */
 if (ikv == null) {
+current.stop();
   return;
 }
 
@@ -483,6 +517,7 @@ public class Indexer extends BaseRegionObserver {
   // references originally - therefore, we just pass in a null factory 
here and use the ones
   // already specified on each reference
   try {
+current.addTimelineAnnotation(Actually doing index update for 
first time);
   writer.writeAndKillYourselfOnFailure(indexUpdates);
   } finally {
 // With a custom kill 

[2/3] PHOENIX-177: Collect usage and performance metrics

2014-07-28 Thread jyates
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e8def027/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
index e24591d..b3bec6e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/Indexer.java
@@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.regionserver.ScanType;
 import org.apache.hadoop.hbase.regionserver.Store;
 import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.hbase.index.builder.IndexBuildManager;
 import org.apache.phoenix.hbase.index.builder.IndexBuilder;
@@ -64,6 +65,11 @@ import org.apache.phoenix.hbase.index.write.IndexWriter;
 import org.apache.phoenix.hbase.index.write.recovery.PerRegionIndexWriteCache;
 import 
org.apache.phoenix.hbase.index.write.recovery.StoreFailuresInCachePolicy;
 import 
org.apache.phoenix.hbase.index.write.recovery.TrackingParallelWriterIndexCommitter;
+import org.apache.phoenix.trace.TracingCompat;
+import org.apache.phoenix.trace.util.NullSpan;
+import org.apache.phoenix.trace.util.Tracing;
+import org.cloudera.htrace.Span;
+import org.cloudera.htrace.Trace;
 
 import com.google.common.collect.Multimap;
 
@@ -134,10 +140,18 @@ public class Indexer extends BaseRegionObserver {
 private static final int INDEX_WAL_COMPRESSION_MINIMUM_SUPPORTED_VERSION = 
VersionUtil
 .encodeVersion(0.94.9);
 
+/**
+ * Raw configuration, for tracing. Coprocessors generally will get a 
subset configuration (if
+ * they are on a per-table basis), so we need the raw one from the server, 
so we can get the
+ * actual configuration keys
+ */
+private Configuration rawConf;
+
   @Override
   public void start(CoprocessorEnvironment e) throws IOException {
   try {
 final RegionCoprocessorEnvironment env = 
(RegionCoprocessorEnvironment) e;
+this.rawConf = env.getRegionServerServices().getConfiguration();
 String serverName = 
env.getRegionServerServices().getServerName().getServerName();
 if (env.getConfiguration().getBoolean(CHECK_VERSION_CONF_KEY, true)) {
   // make sure the right version - combinations are allowed.
@@ -312,12 +326,24 @@ public class Indexer extends BaseRegionObserver {
 // don't worry which one we get
 WALEdit edit = miniBatchOp.getWalEdit(0);
 
+// get the current span, or just use a null-span to avoid a bunch of 
if statements
+Span current = Trace.startSpan(Starting to build index 
updates).getSpan();
+if (current == null) {
+current = NullSpan.INSTANCE;
+}
+
 // get the index updates for all elements in this batch
 CollectionPairMutation, byte[] indexUpdates =
 this.builder.getIndexUpdate(miniBatchOp, mutations.values());
 
+current.addTimelineAnnotation(Built index updates, doing preStep);
+TracingCompat.addAnnotation(current, index update count, 
indexUpdates.size());
+
 // write them, either to WAL or the index tables
 doPre(indexUpdates, edit, durability);
+
+// close the span
+current.stop();
   }
 
   private class MultiMutation extends Mutation {
@@ -458,16 +484,24 @@ public class Indexer extends BaseRegionObserver {
   return;
 }
 
+// get the current span, or just use a null-span to avoid a bunch of 
if statements
+Span current = Trace.startSpan(Completing index writes).getSpan();
+if (current == null) {
+current = NullSpan.INSTANCE;
+}
+
 // there is a little bit of excess here- we iterate all the non-indexed 
kvs for this check first
 // and then do it again later when getting out the index updates. This 
should be pretty minor
 // though, compared to the rest of the runtime
 IndexedKeyValue ikv = getFirstIndexedKeyValue(edit);
+
 /*
  * early exit - we have nothing to write, so we don't need to do anything 
else. NOTE: we don't
  * release the WAL Rolling lock (INDEX_UPDATE_LOCK) since we never take it 
in doPre if there are
  * no index updates.
  */
 if (ikv == null) {
+current.stop();
   return;
 }
 
@@ -483,6 +517,7 @@ public class Indexer extends BaseRegionObserver {
   // references originally - therefore, we just pass in a null factory 
here and use the ones
   // already specified on each reference
   try {
+current.addTimelineAnnotation(Actually doing index update for 
first time);
   writer.writeAndKillYourselfOnFailure(indexUpdates);
   } finally {
 // With a custom kill