You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by vj...@apache.org on 2023/12/13 04:19:57 UTC

(phoenix) branch 5.1 updated: PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements (#1735) (#1757)

This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch 5.1
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.1 by this push:
     new b05fac58fa PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements (#1735) (#1757)
b05fac58fa is described below

commit b05fac58faf30e9e81806e1641fa553141ee61ed
Author: Divneet18 <di...@ucsd.edu>
AuthorDate: Wed Dec 13 09:49:52 2023 +0530

    PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements (#1735) (#1757)
---
 .../phoenix/coprocessor/MetaDataRegionObserver.java | 21 ++++++++++++++++++---
 .../org/apache/phoenix/query/QueryServices.java     |  1 +
 .../apache/phoenix/query/QueryServicesOptions.java  |  1 +
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
index 7691aceb50..4708b99af4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataRegionObserver.java
@@ -17,6 +17,8 @@
  */
 package org.apache.phoenix.coprocessor;
 
+import static org.apache.phoenix.query.QueryServices.STATS_COLLECTION_ENABLED;
+import static org.apache.phoenix.query.QueryServicesOptions.DEFAULT_STATS_COLLECTION_ENABLED;
 import static org.apache.phoenix.schema.types.PDataType.TRUE_BYTES;
 
 import java.io.IOException;
@@ -72,6 +74,7 @@ import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.types.PLong;
+import org.apache.phoenix.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.util.IndexUtil;
@@ -109,6 +112,8 @@ public class MetaDataRegionObserver implements RegionObserver,RegionCoprocessor
             QueryConstants.SYSTEM_SCHEMA_NAME_BYTES,
             PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE_BYTES);
     protected ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
+    private ScheduledThreadPoolExecutor truncateTaskExectuor = new ScheduledThreadPoolExecutor(1,
+            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("task-truncated-%d").build());
     private boolean enableRebuildIndex = QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD;
     private long rebuildIndexTimeInterval = QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_INTERVAL;
     private static Map<PName, Long> batchExecutedPerTableMap = new HashMap<PName, Long>();
@@ -116,6 +121,7 @@ public class MetaDataRegionObserver implements RegionObserver,RegionCoprocessor
     private static Properties rebuildIndexConnectionProps;
     // Added for test purposes
     private long initialRebuildTaskDelay;
+    private long statsTruncateTaskDelay;
 
     @Override
     public void preClose(final ObserverContext<RegionCoprocessorEnvironment> c,
@@ -156,6 +162,10 @@ public class MetaDataRegionObserver implements RegionObserver,RegionCoprocessor
                 config.getLong(
                     QueryServices.INDEX_REBUILD_TASK_INITIAL_DELAY,
                     QueryServicesOptions.DEFAULT_INDEX_REBUILD_TASK_INITIAL_DELAY);
+        statsTruncateTaskDelay =
+                config.getLong(
+                        QueryServices.START_TRUNCATE_TASK_DELAY,
+                        QueryServicesOptions.DEFAULT_START_TRUNCATE_TASK_DELAY);
     }
     
     @Override
@@ -202,9 +212,14 @@ public class MetaDataRegionObserver implements RegionObserver,RegionCoprocessor
                 }
             }
         };
-        Thread t = new Thread(r);
-        t.setDaemon(true);
-        t.start();
+
+        if (env.getConfiguration()
+                .getBoolean(STATS_COLLECTION_ENABLED, DEFAULT_STATS_COLLECTION_ENABLED)) {
+            truncateTaskExectuor.schedule(r, statsTruncateTaskDelay, TimeUnit.MILLISECONDS);
+        } else {
+            LOGGER.info("Stats collection is disabled");
+        }
+
 
         if (!enableRebuildIndex) {
             LOGGER.info("Failure Index Rebuild is skipped by configuration.");
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
index 5d40fede5b..d66a07d719 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServices.java
@@ -158,6 +158,7 @@ public interface QueryServices extends SQLCloseable {
     public static final String INDEX_FAILURE_HANDLING_REBUILD_INTERVAL_ATTRIB =
         "phoenix.index.failure.handling.rebuild.interval";
     public static final String INDEX_REBUILD_TASK_INITIAL_DELAY = "phoenix.index.rebuild.task.initial.delay";
+    public static final String START_TRUNCATE_TASK_DELAY = "phoenix.start.truncate.task.delay";
     
     public static final String INDEX_FAILURE_HANDLING_REBUILD_NUMBER_OF_BATCHES_PER_TABLE = "phoenix.index.rebuild.batch.perTable";
     // If index disable timestamp is older than this threshold, then index rebuild task won't attempt to rebuild it
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
index f91425e825..212b31611b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java
@@ -207,6 +207,7 @@ public class QueryServicesOptions {
     public static final boolean DEFAULT_INDEX_FAILURE_THROW_EXCEPTION = true;
     public static final long DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_INTERVAL = 60000; // 60 secs
     public static final long DEFAULT_INDEX_REBUILD_TASK_INITIAL_DELAY = 10000; // 10 secs
+    public static final long DEFAULT_START_TRUNCATE_TASK_DELAY = 20000; // 20 secs
     public static final long DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_BACKWARD_TIME = 1; // 1 ms
     public static final long DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_FORWARD_TIME = 60000 * 3; // 3 mins
     // 30 min rpc timeout * 5 tries, with 2100ms total pause time between retries