You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by tk...@apache.org on 2023/11/20 18:03:02 UTC
(phoenix) branch master updated: PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements (#1735)
This is an automated email from the ASF dual-hosted git repository.
tkhurana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 5128ad0e7d PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements (#1735)
5128ad0e7d is described below
commit 5128ad0e7d95bf45dcca85f9663fd629152f8835
Author: Divneet18 <di...@ucsd.edu>
AuthorDate: Mon Nov 20 23:32:56 2023 +0530
PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements (#1735)
* PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements
* updated import and fixed checkstyle
* fixed checkstyle
* changed varialbe names and few other nits
* Added logger info
---------
Co-authored-by: divneet-kaur <di...@salesforce.com>
---
.../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 567a6e5bd7..b6c11cdc4d 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 e477f28cf4..66759b429f 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
@@ -159,6 +159,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 b39fb788a6..e4a1399e58 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
@@ -221,6 +221,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