Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat: add query_disk_info support for replica_server #409

Merged
merged 21 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/dsn/dist/replication/replication.codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ MAKE_EVENT_CODE_AIO(LPC_WRITE_REPLICATION_LOG_SHARED, TASK_PRIORITY_HIGH)
MAKE_EVENT_CODE(LPC_QUERY_CONFIGURATION_ALL, TASK_PRIORITY_HIGH)
MAKE_EVENT_CODE(LPC_MEM_RELEASE, TASK_PRIORITY_COMMON)
MAKE_EVENT_CODE(LPC_CREATE_CHILD, TASK_PRIORITY_COMMON)
MAKE_EVENT_CODE_RPC(RPC_QUERY_DISK_INFO, TASK_PRIORITY_COMMON)
#undef CURRENT_THREAD_POOL

// THREAD_POOL_META_SERVER
Expand Down
209 changes: 209 additions & 0 deletions include/dsn/dist/replication/replication_types.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 43 additions & 44 deletions src/dist/replication/common/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <dsn/utility/utils.h>
#include <dsn/utility/filesystem.h>
#include <thread>
#include <dsn/dist/fmt_logging.h>

namespace dsn {
namespace replication {
Expand Down Expand Up @@ -80,38 +81,39 @@ void dir_node::update_disk_stat()
disk_capacity_mb = info.capacity / 1024 / 1024;
disk_available_mb = info.available / 1024 / 1024;
disk_available_ratio =
disk_capacity_mb == 0 ? 0 : disk_available_mb * 100 / disk_capacity_mb;
ddebug("update disk space succeed: dir = %s, capacity_mb = %" PRId64
", available_mb = %" PRId64 ", available_ratio = %" PRId64 "%%",
full_dir.c_str(),
disk_capacity_mb,
disk_available_mb,
disk_available_ratio);
static_cast<int>(disk_capacity_mb == 0 ? 0 : std::round((double)disk_available_mb *
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
100 / disk_capacity_mb));
ddebug_f("update disk space succeed: dir = {}, capacity_mb = {}, available_mb = {}, "
"available_ratio = {}%",
full_dir.c_str(),
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
disk_capacity_mb,
disk_available_mb,
disk_available_ratio);
} else {
derror("update disk space failed: dir = %s", full_dir.c_str());
derror_f("update disk space failed: dir = {}", full_dir.c_str());
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
}
}

fs_manager::fs_manager(bool for_test)
{
if (!for_test) {
_counter_capacity_total_mb.init_app_counter("eon.replica_stub",
_counter_total_capacity_mb.init_app_counter("eon.replica_stub",
neverchanje marked this conversation as resolved.
Show resolved Hide resolved
"disk.capacity.total(MB)",
COUNTER_TYPE_NUMBER,
"total disk capacity in MB");
_counter_available_total_mb.init_app_counter("eon.replica_stub",
_counter_total_available_mb.init_app_counter("eon.replica_stub",
"disk.available.total(MB)",
COUNTER_TYPE_NUMBER,
"total disk available in MB");
_counter_available_total_ratio.init_app_counter("eon.replica_stub",
_counter_total_available_ratio.init_app_counter("eon.replica_stub",
"disk.available.total.ratio",
COUNTER_TYPE_NUMBER,
"total disk available ratio");
_counter_available_min_ratio.init_app_counter("eon.replica_stub",
_counter_min_available_ratio.init_app_counter("eon.replica_stub",
"disk.available.min.ratio",
COUNTER_TYPE_NUMBER,
"minimal disk available ratio in all disks");
_counter_available_max_ratio.init_app_counter("eon.replica_stub",
_counter_max_available_ratio.init_app_counter("eon.replica_stub",
"disk.available.max.ratio",
COUNTER_TYPE_NUMBER,
"maximal disk available ratio in all disks");
Expand Down Expand Up @@ -279,36 +281,33 @@ bool fs_manager::for_each_dir_node(const std::function<bool(const dir_node &)> &

void fs_manager::update_disk_stat()
{
int64_t capacity_total_mb = 0;
int64_t available_total_mb = 0;
int64_t available_total_ratio = 0;
int64_t available_min_ratio = 100;
int64_t available_max_ratio = 0;
for (auto &n : _dir_nodes) {
n->update_disk_stat();
capacity_total_mb += n->disk_capacity_mb;
available_total_mb += n->disk_available_mb;
if (n->disk_available_ratio < available_min_ratio)
available_min_ratio = n->disk_available_ratio;
if (n->disk_available_ratio > available_max_ratio)
available_max_ratio = n->disk_available_ratio;
reset_disk_stat();
for (auto &dir_node : _dir_nodes) {
dir_node->update_disk_stat();
_total_capacity_mb += dir_node->disk_capacity_mb;
_total_available_mb += dir_node->disk_available_mb;
_min_available_ratio = std::min(dir_node->disk_available_ratio, _min_available_ratio);
_max_available_ratio = std::max(dir_node->disk_available_ratio, _max_available_ratio);
}
available_total_ratio =
capacity_total_mb == 0 ? 0 : available_total_mb * 100 / capacity_total_mb;
ddebug("update disk space succeed: disk_count = %d, capacity_total_mb = %" PRId64
", available_total_mb = %" PRId64 ", available_total_ratio = %" PRId64
"%%, available_min_ratio = %" PRId64 "%%, available_max_ratio = %" PRId64 "%%",
(int)_dir_nodes.size(),
capacity_total_mb,
available_total_mb,
available_total_ratio,
available_min_ratio,
available_max_ratio);
_counter_capacity_total_mb->set(capacity_total_mb);
_counter_available_total_mb->set(available_total_mb);
_counter_available_total_ratio->set(available_total_ratio);
_counter_available_min_ratio->set(available_min_ratio);
_counter_available_max_ratio->set(available_max_ratio);
}
}
_total_available_ratio =
static_cast<int>(_total_capacity_mb == 0 ? 0 : std::round((double)_total_available_mb *
100 / _total_capacity_mb));
compute_disk_density();

ddebug_f("update disk space succeed: disk_count = {}, total_capacity_mb = {}, "
"total_available_mb = {}, total_available_ratio = {}%, min_available_ratio = {}%, "
"max_available_ratio = {}%",
_dir_nodes.size(),
_total_capacity_mb,
_total_available_mb,
_total_available_ratio,
_min_available_ratio,
_max_available_ratio);
_counter_total_capacity_mb->set(_total_capacity_mb);
_counter_total_available_mb->set(_total_available_mb);
_counter_total_available_ratio->set(_total_available_ratio);
_counter_min_available_ratio->set(_min_available_ratio);
_counter_max_available_ratio->set(_max_available_ratio);
}
} // namespace replication
} // namespace dsn
Loading