summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-07-09 11:07:32 +0200
committerMartin Polden <mpolden@mpolden.no>2020-07-09 14:51:26 +0200
commitae0051eb76a2600bdcce5a119de06f367be7d164 (patch)
treecdd7137df82d32f3a72fb268a36b059c9a82a7d0 /vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java
parentfa1346f02f2588de9e04fee801a75c63b0cc05db (diff)
Control maintenance jobs with feature flag
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java44
1 files changed, 8 insertions, 36 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java
index 896443117c9..583337203ab 100644
--- a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java
+++ b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/JobControl.java
@@ -5,11 +5,12 @@ import com.yahoo.transaction.Mutex;
import java.util.Collections;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListMap;
/**
- * Provides status and control over running maintenance jobs.
+ * Provides status over running maintenance jobs.
*
* This is multi-thread safe.
*
@@ -20,11 +21,11 @@ public class JobControl {
/** This is not persisted as all nodes start all jobs */
private final Map<String, Maintainer> startedJobs = new ConcurrentSkipListMap<>();
- /** Used to store deactivation in a persistent shared database to make changes take effect on all nodes */
- private final Db db;
+ /** Used for managing shared persistent state, to make changes take effect on all nodes */
+ private final JobControlState state;
- public JobControl(Db db) {
- this.db = db;
+ public JobControl(JobControlState state) {
+ this.state = Objects.requireNonNull(state);
}
/** Notifies this that a job was started */
@@ -39,25 +40,13 @@ public class JobControl {
public Set<String> jobs() { return Collections.unmodifiableSet(startedJobs.keySet()); }
/** Returns a snapshot containing the currently inactive jobs in this */
- public Set<String> inactiveJobs() { return db.readInactiveJobs(); }
+ public Set<String> inactiveJobs() { return state.readInactiveJobs(); }
/** Returns true if this job is not currently deactivated */
public boolean isActive(String jobSimpleClassName) {
return ! inactiveJobs().contains(jobSimpleClassName);
}
- /** Set a job active or inactive */
- public void setActive(String jobSimpleClassName, boolean active) {
- try (var lock = db.lockInactiveJobs()) {
- Set<String> inactiveJobs = db.readInactiveJobs();
- if (active)
- inactiveJobs.remove(jobSimpleClassName);
- else
- inactiveJobs.add(jobSimpleClassName);
- db.writeInactiveJobs(inactiveJobs);
- }
- }
-
/** Run given job (inactive or not) immediately */
public void run(String jobSimpleClassName) {
var job = startedJobs.get(jobSimpleClassName);
@@ -67,24 +56,7 @@ public class JobControl {
/** Acquire lock for running given job */
public Mutex lockJob(String jobSimpleClassName) {
- return db.lockMaintenanceJob(jobSimpleClassName);
- }
-
- /** The database used for managing job state and synchronization */
- public interface Db {
-
- /** Returns the set of jobs that are temporarily inactive */
- Set<String> readInactiveJobs();
-
- /** Make given jobs as inactive */
- void writeInactiveJobs(Set<String> inactiveJobs);
-
- /** Acquire lock for changing jobs */
- Mutex lockInactiveJobs();
-
- /** Acquire lock for running given job */
- Mutex lockMaintenanceJob(String job);
-
+ return state.lockMaintenanceJob(jobSimpleClassName);
}
}