phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] BinShi-SecularBird commented on a change in pull request #419: PHOENIX-4009 Run UPDATE STATISTICS command by using MR integration on…
Date Wed, 09 Jan 2019 03:42:54 GMT
BinShi-SecularBird commented on a change in pull request #419: PHOENIX-4009 Run UPDATE STATISTICS
command by using MR integration on…
URL: https://github.com/apache/phoenix/pull/419#discussion_r246252222
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/schema/stats/DefaultStatisticsCollector.java
 ##########
 @@ -121,92 +110,69 @@
             cachedGuidePosts = null;
         }
     }
-    
-    private void initGuidepostDepth() throws IOException, ClassNotFoundException, SQLException
{
-        // First check is if guidepost info set on statement itself
+
+    @Override
+    public void init() throws IOException {
+        try {
+            initGuidepostDepth();
+            initStatsWriter();
+        } catch (SQLException e) {
+            throw new IOException(e);
+        }
+        LOG.info("Initialization complete for " +
+                this.getClass() + " statistics collector for table " + tableName);
+    }
+
+    /**
+     * Determine the GPW for statistics collection for the table.
+     * The order of priority is as follows
+     * 1. Value provided in UPDATE STATISTICS SQL statement (N/A for MR jobs)
+     * 2. GPW column in SYSTEM.CATALOG for the table is not null
+     * 3. Value from global configuration parameters from hbase-site.xml
+     */
+    private void initGuidepostDepth() throws IOException, SQLException {
         if (guidePostPerRegionBytes != null || guidePostWidthBytes != null) {
-            int guidepostPerRegion = 0;
-            long guidepostWidth = QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_WIDTH_BYTES;
-            if (guidePostPerRegionBytes != null) {
-                guidepostPerRegion = PInteger.INSTANCE.getCodec().decodeInt(guidePostPerRegionBytes,
0, SortOrder.getDefault());
-            }
-            if (guidePostWidthBytes != null) {
-                guidepostWidth = PLong.INSTANCE.getCodec().decodeInt(guidePostWidthBytes,
0, SortOrder.getDefault());
-            }
-            this.guidePostDepth = StatisticsUtil.getGuidePostDepth(guidepostPerRegion, guidepostWidth,
-                env.getRegion().getTableDesc());
+            getGuidePostDepthFromStatement();
+            LOG.info("Guide post depth determined from SQL statement: " + guidePostDepth);
         } else {
-            long guidepostWidth = -1;
-            HTableInterface htable = null;
-            try {
-                // Next check for GUIDE_POST_WIDTH on table
-                htable = env.getTable(
-                    SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES,
env.getConfiguration()));
-                Get get = new Get(ptableKey);
-                get.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
-                Result result = htable.get(get);
-                if (!result.isEmpty()) {
-                    Cell cell = result.listCells().get(0);
-                    guidepostWidth = PLong.INSTANCE.getCodec().decodeLong(cell.getValueArray(),
cell.getValueOffset(), SortOrder.getDefault());
-                } else if (!isViewIndexTable) {
-                    /*
-                     * The table we are collecting stats for is potentially a base table,
or local
-                     * index or a global index. For view indexes, we rely on the the guide
post
-                     * width column in the parent data table's metadata which we already
tried
-                     * retrieving above.
-                     */
-                    try (Connection conn =
-                            QueryUtil.getConnectionOnServer(env.getConfiguration())) {
-                        PTable table = PhoenixRuntime.getTable(conn, tableName);
-                        if (table.getType() == PTableType.INDEX
-                                && table.getIndexType() == IndexType.GLOBAL) {
-                            /*
-                             * For global indexes, we need to get the parentName first and
then
-                             * fetch guide post width configured for the parent table.
-                             */
-                            PName parentName = table.getParentName();
-                            byte[] parentKey =
-                                    SchemaUtil.getTableKeyFromFullName(parentName.getString());
-                            get = new Get(parentKey);
-                            get.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
-                                PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
-                            result = htable.get(get);
-                            if (!result.isEmpty()) {
-                                Cell cell = result.listCells().get(0);
-                                guidepostWidth =
-                                        PLong.INSTANCE.getCodec().decodeLong(cell.getValueArray(),
-                                            cell.getValueOffset(), SortOrder.getDefault());
-                            }
-                        }
-                    }
-
-                }
-            } finally {
-                if (htable != null) {
-                    try {
-                        htable.close();
-                    } catch (IOException e) {
-                        LOG.warn("Failed to close " + htable.getName(), e);
-                    }
-                }
-            }
+            long guidepostWidth = getGuidePostDepthFromSystemCatalog();
             if (guidepostWidth >= 0) {
                 this.guidePostDepth = guidepostWidth;
+                LOG.info("Guide post depth determined from SYSTEM.CATALOG: " + guidePostDepth);
             } else {
                 // Last use global config value
 
 Review comment:
   This comment "// Last use global config value" isn't necessary any more as you have already
commented the order of priority on the function.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message