blob: 52a348d7a8b0931a9ec73e32359166973d4c07b4 (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "i_blockable_maintenance_job.h"
#include "i_move_operation_limiter.h"
#include <mutex>
#include <unordered_set>
namespace proton {
class BlockableMaintenanceJobConfig;
class DiskMemUsageState;
class IMaintenanceJobRunner;
struct IMoveOperationLimiter;
/**
* Implementation of a maintenance job that can be blocked and unblocked due to various external reasons.
* A blocked job is not executed by the IMaintenanceJobRunner wrapping the job.
* When unblocked for a given reason, the job is scheduled for execution again if it is totally unblocked.
*/
class BlockableMaintenanceJob : public IBlockableMaintenanceJob {
private:
using LockGuard = std::lock_guard<std::mutex>;
using ReasonSet = std::unordered_set<BlockedReason>;
mutable std::mutex _mutex;
ReasonSet _blockReasons;
bool _blocked;
IMaintenanceJobRunner *_runner;
double _resourceLimitFactor;
std::shared_ptr<IMoveOperationLimiter> _moveOpsLimiter;
void updateBlocked(const LockGuard &guard);
protected:
void internalNotifyDiskMemUsage(const DiskMemUsageState &state);
public:
BlockableMaintenanceJob(const vespalib::string &name,
vespalib::duration delay,
vespalib::duration interval);
BlockableMaintenanceJob(const vespalib::string &name,
vespalib::duration delay,
vespalib::duration interval,
const BlockableMaintenanceJobConfig &config);
~BlockableMaintenanceJob() override;
bool isBlocked(BlockedReason reason);
void considerRun();
void onStop() override;
void setBlocked(BlockedReason reason) override;
void unBlock(BlockedReason reason) override;
bool isBlocked() const override;
void registerRunner(IMaintenanceJobRunner *runner) override { _runner = runner; }
IMoveOperationLimiter & getLimiter() { return *_moveOpsLimiter; }
const IMoveOperationLimiter & getLimiter() const { return *_moveOpsLimiter; }
};
}
|