Fix comparison for min time before doing an update stats and set small min in 
test


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

Branch: refs/heads/3.0
Commit: 66a8808e0bb7f168c649bd2079b54e02542dbf03
Parents: b67b0c1
Author: James Taylor <jtay...@salesforce.com>
Authored: Mon Oct 6 01:16:36 2014 -0700
Committer: James Taylor <jtay...@salesforce.com>
Committed: Mon Oct 6 01:16:36 2014 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/ParallelIteratorsIT.java    |  5 +++--
 .../java/org/apache/phoenix/schema/MetaDataClient.java | 13 ++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/66a8808e/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
index d256641..8e0866b 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelIteratorsIT.java
@@ -65,6 +65,7 @@ public class ParallelIteratorsIT extends 
BaseHBaseManagedTimeIT {
         // Must update config before starting server
         props.put(QueryServices.HISTOGRAM_BYTE_DEPTH_ATTRIB, 
Long.toString(20));
         props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
+        props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, 
Integer.toString(1));
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
     }
 
@@ -83,7 +84,7 @@ public class ParallelIteratorsIT extends 
BaseHBaseManagedTimeIT {
         pstmt = conn.prepareStatement("SELECT COUNT(*) FROM 
STABLE").unwrap(PhoenixPreparedStatement.class);
         pstmt.execute();
         keyRanges = getAllSplits(conn);
-        assertEquals("Unexpected number of splits: " + keyRanges, 5, 
keyRanges.size());
+        assertEquals("Unexpected number of splits: " + keyRanges, 7, 
keyRanges.size());
         assertEquals(newKeyRange(KeyRange.UNBOUND, KMIN), keyRanges.get(0));
         assertEquals(newKeyRange(KMIN, K3), keyRanges.get(1));
         assertEquals(newKeyRange(K3, K4), keyRanges.get(2));
@@ -123,7 +124,7 @@ public class ParallelIteratorsIT extends 
BaseHBaseManagedTimeIT {
         stmt.execute();
         conn.prepareStatement("SELECT COUNT(*) FROM STABLE").executeQuery(); 
         keyRanges = getAllSplits(conn);
-        assertEquals(4, keyRanges.size());
+        assertEquals(7, keyRanges.size());
         upsert(conn, new byte[][] { KMIN2, K5, K12 });
         stmt = conn.prepareStatement("ANALYZE STABLE");
         stmt.execute();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/66a8808e/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 36d70b1..3d5f53c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -48,7 +48,6 @@ import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SALT_BUCKETS;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SORT_ORDER;
 import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA;
 import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE;
-import static 
org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_STATS_TABLE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SEQ_NUM;
@@ -474,7 +473,7 @@ public class MetaDataClient {
 
     public MutationState updateStatistics(UpdateStatisticsStatement 
updateStatisticsStmt) throws SQLException {
         // Check before updating the stats if we have reached the configured 
time to reupdate the stats once again
-        long minTimeForStatsUpdate = connection.getQueryServices().getProps()
+        long msMinBetweenUpdates = connection.getQueryServices().getProps()
                 .getLong(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, 
QueryServicesOptions.DEFAULT_STATS_UPDATE_FREQ_MS);
         ColumnResolver resolver = 
FromCompiler.getResolver(updateStatisticsStmt, connection);
         PTable table = resolver.getTables().get(0).getTable();
@@ -486,15 +485,15 @@ public class MetaDataClient {
         connection.getQueryServices().clearCacheForTable(tenantIdBytes,
                 
Bytes.toBytes(SchemaUtil.getSchemaNameFromFullName(physicalName.getString())),
                 
Bytes.toBytes(SchemaUtil.getTableNameFromFullName(physicalName.getString())), 
clientTS);
-        String query = "SELECT CURRENT_DATE(),"+ LAST_STATS_UPDATE_TIME + " 
FROM " + SYSTEM_CATALOG_SCHEMA
-                + "." + SYSTEM_STATS_TABLE + " WHERE " + PHYSICAL_NAME + "='" 
+ physicalName.getString() + "' AND " + COLUMN_FAMILY
+        String query = "SELECT CURRENT_DATE(),"+ LAST_STATS_UPDATE_TIME + " 
FROM " + PhoenixDatabaseMetaData.SYSTEM_STATS_NAME
+                + " WHERE " + PHYSICAL_NAME + "='" + physicalName.getString() 
+ "' AND " + COLUMN_FAMILY
                 + " IS NULL AND " + REGION_NAME + " IS NULL";
         ResultSet rs = connection.createStatement().executeQuery(query);
-        long lastUpdatedTime = 0;
+        long msSinceLastUpdate = Long.MAX_VALUE;
         if (rs.next() && rs.getDate(2) != null) {
-            lastUpdatedTime = rs.getDate(1).getTime() - 
rs.getDate(2).getTime();
+            msSinceLastUpdate = rs.getDate(1).getTime() - 
rs.getDate(2).getTime();
         }
-        if (minTimeForStatsUpdate  > lastUpdatedTime) {
+        if (msSinceLastUpdate >= msMinBetweenUpdates) {
             // Here create the select query.
             String countQuery = "SELECT /*+ NO_CACHE */ count(*) FROM " + 
table.getName().getString();
             PhoenixStatement statement = (PhoenixStatement) 
connection.createStatement();

Reply via email to