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

@ -19,44 +19,48 @@ using namespace oceanbase;
using namespace sql;
using namespace common;
using namespace share;
using namespace schema;
using namespace share::schema;
ObSessionValMap::ObSessionValMap()
: block_allocator_(
SMALL_BLOCK_SIZE, common::OB_MALLOC_NORMAL_BLOCK_SIZE, ObMalloc(ObModIds::OB_SQL_SESSION_VAR_MAP)),
var_name_val_map_allocer_(SMALL_BLOCK_SIZE, ObWrapperAllocator(&block_allocator_)),
str_buf1_(ObModIds::OB_SQL_SESSION_VAR_MAP, 64 * 1024),
str_buf2_(ObModIds::OB_SQL_SESSION_VAR_MAP, 64 * 1024),
current_buf_index_(0),
bucket_allocator_(ObModIds::OB_SQL_SESSION_VAR_MAP),
bucket_allocator_wrapper_(&bucket_allocator_),
str_buf_free_threshold_(0),
next_free_mem_point_(str_buf_free_threshold_)
: block_allocator_(SMALL_BLOCK_SIZE, common::OB_MALLOC_NORMAL_BLOCK_SIZE,
ObMalloc(ObModIds::OB_SQL_SESSION_VAR_MAP)),
var_name_val_map_allocer_(SMALL_BLOCK_SIZE, ObWrapperAllocator(&block_allocator_)),
str_buf1_(ObModIds::OB_SQL_SESSION_VAR_MAP, 64 * 1024),
str_buf2_(ObModIds::OB_SQL_SESSION_VAR_MAP, 64 * 1024),
current_buf_index_(0),
bucket_allocator_(ObModIds::OB_SQL_SESSION_VAR_MAP),
bucket_allocator_wrapper_(&bucket_allocator_),
str_buf_free_threshold_(0),
next_free_mem_point_(str_buf_free_threshold_)
{
str_buf_[0] = &str_buf1_;
str_buf_[1] = &str_buf2_;
}
ObSessionValMap::ObSessionValMap(const int64_t block_size, const ObWrapperAllocator& block_allocator)
: block_allocator_(
SMALL_BLOCK_SIZE, common::OB_MALLOC_NORMAL_BLOCK_SIZE, ObMalloc(ObModIds::OB_SQL_SESSION_VAR_MAP)),
var_name_val_map_allocer_(block_size, block_allocator),
str_buf1_(ObModIds::OB_SQL_SESSION_VAR_MAP),
str_buf2_(ObModIds::OB_SQL_SESSION_VAR_MAP),
current_buf_index_(0),
bucket_allocator_(ObModIds::OB_SQL_SESSION_VAR_MAP),
bucket_allocator_wrapper_(&bucket_allocator_),
str_buf_free_threshold_(0),
next_free_mem_point_(str_buf_free_threshold_)
ObSessionValMap::ObSessionValMap(const int64_t block_size,
const ObWrapperAllocator &block_allocator)
: block_allocator_(SMALL_BLOCK_SIZE, common::OB_MALLOC_NORMAL_BLOCK_SIZE,
ObMalloc(ObModIds::OB_SQL_SESSION_VAR_MAP)),
var_name_val_map_allocer_(block_size, block_allocator),
str_buf1_(ObModIds::OB_SQL_SESSION_VAR_MAP),
str_buf2_(ObModIds::OB_SQL_SESSION_VAR_MAP),
current_buf_index_(0),
bucket_allocator_(ObModIds::OB_SQL_SESSION_VAR_MAP),
bucket_allocator_wrapper_(&bucket_allocator_),
str_buf_free_threshold_(0),
next_free_mem_point_(str_buf_free_threshold_)
{
str_buf_[0] = &str_buf1_;
str_buf_[1] = &str_buf2_;
}
ObSessionValMap::~ObSessionValMap()
{}
{
}
int ObSessionValMap::init(int64_t free_threshold, int64_t bucket_num, common::ObWrapperAllocator* bucket_allocator)
int ObSessionValMap::init(int64_t free_threshold,
int64_t bucket_num,
common::ObWrapperAllocator *bucket_allocator)
{
int ret = OB_SUCCESS;
str_buf_free_threshold_ = free_threshold;
@ -65,7 +69,8 @@ int ObSessionValMap::init(int64_t free_threshold, int64_t bucket_num, common::Ob
bucket_allocator_wrapper_.set_alloc(bucket_allocator);
}
if (OB_FAIL(map_.create(bucket_num, &var_name_val_map_allocer_, &bucket_allocator_wrapper_))) {
if (OB_FAIL(map_.create(bucket_num, &var_name_val_map_allocer_,
&bucket_allocator_wrapper_))) {
_OB_LOG(WARN, "fail to create hashmap:ret[%d]", ret);
}
return ret;
@ -87,7 +92,9 @@ void ObSessionValMap::reset()
block_allocator_.reset();
}
int ObSessionValMap::set_refactored(const common::ObString& name, const ObSessionVariable& sess_var)
// 成功则返回OB_SUCCESS
// 其他返回码均表示不成功
int ObSessionValMap::set_refactored(const common::ObString &name, const ObSessionVariable &sess_var)
{
int ret = 0;
ObString tmp_name;
@ -101,9 +108,12 @@ int ObSessionValMap::set_refactored(const common::ObString& name, const ObSessio
} else if (OB_FAIL(free_mem())) {
LOG_WARN("fail to free mem", K(ret));
} else if (OB_FAIL(str_buf_[current_buf_index_]->write_string(name, &tmp_name))) {
LOG_WARN("fail to write name to string_buf", K(ret), K(current_buf_index_), K(name), K(sess_var));
} else if (OB_FAIL(str_buf_[current_buf_index_]->write_obj(sess_var.value_, &tmp_sess_var.value_))) {
LOG_WARN("fail to write obj to string_buf", K(ret), K(current_buf_index_), K(name), K(sess_var));
LOG_WARN("fail to write name to string_buf", K(ret), K(current_buf_index_),
K(name), K(sess_var));
} else if (OB_FAIL(str_buf_[current_buf_index_]->write_obj(sess_var.value_,
&tmp_sess_var.value_))) {
LOG_WARN("fail to write obj to string_buf", K(ret), K(current_buf_index_),
K(name), K(sess_var));
} else if (FALSE_IT(tmp_sess_var.meta_ = sess_var.meta_)) {
} else if (OB_FAIL(map_.set_refactored(tmp_name, tmp_sess_var, 1))) {
LOG_WARN("fail to add item to hash", K(ret), K(tmp_name), K(tmp_sess_var));
@ -111,31 +121,31 @@ int ObSessionValMap::set_refactored(const common::ObString& name, const ObSessio
return ret;
}
int ObSessionValMap::get_refactored(const ObString& name, ObSessionVariable& sess_var) const
int ObSessionValMap::get_refactored(const ObString &name, ObSessionVariable &sess_var) const
{
return map_.get_refactored(name, sess_var);
}
const ObSessionVariable* ObSessionValMap::get(const common::ObString& name) const
const ObSessionVariable *ObSessionValMap::get(const common::ObString &name) const
{
return map_.get(name);
}
int ObSessionValMap::erase_refactored(const ObString& key, ObSessionVariable* sess_var)
int ObSessionValMap::erase_refactored(const ObString &key, ObSessionVariable *sess_var)
{
return map_.erase_refactored(key, sess_var);
}
int ObSessionValMap::assign(const ObSessionValMap& other)
int ObSessionValMap::assign(const ObSessionValMap &other)
{
int ret = OB_SUCCESS;
reuse();
if (other.size() > 0) {
for (VarNameValMap::const_iterator iter = other.map_.begin(); (OB_SUCCESS == ret) && iter != other.map_.end();
iter++) {
const ObString& key = iter->first;
const ObSessionVariable& value = iter->second;
ret = set_refactored(key, value);
for (VarNameValMap::const_iterator iter = other.map_.begin();
(OB_SUCCESS ==ret ) && iter != other.map_.end(); iter++) {
const ObString &key = iter->first;
const ObSessionVariable &value = iter->second;
ret = set_refactored(key, value);
}
}
return ret;
@ -151,20 +161,19 @@ int ObSessionValMap::free_mem()
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("invalid internal args", KP(str_buf_[current_buf_index_]));
} else if (str_buf_[current_buf_index_]->used() > next_free_mem_point_) {
_OB_LOG(DEBUG,
"string buf[%d] is large[%ld], switch string buf",
current_buf_index_,
str_buf_[current_buf_index_]->used());
_OB_LOG(DEBUG, "string buf[%d] is large[%ld], switch string buf", current_buf_index_,
str_buf_[current_buf_index_]->used());
int32_t next_index = (current_buf_index_ == 0 ? 1 : 0);
int64_t count = 0;
if (map_.size() > 0) {
VarNameValMap::iterator iter;
for (iter = map_.begin(); OB_SUCC(ret) && iter != map_.end(); ++iter) {
count++;
for (iter = map_.begin(); OB_SUCC(ret) && iter != map_.end(); ++ iter) {
count ++;
if (OB_FAIL(str_buf_[next_index]->write_string(iter->first, &(iter->first)))) {
_OB_LOG(WARN, "fail to write string:ret[%d]", ret);
} else if (OB_FAIL(str_buf_[next_index]->write_obj(iter->second.value_, &(iter->second.value_)))) {
} else if (OB_FAIL(str_buf_[next_index]->write_obj(iter->second.value_,
&(iter->second.value_)))) {
_OB_LOG(WARN, "fail to write obj:ret[%d]", ret);
}
}
@ -186,9 +195,10 @@ DEFINE_SERIALIZE(ObSessionValMap)
int64_t num_of_entries = size();
OB_UNIS_ENCODE(num_of_entries);
if (OB_SUCC(ret) && num_of_entries > 0) {
for (VarNameValMap::const_iterator iter = map_.begin(); (OB_SUCC(ret)) && iter != map_.end(); iter++) {
const ObString& key = iter->first;
const ObSessionVariable& value = iter->second;
for (VarNameValMap::const_iterator iter = map_.begin();
(OB_SUCC(ret)) && iter != map_.end(); iter++) {
const ObString &key = iter->first;
const ObSessionVariable &value = iter->second;
OB_UNIS_ENCODE(key);
OB_UNIS_ENCODE(value.meta_);
OB_UNIS_ENCODE(value.value_);
@ -216,7 +226,7 @@ DEFINE_DESERIALIZE(ObSessionValMap)
OB_UNIS_DECODE(key);
OB_UNIS_DECODE(value.meta_);
OB_UNIS_DECODE(value.value_);
ret = this->set_refactored(key, value);
ret = this->set_refactored(key,value);
if (OB_FAIL(ret)) {
SQL_ENG_LOG(WARN, "Insert value into map failed", K(ret));
}
@ -230,9 +240,10 @@ DEFINE_GET_SERIALIZE_SIZE(ObSessionValMap)
int64_t num_of_entries = size();
OB_UNIS_ADD_LEN(num_of_entries);
if (num_of_entries > 0) {
for (VarNameValMap::const_iterator iter = map_.begin(); (iter != map_.end()); iter++) {
const ObString& key = iter->first;
const ObSessionVariable& value = iter->second;
for (VarNameValMap::const_iterator iter = map_.begin();
(iter != map_.end()); iter++) {
const ObString &key = iter->first;
const ObSessionVariable &value = iter->second;
OB_UNIS_ADD_LEN(key);
OB_UNIS_ADD_LEN(value.meta_);
OB_UNIS_ADD_LEN(value.value_);