mcvsubbu commented on a change in pull request #3622: Start and stop
ControllerPeriodicTasks based on leadership changes
URL: https://github.com/apache/incubator-pinot/pull/3622#discussion_r243671750
##########
File path:
pinot-controller/src/main/java/com/linkedin/pinot/controller/helix/core/periodictask/ControllerPeriodicTask.java
##########
@@ -55,67 +57,90 @@ private static long getRandomInitialDelayInSeconds() {
return MIN_INITIAL_DELAY_IN_SECONDS +
RANDOM.nextInt(MAX_INITIAL_DELAY_IN_SECONDS - MIN_INITIAL_DELAY_IN_SECONDS);
}
+ /**
+ * Reset flags, and call initTask which initializes each individual task
+ */
@Override
- public void init() {
+ public final void init() {
+ _stopPeriodicTask = false;
+ _periodicTaskInProgress = false;
+ initTask();
}
+ /**
+ * Execute the ControllerPeriodicTask.
+ * The _periodicTaskInProgress is enabled at the beginning and disabled
before exiting,
+ * to ensure that we can wait for a task in progress to finish when stop has
been invoked
+ */
@Override
- public void run() {
- if (!isLeader()) {
- skipLeaderTask();
- } else {
- List<String> allTableNames = _pinotHelixResourceManager.getAllTables();
- processLeaderTask(allTableNames);
- }
- }
-
- private void skipLeaderTask() {
- if (_isLeader) {
- LOGGER.info("Current pinot controller lost leadership.");
- _isLeader = false;
- onBecomeNotLeader();
- }
- LOGGER.info("Skip running periodic task: {} on non-leader controller",
_taskName);
- }
+ public final void run() {
+ _periodicTaskInProgress = true;
- private void processLeaderTask(List<String> tables) {
- if (!_isLeader) {
- LOGGER.info("Current pinot controller became leader. Starting {} with
running frequency of {} seconds.",
- _taskName, _intervalInSeconds);
- _isLeader = true;
- onBecomeLeader();
- }
+ List<String> tableNamesWithType =
_pinotHelixResourceManager.getAllTables();
Review comment:
OK, I think the way ControllerPeriodicTask is right now, it has no clue
whether it has been scheduled or not (until the first time it's run method is
called). So, I think the states may not work right. Let us leave it at two
booleans for now.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]