Fix a bug which convert cluster id string may be overflow
This commit is contained in:
@ -4333,17 +4333,22 @@ int ObRestoreSourceServiceAttr::set_service_user(const char *user, const char *t
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObRestoreSourceServiceAttr::set_service_tenant_id(const char *tenant_id)
|
int ObRestoreSourceServiceAttr::set_service_tenant_id(const char *tenant_id_str)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
user_.tenant_id_ = atoi(tenant_id);
|
char *p_end = nullptr;
|
||||||
|
if (OB_FAIL(ob_strtoull(tenant_id_str, p_end, user_.tenant_id_))) {
|
||||||
|
LOG_WARN("fail to set service tenant id from string", K(tenant_id_str));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObRestoreSourceServiceAttr::set_service_cluster_id(const char *cluster_id)
|
int ObRestoreSourceServiceAttr::set_service_cluster_id(const char *cluster_id_str)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
user_.cluster_id_ = atoi(cluster_id);
|
if (OB_FAIL(ob_atoll(cluster_id_str, user_.cluster_id_))) {
|
||||||
|
LOG_WARN("fail to set service cluster id from string", K(cluster_id_str));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4572,9 +4577,9 @@ int ObRestoreSourceServiceAttr::gen_service_attr_str(char *buf, const int64_t bu
|
|||||||
LOG_WARN("get compatibility mode str failed");
|
LOG_WARN("get compatibility mode str failed");
|
||||||
} else if (OB_FAIL(get_is_encrypted_str_(is_encrypted_str))) {
|
} else if (OB_FAIL(get_is_encrypted_str_(is_encrypted_str))) {
|
||||||
LOG_WARN("get encrypted str failed");
|
LOG_WARN("get encrypted str failed");
|
||||||
} else if (OB_FAIL(str.assign_fmt("IP_LIST=%s,USER=%s,PASSWORD=%s,TENANT_ID=%ld,CLUSTER_ID=%ld,COMPATIBILITY_MODE=%s",
|
} else if (OB_FAIL(str.assign_fmt("IP_LIST=%s,USER=%s,PASSWORD=%s,TENANT_ID=%ld,CLUSTER_ID=%ld,COMPATIBILITY_MODE=%s,IS_ENCRYPTED=%s",
|
||||||
ip_str.ptr(), user_str.ptr(), passwd_str.ptr(), user_.tenant_id_, user_.cluster_id_, compat_str.ptr()))) {
|
ip_str.ptr(), user_str.ptr(), passwd_str.ptr(), user_.tenant_id_, user_.cluster_id_, compat_str.ptr(), is_encrypted_str.ptr()))) {
|
||||||
LOG_WARN("fail to assign str");
|
LOG_WARN("fail to assign str", K(compat_str), K(is_encrypted_str));
|
||||||
} else if (OB_FAIL(databuff_printf(buf, buf_size, "%.*s", static_cast<int>(str.length()), str.ptr()))) {
|
} else if (OB_FAIL(databuff_printf(buf, buf_size, "%.*s", static_cast<int>(str.length()), str.ptr()))) {
|
||||||
LOG_WARN("fail to print str", K(str));
|
LOG_WARN("fail to print str", K(str));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,3 +36,4 @@ ob_unittest(test_server_log_block_mgr)
|
|||||||
log_unittest(test_role_change_handler)
|
log_unittest(test_role_change_handler)
|
||||||
log_unittest(test_log_mode_mgr)
|
log_unittest(test_log_mode_mgr)
|
||||||
ob_unittest(test_palf_throttling)
|
ob_unittest(test_palf_throttling)
|
||||||
|
ob_unittest(test_net_standby_restore_source)
|
||||||
|
|||||||
106
unittest/logservice/test_net_standby_restore_source.cpp
Normal file
106
unittest/logservice/test_net_standby_restore_source.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OceanBase
|
||||||
|
* OceanBase CE is licensed under Mulan PubL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||||
|
* You may obtain a copy of Mulan PubL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PubL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "src/share/backup/ob_backup_struct.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
namespace oceanbase
|
||||||
|
{
|
||||||
|
using namespace common;
|
||||||
|
using namespace palf;
|
||||||
|
|
||||||
|
namespace unittest
|
||||||
|
{
|
||||||
|
|
||||||
|
TEST(TestRestoreSource, test_net_standby_restore_source)
|
||||||
|
{
|
||||||
|
ObSqlString source_str;
|
||||||
|
char original_str[1000] = "ip_list=127.0.0.1:1001;127.0.0.1:1002,USER=restore_user@primary_tenant,PASSWORD=38344B42344C61477232324839306F3093231FF975D957829E4813195215E5B0,TENANT_ID=9223372036854775807,CLUSTER_ID=4294967295,COMPATIBILITY_MODE=MYSQL,IS_ENCRYPTED=false";
|
||||||
|
char passwd_str[OB_MAX_PASSWORD_LENGTH + 1] = { 0 };
|
||||||
|
source_str.assign(original_str);
|
||||||
|
|
||||||
|
ObSqlString user_and_tenant;
|
||||||
|
ObSqlString ip_list;
|
||||||
|
ObSqlString user_str;
|
||||||
|
ObSqlString tenant_id_str;
|
||||||
|
ObSqlString cluster_id_str;
|
||||||
|
ObSqlString mode_str;
|
||||||
|
|
||||||
|
share::ObRestoreSourceServiceAttr attr, tmp_attr;
|
||||||
|
(void)attr.parse_service_attr_from_str(source_str);
|
||||||
|
|
||||||
|
EXPECT_TRUE(attr.is_valid());
|
||||||
|
ASSERT_EQ(OB_SUCCESS, tmp_attr.assign(attr));
|
||||||
|
EXPECT_TRUE(tmp_attr.is_valid());
|
||||||
|
|
||||||
|
// check attr.user_
|
||||||
|
EXPECT_EQ(attr.user_.tenant_id_, 9223372036854775807);
|
||||||
|
EXPECT_EQ(attr.user_.cluster_id_, 4294967295);
|
||||||
|
EXPECT_EQ(0, STRCMP(attr.user_.user_name_, "restore_user"));
|
||||||
|
EXPECT_EQ(0, STRCMP(attr.user_.tenant_name_, "primary_tenant"));
|
||||||
|
EXPECT_EQ(attr.user_.mode_, ObCompatibilityMode::MYSQL_MODE);
|
||||||
|
EXPECT_TRUE(attr.user_ == tmp_attr.user_);
|
||||||
|
|
||||||
|
|
||||||
|
// check attr
|
||||||
|
common::ObAddr addr1(common::ObAddr::VER::IPV4, "127.0.0.1", 1001);
|
||||||
|
EXPECT_TRUE(attr.addr_.at(0) == addr1);
|
||||||
|
common::ObAddr addr2(common::ObAddr::VER::IPV4, "127.0.0.1", 1002);
|
||||||
|
EXPECT_TRUE(attr.addr_.at(1) == addr2);
|
||||||
|
|
||||||
|
(void)attr.get_ip_list_str_(ip_list);
|
||||||
|
EXPECT_EQ(0, STRCMP(ip_list.ptr(),"127.0.0.1:1001;127.0.0.1:1002"));
|
||||||
|
|
||||||
|
(void)attr.get_user_str_(user_and_tenant);
|
||||||
|
EXPECT_EQ(0, STRCMP(user_and_tenant.ptr(), "restore_user@primary_tenant"));
|
||||||
|
|
||||||
|
(void)attr.get_tenant_id_str_(tenant_id_str);
|
||||||
|
EXPECT_EQ(0, STRCMP(tenant_id_str.ptr(), "9223372036854775807"));
|
||||||
|
|
||||||
|
(void)attr.get_cluster_id_str_(cluster_id_str);
|
||||||
|
EXPECT_EQ(0, STRCMP(cluster_id_str.ptr(), "4294967295"));
|
||||||
|
|
||||||
|
(void)attr.get_compatibility_mode_str_(mode_str);
|
||||||
|
EXPECT_EQ(0, STRCMP(mode_str.ptr(), "MYSQL"));
|
||||||
|
|
||||||
|
|
||||||
|
EXPECT_TRUE(attr.service_user_is_valid());
|
||||||
|
EXPECT_TRUE(attr.service_host_is_valid());
|
||||||
|
EXPECT_TRUE(attr.is_valid());
|
||||||
|
EXPECT_TRUE(attr.compare_addr_(tmp_attr.addr_));
|
||||||
|
EXPECT_TRUE(attr == tmp_attr);
|
||||||
|
|
||||||
|
// check invalid attr
|
||||||
|
share::ObRestoreSourceServiceAttr attr1, attr2, attr3;
|
||||||
|
(void)attr1.assign(attr);
|
||||||
|
attr1.set_service_cluster_id("-1");
|
||||||
|
EXPECT_FALSE(attr1.is_valid());
|
||||||
|
|
||||||
|
(void)attr2.assign(attr);
|
||||||
|
attr2.set_service_tenant_id("0");
|
||||||
|
EXPECT_FALSE(attr2.is_valid());
|
||||||
|
|
||||||
|
(void)attr3.assign(attr);
|
||||||
|
attr3.addr_.destroy();
|
||||||
|
EXPECT_FALSE(attr3.is_valid());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of unittest
|
||||||
|
} // end of oceanbase
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
OB_LOGGER.set_file_name("test_net_standby_restore_source.log", true);
|
||||||
|
OB_LOGGER.set_log_level("INFO");
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user