[FEAT MERGE] [OBKV] support TTL

Co-authored-by: IHEII <602280108@qq.com>
This commit is contained in:
shenyunlong.syl
2023-09-04 01:10:36 +00:00
committed by ob-robot
parent 464ba63de9
commit b60e4f8d97
133 changed files with 12634 additions and 725 deletions

View File

@ -4309,6 +4309,71 @@ int ObAlterSystemResolverUtil::get_tenant_ids(const ParseNode &t_node, ObIArray<
return ret;
}
int ObTableTTLResolver::resolve(const ParseNode& parse_tree)
{
int ret = OB_SUCCESS;
uint64_t tenant_data_version = 0;;
const uint64_t cur_tenant_id = session_info_->get_effective_tenant_id();
if (OB_FAIL(GET_MIN_DATA_VERSION(cur_tenant_id, tenant_data_version))) {
LOG_WARN("get tenant data version failed", K(ret));
} else if (tenant_data_version < DATA_VERSION_4_2_1_0) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("TTL command is not supported in data version less than 4.2.1", K(ret), K(tenant_data_version));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "TTL command is not supported in data version less than 4.2.1");
} else if (OB_UNLIKELY(T_TABLE_TTL != parse_tree.type_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("type is not T_TABLE_TTL", "type", get_type_name(parse_tree.type_));
} else if (OB_UNLIKELY(NULL == parse_tree.children_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("children should not be null", K(ret));
} else if (OB_UNLIKELY(2 != parse_tree.num_child_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("children num not match", K(ret), "num_child", parse_tree.num_child_);
} else if (OB_ISNULL(session_info_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session info should not be null", K(ret));
} else {
ObTableTTLStmt* ttl_stmt = create_stmt<ObTableTTLStmt>();
const int64_t type = parse_tree.children_[0]->value_;
ParseNode *opt_tenant_list_v2 = parse_tree.children_[1];
if (NULL == ttl_stmt) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("create ObTableTTLStmt failed");
} else if (OB_FAIL(ttl_stmt->set_type(type))) {
LOG_WARN("fail to set param", K(ret), K(type));
} else {
if (NULL == opt_tenant_list_v2) {
if (OB_SYS_TENANT_ID == cur_tenant_id) {
ttl_stmt->set_ttl_all(true);
} else if (OB_FAIL(ttl_stmt->get_tenant_ids().push_back(cur_tenant_id))) {
LOG_WARN("fail to push owned tenant id ", KR(ret), "owned tenant_id", cur_tenant_id);
}
} else if (OB_SYS_TENANT_ID != cur_tenant_id) {
ret = OB_ERR_NO_PRIVILEGE;
LOG_WARN("only sys tenant can add suffix opt(tenant=name)", KR(ret), K(cur_tenant_id));
} else {
bool affect_all = false;
bool affect_all_user = false;
bool affect_all_meta = false;
if (OB_FAIL(Util::resolve_tenant(*opt_tenant_list_v2, cur_tenant_id, ttl_stmt->get_tenant_ids(), affect_all, affect_all_user, affect_all_meta))) {
LOG_WARN("fail to resolve tenant", KR(ret), KP(opt_tenant_list_v2), K(cur_tenant_id));
} else if (affect_all_meta) {
ret = OB_NOT_SUPPORTED;
LOG_WARN("affect_all_meta and affect_all_user is not supported", KR(ret), K(affect_all_meta), K(affect_all_user));
LOG_USER_WARN(OB_NOT_SUPPORTED, "affect_all_meta and affect_all_user");
} else if (affect_all || affect_all_user) {
ttl_stmt->set_ttl_all(true);
}
}
}
if (OB_SUCC(ret)) {
stmt_ = ttl_stmt;
}
}
return ret;
}
int ObBackupManageResolver::resolve(const ParseNode &parse_tree)
{
int ret = OB_SUCCESS;

View File

@ -250,6 +250,7 @@ DEF_SIMPLE_CMD_RESOLVER(ObEnableSqlThrottleResolver);
DEF_SIMPLE_CMD_RESOLVER(ObDisableSqlThrottleResolver);
DEF_SIMPLE_CMD_RESOLVER(ObSetRegionBandwidthResolver);
DEF_SIMPLE_CMD_RESOLVER(ObCancelRestoreResolver);
DEF_SIMPLE_CMD_RESOLVER(ObTableTTLResolver);
#undef DEF_SIMPLE_CMD_RESOLVER

View File

@ -1173,6 +1173,47 @@ private:
share::ObBackupPathString backup_dest_;
ObString encrypt_key_;
};
class ObTableTTLStmt : public ObSystemCmdStmt {
public:
ObTableTTLStmt()
: ObSystemCmdStmt(stmt::T_TABLE_TTL),
type_(obrpc::ObTTLRequestArg::TTL_INVALID_TYPE),
opt_tenant_ids_(),
ttl_all_(false)
{}
virtual ~ObTableTTLStmt()
{}
obrpc::ObTTLRequestArg::TTLRequestType get_type() const
{
return type_;
}
int set_type(const int64_t type)
{
int ret = common::OB_SUCCESS;
if (type < 0 || type >= obrpc::ObTTLRequestArg::TTL_MOVE_TYPE) {
ret = OB_INVALID_ARGUMENT;
COMMON_LOG(WARN, "invalid args", K(type));
} else {
type_ = static_cast<obrpc::ObTTLRequestArg::TTLRequestType>(type);
}
return ret;
}
inline common::ObSArray<uint64_t> &get_tenant_ids() { return opt_tenant_ids_; }
bool is_ttl_all() const { return ttl_all_; }
void set_ttl_all(bool ttl_all) { ttl_all_ = ttl_all; }
TO_STRING_KV(N_STMT_TYPE, ((int)stmt_type_), K_(tenant_id), K_(type),
K_(opt_tenant_ids), K_(ttl_all));
private:
uint64_t tenant_id_;
obrpc::ObTTLRequestArg::TTLRequestType type_;
common::ObSArray<uint64_t> opt_tenant_ids_;
bool ttl_all_;
};
class ObBackupSetEncryptionStmt : public ObSystemCmdStmt
{