patch 4.0
This commit is contained in:
@ -12,16 +12,20 @@
|
||||
|
||||
#define USING_LOG_PREFIX STORAGE
|
||||
#include "ob_file_system_router.h"
|
||||
#include "share/config/ob_server_config.h"
|
||||
#include "observer/ob_server_struct.h"
|
||||
#include "storage/ob_file_system_util.h"
|
||||
#include "share/config/ob_server_config.h"
|
||||
#include "share/ob_io_device_helper.h"
|
||||
|
||||
namespace oceanbase {
|
||||
using namespace common;
|
||||
using namespace share;
|
||||
using namespace rootserver;
|
||||
using namespace blocksstable;
|
||||
namespace storage {
|
||||
|
||||
ObFileSystemRouter& ObFileSystemRouter::get_instance()
|
||||
/**
|
||||
* -------------------------------------ObFileSystemRouter-----------------------------------------
|
||||
*/
|
||||
ObFileSystemRouter & ObFileSystemRouter::get_instance()
|
||||
{
|
||||
static ObFileSystemRouter instance_;
|
||||
return instance_;
|
||||
@ -29,7 +33,20 @@ ObFileSystemRouter& ObFileSystemRouter::get_instance()
|
||||
|
||||
ObFileSystemRouter::ObFileSystemRouter()
|
||||
{
|
||||
reset();
|
||||
data_dir_[0] = '\0';
|
||||
slog_dir_[0] = '\0';
|
||||
clog_dir_[0] = '\0';
|
||||
sstable_dir_[0] = '\0';
|
||||
|
||||
clog_file_spec_.retry_write_policy_ = "normal";
|
||||
clog_file_spec_.log_create_policy_ = "normal";
|
||||
clog_file_spec_.log_write_policy_ = "truncate";
|
||||
|
||||
slog_file_spec_.retry_write_policy_ = "normal";
|
||||
slog_file_spec_.log_create_policy_ = "normal";
|
||||
slog_file_spec_.log_write_policy_ = "truncate";
|
||||
svr_seq_ = 0;
|
||||
is_inited_ = false;
|
||||
}
|
||||
|
||||
void ObFileSystemRouter::reset()
|
||||
@ -37,30 +54,47 @@ void ObFileSystemRouter::reset()
|
||||
data_dir_[0] = '\0';
|
||||
slog_dir_[0] = '\0';
|
||||
clog_dir_[0] = '\0';
|
||||
ilog_dir_[0] = '\0';
|
||||
clog_shm_dir_[0] = '\0';
|
||||
ilog_shm_dir_[0] = '\0';
|
||||
sstable_dir_[0] = '\0';
|
||||
|
||||
clog_file_spec_.retry_write_policy_ = "normal";
|
||||
clog_file_spec_.log_create_policy_ = "normal";
|
||||
clog_file_spec_.log_write_policy_ = "truncate";
|
||||
|
||||
slog_file_spec_.retry_write_policy_ = "normal";
|
||||
slog_file_spec_.log_create_policy_ = "normal";
|
||||
slog_file_spec_.log_write_policy_ = "truncate";
|
||||
|
||||
svr_seq_ = 0;
|
||||
is_inited_ = false;
|
||||
}
|
||||
|
||||
int ObFileSystemRouter::init(const char* data_dir, const char* cluster_name, const int64_t cluster_id, const char* zone,
|
||||
const char* svr_ip_port_str)
|
||||
int ObFileSystemRouter::init(
|
||||
const char *data_dir,
|
||||
const char *cluster_name,
|
||||
const int64_t cluster_id,
|
||||
const char *zone,
|
||||
const ObAddr &svr_addr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
if (OB_UNLIKELY(is_inited_)) {
|
||||
ret = OB_INIT_TWICE;
|
||||
LOG_WARN("init twice", K(ret));
|
||||
} else if (OB_ISNULL(data_dir) || OB_ISNULL(cluster_name) || OB_ISNULL(svr_ip_port_str) ||
|
||||
OB_UNLIKELY(cluster_id < 0) || OB_ISNULL(zone)) {
|
||||
} else if (OB_ISNULL(data_dir) || OB_ISNULL(cluster_name) || OB_UNLIKELY(!svr_addr.is_valid())
|
||||
|| OB_UNLIKELY(cluster_id < 0) || OB_ISNULL(zone)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), KP(data_dir), KP(cluster_name), KP(svr_ip_port_str), K(cluster_id), KP(zone));
|
||||
} else if (OB_FAIL(init_shm_file(data_dir))) {
|
||||
LOG_WARN("init shm file fail fail", K(ret), K(data_dir));
|
||||
LOG_WARN("invalid argument", K(ret), KP(data_dir), KP(cluster_name), K(svr_addr),
|
||||
K(cluster_id), KP(zone));
|
||||
} else if (OB_FAIL(init_local_dirs(data_dir))) {
|
||||
LOG_WARN("init local dir fail", K(ret), K(data_dir));
|
||||
} else {
|
||||
clog_file_spec_.retry_write_policy_ = "normal";
|
||||
clog_file_spec_.log_create_policy_ = "normal";
|
||||
clog_file_spec_.log_write_policy_ = "truncate";
|
||||
|
||||
slog_file_spec_.retry_write_policy_ = "normal";
|
||||
slog_file_spec_.log_create_policy_ = "normal";
|
||||
slog_file_spec_.log_write_policy_ = "truncate";
|
||||
is_inited_ = true;
|
||||
}
|
||||
|
||||
@ -70,6 +104,21 @@ int ObFileSystemRouter::init(const char* data_dir, const char* cluster_name, con
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFileSystemRouter::get_tenant_clog_dir(
|
||||
const uint64_t tenant_id,
|
||||
char (&tenant_clog_dir)[common::MAX_PATH_SIZE])
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int pret = 0;
|
||||
pret = snprintf(tenant_clog_dir, MAX_PATH_SIZE, "%s/tenant_%" PRIu64,
|
||||
clog_dir_, tenant_id);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
LOG_ERROR("construct tenant clog path fail", K(ret), K(tenant_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFileSystemRouter::init_local_dirs(const char* data_dir)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
@ -99,30 +148,6 @@ int ObFileSystemRouter::init_local_dirs(const char* data_dir)
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pret = snprintf(ilog_dir_, MAX_PATH_SIZE, "%s/ilog", data_dir);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
LOG_ERROR("construct ilog path fail", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pret = snprintf(clog_shm_dir_, MAX_PATH_SIZE, "%s/clog_shm", data_dir);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
LOG_ERROR("construct clog shm path fail", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pret = snprintf(ilog_shm_dir_, MAX_PATH_SIZE, "%s/ilog_shm", data_dir);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
LOG_ERROR("construct ilog shm path fail", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pret = snprintf(sstable_dir_, MAX_PATH_SIZE, "%s/sstable", data_dir);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
@ -133,65 +158,11 @@ int ObFileSystemRouter::init_local_dirs(const char* data_dir)
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
LOG_INFO("succeed to construct local dir",
|
||||
K(data_dir_),
|
||||
K(slog_dir_),
|
||||
K(clog_dir_),
|
||||
K(ilog_dir_),
|
||||
K(clog_shm_dir_),
|
||||
K(ilog_shm_dir_),
|
||||
K(sstable_dir_));
|
||||
K(data_dir_), K(slog_dir_), K(clog_dir_), K(sstable_dir_));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObFileSystemRouter::init_shm_file(const char* data_dir)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int pret = 0;
|
||||
char cur_work_dir[MAX_PATH_SIZE] = {};
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pret = snprintf(data_dir_, MAX_PATH_SIZE, "%s", data_dir);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
LOG_WARN("copy data_dir fail", K(ret), K(data_dir));
|
||||
}
|
||||
}
|
||||
|
||||
// mmap files
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_ISNULL(::getcwd(cur_work_dir, sizeof(cur_work_dir)))) {
|
||||
ret = common::OB_IO_ERROR;
|
||||
LOG_ERROR("getcwd fail", K(ret), K(errno), KERRMSG);
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pret = snprintf(clog_shm_dir_, MAX_PATH_SIZE, "%s/store/clog_shm", cur_work_dir);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
LOG_ERROR("construct clog shm path fail", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pret = snprintf(ilog_shm_dir_, MAX_PATH_SIZE, "%s/store/ilog_shm", cur_work_dir);
|
||||
if (pret < 0 || pret >= MAX_PATH_SIZE) {
|
||||
ret = OB_BUF_NOT_ENOUGH;
|
||||
LOG_ERROR("construct ilog shm path fail", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
LOG_INFO("succeed to construct shm file path",
|
||||
K(data_dir_),
|
||||
K(slog_dir_),
|
||||
K(clog_dir_),
|
||||
K(ilog_dir_),
|
||||
K(clog_shm_dir_),
|
||||
K(ilog_shm_dir_));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace storage
|
||||
} // namespace oceanbase
|
||||
} // namespace storage
|
||||
} // namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user