未验证 提交 cc7f230a 编写于 作者: 刘汉乙 提交者: GitHub

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
上级 281285bd
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#include <sys/vfs.h> #include <sys/vfs.h>
#include <sys/statvfs.h>
#include <libgen.h> #include <libgen.h>
#include "lib/file/ob_file.h" #include "lib/file/ob_file.h"
#include "lib/stat/ob_diagnose_info.h" #include "lib/stat/ob_diagnose_info.h"
...@@ -112,7 +113,7 @@ int ObLogWriteFilePool::init(ObILogDir* log_dir, const int64_t file_size, const ...@@ -112,7 +113,7 @@ int ObLogWriteFilePool::init(ObILogDir* log_dir, const int64_t file_size, const
CLOG_LOG(ERROR, "unexpected type", K(type)); 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)); CLOG_LOG(WARN, "update free quota error", K(ret));
} else { } else {
memset(&ctx_, 0, sizeof(ctx_)); memset(&ctx_, 0, sizeof(ctx_));
...@@ -325,6 +326,7 @@ void ObLogWriteFilePool::try_recycle_file() ...@@ -325,6 +326,7 @@ void ObLogWriteFilePool::try_recycle_file()
int ObLogWriteFilePool::get_total_used_size(int64_t& total_size) const int ObLogWriteFilePool::get_total_used_size(int64_t& total_size) const
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
if (!is_inited_) { if (!is_inited_) {
ret = OB_NOT_INIT; ret = OB_NOT_INIT;
} else { } else {
...@@ -417,19 +419,54 @@ int ObLogWriteFilePool::create_tmp_file(const file_id_t file_id, char* fname, co ...@@ -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 ObLogWriteFilePool::update_free_quota(const char* path, const int64_t percent, const int64_t limit_percent)
{ {
int ret = OB_SUCCESS; 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) { if (NULL == path || 0 > percent || 100 < percent || 0 > limit_percent || 100 < limit_percent) {
ret = OB_INVALID_ARGUMENT; 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; ret = OB_IO_ERROR;
CLOG_LOG(ERROR, "statfs error", K(ret), K(path), K(errno), KERRMSG); CLOG_LOG(ERROR, "calculate free quota error", K(ret), K(path), K(errno), KERRMSG);
} else { }
const int64_t total_size = (int64_t)fsst.f_bsize * (int64_t)fsst.f_blocks; return ret;
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); int ObLogWriteFilePool::init_free_quota(const char* path, const int64_t percent, const int64_t limit_percent)
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)); 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) { if (100 == limit_percent) {
limit_quota = limit_quota - RESERVED_QUOTA_2; limit_quota = limit_quota - RESERVED_QUOTA_2;
} }
......
...@@ -86,6 +86,8 @@ protected: ...@@ -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_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 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 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(); void remove_overquota_file();
int init_raw_file(const int fd, const int64_t start_pos, const int64_t size); 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); int get_recyclable_file(file_id_t& file_id);
......
...@@ -867,6 +867,11 @@ int ObServer::init_config() ...@@ -867,6 +867,11 @@ int ObServer::init_config()
config_.syslog_level.set_value(OB_LOGGER.get_level_str()); 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 (opts_.optstr_ && strlen(opts_.optstr_) > 0) {
if (OB_FAIL(config_.add_extra_config(opts_.optstr_, start_time_))) { if (OB_FAIL(config_.add_extra_config(opts_.optstr_, start_time_))) {
LOG_ERROR("invalid config from cmdline options", K(opts_.optstr_), K(ret)); LOG_ERROR("invalid config from cmdline options", K(opts_.optstr_), K(ret));
...@@ -888,11 +893,6 @@ int ObServer::init_config() ...@@ -888,11 +893,6 @@ int ObServer::init_config()
LOG_INFO("set CLUSTER_ID for rpc", "cluster_id", config_.cluster_id.get_value()); 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 // The command line is specified, subject to the command line
if (opts_.use_ipv6_) { if (opts_.use_ipv6_) {
config_.use_ipv6 = opts_.use_ipv6_; config_.use_ipv6 = opts_.use_ipv6_;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "sql/plan_cache/ob_plan_cache_util.h" #include "sql/plan_cache/ob_plan_cache_util.h"
#include "share/ob_encryption_util.h" #include "share/ob_encryption_util.h"
#include "share/table/ob_ttl_util.h" #include "share/table/ob_ttl_util.h"
#include <sys/statvfs.h>
namespace oceanbase { namespace oceanbase {
using namespace share; using namespace share;
...@@ -476,6 +477,28 @@ bool ObConfigUseLargePagesChecker::check(const ObConfigItem& t) const ...@@ -476,6 +477,28 @@ bool ObConfigUseLargePagesChecker::check(const ObConfigItem& t) const
return is_valid; 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 ObConfigBoolParser::get(const char* str, bool& valid)
{ {
bool value = true; bool value = true;
......
...@@ -417,6 +417,17 @@ private: ...@@ -417,6 +417,17 @@ private:
DISALLOW_COPY_AND_ASSIGN(ObTTLDutyDurationChecker); 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 // config item container
class ObConfigStringKey { class ObConfigStringKey {
public: public:
......
...@@ -52,6 +52,7 @@ const char* const SSL_EXTERNAL_KMS_INFO = "ssl_external_kms_info"; ...@@ -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 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_USAGE_LIMIT_PERCENTAGE = "clog_disk_usage_limit_percentage";
const char* const CLOG_DISK_UTILIZATION_THRESHOLD = "clog_disk_utilization_threshold"; 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_ID = "cluster_id";
const char *const CLUSTER_NAME = "cluster"; const char *const CLUSTER_NAME = "cluster";
......
...@@ -762,6 +762,10 @@ DEF_INT(clog_disk_utilization_threshold, OB_CLUSTER_PARAMETER, "80", "[10, 100)" ...@@ -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. " "clog disk utilization threshold before reuse clog files, should be less than clog_disk_usage_limit_percentage. "
"Range: [10, 100)", "Range: [10, 100)",
ObParameterAttr(Section::TRANS, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); 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]", 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" "If leader_revoke, this replica cannot be elected to leader in election_blacklist_interval"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "lib/thread/thread_mgr.h" #include "lib/thread/thread_mgr.h"
#include "lib/checksum/ob_crc64.h" #include "lib/checksum/ob_crc64.h"
#include "share/ob_thread_mgr.h" #include "share/ob_thread_mgr.h"
#include <sys/statfs.h> #include <sys/statvfs.h>
#include "common/log/ob_log_dir_scanner.h" #include "common/log/ob_log_dir_scanner.h"
#include "share/ob_thread_define.h" #include "share/ob_thread_define.h"
#include "clog/ob_log_file_pool.h" #include "clog/ob_log_file_pool.h"
...@@ -1965,17 +1965,23 @@ int ObLogDiskManager::get_total_disk_space(int64_t& total_space) const ...@@ -1965,17 +1965,23 @@ int ObLogDiskManager::get_total_disk_space(int64_t& total_space) const
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; int ret = OB_SUCCESS;
struct statfs fsst; 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 // try every disk until succeed
for (int32_t i = 0; OB_FAIL(ret) && i < MAX_DISK_COUNT; i++) { for (int32_t i = 0; OB_FAIL(ret) && i < MAX_DISK_COUNT; i++) {
if (OB_LDS_GOOD == disk_slots_[i].get_state()) { if (OB_LDS_GOOD == disk_slots_[i].get_state()) {
if (0 != ::statfs(disk_slots_[i].get_disk_path(), &fsst)) { if (0 != ::statvfs(disk_slots_[i].get_disk_path(), &svfs)) {
ret = OB_IO_ERROR; ret = OB_IO_ERROR;
COMMON_LOG(WARN, "statfs error", K(ret), K(errno), KERRMSG); COMMON_LOG(WARN, "statvfs error", K(ret), K(errno), KERRMSG);
} else { } else {
ret = OB_SUCCESS; ret = OB_SUCCESS;
total_space = (int64_t)fsst.f_bsize * (int64_t)fsst.f_blocks; total_space = ((int64_t)svfs.f_bsize * (int64_t)svfs.f_blocks);
} }
} }
} }
...@@ -1984,6 +1990,8 @@ int ObLogDiskManager::get_total_disk_space_(int64_t& total_space) const ...@@ -1984,6 +1990,8 @@ int ObLogDiskManager::get_total_disk_space_(int64_t& total_space) const
ret = OB_IO_ERROR; ret = OB_IO_ERROR;
COMMON_LOG(ERROR, "all disks fail", K(ret)); COMMON_LOG(ERROR, "all disks fail", K(ret));
} }
}
return ret; return ret;
} }
......
...@@ -33,3 +33,4 @@ config: ...@@ -33,3 +33,4 @@ config:
enable_merge_by_turn: 'FALSE' enable_merge_by_turn: 'FALSE'
syslog_io_bandwidth_limit: '10G' syslog_io_bandwidth_limit: '10G'
enable_async_syslog: 'FALSE' enable_async_syslog: 'FALSE'
log_disk_size: '30G'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册