aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/i_blockable_maintenance_job.h
blob: 39d281789b618d242bd645b9e3d782aa58155167 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "i_maintenance_job.h"

namespace proton {

/**
 * Interface for a maintenance job that can be blocked and unblocked due to various external reasons.
 * A blocked job is not executed. When unblocked, the job should be scheduled for execution again.
 */
class IBlockableMaintenanceJob : public IMaintenanceJob {
public:
    enum class BlockedReason {
        RESOURCE_LIMITS = 0,
        FROZEN_BUCKET = 1,
        CLUSTER_STATE = 2,
        OUTSTANDING_OPS = 3
    };

    IBlockableMaintenanceJob(const vespalib::string &name,
                             vespalib::duration delay,
                             vespalib::duration interval)
        : IMaintenanceJob(name, delay, interval)
    {}

    /**
     * Block this job due to the given reason.
     * Should be called from the same executor thread as the one used in IMaintenanceJobRunner.
     */
    virtual void setBlocked(BlockedReason reason) = 0;

    /**
     * Unblock this job for the given reason and consider running the job again if not blocked anymore.
     * Can be called from any thread.
     */
    virtual void unBlock(BlockedReason reason) = 0;

    IBlockableMaintenanceJob *asBlockable() override { return this; }
};

}