-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit the disk usage to avoid running out of disk capacity #1702
Changes from all commits
64f1e1a
f6624da
a40ae0e
22ec824
cccc93f
3ae23c1
5dde799
1c14526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
|
||
namespace doris { | ||
|
||
class DataDir; | ||
class Merger; | ||
|
||
// This class is a base class for compaction. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,14 +59,14 @@ DataDir::DataDir(const std::string& path, int64_t capacity_bytes, | |
TabletManager* tablet_manager, TxnManager* txn_manager) | ||
: _path(path), | ||
_capacity_bytes(capacity_bytes), | ||
_available_bytes(0), | ||
_disk_capacity_bytes(0), | ||
_is_used(false), | ||
_tablet_manager(tablet_manager), | ||
_txn_manager(txn_manager), | ||
_cluster_id(-1), | ||
_available_bytes(0), | ||
_used_bytes(0), | ||
_current_shard(0), | ||
_is_used(false), | ||
_to_be_deleted(false), | ||
_current_shard(0), | ||
_test_file_read_buf(nullptr), | ||
_test_file_write_buf(nullptr), | ||
_meta(nullptr) { | ||
|
@@ -100,6 +100,7 @@ Status DataDir::init() { | |
return Status::InternalError("invalid root path: "); | ||
} | ||
|
||
RETURN_IF_ERROR(update_capacity()); | ||
RETURN_IF_ERROR(_init_cluster_id()); | ||
RETURN_IF_ERROR(_init_extension_and_capacity()); | ||
RETURN_IF_ERROR(_init_file_system()); | ||
|
@@ -1057,4 +1058,35 @@ void DataDir::_remove_check_paths_no_lock(const std::set<std::string>& paths) { | |
} | ||
} | ||
|
||
Status DataDir::update_capacity() { | ||
try { | ||
boost::filesystem::path path_name(_path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::filesystem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C++14 not support std::filesystem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C++14 not support std::filesystem |
||
boost::filesystem::space_info path_info = boost::filesystem::space(path_name); | ||
_available_bytes = path_info.available; | ||
if (_disk_capacity_bytes == 0) { | ||
// disk capacity only need to be set once | ||
_disk_capacity_bytes = path_info.capacity; | ||
} | ||
} catch (boost::filesystem::filesystem_error& e) { | ||
LOG(WARNING) << "get space info failed. path: " << _path << " erro:" << e.what(); | ||
return Status::InternalError("get path available capacity failed"); | ||
} | ||
LOG(INFO) << "path: " << _path << " total capacity: " << _disk_capacity_bytes | ||
<< ", available capacity: " << _available_bytes; | ||
|
||
return Status::OK(); | ||
} | ||
|
||
bool DataDir::reach_capacity_limit(int64_t incoming_data_size) { | ||
double used_pct = (_available_bytes + incoming_data_size) / (double) _disk_capacity_bytes; | ||
int64_t left_bytes = _disk_capacity_bytes - _available_bytes - incoming_data_size; | ||
|
||
if (used_pct >= config::storage_flood_stage_usage_percent / 100.0 | ||
&& left_bytes <= config::storage_flood_stage_left_capacity_bytes) { | ||
LOG(WARNING) << "reach capacity limit. used pct: " << used_pct << ", left bytes: " << left_bytes | ||
<< ", path: " << _path; | ||
return true; | ||
} | ||
return false; | ||
} | ||
} // namespace doris |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_capacity_bytes and _disk_capacity_bytes are redundant ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No,
_capacity_bytes
is user specified disk capacity, but it currently not used._disk_capacity_bytes
is the capacity of the disk