Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 6c4c13b01 -> 7d67e205d


PHOENIX-2763 rowcount stats not correct after major compaction


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 7d67e205d92f511964c81760b7b32a238d18357f
Parents: 6c4c13b
Author: Ankit Singhal <[email protected]>
Authored: Mon Mar 14 20:58:42 2016 +0530
Committer: Ankit Singhal <[email protected]>
Committed: Mon Mar 14 20:58:42 2016 +0530

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/StatsCollectorIT.java   | 13 ++++++++++---
 .../schema/stats/DefaultStatisticsCollector.java       |  6 +++++-
 2 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7d67e205/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
index bc575fd..2284ee2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StatsCollectorIT.java
@@ -39,6 +39,7 @@ import java.util.Properties;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
@@ -366,11 +367,13 @@ public class StatsCollectorIT extends 
StatsCollectorAbstractIT {
             props.setProperty(QueryServices.MIN_STATS_UPDATE_FREQ_MS_ATTRIB, 
minStatsUpdateFreq.toString());
         }
         conn = DriverManager.getConnection(getUrl(), props);
-        conn.createStatement().execute("CREATE TABLE " + tableName + "(k 
CHAR(1) PRIMARY KEY, v INTEGER) " + HColumnDescriptor.KEEP_DELETED_CELLS + "=" 
+ Boolean.FALSE);
-        stmt = conn.prepareStatement("UPSERT INTO " + tableName + " 
VALUES(?,?)");
+        conn.createStatement().execute("CREATE TABLE " + tableName + "(k 
CHAR(1) PRIMARY KEY, v INTEGER, w INTEGER) "
+                + HColumnDescriptor.KEEP_DELETED_CELLS + "=" + Boolean.FALSE);
+        stmt = conn.prepareStatement("UPSERT INTO " + tableName + " 
VALUES(?,?,?)");
         for (int i = 0; i < nRows; i++) {
             stmt.setString(1, Character.toString((char) ('a' + i)));
             stmt.setInt(2, i);
+            stmt.setInt(3, i);
             stmt.executeUpdate();
         }
         conn.commit();
@@ -392,7 +395,7 @@ public class StatsCollectorIT extends 
StatsCollectorAbstractIT {
         List<KeyRange>keyRanges = getAllSplits(conn, tableName);
         assertEquals(nRows+1, keyRanges.size());
         
-        int nDeletedRows = conn.createStatement().executeUpdate("DELETE FROM " 
+ tableName + " WHERE V < 5");
+        int nDeletedRows = conn.createStatement().executeUpdate("DELETE FROM " 
+ tableName + " WHERE V < " + nRows / 2);
         conn.commit();
         assertEquals(5, nDeletedRows);
         
@@ -411,6 +414,10 @@ public class StatsCollectorIT extends 
StatsCollectorAbstractIT {
             keyRanges = getAllSplits(conn, tableName);
         }
         assertEquals(nRows/2+1, keyRanges.size());
+        ResultSet rs = conn.createStatement().executeQuery("SELECT 
SUM(GUIDE_POSTS_ROW_COUNT) FROM "
+                + PhoenixDatabaseMetaData.SYSTEM_STATS_NAME + " WHERE 
PHYSICAL_NAME='" + tableName + "'");
+        rs.next();
+        assertEquals(nRows - nDeletedRows, rs.getLong(1));
         
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7d67e205/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/DefaultStatisticsCollector.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/DefaultStatisticsCollector.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/DefaultStatisticsCollector.java
index 7b519a0..9d47358 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/DefaultStatisticsCollector.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/DefaultStatisticsCollector.java
@@ -166,6 +166,7 @@ public class DefaultStatisticsCollector implements 
StatisticsCollector {
     @Override
     public void collectStatistics(final List<Cell> results) {
         Map<ImmutableBytesPtr, Boolean> famMap = Maps.newHashMap();
+        boolean incrementRow = true;
         for (Cell cell : results) {
             KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
             maxTimeStamp = Math.max(maxTimeStamp, kv.getTimestamp());
@@ -185,7 +186,10 @@ public class DefaultStatisticsCollector implements 
StatisticsCollector {
                 }
             } else {
                 gps = cachedGps;
-                cachedGps.getSecond().incrementRowCount();
+                if (incrementRow) {
+                    cachedGps.getSecond().incrementRowCount();
+                    incrementRow = false;
+                }
             }
             int kvLength = kv.getLength();
             long byteCount = gps.getFirst() + kvLength;

Reply via email to