Return-Path: X-Original-To: apmail-phoenix-commits-archive@minotaur.apache.org Delivered-To: apmail-phoenix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7BC5918B9A for ; Mon, 14 Mar 2016 15:27:52 +0000 (UTC) Received: (qmail 20659 invoked by uid 500); 14 Mar 2016 15:27:52 -0000 Delivered-To: apmail-phoenix-commits-archive@phoenix.apache.org Received: (qmail 20622 invoked by uid 500); 14 Mar 2016 15:27:51 -0000 Mailing-List: contact commits-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list commits@phoenix.apache.org Received: (qmail 20613 invoked by uid 99); 14 Mar 2016 15:27:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Mar 2016 15:27:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A0CBEDFAB5; Mon, 14 Mar 2016 15:27:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ankit@apache.org To: commits@phoenix.apache.org Message-Id: <231a7930c9404015a0731db88fe94c67@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: phoenix git commit: PHOENIX-2763 rowcount stats not correct after major compaction Date: Mon, 14 Mar 2016 15:27:51 +0000 (UTC) Repository: phoenix Updated Branches: refs/heads/master 5d33fba63 -> cc98e469d 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/cc98e469 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cc98e469 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cc98e469 Branch: refs/heads/master Commit: cc98e469d7bdb41c822fbf4f395d0c796f12be74 Parents: 5d33fba Author: Ankit Singhal Authored: Mon Mar 14 20:57:16 2016 +0530 Committer: Ankit Singhal Committed: Mon Mar 14 20:57:16 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/cc98e469/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 { ListkeyRanges = 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/cc98e469/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 b81d206..0db204d 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 @@ class DefaultStatisticsCollector implements StatisticsCollector { @Override public void collectStatistics(final List results) { Map 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 @@ 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;