phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject [1/3] phoenix git commit: PHOENIX-1496 Further reduce work in StatsCollector.
Date Tue, 02 Dec 2014 18:11:44 GMT
Repository: phoenix
Updated Branches:
  refs/heads/3.0 9313d1052 -> 6cec3465b
  refs/heads/4.0 bd2579542 -> f57eac18e
  refs/heads/master 766eec2b5 -> d6ba63570


PHOENIX-1496 Further reduce work in StatsCollector.


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

Branch: refs/heads/master
Commit: d6ba63570975a276c2ba09fb7f99fdce096bd7b9
Parents: 766eec2
Author: Lars Hofhansl <larsh@apache.org>
Authored: Tue Dec 2 10:03:01 2014 -0800
Committer: Lars Hofhansl <larsh@apache.org>
Committed: Tue Dec 2 10:03:01 2014 -0800

----------------------------------------------------------------------
 .../UngroupedAggregateRegionObserver.java       |  4 ++-
 .../schema/stats/StatisticsCollector.java       | 38 ++++++++++++++------
 .../phoenix/schema/stats/StatisticsScanner.java |  1 -
 3 files changed, 30 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d6ba6357/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index e0ff5b3..ff05dad 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -466,7 +466,9 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver{
                 // when background tasks are updating stats. Instead we track the max timestamp
of
                 // the cells and use that.
                 long clientTimeStamp = useCurrentTime ? TimeKeeper.SYSTEM.getCurrentTime()
: StatisticsCollector.NO_TIMESTAMP;
-                StatisticsCollector stats = new StatisticsCollector(c.getEnvironment(), table.getNameAsString(),
clientTimeStamp);
+                StatisticsCollector stats = new StatisticsCollector(
+                        c.getEnvironment(), table.getNameAsString(),
+                        clientTimeStamp, store.getFamily().getName());
                 internalScanner = stats.createCompactionScanner(c.getEnvironment().getRegion(),
store, scanner);
             } catch (IOException e) {
                 // If we can't reach the stats table, don't interrupt the normal

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d6ba6357/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsCollector.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsCollector.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsCollector.java
index 4123ebe..b943b97 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsCollector.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsCollector.java
@@ -65,8 +65,13 @@ public class StatisticsCollector {
     // Tracks the bytecount per family if it has reached the guidePostsDepth
     private Map<ImmutableBytesPtr, Boolean> familyMap = Maps.newHashMap();
     protected StatisticsWriter statsTable;
+    private Pair<Long,GuidePostsInfo> cachedGps = null;
 
     public StatisticsCollector(RegionCoprocessorEnvironment env, String tableName, long clientTimeStamp)
throws IOException {
+        this(env, tableName, clientTimeStamp, null);
+    }
+
+    public StatisticsCollector(RegionCoprocessorEnvironment env, String tableName, long clientTimeStamp,
byte[] family) throws IOException {
         Configuration config = env.getConfiguration();
         int guidepostPerRegion = config.getInt(QueryServices.STATS_GUIDEPOST_PER_REGION_ATTRIB,

                 QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_PER_REGION);
@@ -76,6 +81,13 @@ public class StatisticsCollector {
         // Get the stats table associated with the current table on which the CP is
         // triggered
         this.statsTable = StatisticsWriter.newWriter(env, tableName, clientTimeStamp);
+        // in a compaction we know the one family ahead of time
+        if (family != null) {
+            ImmutableBytesPtr cfKey = new ImmutableBytesPtr(family);
+            familyMap.put(cfKey, true);
+            cachedGps = new Pair<Long,GuidePostsInfo>(0L,new GuidePostsInfo(0, Collections.<byte[]>emptyList()));
+            guidePostsMap.put(cfKey, cachedGps);
+        }
     }
     
     public long getMaxTimeStamp() {
@@ -147,8 +159,7 @@ public class StatisticsCollector {
         if (logger.isDebugEnabled()) {
             logger.debug("Compaction scanner created for stats");
         }
-        // FIXME: no way to get cf as byte[] ?
-        ImmutableBytesPtr cfKey = new ImmutableBytesPtr(Bytes.toBytes(store.getColumnFamilyName()));
+        ImmutableBytesPtr cfKey = new ImmutableBytesPtr(store.getFamily().getName());
         return getInternalScanner(region, store, s, cfKey);
     }
 
@@ -192,17 +203,22 @@ public class StatisticsCollector {
         maxTimeStamp = Math.max(maxTimeStamp, timestamp);
     }
     
-    @SuppressWarnings("deprecation")
     public void updateStatistic(KeyValue kv) {
-        ImmutableBytesPtr cfKey = new ImmutableBytesPtr(kv.getBuffer(), kv.getFamilyOffset(),
kv.getFamilyLength());
-        familyMap.put(cfKey, true);
-        
         maxTimeStamp = Math.max(maxTimeStamp, kv.getTimestamp());
-        // TODO : This can be moved to an interface so that we could collect guide posts
in different ways
-        Pair<Long,GuidePostsInfo> gps = guidePostsMap.get(cfKey);
-        if (gps == null) {
-            gps = new Pair<Long,GuidePostsInfo>(0L,new GuidePostsInfo(0, Collections.<byte[]>emptyList()));
-            guidePostsMap.put(cfKey, gps);
+
+        Pair<Long,GuidePostsInfo> gps;
+        if (cachedGps == null) {
+            ImmutableBytesPtr cfKey = new ImmutableBytesPtr(kv.getFamilyArray(), kv.getFamilyOffset(),
kv.getFamilyLength());
+            familyMap.put(cfKey, true);
+
+            // TODO : This can be moved to an interface so that we could collect guide posts
in different ways
+            gps = guidePostsMap.get(cfKey);
+            if (gps == null) {
+                gps = new Pair<Long,GuidePostsInfo>(0L,new GuidePostsInfo(0, Collections.<byte[]>emptyList()));
+                guidePostsMap.put(cfKey, gps);
+            }
+        } else {
+            gps = cachedGps;
         }
         int kvLength = kv.getLength();
         long byteCount = gps.getFirst() + kvLength;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d6ba6357/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
index 51b6a6b..dddfc52 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
@@ -40,7 +40,6 @@ public class StatisticsScanner implements InternalScanner {
         this.delegate = delegate;
         this.region = region;
         this.family = family;
-        this.tracker.clear();
     }
 
     @Override


Mime
View raw message