[FEAT MERGE] datafile auto extend

This commit is contained in:
obdev
2023-04-26 15:45:40 +00:00
committed by ob-robot
parent d525c7da3f
commit 2293904cc0
24 changed files with 350 additions and 34 deletions

View File

@ -19,6 +19,7 @@
#include "share/config/ob_server_config.h"
#include "share/ob_resource_limit.h"
#include "storage/blocksstable/ob_block_sstable_struct.h"
#include "storage/slog/ob_storage_logger_manager.h"
using namespace oceanbase::common;
@ -173,6 +174,7 @@ int ObLocalDevice::init(const common::ObIODOpts &opts)
if (OB_UNLIKELY(!is_inited_)) {
destroy();
}
return ret;
}
@ -1294,6 +1296,43 @@ int64_t ObLocalDevice::get_reserved_block_count() const
return 2;// reserved only for supper block.
}
int64_t ObLocalDevice::get_max_block_count(int64_t reserved_size) const
{
return get_max_block_size(reserved_size) / block_size_;
}
int64_t ObLocalDevice::get_max_block_size(int64_t reserved_size) const
{
int ret = OB_SUCCESS;
int64_t ret_size = 0;
struct statvfs svfs;
const int64_t config_max_file_size = GCONF.datafile_maxsize;
int64_t block_file_max_size = block_file_size_;
if (config_max_file_size < block_file_max_size) {
// auto extend is off
} else if (OB_ISNULL(sstable_dir_)) {
ret = OB_ERR_UNEXPECTED;
SHARE_LOG(WARN, "Failed to get max block size", K(ret), K(sstable_dir_));
} else if (OB_UNLIKELY(0 != statvfs(sstable_dir_, &svfs))) {
ret = convert_sys_errno();
SHARE_LOG(WARN, "Failed to get disk space", K(ret), K(sstable_dir_));
} else {
const int64_t free_space = std::max(0L, (int64_t)(svfs.f_bavail * svfs.f_bsize - reserved_size));
const int64_t max_file_size = block_file_size_ + free_space - reserved_size;
/* when datafile_maxsize is large than current datafile_size, we should return
the Maximun left space that can be extend. */
if (max_file_size > config_max_file_size) {
block_file_max_size = lower_align(config_max_file_size, block_size_);
} else {
block_file_max_size = lower_align(max_file_size, block_size_);
}
}
// still return current block file size when ret=fail
return block_file_max_size;
}
int ObLocalDevice::check_space_full(const int64_t required_size) const
{
int ret = OB_SUCCESS;
@ -1304,9 +1343,17 @@ int ObLocalDevice::check_space_full(const int64_t required_size) const
ret = OB_INVALID_ARGUMENT;
SHARE_LOG(WARN, "invalid argument", K(ret), K(required_size));
} else {
int64_t reserved_size = 4 * 1024 * 1024 * 1024L; // default RESERVED_DISK_SIZE -> 4G
(void) SLOGGERMGR.get_reserved_size(reserved_size);
int64_t max_block_cnt = get_max_block_count(reserved_size);
int64_t actual_free_block_cnt = free_block_cnt_;
if (max_block_cnt > total_block_cnt_) { // auto extend is on
actual_free_block_cnt = max_block_cnt - total_block_cnt_ + free_block_cnt_;
}
const int64_t NO_LIMIT_PERCENT = 100;
const int64_t required_count = required_size / block_size_;
const int64_t free_count = free_block_cnt_ - required_count;
const int64_t free_count = actual_free_block_cnt - required_count;
const int64_t used_percent = 100 - 100 * free_count / total_block_cnt_;
if (GCONF.data_disk_usage_limit_percentage != NO_LIMIT_PERCENT
&& used_percent >= GCONF.data_disk_usage_limit_percentage) {