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
This commit is contained in:
parent
281285bde0
commit
cc7f230ae5
59
src/clog/ob_log_file_pool.cpp
Normal file → Executable file
59
src/clog/ob_log_file_pool.cpp
Normal file → Executable file
@ -14,6 +14,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <libgen.h>
|
||||
#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;
|
||||
}
|
||||
|
2
src/clog/ob_log_file_pool.h
Normal file → Executable file
2
src/clog/ob_log_file_pool.h
Normal file → Executable file
@ -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);
|
||||
|
@ -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_;
|
||||
|
23
src/share/config/ob_config_helper.cpp
Normal file → Executable file
23
src/share/config/ob_config_helper.cpp
Normal file → Executable file
@ -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 <sys/statvfs.h>
|
||||
|
||||
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;
|
||||
|
11
src/share/config/ob_config_helper.h
Normal file → Executable file
11
src/share/config/ob_config_helper.h
Normal file → Executable file
@ -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:
|
||||
|
1
src/share/config/ob_server_config.h
Normal file → Executable file
1
src/share/config/ob_server_config.h
Normal file → Executable file
@ -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";
|
||||
|
||||
|
4
src/share/parameter/ob_parameter_seed.ipp
Normal file → Executable file
4
src/share/parameter/ob_parameter_seed.ipp
Normal file → Executable file
@ -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"
|
||||
|
40
src/share/redolog/ob_log_disk_manager.cpp
Normal file → Executable file
40
src/share/redolog/ob_log_disk_manager.cpp
Normal file → Executable file
@ -14,7 +14,7 @@
|
||||
#include "lib/thread/thread_mgr.h"
|
||||
#include "lib/checksum/ob_crc64.h"
|
||||
#include "share/ob_thread_mgr.h"
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/statvfs.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -33,3 +33,4 @@ config:
|
||||
enable_merge_by_turn: 'FALSE'
|
||||
syslog_io_bandwidth_limit: '10G'
|
||||
enable_async_syslog: 'FALSE'
|
||||
log_disk_size: '30G'
|
||||
|
Loading…
x
Reference in New Issue
Block a user