From e6dca26cce5a5368dbb5c031bc00aa2f8b45dad2 Mon Sep 17 00:00:00 2001 From: Muthu Chidambaram Date: Mon, 4 Mar 2024 06:17:28 +0000 Subject: [PATCH] [PLAT-11862] Turning off background tasks for YBA follower 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 --- .../java/com/yugabyte/yw/commissioner/TaskExecutor.java | 8 ++++++++ .../java/com/yugabyte/yw/common/PlatformScheduler.java | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/managed/src/main/java/com/yugabyte/yw/commissioner/TaskExecutor.java b/managed/src/main/java/com/yugabyte/yw/commissioner/TaskExecutor.java index 62908eb67395..956e8aecabca 100644 --- a/managed/src/main/java/com/yugabyte/yw/commissioner/TaskExecutor.java +++ b/managed/src/main/java/com/yugabyte/yw/commissioner/TaskExecutor.java @@ -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; @@ -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. * @@ -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(); diff --git a/managed/src/main/java/com/yugabyte/yw/common/PlatformScheduler.java b/managed/src/main/java/com/yugabyte/yw/common/PlatformScheduler.java index fad24639b56e..214a3ad7c0a0 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/PlatformScheduler.java +++ b/managed/src/main/java/com/yugabyte/yw/common/PlatformScheduler.java @@ -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; @@ -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 { @@ -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); } },