Skip to content

Commit

Permalink
PHOENIX-7076 : MetaDataRegionObserver#postOpen hook improvements (#1735)
Browse files Browse the repository at this point in the history
* 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 <divneet.kaur@salesforce.com>
  • Loading branch information
Divneet18 and Divneet18 committed Nov 20, 2023
1 parent b64a973 commit 5128ad0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +74,7 @@
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;
Expand Down Expand Up @@ -109,13 +112,16 @@ 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>();
@GuardedBy("MetaDataRegionObserver.class")
private static Properties rebuildIndexConnectionProps;
// Added for test purposes
private long initialRebuildTaskDelay;
private long statsTruncateTaskDelay;

@Override
public void preClose(final ObserverContext<RegionCoprocessorEnvironment> c,
Expand Down Expand Up @@ -156,6 +162,10 @@ public void start(CoprocessorEnvironment env) throws IOException {
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
Expand Down Expand Up @@ -202,9 +212,14 @@ public Void run() throws Exception {
}
}
};
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.");
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 5128ad0

Please sign in to comment.