From cc7f230ae51bf13543ee1c96ed58591d8a29f883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B1=89=E4=B9=99?= <32936914+Vendredimatin@users.noreply.github.com> Date: Fri, 26 Aug 2022 11:11:37 +0800 Subject: [PATCH] fixed 990, provide a parameter to assign the size of clog disk (#1003) * fixed , provide a parameter to assign the size of clog disk * fixed , remove redundant log * fixed , modify codes accroding to comment * fixed , change statfs to statvfs * fixed #990, rename clog_disk_limit_size to log_disk_size * fixed #990, merge master and add config to observer.include.yaml --- src/clog/ob_log_file_pool.cpp | 59 ++++++++++++++++++----- src/clog/ob_log_file_pool.h | 2 + src/observer/ob_server.cpp | 10 ++-- src/share/config/ob_config_helper.cpp | 23 +++++++++ src/share/config/ob_config_helper.h | 11 +++++ src/share/config/ob_server_config.h | 1 + src/share/parameter/ob_parameter_seed.ipp | 4 ++ src/share/redolog/ob_log_disk_manager.cpp | 40 +++++++++------ tools/deploy/obd/observer.include.yaml | 1 + 9 files changed, 119 insertions(+), 32 deletions(-) mode change 100644 => 100755 src/clog/ob_log_file_pool.cpp mode change 100644 => 100755 src/clog/ob_log_file_pool.h mode change 100644 => 100755 src/share/config/ob_config_helper.cpp mode change 100644 => 100755 src/share/config/ob_config_helper.h mode change 100644 => 100755 src/share/config/ob_server_config.h mode change 100644 => 100755 src/share/parameter/ob_parameter_seed.ipp mode change 100644 => 100755 src/share/redolog/ob_log_disk_manager.cpp diff --git a/src/clog/ob_log_file_pool.cpp b/src/clog/ob_log_file_pool.cpp old mode 100644 new mode 100755 index e543bdaba9..58eec5e743 --- a/src/clog/ob_log_file_pool.cpp +++ b/src/clog/ob_log_file_pool.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "lib/file/ob_file.h" #include "lib/stat/ob_diagnose_info.h" @@ -112,7 +113,7 @@ int ObLogWriteFilePool::init(ObILogDir* log_dir, const int64_t file_size, const CLOG_LOG(ERROR, "unexpected type", K(type)); } - if (OB_FAIL(update_free_quota(log_dir->get_dir_name(), disk_use_percent, hard_limit_free_quota))) { + if (OB_FAIL(init_free_quota(log_dir->get_dir_name(), disk_use_percent, hard_limit_free_quota))) { CLOG_LOG(WARN, "update free quota error", K(ret)); } else { memset(&ctx_, 0, sizeof(ctx_)); @@ -325,6 +326,7 @@ void ObLogWriteFilePool::try_recycle_file() int ObLogWriteFilePool::get_total_used_size(int64_t& total_size) const { int ret = OB_SUCCESS; + if (!is_inited_) { ret = OB_NOT_INIT; } else { @@ -417,19 +419,54 @@ int ObLogWriteFilePool::create_tmp_file(const file_id_t file_id, char* fname, co int ObLogWriteFilePool::update_free_quota(const char* path, const int64_t percent, const int64_t limit_percent) { int ret = OB_SUCCESS; - struct statfs fsst; + int64_t used_size = 0; + if (NULL == path || 0 > percent || 100 < percent || 0 > limit_percent || 100 < limit_percent) { ret = OB_INVALID_ARGUMENT; - } else if (OB_UNLIKELY(0 != statfs(path, &fsst))) { + } else if (OB_FAIL(get_total_used_size(used_size))) { + ret = OB_IO_ERROR; + COMMON_LOG(ERROR, "get_total_used_size fail", K(ret)); + } else if(OB_FAIL(calculate_free_quota(path, used_size, percent, limit_percent))){ ret = OB_IO_ERROR; - CLOG_LOG(ERROR, "statfs error", K(ret), K(path), K(errno), KERRMSG); - } else { - const int64_t total_size = (int64_t)fsst.f_bsize * (int64_t)fsst.f_blocks; - const int64_t free_quota = - (int64_t)fsst.f_bsize * ((int64_t)fsst.f_blocks * percent / 100LL - (int64_t)(fsst.f_blocks - fsst.f_bavail)); - const int64_t used_size = (int64_t)fsst.f_bsize * (int64_t)(fsst.f_blocks - fsst.f_bavail); - int64_t limit_quota = (int64_t)fsst.f_bsize * - ((int64_t)fsst.f_blocks * limit_percent / 100LL - (int64_t)(fsst.f_blocks - fsst.f_bavail)); + CLOG_LOG(ERROR, "calculate free quota error", K(ret), K(path), K(errno), KERRMSG); + } + return ret; +} + +int ObLogWriteFilePool::init_free_quota(const char* path, const int64_t percent, const int64_t limit_percent) +{ + int ret = OB_SUCCESS; + const int64_t used_size = 0; + + if (NULL == path || 0 > percent || 100 < percent || 0 > limit_percent || 100 < limit_percent) { + ret = OB_INVALID_ARGUMENT; + } else if(OB_FAIL(calculate_free_quota(path, used_size, percent, limit_percent))){ + ret = OB_IO_ERROR; + CLOG_LOG(ERROR, "calculate free quota error", K(ret), K(path), K(errno), KERRMSG); + } + return ret; +} + +int ObLogWriteFilePool::calculate_free_quota(const char* path, const int64_t used_size, const int64_t percent, const int64_t limit_percent) +{ + int ret = OB_SUCCESS; + struct statvfs svfs; + const int64_t log_disk_size = ObServerConfig::get_instance().log_disk_size; + int64_t total_size = 0; + + if (OB_UNLIKELY(0 != statvfs(path, &svfs))) { + ret = OB_IO_ERROR; + CLOG_LOG(ERROR, "statvfs error", K(ret), K(path), K(errno), KERRMSG); + } else{ + if (log_disk_size != 0){ + total_size = log_disk_size; + }else{ + total_size = (int64_t)svfs.f_bsize * (int64_t)svfs.f_blocks; + } + + const int64_t free_quota = total_size * percent / 100LL - used_size; + int64_t limit_quota = total_size * limit_percent / 100LL - used_size; + if (100 == limit_percent) { limit_quota = limit_quota - RESERVED_QUOTA_2; } diff --git a/src/clog/ob_log_file_pool.h b/src/clog/ob_log_file_pool.h old mode 100644 new mode 100755 index 1fb9a93d7e..c43ae53a39 --- a/src/clog/ob_log_file_pool.h +++ b/src/clog/ob_log_file_pool.h @@ -86,6 +86,8 @@ protected: int create_new_file(const int dest_dir_fd, const int dest_file_id, const char* dest_file, int& fd); int create_tmp_file(const file_id_t file_id, char* fname, const int64_t size, int& fd, int& dir_fd); int update_free_quota(const char* dir, const int64_t percent, const int64_t limit_percent); + int init_free_quota(const char* dir, const int64_t percent, const int64_t limit_percent); + int calculate_free_quota(const char* dir, const int64_t used_size, const int64_t percent, const int64_t limit_percent); void remove_overquota_file(); int init_raw_file(const int fd, const int64_t start_pos, const int64_t size); int get_recyclable_file(file_id_t& file_id); diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index 3f0a0be710..33a74ccb3a 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -867,6 +867,11 @@ int ObServer::init_config() config_.syslog_level.set_value(OB_LOGGER.get_level_str()); + if (opts_.data_dir_ && strlen(opts_.data_dir_) > 0) { + config_.data_dir.set_value(opts_.data_dir_); + config_.data_dir.set_version(start_time_); + } + if (opts_.optstr_ && strlen(opts_.optstr_) > 0) { if (OB_FAIL(config_.add_extra_config(opts_.optstr_, start_time_))) { LOG_ERROR("invalid config from cmdline options", K(opts_.optstr_), K(ret)); @@ -888,11 +893,6 @@ int ObServer::init_config() LOG_INFO("set CLUSTER_ID for rpc", "cluster_id", config_.cluster_id.get_value()); } - if (opts_.data_dir_ && strlen(opts_.data_dir_) > 0) { - config_.data_dir.set_value(opts_.data_dir_); - config_.data_dir.set_version(start_time_); - } - // The command line is specified, subject to the command line if (opts_.use_ipv6_) { config_.use_ipv6 = opts_.use_ipv6_; diff --git a/src/share/config/ob_config_helper.cpp b/src/share/config/ob_config_helper.cpp old mode 100644 new mode 100755 index 607b1139e5..b1e74809c7 --- a/src/share/config/ob_config_helper.cpp +++ b/src/share/config/ob_config_helper.cpp @@ -26,6 +26,7 @@ #include "sql/plan_cache/ob_plan_cache_util.h" #include "share/ob_encryption_util.h" #include "share/table/ob_ttl_util.h" +#include namespace oceanbase { using namespace share; @@ -476,6 +477,28 @@ bool ObConfigUseLargePagesChecker::check(const ObConfigItem& t) const return is_valid; } +bool ObConfigLogDiskSizeChecker::check(const ObConfigItem& t) const +{ + bool is_valid = false; + struct statvfs svfs; + const char* path = GCONF.data_dir; + + int64_t log_disk_size = ObConfigCapacityParser::get(t.str(), is_valid); + if (is_valid){ + if (OB_UNLIKELY(0 != statvfs(path, &svfs))) { + is_valid = false; + OB_LOG(ERROR, "statvfs error", K(OB_IO_ERROR), K(path)); + } else { + const int64_t total_disk_size = (int64_t)svfs.f_bsize * (int64_t)svfs.f_blocks; + is_valid = (log_disk_size <= total_disk_size); + if (!is_valid) { + OB_LOG(ERROR,"log_disk_size is greater than total disk size.", K(log_disk_size), K(total_disk_size)); + } + } + } + return is_valid; +} + bool ObConfigBoolParser::get(const char* str, bool& valid) { bool value = true; diff --git a/src/share/config/ob_config_helper.h b/src/share/config/ob_config_helper.h old mode 100644 new mode 100755 index c7d7b4a67c..f2720976e7 --- a/src/share/config/ob_config_helper.h +++ b/src/share/config/ob_config_helper.h @@ -417,6 +417,17 @@ private: DISALLOW_COPY_AND_ASSIGN(ObTTLDutyDurationChecker); }; +class ObConfigLogDiskSizeChecker : public ObConfigChecker { +public: + ObConfigLogDiskSizeChecker() + {} + virtual ~ObConfigLogDiskSizeChecker(){}; + bool check(const ObConfigItem& t) const; + +private: + DISALLOW_COPY_AND_ASSIGN(ObConfigLogDiskSizeChecker); +}; + // config item container class ObConfigStringKey { public: diff --git a/src/share/config/ob_server_config.h b/src/share/config/ob_server_config.h old mode 100644 new mode 100755 index d76f74e04f..533c2d22f3 --- a/src/share/config/ob_server_config.h +++ b/src/share/config/ob_server_config.h @@ -52,6 +52,7 @@ const char* const SSL_EXTERNAL_KMS_INFO = "ssl_external_kms_info"; const char* const ENABLE_ONE_PHASE_COMMIT = "enable_one_phase_commit"; const char* const CLOG_DISK_USAGE_LIMIT_PERCENTAGE = "clog_disk_usage_limit_percentage"; const char* const CLOG_DISK_UTILIZATION_THRESHOLD = "clog_disk_utilization_threshold"; +const char* const LOG_DISK_SIZE = "log_disk_size"; const char *const CLUSTER_ID = "cluster_id"; const char *const CLUSTER_NAME = "cluster"; diff --git a/src/share/parameter/ob_parameter_seed.ipp b/src/share/parameter/ob_parameter_seed.ipp old mode 100644 new mode 100755 index c3ff9c2e7c..a54b0783e8 --- a/src/share/parameter/ob_parameter_seed.ipp +++ b/src/share/parameter/ob_parameter_seed.ipp @@ -762,6 +762,10 @@ DEF_INT(clog_disk_utilization_threshold, OB_CLUSTER_PARAMETER, "80", "[10, 100)" "clog disk utilization threshold before reuse clog files, should be less than clog_disk_usage_limit_percentage. " "Range: [10, 100)", ObParameterAttr(Section::TRANS, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); +DEF_CAP_WITH_CHECKER(log_disk_size, OB_CLUSTER_PARAMETER, "0G", common::ObConfigLogDiskSizeChecker,"[0G,)", + "maximum of clog disk size before reuse clog files, should be less than log_disk_size." + "Range: [0G, +∞)", + ObParameterAttr(Section::TRANS, Source::DEFAULT, EditLevel::STATIC_EFFECTIVE)); DEF_TIME(election_blacklist_interval, OB_CLUSTER_PARAMETER, "1800s", "[0s, 24h]", "If leader_revoke, this replica cannot be elected to leader in election_blacklist_interval" diff --git a/src/share/redolog/ob_log_disk_manager.cpp b/src/share/redolog/ob_log_disk_manager.cpp old mode 100644 new mode 100755 index f6668c7f26..8bc3eddb6d --- a/src/share/redolog/ob_log_disk_manager.cpp +++ b/src/share/redolog/ob_log_disk_manager.cpp @@ -14,7 +14,7 @@ #include "lib/thread/thread_mgr.h" #include "lib/checksum/ob_crc64.h" #include "share/ob_thread_mgr.h" -#include +#include #include "common/log/ob_log_dir_scanner.h" #include "share/ob_thread_define.h" #include "clog/ob_log_file_pool.h" @@ -1965,25 +1965,33 @@ int ObLogDiskManager::get_total_disk_space(int64_t& total_space) const int ObLogDiskManager::get_total_disk_space_(int64_t& total_space) const { - int ret = OB_EAGAIN; - struct statfs fsst; - // try every disk until succeed - for (int32_t i = 0; OB_FAIL(ret) && i < MAX_DISK_COUNT; i++) { - if (OB_LDS_GOOD == disk_slots_[i].get_state()) { - if (0 != ::statfs(disk_slots_[i].get_disk_path(), &fsst)) { - ret = OB_IO_ERROR; - COMMON_LOG(WARN, "statfs error", K(ret), K(errno), KERRMSG); - } else { - ret = OB_SUCCESS; - total_space = (int64_t)fsst.f_bsize * (int64_t)fsst.f_blocks; + int ret = OB_SUCCESS; + const int64_t log_disk_size = ObServerConfig::get_instance().log_disk_size; + + if (log_disk_size != 0){ + total_space = log_disk_size; + }else{ + struct statvfs svfs; + ret = OB_EAGAIN; + // try every disk until succeed + for (int32_t i = 0; OB_FAIL(ret) && i < MAX_DISK_COUNT; i++) { + if (OB_LDS_GOOD == disk_slots_[i].get_state()) { + if (0 != ::statvfs(disk_slots_[i].get_disk_path(), &svfs)) { + ret = OB_IO_ERROR; + COMMON_LOG(WARN, "statvfs error", K(ret), K(errno), KERRMSG); + } else { + ret = OB_SUCCESS; + total_space = ((int64_t)svfs.f_bsize * (int64_t)svfs.f_blocks); + } } } - } - if (OB_FAIL(ret)) { - ret = OB_IO_ERROR; - COMMON_LOG(ERROR, "all disks fail", K(ret)); + if (OB_FAIL(ret)) { + ret = OB_IO_ERROR; + COMMON_LOG(ERROR, "all disks fail", K(ret)); + } } + return ret; } diff --git a/tools/deploy/obd/observer.include.yaml b/tools/deploy/obd/observer.include.yaml index 3da86b2b9a..c07aa86b9a 100644 --- a/tools/deploy/obd/observer.include.yaml +++ b/tools/deploy/obd/observer.include.yaml @@ -33,3 +33,4 @@ config: enable_merge_by_turn: 'FALSE' syslog_io_bandwidth_limit: '10G' enable_async_syslog: 'FALSE' + log_disk_size: '30G' -- GitLab