patch 4.0
This commit is contained in:
@ -13,18 +13,22 @@
|
||||
#include "share/config/ob_server_config.h"
|
||||
#include "share/ob_cluster_version.h"
|
||||
#include "lib/string/ob_string.h"
|
||||
namespace oceanbase {
|
||||
namespace common {
|
||||
static int parse_version(const char* str, int* versions, const int64_t size)
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
// for compat, cluster_version str("a.b.c"/"a.b.c.0") which is less than "3.2.3" will be parsed as "a.b.0.c".
|
||||
static int parse_version(const char *str, uint64_t *versions, const int64_t size)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t i = 0;
|
||||
char buf[64] = {0};
|
||||
char* ptr = buf;
|
||||
const char* delim = ".";
|
||||
char* saveptr = NULL;
|
||||
char* token = NULL;
|
||||
const int64_t VERSION_ITEM = 3;
|
||||
char *ptr = buf;
|
||||
const char *delim = ".";
|
||||
char *saveptr = NULL;
|
||||
char *token = NULL;
|
||||
const int64_t VERSION_ITEM = 4;
|
||||
const int64_t LAST_VERSION_ITEM = VERSION_ITEM - 1;
|
||||
|
||||
if (NULL == str || NULL == versions || VERSION_ITEM > size) {
|
||||
COMMON_LOG(WARN, "invalid argument", KP(str), KP(versions), K(size));
|
||||
@ -37,29 +41,59 @@ static int parse_version(const char* str, int* versions, const int64_t size)
|
||||
for (i = 0; i < size; i++) {
|
||||
if (NULL != (token = strtok_r(ptr, delim, &saveptr))) {
|
||||
versions[i] = atoi(token);
|
||||
// COMMON_LOG(INFO, "token", K(versions[i]));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
ptr = NULL;
|
||||
}
|
||||
if (VERSION_ITEM != i) {
|
||||
COMMON_LOG(WARN, "invalid package version", "version", str, K(i), K(VERSION_ITEM));
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
if (VERSION_ITEM < i || LAST_VERSION_ITEM > i) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
COMMON_LOG(WARN, "invalid package version", KR(ret), "version", str, K(i), K(VERSION_ITEM));
|
||||
} else if (i == LAST_VERSION_ITEM) {
|
||||
// padding cluster_versions with 0
|
||||
versions[VERSION_ITEM - 1] = 0;
|
||||
}
|
||||
// cluster version str which is less than "3.2.3"
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (versions[ObClusterVersion::MAJOR_POS] < 3
|
||||
|| (3 == versions[ObClusterVersion::MAJOR_POS]
|
||||
&& versions[ObClusterVersion::MINOR_POS] < 2)
|
||||
|| (3 == versions[ObClusterVersion::MAJOR_POS]
|
||||
&& 2 == versions[ObClusterVersion::MINOR_POS]
|
||||
&& versions[ObClusterVersion::MAJOR_PATCH_POS] < 3)) {
|
||||
if (OB_UNLIKELY(0 != versions[ObClusterVersion::MINOR_PATCH_POS])) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
COMMON_LOG(WARN, "invalid package version", KR(ret), "version", str);
|
||||
} else {
|
||||
// convert "a.b.c" or "a.b.c.0" to "a.b.0.c"
|
||||
versions[ObClusterVersion::MINOR_PATCH_POS] = versions[ObClusterVersion::MAJOR_PATCH_POS];
|
||||
versions[ObClusterVersion::MAJOR_PATCH_POS] = 0;
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_UNLIKELY(
|
||||
versions[ObClusterVersion::MAJOR_POS] > OB_VSN_MAJOR_MASK
|
||||
|| versions[ObClusterVersion::MINOR_POS] > OB_VSN_MINOR_MASK
|
||||
|| versions[ObClusterVersion::MAJOR_PATCH_POS] > OB_VSN_MAJOR_PATCH_MASK
|
||||
|| versions[ObClusterVersion::MINOR_PATCH_POS] > OB_VSN_MINOR_PATCH_MASK)) {
|
||||
ret = OB_SIZE_OVERFLOW;
|
||||
COMMON_LOG(WARN, "invalid package version",
|
||||
KR(ret), "version", str,
|
||||
"major", versions[ObClusterVersion::MAJOR_POS],
|
||||
"minor", versions[ObClusterVersion::MINOR_POS],
|
||||
"major_patch", versions[ObClusterVersion::MAJOR_PATCH_POS],
|
||||
"minor_patch", versions[ObClusterVersion::MINOR_PATCH_POS]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ObClusterVersion::ObClusterVersion() : is_inited_(false), config_(NULL), cluster_version_(0)
|
||||
{
|
||||
cluster_version_ = cal_version(DEF_MAJOR_VERSION, DEF_MINOR_VERSION, DEF_PATCH_VERSION);
|
||||
}
|
||||
|
||||
uint64_t cal_version(const uint64_t major, const uint64_t minor, const uint64_t patch)
|
||||
{
|
||||
return (major << 32) + (minor << 16) + patch;
|
||||
cluster_version_ = cal_version(DEF_MAJOR_VERSION,
|
||||
DEF_MINOR_VERSION,
|
||||
DEF_MAJOR_PATCH_VERSION,
|
||||
DEF_MINOR_PATCH_VERSION);
|
||||
}
|
||||
|
||||
int ObClusterVersion::init(const uint64_t cluster_version)
|
||||
@ -67,8 +101,11 @@ int ObClusterVersion::init(const uint64_t cluster_version)
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
if (is_inited_) {
|
||||
COMMON_LOG(ERROR, "cluster version init twice", K(cluster_version));
|
||||
ret = OB_INIT_TWICE;
|
||||
COMMON_LOG(ERROR, "cluster version init twice", KR(ret), K(cluster_version));
|
||||
} else if (!check_version_valid_(cluster_version)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
COMMON_LOG(WARN, "invalid cluster version", KR(ret), K(cluster_version));
|
||||
} else {
|
||||
ATOMIC_SET(&cluster_version_, cluster_version);
|
||||
COMMON_LOG(INFO, "cluster version inited success", K(cluster_version));
|
||||
@ -78,7 +115,7 @@ int ObClusterVersion::init(const uint64_t cluster_version)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObClusterVersion::init(const ObServerConfig* config)
|
||||
int ObClusterVersion::init(const ObServerConfig *config)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
@ -108,47 +145,65 @@ void ObClusterVersion::destroy()
|
||||
}
|
||||
}
|
||||
|
||||
int64_t ObClusterVersion::to_string(char* buf, const int64_t buf_len) const
|
||||
int64_t ObClusterVersion::to_string(char *buf, const int64_t buf_len) const
|
||||
{
|
||||
int64_t pos = 0;
|
||||
const uint64_t version = ATOMIC_LOAD(&cluster_version_);
|
||||
const uint16_t major = static_cast<const uint16_t>((version >> 32) & 0xffff);
|
||||
const uint16_t minor = static_cast<const uint16_t>((version >> 16) & 0xffff);
|
||||
const uint16_t patch = static_cast<const uint16_t>(version & 0xffff);
|
||||
databuff_printf(buf, buf_len, pos, "%lu(%u, %u, %u)", version, major, minor, patch);
|
||||
return pos;
|
||||
return print_vsn(buf, buf_len, version);
|
||||
}
|
||||
|
||||
int64_t ObClusterVersion::print_vsn(char* buf, const int64_t buf_len, uint64_t version)
|
||||
int64_t ObClusterVersion::print_vsn(char *buf, const int64_t buf_len, uint64_t version)
|
||||
{
|
||||
int64_t pos = 0;
|
||||
const uint16_t major = OB_VSN_MAJOR(version);
|
||||
const uint32_t major = OB_VSN_MAJOR(version);
|
||||
const uint16_t minor = OB_VSN_MINOR(version);
|
||||
const uint16_t patch = OB_VSN_PATCH(version);
|
||||
databuff_printf(buf, buf_len, pos, "%lu(%u, %u, %u)", version, major, minor, patch);
|
||||
const uint8_t major_patch = OB_VSN_MAJOR_PATCH(version);
|
||||
const uint8_t minor_patch = OB_VSN_MINOR_PATCH(version);
|
||||
if (OB_UNLIKELY(!check_version_valid_(version))) {
|
||||
pos = OB_INVALID_INDEX;
|
||||
COMMON_LOG(ERROR, "invalid cluster version", KR(version), K(lbt()));
|
||||
} else if (major < 3
|
||||
|| (3 == major && minor < 2)
|
||||
|| (3 == major && 2 == minor && 0 == major_patch && minor_patch < 3)) {
|
||||
databuff_printf(buf, buf_len, pos, "%lu(%u, %u, %u)", version, major, minor, minor_patch);
|
||||
} else {
|
||||
databuff_printf(buf, buf_len, pos, "%lu(%u, %u, %u, %u)", version, major, minor, major_patch, minor_patch);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
int64_t ObClusterVersion::print_version_str(char* buf, const int64_t buf_len, uint64_t version)
|
||||
int64_t ObClusterVersion::print_version_str(char *buf, const int64_t buf_len, uint64_t version)
|
||||
{
|
||||
int64_t pos = 0;
|
||||
const uint16_t major = OB_VSN_MAJOR(version);
|
||||
const uint32_t major = OB_VSN_MAJOR(version);
|
||||
const uint16_t minor = OB_VSN_MINOR(version);
|
||||
const uint16_t patch = OB_VSN_PATCH(version);
|
||||
databuff_printf(buf, buf_len, pos, "%u.%u.%u", major, minor, patch);
|
||||
const uint8_t major_patch = OB_VSN_MAJOR_PATCH(version);
|
||||
const uint8_t minor_patch = OB_VSN_MINOR_PATCH(version);
|
||||
if (OB_UNLIKELY(!check_version_valid_(version))) {
|
||||
pos = OB_INVALID_INDEX;
|
||||
COMMON_LOG(ERROR, "invalid cluster version", KR(version), K(lbt()));
|
||||
} else if (major < 3
|
||||
|| (3 == major && minor < 2)
|
||||
|| (3 == major && 2 == minor && 0 == major_patch && minor_patch < 3)) {
|
||||
databuff_printf(buf, buf_len, pos, "%u.%u.%u", major, minor, minor_patch);
|
||||
} else {
|
||||
databuff_printf(buf, buf_len, pos, "%u.%u.%u.%u", major, minor, major_patch, minor_patch);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
int ObClusterVersion::refresh_cluster_version(const char* verstr)
|
||||
int ObClusterVersion::refresh_cluster_version(const char *verstr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int items[MAX_VERSION_ITEM] = {0};
|
||||
uint64_t items[MAX_VERSION_ITEM] = {0};
|
||||
if (NULL == verstr) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
} else if (OB_FAIL(parse_version(verstr, items, MAX_VERSION_ITEM))) {
|
||||
// do nothing
|
||||
} else {
|
||||
const uint64_t version = cal_version(items[0], items[1], items[2]);
|
||||
const uint64_t version = cal_version(items[ObClusterVersion::MAJOR_POS],
|
||||
items[ObClusterVersion::MINOR_POS],
|
||||
items[ObClusterVersion::MAJOR_PATCH_POS],
|
||||
items[ObClusterVersion::MINOR_PATCH_POS]);
|
||||
ATOMIC_SET(&cluster_version_, version);
|
||||
COMMON_LOG(INFO, "refresh cluster version", "cluster_version", *this);
|
||||
}
|
||||
@ -170,20 +225,15 @@ int ObClusterVersion::reload_config()
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t ObClusterVersion::get_cluster_version()
|
||||
{
|
||||
return ATOMIC_LOAD(&cluster_version_);
|
||||
}
|
||||
|
||||
void ObClusterVersion::update_cluster_version(const uint64_t cluster_version)
|
||||
{
|
||||
ATOMIC_SET(&cluster_version_, cluster_version);
|
||||
}
|
||||
|
||||
int ObClusterVersion::is_valid(const char* verstr)
|
||||
int ObClusterVersion::is_valid(const char *verstr)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int items[MAX_VERSION_ITEM] = {0};
|
||||
uint64_t items[MAX_VERSION_ITEM] = {0};
|
||||
if (NULL == verstr) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
} else if (OB_FAIL(parse_version(verstr, items, MAX_VERSION_ITEM))) {
|
||||
@ -192,7 +242,7 @@ int ObClusterVersion::is_valid(const char* verstr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObClusterVersion::get_version(const common::ObString& verstr, uint64_t& version)
|
||||
int ObClusterVersion::get_version(const common::ObString &verstr, uint64_t &version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char buf[OB_CLUSTER_VERSION_LENGTH];
|
||||
@ -207,25 +257,51 @@ int ObClusterVersion::get_version(const common::ObString& verstr, uint64_t& vers
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObClusterVersion::get_version(const char* verstr, uint64_t& version)
|
||||
int ObClusterVersion::get_version(const char *verstr, uint64_t &version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int items[MAX_VERSION_ITEM] = {0};
|
||||
uint64_t items[MAX_VERSION_ITEM] = {0};
|
||||
if (NULL == verstr) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
} else if (OB_FAIL(parse_version(verstr, items, MAX_VERSION_ITEM))) {
|
||||
COMMON_LOG(WARN, "invalid version", "version_str", verstr);
|
||||
} else {
|
||||
version = cal_version(items[0], items[1], items[2]);
|
||||
version = cal_version(items[ObClusterVersion::MAJOR_POS],
|
||||
items[ObClusterVersion::MINOR_POS],
|
||||
items[ObClusterVersion::MAJOR_PATCH_POS],
|
||||
items[ObClusterVersion::MINOR_PATCH_POS]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ObClusterVersion& ObClusterVersion::get_instance()
|
||||
bool ObClusterVersion::check_version_valid_(const uint64_t version)
|
||||
{
|
||||
bool bret = true;
|
||||
const uint32_t major = OB_VSN_MAJOR(version);
|
||||
const uint16_t minor = OB_VSN_MINOR(version);
|
||||
const uint8_t major_patch = OB_VSN_MAJOR_PATCH(version);
|
||||
const uint8_t minor_patch = OB_VSN_MINOR_PATCH(version);
|
||||
if (major < 3 || (3 == major && minor < 2)) {
|
||||
// cluster_version is less than "3.2":
|
||||
// - should be "a.b.0.c";
|
||||
bret = (0 == major_patch);
|
||||
} else if (3 == major && 2 == minor) {
|
||||
// cluster_version's prefix is "3.2":
|
||||
// - cluster_version == 3.2.0.0/1/2
|
||||
// - cluster_version >= 3.2.3.x
|
||||
bret = (0 == major_patch && minor_patch <= 2) || (major_patch >= 3);
|
||||
} else {
|
||||
// cluster_version is greator than "3.2"
|
||||
bret = true;
|
||||
}
|
||||
return bret;
|
||||
}
|
||||
|
||||
ObClusterVersion &ObClusterVersion::get_instance()
|
||||
{
|
||||
static ObClusterVersion cluster_version;
|
||||
return cluster_version;
|
||||
}
|
||||
|
||||
} // end namespace common
|
||||
} // end namespace oceanbase
|
||||
} // end namespace common
|
||||
} // end namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user