-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathDiskUtilChecker.cpp
67 lines (60 loc) · 2.28 KB
/
DiskUtilChecker.cpp
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
62
63
64
65
66
67
#include "DiskUtilChecker.h"
#include <Disks/DiskFactory.h>
#include <Interpreters/Context.h>
#include <Common/logger_useful.h>
namespace DB
{
namespace ErrorCodes
{
extern const int DISK_USAGE_RATIO_THRESHOLD_EXCEEDED;
}
DiskUtilChecker::DiskUtilChecker(const ContextPtr & global_context_)
: WithContext(global_context_), log(&Poco::Logger::get("AsynchronousMetrics"))
{
max_local_disk_usage_ratio = global_context_->getConfigRef().getDouble("max_local_disk_usage_ratio", 0.9);
updateUtils(global_context_->getDisksMap());
}
/// We don't need hold locks here since we assume local disk volumes can't be changed
/// during the lifecycle of proton. We don't even need make the util atomic since slightly
/// out of sync in different CPUs doesn't matter in this case in practice.
void NO_SANITIZE_THREAD DiskUtilChecker::updateUtils(const DisksMap & disks_map)
{
for (const auto & [name, disk] : disks_map)
{
auto total = disk->getTotalSpace();
auto available = disk->getAvailableSpace();
disk_utils[name] = ((total - available) * 1.0) / total;
}
}
void NO_SANITIZE_THREAD DiskUtilChecker::check(const std::string & disk_name) const
{
if (disk_name.empty())
{
for (const auto & [name, util] : disk_utils)
{
if (util >= max_local_disk_usage_ratio)
{
LOG_ERROR(log, "Disk {} utilization is {}, exceeds the max_disk_util {}", name, util, max_local_disk_usage_ratio);
throw Exception(
ErrorCodes::DISK_USAGE_RATIO_THRESHOLD_EXCEEDED,
"Disk {} utilization is {}, exceeds the max_disk_util {}",
name,
util,
max_local_disk_usage_ratio);
}
}
return;
}
auto it = disk_utils.find(disk_name);
if (it != disk_utils.end() && it->second >= max_local_disk_usage_ratio)
{
LOG_ERROR(log, "Disk {} utilization is {} bytes, exceeds the max_disk_util {}", disk_name, it->second, max_local_disk_usage_ratio);
throw Exception(
ErrorCodes::DISK_USAGE_RATIO_THRESHOLD_EXCEEDED,
"Disk {} utilization is {} bytes, exceeds the max_disk_util {}",
disk_name,
it->second,
max_local_disk_usage_ratio);
}
}
}