Skip to content

Commit

Permalink
[PLAT-11862] Turning off background tasks for YBA follower
Browse files Browse the repository at this point in the history
Summary: Today follower YBA operates almost exactly the same as HA leader, except for API being disabled. We also want any background tasks/threads that are started during AppInit to be skipped for follower YBA, as there isn't a reason it should be operational and it could lead to more corner cases where universes were operated on with incorrect metadata.

Test Plan: Start up follower with diff, ensure that standby promotion and all still works but that AppInit doesn't fire off taskGC and others.

Reviewers: dshubin, sanketh, nsingh, amalyshev

Reviewed By: nsingh, amalyshev

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D32719
  • Loading branch information
mchiddy committed Mar 4, 2024
1 parent 728802b commit e6dca26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.yugabyte.yw.common.ha.PlatformReplicationManager;
import com.yugabyte.yw.forms.ITaskParams;
import com.yugabyte.yw.models.CustomerTask;
import com.yugabyte.yw.models.HighAvailabilityConfig;
import com.yugabyte.yw.models.ScheduleTask;
import com.yugabyte.yw.models.TaskInfo;
import com.yugabyte.yw.models.TaskInfo.State;
Expand Down Expand Up @@ -288,6 +289,12 @@ private void checkTaskExecutorState() {
}
}

private void checkHAFollowerState() {
if (HighAvailabilityConfig.isFollower()) {
throw new IllegalStateException("Can not submit task on HA follower");
}
}

/**
* Instantiates the task for the task class.
*
Expand Down Expand Up @@ -344,6 +351,7 @@ public RunnableTask createRunnableTask(ITask task, UUID taskUUID) {
*/
public UUID submit(RunnableTask runnableTask, ExecutorService taskExecutorService) {
checkTaskExecutorState();
checkHAFollowerState();
checkNotNull(runnableTask, "Task runnable must not be null");
checkNotNull(taskExecutorService, "Task executor service must not be null");
UUID taskUUID = runnableTask.getTaskUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.yugabyte.yw.common;

import com.yugabyte.yw.models.HighAvailabilityConfig;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.inject.Inject;
Expand Down Expand Up @@ -46,7 +47,9 @@ public Cancellable schedule(
synchronized (lock) {
// Synchronized block in shutdown and this should be serialized.
shouldRun =
!shutdownHookHandler.isShutdown() && isRunning.compareAndSet(false, true);
!shutdownHookHandler.isShutdown()
&& !HighAvailabilityConfig.isFollower()
&& isRunning.compareAndSet(false, true);
}
if (shouldRun) {
try {
Expand All @@ -61,7 +64,8 @@ public Cancellable schedule(
}
} else {
log.warn(
"Previous run of scheduler {} is in progress or it is being shut down",
"Previous run of scheduler {} is in progress, is being shut down, or YBA is"
+ " in follower mode.",
name);
}
},
Expand Down

0 comments on commit e6dca26

Please sign in to comment.