patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -10,8 +10,8 @@
* See the Mulan PubL v2 for more details.
*/
#ifndef OCEANBASE_SQL_RESOLVER_DDL_OB_DATABASE_RESOLVER_H
#define OCEANBASE_SQL_RESOLVER_DDL_OB_DATABASE_RESOLVER_H
#ifndef OCEANBASE_SQL_OB_DATABASE_RESOLVER_
#define OCEANBASE_SQL_OB_DATABASE_RESOLVER_
#include "lib/oblog/ob_log.h"
#include "lib/string/ob_sql_string.h"
@ -19,48 +19,50 @@
#include "sql/resolver/ob_stmt.h"
#include "lib/charset/ob_charset.h"
namespace oceanbase {
namespace sql {
namespace oceanbase
{
namespace sql
{
/*关于为什么使用模版而不用继承,请看ddl/ob_tenant_resolver.h的解释*/
template <class T>
class ObDatabaseResolver {
class ObDatabaseResolver
{
public:
ObDatabaseResolver() : alter_option_bitset_(), collation_already_set_(false)
{}
~ObDatabaseResolver(){};
ObDatabaseResolver() :
alter_option_bitset_(),
collation_already_set_(false)
{
}
~ObDatabaseResolver() {};
private:
DISALLOW_COPY_AND_ASSIGN(ObDatabaseResolver);
public:
static int resolve_primary_zone(T* stmt, ParseNode* node);
int resolve_database_options(T* stmt, ParseNode* node);
const common::ObBitSet<>& get_alter_option_bitset() const
{
return alter_option_bitset_;
};
static int resolve_primary_zone(T *stmt, ParseNode *node);
int resolve_database_options(T *stmt, ParseNode *node);
const common::ObBitSet<> &get_alter_option_bitset() const { return alter_option_bitset_; };
private:
int resolve_database_option(T* stmt, ParseNode* node);
int resolve_zone_list(T* stmt, ParseNode* node) const;
int resolve_database_option(T *stmt, ParseNode *node);
int resolve_zone_list(T *stmt, ParseNode *node) const;
private:
common::ObBitSet<> alter_option_bitset_;
// 一条create/alter database语句中可能出现多次charset/collate,用于标记是否已出现过的flag
bool collation_already_set_;
};
template <class T>
int ObDatabaseResolver<T>::resolve_database_options(T* stmt, ParseNode* node)
int ObDatabaseResolver<T>::resolve_database_options(T *stmt, ParseNode *node)
{
int ret = common::OB_SUCCESS;
if (OB_ISNULL(stmt) || OB_ISNULL(node)) {
ret = common::OB_INVALID_ARGUMENT;
OB_LOG(WARN, "invalid argument", K(stmt), K(node));
} else if (OB_UNLIKELY(T_DATABASE_OPTION_LIST != node->type_) || OB_UNLIKELY(0 > node->num_child_) ||
OB_ISNULL(node->children_)) {
} else if (OB_UNLIKELY(T_DATABASE_OPTION_LIST != node->type_)
|| OB_UNLIKELY(0 > node->num_child_)
|| OB_ISNULL(node->children_)) {
ret = common::OB_ERR_UNEXPECTED;
OB_LOG(WARN, "invalid node info", K(node->type_), K(node->num_child_), K(node->children_));
} else {
ParseNode* option_node = NULL;
ParseNode *option_node = NULL;
int32_t num = node->num_child_;
for (int32_t i = 0; ret == common::OB_SUCCESS && i < num; i++) {
option_node = node->children_[i];
@ -73,7 +75,7 @@ int ObDatabaseResolver<T>::resolve_database_options(T* stmt, ParseNode* node)
}
template <class T>
int ObDatabaseResolver<T>::resolve_primary_zone(T* stmt, ParseNode* node)
int ObDatabaseResolver<T>::resolve_primary_zone(T *stmt, ParseNode *node)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(node) || OB_ISNULL(stmt)) {
@ -97,8 +99,10 @@ int ObDatabaseResolver<T>::resolve_primary_zone(T* stmt, ParseNode* node)
}
} else {
common::ObString primary_zone;
primary_zone.assign_ptr(const_cast<char*>(node->str_value_), static_cast<int32_t>(node->str_len_));
if (GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_2000 && primary_zone.empty()) {
primary_zone.assign_ptr(const_cast<char *>(node->str_value_),
static_cast<int32_t>(node->str_len_));
if (GET_MIN_CLUSTER_VERSION() >= CLUSTER_VERSION_2000
&& primary_zone.empty()) {
ret = OB_OP_NOT_ALLOW;
SQL_RESV_LOG(WARN, "set primary_zone empty is not allowed now", K(ret));
LOG_USER_ERROR(OB_OP_NOT_ALLOW, "set primary_zone empty");
@ -110,15 +114,15 @@ int ObDatabaseResolver<T>::resolve_primary_zone(T* stmt, ParseNode* node)
}
template <class T>
int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
int ObDatabaseResolver<T>::resolve_database_option(T *stmt, ParseNode *node)
{
int ret = common::OB_SUCCESS;
ParseNode* option_node = node;
ParseNode *option_node = node;
if (OB_ISNULL(stmt)) {
ret = common::OB_INVALID_ARGUMENT;
OB_LOG(WARN, "invalid argument", K(stmt), K(node));
} else if (OB_ISNULL(option_node)) {
// nothing to do
//nothing to do
} else {
switch (option_node->type_) {
case T_REPLICA_NUM: {
@ -128,7 +132,8 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
OB_LOG(WARN, "Invalid replica_num", K(replica_num));
} else {
if (stmt::T_ALTER_DATABASE == stmt->get_stmt_type()) {
if (OB_FAIL(alter_option_bitset_.add_member(obrpc::ObAlterDatabaseArg::REPLICA_NUM))) {
if (OB_FAIL(alter_option_bitset_.add_member(
obrpc::ObAlterDatabaseArg::REPLICA_NUM))) {
OB_LOG(WARN, "failed to add member to bitset!", K(ret));
}
}
@ -138,7 +143,7 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
case T_PRIMARY_ZONE: {
if (NULL == option_node->children_ || option_node->num_child_ != 1) {
ret = common::OB_INVALID_ARGUMENT;
SQL_RESV_LOG(WARN, "invalid primary_zone argument", K(ret), "num_child", option_node->num_child_);
SQL_RESV_LOG(WARN, "invalid primary_zone argument", K(ret), "num_child", option_node->num_child_);
} else if (OB_FAIL(ObDatabaseResolver<T>::resolve_primary_zone(stmt, option_node->children_[0]))) {
SQL_RESV_LOG(WARN, "failed to resolve primary zone", K(ret));
} else if (stmt::T_ALTER_DATABASE == stmt->get_stmt_type()) {
@ -161,16 +166,16 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
LOG_USER_ERROR(OB_ERR_UNKNOWN_CHARSET, charset.length(), charset.ptr());
} else if (OB_UNLIKELY(common::CS_TYPE_INVALID == collation_type)) {
ret = common::OB_ERR_UNEXPECTED;
SQL_RESV_LOG(WARN,
"all valid charset types should have default collation type",
K(ret),
K(charset_type),
K(collation_type));
} else if (OB_UNLIKELY(collation_already_set_ && stmt->get_charset_type() != charset_type)) {
SQL_RESV_LOG(WARN, "all valid charset types should have default collation type",
K(ret), K(charset_type), K(collation_type));
} else if (OB_UNLIKELY(collation_already_set_
&& stmt->get_charset_type() != charset_type)) {
// mysql执行下面这条sql时会报错,为了行为与mysql一致,resolve时即检查collation/charset不一致的问题
// create database db charset utf8 charset utf16;
ret = OB_ERR_CONFLICTING_DECLARATIONS;
SQL_RESV_LOG(WARN, "charsets mismatch", K(stmt->get_charset_type()), K(charset_type));
const char* charset_name1 = ObCharset::charset_name(stmt->get_charset_type());
const char* charset_name2 = ObCharset::charset_name(charset_type);
const char *charset_name1 = ObCharset::charset_name(stmt->get_charset_type());
const char *charset_name2 = ObCharset::charset_name(charset_type);
LOG_USER_ERROR(OB_ERR_CONFLICTING_DECLARATIONS, charset_name1, charset_name2);
}
} else {
@ -182,14 +187,13 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
LOG_USER_ERROR(OB_ERR_UNKNOWN_COLLATION, collation.length(), collation.ptr());
} else if (OB_UNLIKELY(common::CHARSET_INVALID == charset_type)) {
ret = common::OB_ERR_UNEXPECTED;
SQL_RESV_LOG(WARN,
"all valid collation types should have corresponding charset type",
K(ret),
K(charset_type),
K(collation_type));
} else if (OB_UNLIKELY(collation_already_set_ && stmt->get_charset_type() != charset_type)) {
SQL_RESV_LOG(WARN, "all valid collation types should have corresponding charset type",
K(ret), K(charset_type), K(collation_type));
} else if (OB_UNLIKELY(collation_already_set_
&& stmt->get_charset_type() != charset_type)) {
ret = OB_ERR_COLLATION_MISMATCH;
SQL_RESV_LOG(WARN, "charset and collation mismatch", K(stmt->get_charset_type()), K(charset_type));
SQL_RESV_LOG(WARN, "charset and collation mismatch",
K(stmt->get_charset_type()), K(charset_type));
}
}
if (OB_SUCC(ret)) {
@ -197,7 +201,8 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
stmt->set_collation_type(collation_type);
collation_already_set_ = true;
if (stmt::T_ALTER_DATABASE == stmt->get_stmt_type()) {
if (OB_FAIL(alter_option_bitset_.add_member(obrpc::ObAlterDatabaseArg::COLLATION_TYPE))) {
if (OB_FAIL(alter_option_bitset_.add_member(
obrpc::ObAlterDatabaseArg::COLLATION_TYPE))) {
OB_LOG(WARN, "failed to add member to bitset!", K(ret));
}
}
@ -207,7 +212,8 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
case T_READ_ONLY: {
if (OB_ISNULL(option_node->children_[0])) {
ret = common::OB_ERR_UNEXPECTED;
OB_LOG(WARN, "invalid option node for read_only", K(option_node), K(option_node->children_[0]));
OB_LOG(WARN, "invalid option node for read_only", K(option_node),
K(option_node->children_[0]));
} else if (T_ON == option_node->children_[0]->type_) {
stmt->set_read_only(true);
} else if (T_OFF == option_node->children_[0]->type_) {
@ -217,7 +223,8 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
OB_LOG(WARN, "unknown read only options", K(ret));
}
if (common::OB_SUCCESS == ret && stmt->get_stmt_type() == stmt::T_ALTER_DATABASE) {
if (OB_FAIL(alter_option_bitset_.add_member(obrpc::ObAlterDatabaseArg::READ_ONLY))) {
if (OB_FAIL(alter_option_bitset_.add_member(
obrpc::ObAlterDatabaseArg::READ_ONLY))) {
OB_LOG(WARN, "failed to add member to bitset!", K(ret));
}
}
@ -230,7 +237,8 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
}
if (common::OB_SUCCESS == ret && stmt->get_stmt_type() == stmt::T_ALTER_DATABASE) {
if (OB_FAIL(alter_option_bitset_.add_member(obrpc::ObAlterDatabaseArg::DEFAULT_TABLEGROUP))) {
if (OB_FAIL(alter_option_bitset_.add_member(
obrpc::ObAlterDatabaseArg::DEFAULT_TABLEGROUP))) {
OB_LOG(WARN, "failed to add member to bitset!", K(ret));
}
}
@ -261,7 +269,7 @@ int ObDatabaseResolver<T>::resolve_database_option(T* stmt, ParseNode* node)
}
template <class T>
int ObDatabaseResolver<T>::resolve_zone_list(T* stmt, ParseNode* node) const
int ObDatabaseResolver<T>::resolve_zone_list(T *stmt, ParseNode *node) const
{
int ret = common::OB_SUCCESS;
if (OB_ISNULL(stmt) || OB_ISNULL(node) || T_ZONE_LIST != node->type_ || OB_ISNULL(node->children_)) {
@ -269,7 +277,7 @@ int ObDatabaseResolver<T>::resolve_zone_list(T* stmt, ParseNode* node) const
OB_LOG(WARN, "invalid argument", K(ret), K(stmt), K(node));
} else {
for (int32_t i = 0; ret == common::OB_SUCCESS && i < node->num_child_; i++) {
ParseNode* elem = node->children_[i];
ParseNode *elem = node->children_[i];
if (OB_ISNULL(elem)) {
ret = common::OB_ERR_PARSER_SYNTAX;
OB_LOG(WARN, "Wrong zone", K(node));
@ -292,5 +300,6 @@ int ObDatabaseResolver<T>::resolve_zone_list(T* stmt, ParseNode* node) const
return ret;
}
} // namespace sql
} // namespace oceanbase
#endif // OCEANBASE_SQL_RESOLVER_DDL_OB_DATABASE_RESOLVER_H
} //namespace oceanbase
#endif