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

@ -12,61 +12,80 @@
#include "ob_row_cache.h"
#include "lib/stat/ob_diagnose_info.h"
#include "storage/ob_sstable.h"
namespace oceanbase {
namespace oceanbase
{
using namespace common;
using namespace storage;
namespace blocksstable {
namespace blocksstable
{
/**
* -----------------------------------------------------ObRowCacheKey------------------------------------------------------
*/
ObRowCacheKey::ObRowCacheKey()
: table_id_(0), file_id_(0), rowkey_size_(0), data_version_(-1), table_type_(ObITable::MAX_TABLE_TYPE)
: rowkey_size_(0),
tenant_id_(0),
tablet_id_(),
data_version_(-1),
table_type_(ObITable::MAX_TABLE_TYPE),
rowkey_(),
datum_utils_(nullptr)
{
rowkey_.assign(NULL, 0);
}
ObRowCacheKey::ObRowCacheKey(const uint64_t table_id, const int64_t file_id, const ObStoreRowkey& rowkey,
const int64_t data_version, const ObITable::TableType table_type)
ObRowCacheKey::ObRowCacheKey(const uint64_t tenant_id,
const ObTabletID &tablet_id,
const ObDatumRowkey &rowkey,
const ObStorageDatumUtils &datum_utils,
const int64_t data_version,
const ObITable::TableType table_type)
{
table_id_ = table_id;
file_id_ = file_id;
rowkey_size_ = rowkey.get_deep_copy_size();
tenant_id_ = tenant_id;
tablet_id_ = tablet_id;
data_version_ = data_version;
table_type_ = table_type;
rowkey.hash();
rowkey_ = rowkey;
datum_utils_ = &datum_utils;
rowkey_size_ = rowkey.get_deep_copy_size();
}
ObRowCacheKey::~ObRowCacheKey()
{}
uint64_t ObRowCacheKey::hash() const
{
uint64_t hash_val = static_cast<uint64_t>(table_type_);
hash_val = common::murmurhash(&table_id_, sizeof(table_id_), hash_val);
hash_val = common::murmurhash(&file_id_, sizeof(file_id_), hash_val);
hash_val = common::murmurhash(&data_version_, sizeof(data_version_), hash_val);
if (NULL != rowkey_.get_obj_ptr() && 0 < rowkey_.get_obj_cnt()) {
hash_val = rowkey_.murmurhash(hash_val);
}
return hash_val;
}
bool ObRowCacheKey::operator==(const ObIKVCacheKey& other) const
int ObRowCacheKey::hash(uint64_t &hash_val) const
{
bool ret = true;
const ObRowCacheKey& other_key = reinterpret_cast<const ObRowCacheKey&>(other);
ret = table_id_ == other_key.table_id_;
ret &= file_id_ == other_key.file_id_;
ret &= (rowkey_size_ == other_key.rowkey_size_);
ret &= (data_version_ == other_key.data_version_);
ret &= (table_type_ == other_key.table_type_);
if (ret && rowkey_size_ > 0) {
if (NULL != rowkey_.get_obj_ptr() && NULL != other_key.rowkey_.get_obj_ptr()) {
ret = rowkey_.simple_equal(other_key.rowkey_);
} else {
ret = false;
int ret = OB_SUCCESS;
hash_val = static_cast<uint64_t>(table_type_);
hash_val = common::murmurhash(&tenant_id_, sizeof(tenant_id_), hash_val);
hash_val = common::murmurhash(&tablet_id_, sizeof(tablet_id_), hash_val);
hash_val = common::murmurhash(&data_version_, sizeof(data_version_), hash_val);
if (rowkey_.is_valid()) {
if (OB_ISNULL(datum_utils_)) {
ret = OB_ERR_UNEXPECTED;
STORAGE_LOG(WARN, "Unexpected error for null datum utils", K(ret), K(*this));
} else if (OB_FAIL(rowkey_.hash(*datum_utils_, hash_val))) {
STORAGE_LOG(WARN, "Failed to calc hash value for datum rowkey", K(ret), K(rowkey_));
}
}
return ret;
}
int ObRowCacheKey::equal(const ObIKVCacheKey &other, bool &equal) const
{
int ret = OB_SUCCESS;
const ObRowCacheKey &other_key = reinterpret_cast<const ObRowCacheKey&>(other);
equal = (rowkey_size_ == other_key.rowkey_size_);
equal &= tenant_id_ == other_key.tenant_id_;
equal &= tablet_id_ == other_key.tablet_id_;
equal &= (data_version_ == other_key.data_version_);
equal &= (table_type_ == other_key.table_type_);
if (equal && rowkey_size_ > 0) {
const ObStorageDatumUtils *datum_utils = (nullptr != datum_utils_) ? datum_utils_ : other_key.datum_utils_;
if (OB_ISNULL(datum_utils)) {
ret = OB_INVALID_ARGUMENT;
STORAGE_LOG(WARN, "Invalid argument to compare row cachekey", K(ret), K(*this), K(other_key));
} else if (OB_FAIL(rowkey_.equal(other_key.rowkey_, *datum_utils, equal))) {
STORAGE_LOG(WARN, "Failed to check rowkey cache key equal", K(ret), K(rowkey_), K(other_key));
}
}
return ret;
@ -74,7 +93,7 @@ bool ObRowCacheKey::operator==(const ObIKVCacheKey& other) const
uint64_t ObRowCacheKey::get_tenant_id() const
{
return extract_tenant_id(table_id_);
return tenant_id_;
}
int64_t ObRowCacheKey::size() const
@ -82,7 +101,7 @@ int64_t ObRowCacheKey::size() const
return sizeof(*this) + rowkey_size_;
}
int ObRowCacheKey::deep_copy(char* buf, const int64_t buf_len, ObIKVCacheKey*& key) const
int ObRowCacheKey::deep_copy(char *buf, const int64_t buf_len, ObIKVCacheKey *&key) const
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(NULL == buf || buf_len < size())) {
@ -92,12 +111,13 @@ int ObRowCacheKey::deep_copy(char* buf, const int64_t buf_len, ObIKVCacheKey*& k
ret = OB_INVALID_DATA;
STORAGE_LOG(WARN, "Invalid row cache key, ", K(*this), K(ret));
} else {
blocksstable::ObRowCacheKey* pkey = new (buf) ObRowCacheKey();
pkey->table_id_ = table_id_;
pkey->file_id_ = file_id_;
blocksstable::ObRowCacheKey *pkey = new (buf) ObRowCacheKey();
pkey->tenant_id_ = tenant_id_;
pkey->tablet_id_ = tablet_id_;
pkey->data_version_ = data_version_;
pkey->table_type_ = table_type_;
if (NULL != rowkey_.get_obj_ptr() && 0 < rowkey_size_) {
pkey->datum_utils_ = nullptr;
if (rowkey_.is_valid() && 0 < rowkey_size_) {
ObRawBufAllocatorWrapper temp_buf(buf + sizeof(*this), rowkey_size_);
if (OB_FAIL(rowkey_.deep_copy(pkey->rowkey_, temp_buf))) {
STORAGE_LOG(WARN, "Fail to deep copy rowkey, ", K(ret));
@ -116,56 +136,40 @@ int ObRowCacheKey::deep_copy(char* buf, const int64_t buf_len, ObIKVCacheKey*& k
bool ObRowCacheKey::is_valid() const
{
return OB_LIKELY(0 != table_id_ && rowkey_size_ > 0 && data_version_ > -1 &&
(ObITable::is_minor_sstable(table_type_) || ObITable::is_major_sstable(table_type_)) &&
NULL != rowkey_.get_obj_ptr());
return OB_LIKELY(0 != tenant_id_ && tablet_id_.is_valid() && rowkey_size_ > 0
&& data_version_ > -1 && (ObITable::is_minor_sstable(table_type_) || ObITable::is_major_sstable(table_type_))
&& rowkey_.is_valid());
}
/**
* -----------------------------------------------------ObRowCacheValue------------------------------------------------------
*/
ObRowCacheValue::ObRowCacheValue()
: obj_array_(NULL),
column_ids_(NULL),
size_(0),
column_cnt_(0),
schema_version_(0),
flag_(-1),
block_id_(),
row_dml_()
: datums_(nullptr),
flag_(),
size_(0),
column_cnt_(0),
start_log_ts_(0),
block_id_()
{}
{
}
ObRowCacheValue::~ObRowCacheValue()
{}
{
}
int ObRowCacheValue::init(
const ObFullMacroBlockMeta& macro_meta, const storage::ObStoreRow* row, const MacroBlockId& block_id)
int ObRowCacheValue::init(const int64_t start_log_ts,
const ObDatumRow &row)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(!macro_meta.is_valid() || NULL == row || !block_id.is_valid())) {
ret = OB_INVALID_ARGUMENT;
STORAGE_LOG(WARN, "Invalid argument, ", K(macro_meta), KP(row), K(block_id), K(ret));
} else {
obj_array_ = row->row_val_.cells_;
column_ids_ = row->is_sparse_row_ ? row->column_ids_ : NULL;
column_cnt_ = row->row_val_.count_;
schema_version_ = macro_meta.meta_->schema_version_;
flag_ = row->flag_;
block_id_ = block_id;
row_dml_.set_dml(row->get_dml());
row_dml_.set_first_dml(row->get_first_dml());
size_ = sizeof(ObObj) * column_cnt_;
if (NULL != column_ids_) {
size_ += sizeof(uint16_t) * column_cnt_;
}
int64_t data_length = 0;
for (int64_t i = 0; OB_SUCC(ret) && i < column_cnt_; i++) {
const common::ObObj& tmp_obj_array = obj_array_[i];
if (tmp_obj_array.need_deep_copy()) {
size_ += tmp_obj_array.get_data_length();
}
}
datums_ = row.storage_datums_;
column_cnt_ = row.get_column_count();
start_log_ts_ = start_log_ts;
flag_ = row.row_flag_;
size_ = sizeof(ObStorageDatum) * column_cnt_;
for (int64_t i = 0; OB_SUCC(ret) && i < column_cnt_; i ++) {
size_ += datums_[i].get_deep_copy_size();
}
return ret;
}
@ -175,7 +179,7 @@ int64_t ObRowCacheValue::size() const
return sizeof(*this) + size_;
}
int ObRowCacheValue::deep_copy(char* buf, const int64_t buf_len, ObIKVCacheValue*& value) const
int ObRowCacheValue::deep_copy(char *buf, const int64_t buf_len, ObIKVCacheValue *&value) const
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(NULL == buf || buf_len < size())) {
@ -185,43 +189,22 @@ int ObRowCacheValue::deep_copy(char* buf, const int64_t buf_len, ObIKVCacheValue
ret = OB_INVALID_DATA;
STORAGE_LOG(WARN, "Invalid row cache value, ", K(*this), K(ret));
} else {
ObRowCacheValue* pvalue = new (buf) ObRowCacheValue();
if (NULL == obj_array_) {
pvalue->obj_array_ = NULL;
ObRowCacheValue *pvalue = new (buf) ObRowCacheValue();
if (NULL == datums_) {
pvalue->datums_ = NULL;
} else {
char* tmp_buf = buf + sizeof(*this);
MEMCPY(tmp_buf, obj_array_, sizeof(ObObj) * column_cnt_);
pvalue->size_ = size_;
pvalue->obj_array_ = reinterpret_cast<ObObj*>(tmp_buf);
pvalue->datums_ = new (buf + sizeof(*this)) ObStorageDatum [column_cnt_];
pvalue->column_cnt_ = column_cnt_;
pvalue->schema_version_ = schema_version_;
pvalue->start_log_ts_ = start_log_ts_;
pvalue->flag_ = flag_;
pvalue->block_id_ = block_id_;
pvalue->row_dml_ = row_dml_;
int64_t data_length = 0;
tmp_buf += sizeof(ObObj) * column_cnt_;
for (int64_t i = 0; OB_SUCC(ret) && i < column_cnt_; i++) {
if (pvalue->obj_array_[i].need_deep_copy()) {
data_length = pvalue->obj_array_[i].get_data_length();
if (pvalue->obj_array_[i].is_string_type() || pvalue->obj_array_[i].is_raw()
|| pvalue->obj_array_[i].is_json()) {
MEMCPY(tmp_buf, pvalue->obj_array_[i].v_.string_, data_length);
pvalue->obj_array_[i].v_.string_ = tmp_buf;
tmp_buf += data_length;
} else if (ob_is_number_tc(pvalue->obj_array_[i].get_type())) {
MEMCPY(tmp_buf, pvalue->obj_array_[i].v_.nmb_digits_, data_length);
pvalue->obj_array_[i].v_.nmb_digits_ = (uint32_t*)tmp_buf;
tmp_buf += data_length;
} else {
ret = OB_ERR_UNEXPECTED;
STORAGE_LOG(WARN, "meta is error, ", K(pvalue->obj_array_[i]), K(ret));
}
int64_t pos = sizeof(ObRowCacheValue) + sizeof(ObStorageDatum) * column_cnt_;
for (int64_t i = 0; OB_SUCC(ret) && i < column_cnt_; i ++) {
if (OB_FAIL(pvalue->datums_[i].deep_copy(datums_[i], buf, buf_len, pos))) {
STORAGE_LOG(WARN, "Failed to deepl copy datum", K(ret), K(i));
}
}
if (NULL != column_ids_) {
MEMCPY(tmp_buf, column_ids_, sizeof(uint16_t) * column_cnt_);
pvalue->column_ids_ = reinterpret_cast<uint16_t*>(tmp_buf);
}
}
value = pvalue;
}
@ -231,15 +214,17 @@ int ObRowCacheValue::deep_copy(char* buf, const int64_t buf_len, ObIKVCacheValue
* -----------------------------------------------------ObRowCache------------------------------------------------------
*/
ObRowCache::ObRowCache()
{}
{
}
ObRowCache::~ObRowCache()
{}
{
}
int ObRowCache::get_row(const ObRowCacheKey& key, ObRowValueHandle& handle)
int ObRowCache::get_row(const ObRowCacheKey &key, ObRowValueHandle &handle)
{
int ret = OB_SUCCESS;
const ObRowCacheValue* value = NULL;
const ObRowCacheValue *value = NULL;
if (OB_UNLIKELY(!key.is_valid())) {
ret = OB_INVALID_ARGUMENT;
@ -261,7 +246,8 @@ int ObRowCache::get_row(const ObRowCacheKey& key, ObRowValueHandle& handle)
return ret;
}
int ObRowCache::put_row(const ObRowCacheKey& key, const ObRowCacheValue& value)
int ObRowCache::put_row(const ObRowCacheKey &key, const ObRowCacheValue &value)
{
int ret = OB_SUCCESS;
bool overwrite = true;
@ -274,5 +260,5 @@ int ObRowCache::put_row(const ObRowCacheKey& key, const ObRowCacheValue& value)
return ret;
}
} // end namespace blocksstable
} // end namespace oceanbase
}//end namespace blocksstable
}//end namespace oceanbase