change sql_statistics collect mode
This commit is contained in:
@ -25,7 +25,7 @@ using namespace common;
|
||||
*/
|
||||
|
||||
ObDirectLoadFastHeapTableCreateParam::ObDirectLoadFastHeapTableCreateParam()
|
||||
: row_count_(0) , column_stat_array_(nullptr)
|
||||
: row_count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ ObDirectLoadFastHeapTableCreateParam::~ObDirectLoadFastHeapTableCreateParam()
|
||||
|
||||
bool ObDirectLoadFastHeapTableCreateParam::is_valid() const
|
||||
{
|
||||
return tablet_id_.is_valid() && row_count_ >= 0 && nullptr != column_stat_array_ ;
|
||||
return tablet_id_.is_valid() && row_count_ >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,45 +43,14 @@ bool ObDirectLoadFastHeapTableCreateParam::is_valid() const
|
||||
*/
|
||||
|
||||
ObDirectLoadFastHeapTable::ObDirectLoadFastHeapTable()
|
||||
: allocator_("TLD_FastHTable"), is_inited_(false)
|
||||
: is_inited_(false)
|
||||
{
|
||||
}
|
||||
|
||||
ObDirectLoadFastHeapTable::~ObDirectLoadFastHeapTable()
|
||||
{
|
||||
for (int64_t i = 0; i < column_stat_array_.count(); ++i) {
|
||||
ObOptOSGColumnStat *col_stat = column_stat_array_.at(i);
|
||||
col_stat->~ObOptOSGColumnStat();
|
||||
col_stat = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int ObDirectLoadFastHeapTable::copy_col_stat(const ObDirectLoadFastHeapTableCreateParam ¶m)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
for (int64_t i = 0; OB_SUCC(ret)&& i < param.column_stat_array_->count(); ++i) {
|
||||
ObOptOSGColumnStat *col_stat = param.column_stat_array_->at(i);
|
||||
ObOptOSGColumnStat *copied_col_stat = NULL;
|
||||
if (OB_ISNULL(col_stat)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null");
|
||||
} else if (OB_ISNULL(copied_col_stat = ObOptOSGColumnStat::create_new_osg_col_stat(allocator_))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed to allocate memory");
|
||||
} else if (OB_FAIL(copied_col_stat->deep_copy(*col_stat))) {
|
||||
LOG_WARN("fail to copy colstat", KR(ret));
|
||||
} else if (OB_FAIL(column_stat_array_.push_back(copied_col_stat))) {
|
||||
LOG_WARN("fail to add table", KR(ret));
|
||||
}
|
||||
if (OB_FAIL(ret) && OB_NOT_NULL(copied_col_stat)) {
|
||||
copied_col_stat->~ObOptOSGColumnStat();
|
||||
copied_col_stat = nullptr;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObDirectLoadFastHeapTable::init(const ObDirectLoadFastHeapTableCreateParam ¶m)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
@ -94,12 +63,7 @@ int ObDirectLoadFastHeapTable::init(const ObDirectLoadFastHeapTableCreateParam &
|
||||
} else {
|
||||
meta_.tablet_id_ = param.tablet_id_;
|
||||
meta_.row_count_ = param.row_count_;
|
||||
allocator_.set_tenant_id(MTL_ID());
|
||||
if (OB_FAIL(copy_col_stat(param))){
|
||||
LOG_WARN("fail to inner init", KR(ret), K(param));
|
||||
} else {
|
||||
is_inited_ = true;
|
||||
}
|
||||
is_inited_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ public:
|
||||
public:
|
||||
common::ObTabletID tablet_id_;
|
||||
int64_t row_count_;
|
||||
common::ObArray<common::ObOptOSGColumnStat*> *column_stat_array_;
|
||||
};
|
||||
|
||||
struct ObDirectLoadFastHeapTableMeta
|
||||
@ -47,21 +46,13 @@ public:
|
||||
ObDirectLoadFastHeapTable();
|
||||
virtual ~ObDirectLoadFastHeapTable();
|
||||
int init(const ObDirectLoadFastHeapTableCreateParam ¶m);
|
||||
const common::ObIArray<ObOptOSGColumnStat*> &get_column_stat_array() const
|
||||
{
|
||||
return column_stat_array_;
|
||||
}
|
||||
const common::ObTabletID &get_tablet_id() const override { return meta_.tablet_id_; }
|
||||
int64_t get_row_count() const override { return meta_.row_count_; }
|
||||
bool is_valid() const override { return is_inited_; }
|
||||
const ObDirectLoadFastHeapTableMeta &get_meta() const { return meta_; }
|
||||
TO_STRING_KV(K_(meta));
|
||||
private:
|
||||
int copy_col_stat(const ObDirectLoadFastHeapTableCreateParam ¶m);
|
||||
private:
|
||||
ObDirectLoadFastHeapTableMeta meta_;
|
||||
common::ObArenaAllocator allocator_;
|
||||
common::ObArray<common::ObOptOSGColumnStat*> column_stat_array_;
|
||||
bool is_inited_;
|
||||
DISABLE_COPY_ASSIGN(ObDirectLoadFastHeapTable);
|
||||
};
|
||||
|
||||
@ -34,13 +34,12 @@ using namespace share;
|
||||
|
||||
ObDirectLoadFastHeapTableBuildParam::ObDirectLoadFastHeapTableBuildParam()
|
||||
: snapshot_version_(0),
|
||||
thread_idx_(0),
|
||||
datum_utils_(nullptr),
|
||||
col_descs_(nullptr),
|
||||
cmp_funcs_(nullptr),
|
||||
insert_table_ctx_(nullptr),
|
||||
fast_heap_table_ctx_(nullptr),
|
||||
dml_row_handler_(nullptr),
|
||||
online_opt_stat_gather_(false)
|
||||
dml_row_handler_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -50,8 +49,8 @@ ObDirectLoadFastHeapTableBuildParam::~ObDirectLoadFastHeapTableBuildParam()
|
||||
|
||||
bool ObDirectLoadFastHeapTableBuildParam::is_valid() const
|
||||
{
|
||||
return tablet_id_.is_valid() && snapshot_version_ > 0 && table_data_desc_.is_valid() &&
|
||||
nullptr != col_descs_ && nullptr != cmp_funcs_ && nullptr != insert_table_ctx_ &&
|
||||
return tablet_id_.is_valid() && snapshot_version_ > 0 && thread_idx_ >= 0 &&
|
||||
table_data_desc_.is_valid() && nullptr != col_descs_ && nullptr != insert_table_ctx_ &&
|
||||
nullptr != fast_heap_table_ctx_ && nullptr != dml_row_handler_ && nullptr != datum_utils_;
|
||||
}
|
||||
|
||||
@ -77,56 +76,6 @@ ObDirectLoadFastHeapTableBuilder::~ObDirectLoadFastHeapTableBuilder()
|
||||
slice_writer_allocator_.free(slice_writer_);
|
||||
slice_writer_ = nullptr;
|
||||
}
|
||||
for (int64_t i = 0; i < column_stat_array_.count(); ++i) {
|
||||
ObOptOSGColumnStat *col_stat = column_stat_array_.at(i);
|
||||
col_stat->~ObOptOSGColumnStat();
|
||||
allocator_.free(col_stat);
|
||||
col_stat = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int ObDirectLoadFastHeapTableBuilder::init_sql_statistics()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < param_.table_data_desc_.column_count_; ++i) {
|
||||
ObOptOSGColumnStat *new_osg_col_stat = ObOptOSGColumnStat::create_new_osg_col_stat(allocator_);
|
||||
if (OB_ISNULL(new_osg_col_stat)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("failed to allocate col stat");
|
||||
} else if (OB_FAIL(column_stat_array_.push_back(new_osg_col_stat))) {
|
||||
LOG_WARN("fail to push back", KR(ret));
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
if (new_osg_col_stat != nullptr) {
|
||||
new_osg_col_stat->~ObOptOSGColumnStat();
|
||||
allocator_.free(new_osg_col_stat);
|
||||
new_osg_col_stat = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadFastHeapTableBuilder::collect_obj(const ObDatumRow &datum_row)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const int64_t extra_rowkey_cnt = ObMultiVersionRowkeyHelpper::get_extra_rowkey_col_cnt();
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < param_.table_data_desc_.column_count_; i++) {
|
||||
const ObStorageDatum &datum =
|
||||
datum_row.storage_datums_[i + extra_rowkey_cnt + 1];
|
||||
const ObCmpFunc &cmp_func = param_.cmp_funcs_->at(i + 1).get_cmp_func();
|
||||
const ObColDesc &col_desc = param_.col_descs_->at(i + 1);
|
||||
ObOptOSGColumnStat *col_stat = column_stat_array_.at(i);
|
||||
bool is_valid = ObColumnStatParam::is_valid_opt_col_type(col_desc.col_type_.get_type());
|
||||
if (col_stat != nullptr && is_valid) {
|
||||
if (OB_FAIL(col_stat->update_column_stat_info(&datum,
|
||||
col_desc.col_type_,
|
||||
cmp_func.cmp_func_))) {
|
||||
LOG_WARN("failed to update column stat info");
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadFastHeapTableBuilder::init(const ObDirectLoadFastHeapTableBuildParam ¶m)
|
||||
@ -142,9 +91,7 @@ int ObDirectLoadFastHeapTableBuilder::init(const ObDirectLoadFastHeapTableBuildP
|
||||
param_ = param;
|
||||
allocator_.set_tenant_id(MTL_ID());
|
||||
slice_writer_allocator_.set_tenant_id(MTL_ID());
|
||||
if (param_.online_opt_stat_gather_ && OB_FAIL(init_sql_statistics())) {
|
||||
LOG_WARN("fail to inner init sql statistics", KR(ret));
|
||||
} else if (OB_FAIL(param_.fast_heap_table_ctx_->get_tablet_context(
|
||||
if (OB_FAIL(param_.fast_heap_table_ctx_->get_tablet_context(
|
||||
param_.tablet_id_, fast_heap_table_tablet_ctx_))) {
|
||||
LOG_WARN("fail to get tablet context", KR(ret));
|
||||
} else if (OB_FAIL(init_sstable_slice_ctx())) {
|
||||
@ -234,7 +181,7 @@ int ObDirectLoadFastHeapTableBuilder::append_row(const ObTabletID &tablet_id,
|
||||
}
|
||||
if (OB_FAIL(slice_writer_->append_row(datum_row_))) {
|
||||
LOG_WARN("fail to append row", KR(ret));
|
||||
} else if (param_.online_opt_stat_gather_ && OB_FAIL(collect_obj(datum_row_))) {
|
||||
} else if (param_.insert_table_ctx_->collect_obj(param_.thread_idx_ ,datum_row_)) {
|
||||
LOG_WARN("fail to collect", KR(ret));
|
||||
} else {
|
||||
++row_count_;
|
||||
@ -262,6 +209,7 @@ int ObDirectLoadFastHeapTableBuilder::close()
|
||||
if (OB_FAIL(slice_writer_->close())) {
|
||||
LOG_WARN("fail to close sstable slice writer", KR(ret));
|
||||
} else {
|
||||
param_.insert_table_ctx_->inc_row_count(row_count_);
|
||||
is_closed_ = true;
|
||||
}
|
||||
}
|
||||
@ -282,7 +230,6 @@ int ObDirectLoadFastHeapTableBuilder::get_tables(
|
||||
ObDirectLoadFastHeapTableCreateParam create_param;
|
||||
create_param.tablet_id_ = param_.tablet_id_;
|
||||
create_param.row_count_ = row_count_;
|
||||
create_param.column_stat_array_ = &column_stat_array_;
|
||||
ObDirectLoadFastHeapTable *fast_heap_table = nullptr;
|
||||
if (OB_ISNULL(fast_heap_table = OB_NEWx(ObDirectLoadFastHeapTable, (&allocator)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
|
||||
@ -39,20 +39,19 @@ public:
|
||||
ObDirectLoadFastHeapTableBuildParam();
|
||||
~ObDirectLoadFastHeapTableBuildParam();
|
||||
bool is_valid() const;
|
||||
TO_STRING_KV(K_(tablet_id), K_(snapshot_version), K_(table_data_desc), KP_(datum_utils),
|
||||
KP_(col_descs), KP_(cmp_funcs), KP_(insert_table_ctx), KP_(fast_heap_table_ctx),
|
||||
KP_(dml_row_handler), K_(online_opt_stat_gather));
|
||||
TO_STRING_KV(K_(tablet_id), K_(snapshot_version), K_(thread_idx), K_(table_data_desc),
|
||||
KP_(datum_utils), KP_(col_descs), KP_(insert_table_ctx), KP_(fast_heap_table_ctx),
|
||||
KP_(dml_row_handler));
|
||||
public:
|
||||
common::ObTabletID tablet_id_;
|
||||
int64_t snapshot_version_;
|
||||
int64_t thread_idx_;
|
||||
ObDirectLoadTableDataDesc table_data_desc_;
|
||||
const blocksstable::ObStorageDatumUtils *datum_utils_;
|
||||
const common::ObIArray<share::schema::ObColDesc> *col_descs_;
|
||||
const blocksstable::ObStoreCmpFuncs *cmp_funcs_;
|
||||
ObDirectLoadInsertTableContext *insert_table_ctx_;
|
||||
ObDirectLoadFastHeapTableContext *fast_heap_table_ctx_;
|
||||
ObDirectLoadDMLRowHandler *dml_row_handler_;
|
||||
bool online_opt_stat_gather_;
|
||||
};
|
||||
|
||||
class ObDirectLoadFastHeapTableBuilder : public ObIDirectLoadPartitionTableBuilder
|
||||
@ -70,8 +69,6 @@ public:
|
||||
int get_tables(common::ObIArray<ObIDirectLoadPartitionTable *> &table_array,
|
||||
common::ObIAllocator &allocator) override;
|
||||
private:
|
||||
int init_sql_statistics();
|
||||
int collect_obj(const blocksstable::ObDatumRow &datum_row);
|
||||
int init_sstable_slice_ctx();
|
||||
int switch_sstable_slice();
|
||||
private:
|
||||
@ -82,7 +79,6 @@ private:
|
||||
ObSSTableInsertSliceWriter *slice_writer_;
|
||||
ObDirectLoadFastHeapTableTabletWriteCtx write_ctx_;
|
||||
blocksstable::ObDatumRow datum_row_;
|
||||
common::ObArray<ObOptOSGColumnStat *> column_stat_array_;
|
||||
int64_t row_count_;
|
||||
bool is_closed_;
|
||||
bool is_inited_;
|
||||
|
||||
@ -13,6 +13,10 @@
|
||||
|
||||
#include "storage/direct_load/ob_direct_load_insert_table_ctx.h"
|
||||
#include "storage/ddl/ob_direct_insert_sstable_ctx.h"
|
||||
#include "share/stat/ob_opt_table_stat.h"
|
||||
#include "share/stat/ob_opt_column_stat.h"
|
||||
#include "share/stat/ob_stat_item.h"
|
||||
#include "observer/table_load/ob_table_load_schema.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
@ -20,13 +24,26 @@ namespace storage
|
||||
{
|
||||
using namespace common;
|
||||
using namespace table;
|
||||
using namespace sql;
|
||||
using namespace observer;
|
||||
|
||||
/**
|
||||
* ObDirectLoadInsertTableParam
|
||||
*/
|
||||
|
||||
ObDirectLoadInsertTableParam::ObDirectLoadInsertTableParam()
|
||||
: table_id_(OB_INVALID_ID), schema_version_(0), snapshot_version_(0), execution_id_(0), ddl_task_id_(0)
|
||||
: table_id_(OB_INVALID_ID),
|
||||
dest_table_id_(OB_INVALID_ID),
|
||||
schema_version_(0),
|
||||
snapshot_version_(0),
|
||||
execution_id_(0),
|
||||
ddl_task_id_(0),
|
||||
data_version_(0),
|
||||
session_cnt_(0),
|
||||
rowkey_column_count_(0),
|
||||
column_count_(0),
|
||||
online_opt_stat_gather_(false),
|
||||
is_heap_table_(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -36,16 +53,25 @@ ObDirectLoadInsertTableParam::~ObDirectLoadInsertTableParam()
|
||||
|
||||
bool ObDirectLoadInsertTableParam::is_valid() const
|
||||
{
|
||||
return OB_INVALID_ID != table_id_ && schema_version_ >= 0 && snapshot_version_ >= 0 &&
|
||||
ls_partition_ids_.count() > 0;
|
||||
return OB_INVALID_ID != table_id_ && OB_INVALID_ID != dest_table_id_ && schema_version_ >= 0 &&
|
||||
snapshot_version_ >= 0 && ls_partition_ids_.count() > 0;
|
||||
}
|
||||
|
||||
int ObDirectLoadInsertTableParam::assign(const ObDirectLoadInsertTableParam &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
table_id_ = other.table_id_;
|
||||
dest_table_id_ = other.dest_table_id_;
|
||||
schema_version_ = other.schema_version_;
|
||||
snapshot_version_ = other.snapshot_version_;
|
||||
data_version_ = other.data_version_;
|
||||
session_cnt_ = other.session_cnt_;
|
||||
rowkey_column_count_ = other.rowkey_column_count_;
|
||||
column_count_ = other.column_count_;
|
||||
online_opt_stat_gather_ = other.online_opt_stat_gather_;
|
||||
is_heap_table_ = other.is_heap_table_;
|
||||
col_descs_ = other.col_descs_;
|
||||
cmp_funcs_ = other.cmp_funcs_;
|
||||
if (OB_FAIL(ls_partition_ids_.assign(other.ls_partition_ids_))) {
|
||||
LOG_WARN("fail to assign ls tablet ids", KR(ret));
|
||||
}
|
||||
@ -57,7 +83,7 @@ int ObDirectLoadInsertTableParam::assign(const ObDirectLoadInsertTableParam &oth
|
||||
*/
|
||||
|
||||
ObDirectLoadInsertTableContext::ObDirectLoadInsertTableContext()
|
||||
: tablet_finish_count_(0), is_inited_(false)
|
||||
: allocator_("TLD_SqlStat"), tablet_finish_count_(0), table_row_count_(0), is_inited_(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -76,6 +102,12 @@ void ObDirectLoadInsertTableContext::reset()
|
||||
}
|
||||
ddl_ctrl_.context_id_ = 0;
|
||||
}
|
||||
for (int64_t i = 0; i < session_sql_ctx_array_.count(); ++i) {
|
||||
ObTableLoadSqlStatistics *sql_statistics = session_sql_ctx_array_.at(i);
|
||||
sql_statistics->~ObTableLoadSqlStatistics();
|
||||
allocator_.free(sql_statistics);
|
||||
}
|
||||
session_sql_ctx_array_.reset();
|
||||
is_inited_ = false;
|
||||
}
|
||||
|
||||
@ -112,6 +144,8 @@ int ObDirectLoadInsertTableContext::init(const ObDirectLoadInsertTableParam &par
|
||||
} else if (OB_FAIL(sstable_insert_mgr.create_table_context(table_insert_param,
|
||||
ddl_ctrl_.context_id_))) {
|
||||
LOG_WARN("fail to create table context", KR(ret), K(table_insert_param));
|
||||
} else if (param_.online_opt_stat_gather_ && OB_FAIL(init_sql_statistics())) {
|
||||
LOG_WARN("fail to init sql statistics", KR(ret));
|
||||
} else {
|
||||
is_inited_ = true;
|
||||
}
|
||||
@ -122,6 +156,163 @@ int ObDirectLoadInsertTableContext::init(const ObDirectLoadInsertTableParam &par
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadInsertTableContext::init_sql_statistics()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObOptTableStat *table_stat = nullptr;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < param_.session_cnt_; ++i) {
|
||||
ObTableLoadSqlStatistics *sql_statistics = nullptr;
|
||||
ObOptTableStat *table_stat = nullptr;
|
||||
if (OB_ISNULL(sql_statistics = OB_NEWx(ObTableLoadSqlStatistics, (&allocator_)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("fail to new ObTableLoadSqlStatistics", KR(ret));
|
||||
} else if (OB_FAIL(sql_statistics->allocate_table_stat(table_stat))) {
|
||||
LOG_WARN("fail to allocate table stat", KR(ret));
|
||||
} else if (OB_FAIL(session_sql_ctx_array_.push_back(sql_statistics))) {
|
||||
LOG_WARN("fail to push back", KR(ret));
|
||||
} else {
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < param_.column_count_; ++j) {
|
||||
ObOptOSGColumnStat *osg_col_stat = nullptr;
|
||||
if (OB_FAIL(sql_statistics->allocate_col_stat(osg_col_stat))) {
|
||||
LOG_WARN("fail to allocate col stat", KR(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
if (nullptr != sql_statistics) {
|
||||
sql_statistics->~ObTableLoadSqlStatistics();
|
||||
allocator_.free(sql_statistics);
|
||||
sql_statistics = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadInsertTableContext::collect_sql_statistics(ObTableLoadSqlStatistics &sql_statistics)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const uint64_t tenant_id = MTL_ID();
|
||||
ObSchemaGetterGuard schema_guard;
|
||||
const ObTableSchema *table_schema = nullptr;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObDirectLoadTabletMergeCtx not init", KR(ret), KP(this));
|
||||
} else if (OB_FAIL(ObTableLoadSchema::get_table_schema(tenant_id, param_.dest_table_id_,
|
||||
schema_guard, table_schema))) {
|
||||
LOG_WARN("fail to get table schema", KR(ret), K(param_));
|
||||
} else if (OB_ISNULL(table_schema)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected error", K(ret));
|
||||
} else {
|
||||
sql_statistics.reset();
|
||||
int64_t table_row_cnt = table_row_count_;
|
||||
int64_t table_avg_len = 0;
|
||||
int64_t col_cnt = param_.column_count_;
|
||||
uint64_t partition_id = -1;
|
||||
ObOptTableStat *table_stat = nullptr;
|
||||
StatLevel stat_level = TABLE_LEVEL;
|
||||
if (table_schema->get_part_level() == PARTITION_LEVEL_ZERO) {
|
||||
partition_id = param_.dest_table_id_;
|
||||
}
|
||||
if (OB_FAIL(sql_statistics.allocate_table_stat(table_stat))) {
|
||||
LOG_WARN("fail to allocate table stat", KR(ret));
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < col_cnt; ++i) {
|
||||
int64_t col_id = param_.is_heap_table_ ? i + 1 : i;
|
||||
ObOptOSGColumnStat *osg_col_stat = nullptr;
|
||||
if (OB_FAIL(sql_statistics.allocate_col_stat(osg_col_stat))) {
|
||||
LOG_WARN("fail to allocate table stat", KR(ret));
|
||||
}
|
||||
// scan session_sql_ctx_array
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < session_sql_ctx_array_.count(); ++j) {
|
||||
ObOptOSGColumnStat *tmp_col_stat =
|
||||
session_sql_ctx_array_.at(j)->get_col_stat_array().at(i);
|
||||
if (OB_FAIL(osg_col_stat->merge_column_stat(*tmp_col_stat))) {
|
||||
LOG_WARN("fail to merge column stat", KR(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
osg_col_stat->col_stat_->calc_avg_len();
|
||||
table_avg_len += osg_col_stat->col_stat_->get_avg_len();
|
||||
osg_col_stat->col_stat_->set_table_id(param_.dest_table_id_);
|
||||
osg_col_stat->col_stat_->set_partition_id(partition_id);
|
||||
osg_col_stat->col_stat_->set_stat_level(stat_level);
|
||||
osg_col_stat->col_stat_->set_column_id(param_.col_descs_->at(col_id).col_id_);
|
||||
osg_col_stat->col_stat_->set_num_distinct(
|
||||
ObGlobalNdvEval::get_ndv_from_llc(osg_col_stat->col_stat_->get_llc_bitmap()));
|
||||
if (OB_FAIL(osg_col_stat->set_min_max_datum_to_obj())) {
|
||||
LOG_WARN("failed to set min max datum to obj", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
table_stat->set_table_id(param_.dest_table_id_);
|
||||
table_stat->set_partition_id(partition_id);
|
||||
table_stat->set_object_type(stat_level);
|
||||
table_stat->set_row_count(table_row_cnt);
|
||||
table_stat->set_avg_row_size(table_avg_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadInsertTableContext::collect_obj(int64_t thread_idx, const ObDatumRow &datum_row)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const int64_t extra_rowkey_cnt = ObMultiVersionRowkeyHelpper::get_extra_rowkey_col_cnt();
|
||||
if (param_.online_opt_stat_gather_) {
|
||||
if (OB_UNLIKELY(thread_idx >= session_sql_ctx_array_.count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected thread idx", KR(ret), K(thread_idx), K(session_sql_ctx_array_.count()));
|
||||
} else {
|
||||
ObTableLoadSqlStatistics *sql_stat = session_sql_ctx_array_.at(thread_idx);
|
||||
if (param_.is_heap_table_ ) {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < param_.column_count_; i++) {
|
||||
const ObStorageDatum &datum = datum_row.storage_datums_[i + extra_rowkey_cnt + 1];
|
||||
const ObColDesc &col_desc = param_.col_descs_->at(i + 1);
|
||||
const ObCmpFunc &cmp_func = param_.cmp_funcs_->at(i + 1).get_cmp_func();
|
||||
ObOptOSGColumnStat *col_stat = sql_stat->get_col_stat_array().at(i);
|
||||
bool is_valid = ObColumnStatParam::is_valid_opt_col_type(col_desc.col_type_.get_type());
|
||||
if (col_stat != nullptr && is_valid) {
|
||||
if (OB_FAIL(col_stat->update_column_stat_info(&datum, col_desc.col_type_, cmp_func.cmp_func_))) {
|
||||
LOG_WARN("Failed to merge obj", K(ret), KP(col_stat));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < param_.rowkey_column_count_; i++) {
|
||||
const ObStorageDatum &datum = datum_row.storage_datums_[i];
|
||||
const ObColDesc &col_desc = param_.col_descs_->at(i);
|
||||
const ObCmpFunc &cmp_func = param_.cmp_funcs_->at(i).get_cmp_func();
|
||||
ObOptOSGColumnStat *col_stat = sql_stat->get_col_stat_array().at(i);
|
||||
bool is_valid = ObColumnStatParam::is_valid_opt_col_type(col_desc.col_type_.get_type());
|
||||
if (col_stat != nullptr && is_valid) {
|
||||
if (OB_FAIL(col_stat->update_column_stat_info(&datum, col_desc.col_type_, cmp_func.cmp_func_))) {
|
||||
LOG_WARN("Failed to merge obj", K(ret), KP(col_stat));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int64_t i = param_.rowkey_column_count_; OB_SUCC(ret) && i < param_.column_count_; i++) {
|
||||
const ObStorageDatum &datum = datum_row.storage_datums_[i + extra_rowkey_cnt];
|
||||
const ObColDesc &col_desc = param_.col_descs_->at(i);
|
||||
const ObCmpFunc &cmp_func = param_.cmp_funcs_->at(i).get_cmp_func();
|
||||
ObOptOSGColumnStat *col_stat = session_sql_ctx_array_.at(thread_idx)->get_col_stat_array().at(i);
|
||||
bool is_valid = ObColumnStatParam::is_valid_opt_col_type(col_desc.col_type_.get_type());
|
||||
if (col_stat != nullptr && is_valid) {
|
||||
if (OB_FAIL(col_stat->update_column_stat_info(&datum, col_desc.col_type_, cmp_func.cmp_func_))) {
|
||||
LOG_WARN("Failed to merge obj", K(ret), KP(col_stat));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadInsertTableContext::add_sstable_slice(const ObTabletID &tablet_id,
|
||||
const ObMacroDataSeq &start_seq,
|
||||
ObNewRowIterator &iter,
|
||||
@ -200,7 +391,7 @@ int ObDirectLoadInsertTableContext::notify_tablet_finish(const ObTabletID &table
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadInsertTableContext::commit()
|
||||
int ObDirectLoadInsertTableContext::commit(ObTableLoadSqlStatistics &sql_statistics)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (IS_NOT_INIT) {
|
||||
@ -214,8 +405,9 @@ int ObDirectLoadInsertTableContext::commit()
|
||||
ObSSTableInsertManager &sstable_insert_mgr = ObSSTableInsertManager::get_instance();
|
||||
if (OB_FAIL(sstable_insert_mgr.finish_table_context(ddl_ctrl_.context_id_, true))) {
|
||||
LOG_WARN("fail to finish table context", KR(ret), K_(ddl_ctrl));
|
||||
} else {
|
||||
ddl_ctrl_.context_id_ = 0;
|
||||
} else if (FALSE_IT(ddl_ctrl_.context_id_ = 0)) {
|
||||
} else if (param_.online_opt_stat_gather_ && OB_FAIL(collect_sql_statistics(sql_statistics))) {
|
||||
LOG_WARN("fail to collect sql stats", KR(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "share/table/ob_table_load_define.h"
|
||||
#include "share/table/ob_table_load_sql_statistics.h"
|
||||
#include "sql/engine/px/ob_sub_trans_ctrl.h"
|
||||
|
||||
namespace oceanbase
|
||||
@ -27,14 +28,25 @@ public:
|
||||
~ObDirectLoadInsertTableParam();
|
||||
int assign(const ObDirectLoadInsertTableParam &other);
|
||||
bool is_valid() const;
|
||||
TO_STRING_KV(K_(table_id), K_(schema_version), K_(snapshot_version), K_(ls_partition_ids), K_(execution_id), K_(ddl_task_id));
|
||||
TO_STRING_KV(K_(table_id), K_(dest_table_id), K_(schema_version), K_(snapshot_version),
|
||||
K_(execution_id), K_(ddl_task_id), K_(data_version), K_(session_cnt),
|
||||
K_(rowkey_column_count), K_(column_count), K_(online_opt_stat_gather),
|
||||
K_(is_heap_table), K_(ls_partition_ids));
|
||||
public:
|
||||
uint64_t table_id_;
|
||||
uint64_t dest_table_id_;
|
||||
int64_t schema_version_;
|
||||
int64_t snapshot_version_;
|
||||
int64_t execution_id_;
|
||||
int64_t ddl_task_id_;
|
||||
int64_t data_version_;
|
||||
int64_t session_cnt_;
|
||||
int64_t rowkey_column_count_;
|
||||
int64_t column_count_;
|
||||
bool online_opt_stat_gather_;
|
||||
bool is_heap_table_;
|
||||
const common::ObIArray<share::schema::ObColDesc> *col_descs_;
|
||||
const blocksstable::ObStoreCmpFuncs *cmp_funcs_;
|
||||
common::ObArray<table::ObTableLoadLSIdAndPartitionId> ls_partition_ids_;
|
||||
};
|
||||
|
||||
@ -45,6 +57,7 @@ public:
|
||||
~ObDirectLoadInsertTableContext();
|
||||
void reset();
|
||||
int init(const ObDirectLoadInsertTableParam ¶m);
|
||||
int collect_obj(int64_t thread_idx, const blocksstable::ObDatumRow &datum_row);
|
||||
int add_sstable_slice(const common::ObTabletID &tablet_id,
|
||||
const blocksstable::ObMacroDataSeq &start_seq,
|
||||
common::ObNewRowIterator &iter,
|
||||
@ -54,12 +67,20 @@ public:
|
||||
ObSSTableInsertSliceWriter *&slice_writer,
|
||||
common::ObIAllocator &allocator);
|
||||
int notify_tablet_finish(const common::ObTabletID &tablet_id);
|
||||
int commit();
|
||||
TO_STRING_KV(K_(param), K_(ddl_ctrl));
|
||||
int commit(table::ObTableLoadSqlStatistics &sql_statistics);
|
||||
void inc_row_count(int64_t row_count) { ATOMIC_AAF(&table_row_count_, row_count); }
|
||||
int64_t get_row_count() const { return table_row_count_; }
|
||||
TO_STRING_KV(K_(param), K_(tablet_finish_count), K_(table_row_count), K_(ddl_ctrl));
|
||||
private:
|
||||
int init_sql_statistics();
|
||||
int collect_sql_statistics(table::ObTableLoadSqlStatistics &sql_statistics);
|
||||
private:
|
||||
common::ObArenaAllocator allocator_;
|
||||
ObDirectLoadInsertTableParam param_;
|
||||
sql::ObDDLCtrl ddl_ctrl_;
|
||||
int64_t tablet_finish_count_ CACHE_ALIGNED;
|
||||
int64_t table_row_count_ CACHE_ALIGNED;
|
||||
common::ObArray<table::ObTableLoadSqlStatistics *> session_sql_ctx_array_;
|
||||
bool is_inited_;
|
||||
};
|
||||
|
||||
|
||||
@ -50,10 +50,8 @@ ObDirectLoadMergeParam::ObDirectLoadMergeParam()
|
||||
snapshot_version_(0),
|
||||
datum_utils_(nullptr),
|
||||
col_descs_(nullptr),
|
||||
cmp_funcs_(nullptr),
|
||||
is_heap_table_(false),
|
||||
is_fast_heap_table_(false),
|
||||
online_opt_stat_gather_(false),
|
||||
insert_table_ctx_(nullptr),
|
||||
dml_row_handler_(nullptr)
|
||||
{
|
||||
@ -67,8 +65,7 @@ bool ObDirectLoadMergeParam::is_valid() const
|
||||
{
|
||||
return OB_INVALID_ID != table_id_ && 0 < rowkey_column_num_ && 0 < store_column_count_ &&
|
||||
snapshot_version_ > 0 && table_data_desc_.is_valid() && nullptr != datum_utils_ &&
|
||||
nullptr != col_descs_ && nullptr != cmp_funcs_ && nullptr != insert_table_ctx_ &&
|
||||
nullptr != dml_row_handler_;
|
||||
nullptr != col_descs_ && nullptr != insert_table_ctx_ && nullptr != dml_row_handler_;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +188,6 @@ int ObDirectLoadTabletMergeCtx::init(const ObDirectLoadMergeParam ¶m,
|
||||
} else {
|
||||
allocator_.set_tenant_id(MTL_ID());
|
||||
param_ = param;
|
||||
target_partition_id_ = target_ls_partition_id.part_tablet_id_.partition_id_;
|
||||
tablet_id_ = ls_partition_id.part_tablet_id_.tablet_id_;
|
||||
target_tablet_id_ = target_ls_partition_id.part_tablet_id_.tablet_id_;
|
||||
is_inited_ = true;
|
||||
@ -200,95 +196,6 @@ int ObDirectLoadTabletMergeCtx::init(const ObDirectLoadMergeParam ¶m,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadTabletMergeCtx::collect_sql_statistics(
|
||||
const ObIArray<ObDirectLoadFastHeapTable *> &fast_heap_table_array, ObTableLoadSqlStatistics &sql_statistics)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const uint64_t tenant_id = MTL_ID();
|
||||
ObSchemaGetterGuard schema_guard;
|
||||
const ObTableSchema *table_schema = nullptr;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObDirectLoadTabletMergeCtx not init", KR(ret), KP(this));
|
||||
} else if (OB_FAIL(ObTableLoadSchema::get_table_schema(tenant_id, param_.target_table_id_, schema_guard,
|
||||
table_schema))) {
|
||||
LOG_WARN("fail to get table schema", KR(ret), K(param_));
|
||||
} else if (OB_ISNULL(table_schema)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected error", K(ret));
|
||||
} else {
|
||||
int64_t table_row_cnt = 0;
|
||||
int64_t table_avg_len = 0;
|
||||
int64_t col_cnt = param_.table_data_desc_.column_count_;
|
||||
ObOptTableStat *table_stat = nullptr;
|
||||
StatLevel stat_level;
|
||||
if (table_schema->get_part_level() == PARTITION_LEVEL_ZERO) {
|
||||
stat_level = TABLE_LEVEL;
|
||||
} else if (table_schema->get_part_level() == PARTITION_LEVEL_ONE) {
|
||||
stat_level = PARTITION_LEVEL;
|
||||
} else if (table_schema->get_part_level() == PARTITION_LEVEL_TWO) {
|
||||
stat_level = SUBPARTITION_LEVEL;
|
||||
} else {
|
||||
stat_level = INVALID_LEVEL;
|
||||
}
|
||||
if (OB_FAIL(sql_statistics.allocate_table_stat(table_stat))) {
|
||||
LOG_WARN("fail to allocate table stat", KR(ret));
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < col_cnt; ++i) {
|
||||
int64_t col_id = param_.is_heap_table_ ? i + 1 : i;
|
||||
int64_t row_count = 0;
|
||||
ObOptOSGColumnStat *osg_col_stat = nullptr;
|
||||
if (OB_FAIL(sql_statistics.allocate_col_stat(osg_col_stat))) {
|
||||
LOG_WARN("fail to allocate table stat", KR(ret));
|
||||
}
|
||||
// scan task_array
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < task_array_.count(); ++j) {
|
||||
ObOptOSGColumnStat *tmp_col_stat = task_array_.at(j)->get_column_stat_array().at(i);
|
||||
if (task_array_.at(j)->get_row_count() != 0) {
|
||||
if (OB_FAIL(osg_col_stat->merge_column_stat(*tmp_col_stat))) {
|
||||
LOG_WARN("fail to merge column stat", KR(ret));
|
||||
} else {
|
||||
row_count += task_array_.at(j)->get_row_count();
|
||||
}
|
||||
}
|
||||
}
|
||||
// scan fast heap table
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < fast_heap_table_array.count(); ++j) {
|
||||
ObOptOSGColumnStat *tmp_col_stat = fast_heap_table_array.at(j)->get_column_stat_array().at(i);
|
||||
if (fast_heap_table_array.at(j)->get_row_count() != 0) {
|
||||
if (OB_FAIL(osg_col_stat->merge_column_stat(*tmp_col_stat))) {
|
||||
LOG_WARN("fail to merge column stat", KR(ret));
|
||||
} else {
|
||||
row_count += fast_heap_table_array.at(j)->get_row_count();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
table_row_cnt = row_count;
|
||||
osg_col_stat->col_stat_->calc_avg_len();
|
||||
table_avg_len += osg_col_stat->col_stat_->get_avg_len();
|
||||
osg_col_stat->col_stat_->set_table_id(param_.target_table_id_);
|
||||
osg_col_stat->col_stat_->set_partition_id(target_partition_id_);
|
||||
osg_col_stat->col_stat_->set_stat_level(stat_level);
|
||||
osg_col_stat->col_stat_->set_column_id(param_.col_descs_->at(col_id).col_id_);
|
||||
osg_col_stat->col_stat_->set_num_distinct(ObGlobalNdvEval::get_ndv_from_llc(osg_col_stat->col_stat_->get_llc_bitmap()));
|
||||
if (OB_FAIL(osg_col_stat->set_min_max_datum_to_obj())) {
|
||||
LOG_WARN("failed to set min max datum to obj", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
table_stat->set_table_id(param_.target_table_id_);
|
||||
table_stat->set_partition_id(target_partition_id_);
|
||||
table_stat->set_object_type(stat_level);
|
||||
table_stat->set_row_count(table_row_cnt);
|
||||
table_stat->set_avg_row_size(table_avg_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadTabletMergeCtx::collect_dml_stat(const common::ObIArray<ObDirectLoadFastHeapTable *> &fast_heap_table_array, ObTableLoadDmlStat &dml_stats)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
@ -51,8 +51,7 @@ public:
|
||||
bool is_valid() const;
|
||||
TO_STRING_KV(K_(table_id), K_(target_table_id), K_(rowkey_column_num), K_(store_column_count),
|
||||
K_(snapshot_version), K_(table_data_desc), KP_(datum_utils), KP_(col_descs),
|
||||
KP_(cmp_funcs), K_(is_heap_table), K_(is_fast_heap_table),
|
||||
K_(online_opt_stat_gather), KP_(insert_table_ctx), KP_(dml_row_handler));
|
||||
K_(is_heap_table), K_(is_fast_heap_table), KP_(insert_table_ctx), KP_(dml_row_handler));
|
||||
public:
|
||||
uint64_t table_id_;
|
||||
uint64_t target_table_id_;
|
||||
@ -62,10 +61,8 @@ public:
|
||||
storage::ObDirectLoadTableDataDesc table_data_desc_;
|
||||
const blocksstable::ObStorageDatumUtils *datum_utils_;
|
||||
const common::ObIArray<share::schema::ObColDesc> *col_descs_;
|
||||
const blocksstable::ObStoreCmpFuncs *cmp_funcs_;
|
||||
bool is_heap_table_;
|
||||
bool is_fast_heap_table_;
|
||||
bool online_opt_stat_gather_;
|
||||
ObDirectLoadInsertTableContext *insert_table_ctx_;
|
||||
ObDirectLoadDMLRowHandler *dml_row_handler_;
|
||||
};
|
||||
@ -109,8 +106,6 @@ public:
|
||||
int build_aggregate_merge_task_for_multiple_heap_table(
|
||||
const common::ObIArray<ObIDirectLoadPartitionTable *> &table_array);
|
||||
int inc_finish_count(bool &is_ready);
|
||||
int collect_sql_statistics(
|
||||
const common::ObIArray<ObDirectLoadFastHeapTable *> &fast_heap_table_array, table::ObTableLoadSqlStatistics &sql_statistics);
|
||||
int collect_dml_stat(const common::ObIArray<ObDirectLoadFastHeapTable *> &fast_heap_table_array,
|
||||
table::ObTableLoadDmlStat &dml_stats);
|
||||
const ObDirectLoadMergeParam &get_param() const { return param_; }
|
||||
@ -120,7 +115,7 @@ public:
|
||||
{
|
||||
return task_array_;
|
||||
}
|
||||
TO_STRING_KV(K_(param), K_(target_partition_id), K_(tablet_id), K_(target_tablet_id));
|
||||
TO_STRING_KV(K_(param), K_(tablet_id), K_(target_tablet_id));
|
||||
private:
|
||||
int init_sstable_array(const common::ObIArray<ObIDirectLoadPartitionTable *> &table_array);
|
||||
int init_multiple_sstable_array(
|
||||
@ -148,7 +143,6 @@ private:
|
||||
private:
|
||||
common::ObArenaAllocator allocator_;
|
||||
ObDirectLoadMergeParam param_;
|
||||
uint64_t target_partition_id_;
|
||||
common::ObTabletID tablet_id_;
|
||||
common::ObTabletID target_tablet_id_;
|
||||
ObDirectLoadOriginTable origin_table_;
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
#include "storage/direct_load/ob_direct_load_multiple_heap_table.h"
|
||||
#include "storage/direct_load/ob_direct_load_origin_table.h"
|
||||
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace storage
|
||||
@ -29,6 +28,7 @@ namespace storage
|
||||
using namespace common;
|
||||
using namespace blocksstable;
|
||||
using namespace share;
|
||||
using namespace table;
|
||||
|
||||
/**
|
||||
* ObDirectLoadPartitionMergeTask
|
||||
@ -48,16 +48,9 @@ ObDirectLoadPartitionMergeTask::ObDirectLoadPartitionMergeTask()
|
||||
|
||||
ObDirectLoadPartitionMergeTask::~ObDirectLoadPartitionMergeTask()
|
||||
{
|
||||
for (int64_t i = 0; i < column_stat_array_.count(); ++i) {
|
||||
ObOptOSGColumnStat *col_stat = column_stat_array_.at(i);
|
||||
if (col_stat != nullptr) {
|
||||
col_stat->~ObOptOSGColumnStat();
|
||||
col_stat = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ObDirectLoadPartitionMergeTask::process()
|
||||
int ObDirectLoadPartitionMergeTask::process(int64_t thread_idx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (IS_NOT_INIT) {
|
||||
@ -70,9 +63,7 @@ int ObDirectLoadPartitionMergeTask::process()
|
||||
ObSSTableInsertSliceWriter *writer = nullptr;
|
||||
ObMacroDataSeq block_start_seq;
|
||||
block_start_seq.set_parallel_degree(parallel_idx_);
|
||||
if (merge_param_->online_opt_stat_gather_ && OB_FAIL(init_sql_statistics())) {
|
||||
LOG_WARN("fail to init sql statistics", KR(ret));
|
||||
} else if (OB_FAIL(construct_row_iter(allocator_, row_iter))) {
|
||||
if (OB_FAIL(construct_row_iter(allocator_, row_iter))) {
|
||||
LOG_WARN("fail to construct row iter", KR(ret));
|
||||
} else if (OB_FAIL(merge_param_->insert_table_ctx_->construct_sstable_slice_writer(
|
||||
target_tablet_id, block_start_seq, writer, allocator_))) {
|
||||
@ -94,7 +85,7 @@ int ObDirectLoadPartitionMergeTask::process()
|
||||
}
|
||||
} else if (OB_FAIL(writer->append_row(*const_cast<ObDatumRow *>(datum_row)))) {
|
||||
LOG_WARN("fail to append row", KR(ret), KPC(datum_row));
|
||||
} else if (merge_param_->online_opt_stat_gather_ && OB_FAIL(collect_obj(*datum_row))) {
|
||||
} else if (OB_FAIL(merge_param_->insert_table_ctx_->collect_obj(thread_idx, *datum_row))) {
|
||||
LOG_WARN("fail to collect statistics", KR(ret));
|
||||
} else {
|
||||
++affected_rows_;
|
||||
@ -103,6 +94,8 @@ int ObDirectLoadPartitionMergeTask::process()
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(writer->close())) {
|
||||
LOG_WARN("fail to close writer", KR(ret));
|
||||
} else {
|
||||
merge_param_->insert_table_ctx_->inc_row_count(affected_rows_);
|
||||
}
|
||||
}
|
||||
LOG_INFO("add sstable slice end", KR(ret), K(target_tablet_id), K(tablet_id),
|
||||
@ -131,74 +124,6 @@ int ObDirectLoadPartitionMergeTask::process()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadPartitionMergeTask::init_sql_statistics()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
for (int64_t i = 0; OB_SUCC(ret)&& i < merge_param_->table_data_desc_.column_count_; ++i) {
|
||||
ObOptOSGColumnStat *col_stat = ObOptOSGColumnStat::create_new_osg_col_stat(allocator_);
|
||||
if (OB_ISNULL(col_stat)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("fail to allocate buffer", KR(ret));
|
||||
} else if (OB_FAIL(column_stat_array_.push_back(col_stat))){
|
||||
LOG_WARN("fail to push back", KR(ret));
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
if (col_stat != nullptr) {
|
||||
col_stat->~ObOptOSGColumnStat();
|
||||
allocator_.free(col_stat);
|
||||
col_stat = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDirectLoadPartitionMergeTask::collect_obj(const ObDatumRow &datum_row)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const int64_t extra_rowkey_cnt = ObMultiVersionRowkeyHelpper::get_extra_rowkey_col_cnt();
|
||||
if (merge_param_->is_heap_table_ ) {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < merge_param_->table_data_desc_.column_count_; i++) {
|
||||
const ObStorageDatum &datum = datum_row.storage_datums_[i + extra_rowkey_cnt + 1];
|
||||
const ObColDesc &col_desc = merge_param_->col_descs_->at(i + 1);
|
||||
const ObCmpFunc &cmp_func = merge_param_->cmp_funcs_->at(i + 1).get_cmp_func();
|
||||
ObOptOSGColumnStat *col_stat = column_stat_array_.at(i);
|
||||
bool is_valid = ObColumnStatParam::is_valid_opt_col_type(col_desc.col_type_.get_type());
|
||||
if (col_stat != nullptr && is_valid) {
|
||||
if (OB_FAIL(col_stat->update_column_stat_info(&datum, col_desc.col_type_, cmp_func.cmp_func_))) {
|
||||
LOG_WARN("Failed to merge obj", K(ret), KP(col_stat));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < merge_param_->rowkey_column_num_; i++) {
|
||||
const ObStorageDatum &datum = datum_row.storage_datums_[i];
|
||||
const ObColDesc &col_desc = merge_param_->col_descs_->at(i);
|
||||
const ObCmpFunc &cmp_func = merge_param_->cmp_funcs_->at(i).get_cmp_func();
|
||||
ObOptOSGColumnStat *col_stat = column_stat_array_.at(i);
|
||||
bool is_valid = ObColumnStatParam::is_valid_opt_col_type(col_desc.col_type_.get_type());
|
||||
if (col_stat != nullptr && is_valid) {
|
||||
if (OB_FAIL(col_stat->update_column_stat_info(&datum, col_desc.col_type_, cmp_func.cmp_func_))) {
|
||||
LOG_WARN("Failed to merge obj", K(ret), KP(col_stat));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int64_t i = merge_param_->rowkey_column_num_; OB_SUCC(ret) && i < merge_param_->table_data_desc_.column_count_; i++) {
|
||||
const ObStorageDatum &datum = datum_row.storage_datums_[i + extra_rowkey_cnt];
|
||||
const ObColDesc &col_desc = merge_param_->col_descs_->at(i);
|
||||
const ObCmpFunc &cmp_func = merge_param_->cmp_funcs_->at(i).get_cmp_func();
|
||||
ObOptOSGColumnStat *col_stat = column_stat_array_.at(i);
|
||||
bool is_valid = ObColumnStatParam::is_valid_opt_col_type(col_desc.col_type_.get_type());
|
||||
if (col_stat != nullptr && is_valid) {
|
||||
if (OB_FAIL(col_stat->update_column_stat_info(&datum, col_desc.col_type_, cmp_func.cmp_func_))) {
|
||||
LOG_WARN("Failed to merge obj", K(ret), KP(col_stat));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObDirectLoadPartitionMergeTask::stop()
|
||||
{
|
||||
is_stop_ = true;
|
||||
|
||||
@ -41,26 +41,18 @@ class ObDirectLoadPartitionMergeTask : public common::ObDLinkBase<ObDirectLoadPa
|
||||
public:
|
||||
ObDirectLoadPartitionMergeTask();
|
||||
virtual ~ObDirectLoadPartitionMergeTask();
|
||||
int process();
|
||||
const common::ObIArray<ObOptOSGColumnStat*> &get_column_stat_array() const
|
||||
{
|
||||
return column_stat_array_;
|
||||
}
|
||||
int process(int64_t thread_idx);
|
||||
int64_t get_row_count() const { return affected_rows_; }
|
||||
void stop();
|
||||
TO_STRING_KV(KPC_(merge_param), KPC_(merge_ctx), K_(parallel_idx));
|
||||
protected:
|
||||
virtual int construct_row_iter(common::ObIAllocator &allocator,
|
||||
ObIStoreRowIterator *&row_iter) = 0;
|
||||
private:
|
||||
int init_sql_statistics();
|
||||
int collect_obj(const blocksstable::ObDatumRow &datum_row);
|
||||
protected:
|
||||
const ObDirectLoadMergeParam *merge_param_;
|
||||
ObDirectLoadTabletMergeCtx *merge_ctx_;
|
||||
int64_t parallel_idx_;
|
||||
int64_t affected_rows_;
|
||||
common::ObArray<ObOptOSGColumnStat*> column_stat_array_;
|
||||
common::ObArenaAllocator allocator_;
|
||||
bool is_stop_;
|
||||
bool is_inited_;
|
||||
|
||||
@ -33,9 +33,9 @@ using namespace table;
|
||||
|
||||
ObDirectLoadTableStoreParam::ObDirectLoadTableStoreParam()
|
||||
: snapshot_version_(0),
|
||||
thread_idx_(-1),
|
||||
datum_utils_(nullptr),
|
||||
col_descs_(nullptr),
|
||||
cmp_funcs_(nullptr),
|
||||
file_mgr_(nullptr),
|
||||
is_multiple_mode_(false),
|
||||
is_fast_heap_table_(false),
|
||||
@ -53,8 +53,8 @@ ObDirectLoadTableStoreParam::~ObDirectLoadTableStoreParam()
|
||||
|
||||
bool ObDirectLoadTableStoreParam::is_valid() const
|
||||
{
|
||||
return snapshot_version_ > 0 && table_data_desc_.is_valid() && nullptr != datum_utils_ &&
|
||||
nullptr != col_descs_ && nullptr != cmp_funcs_ && nullptr != file_mgr_ &&
|
||||
return snapshot_version_ > 0 && thread_idx_ >= 0 && table_data_desc_.is_valid() &&
|
||||
nullptr != datum_utils_ && nullptr != col_descs_ && nullptr != file_mgr_ &&
|
||||
(!is_fast_heap_table_ ||
|
||||
(nullptr != insert_table_ctx_ && nullptr != fast_heap_table_ctx_)) &&
|
||||
nullptr != dml_row_handler_;
|
||||
@ -112,11 +112,10 @@ int ObDirectLoadTableStoreBucket::init(const ObDirectLoadTableStoreParam ¶m,
|
||||
fast_heap_table_build_param.table_data_desc_ = param.table_data_desc_;
|
||||
fast_heap_table_build_param.datum_utils_ = param.datum_utils_;
|
||||
fast_heap_table_build_param.col_descs_ = param.col_descs_;
|
||||
fast_heap_table_build_param.cmp_funcs_ = param.cmp_funcs_;
|
||||
fast_heap_table_build_param.insert_table_ctx_ = param.insert_table_ctx_;
|
||||
fast_heap_table_build_param.fast_heap_table_ctx_ = param.fast_heap_table_ctx_;
|
||||
fast_heap_table_build_param.dml_row_handler_ = param.dml_row_handler_;
|
||||
fast_heap_table_build_param.online_opt_stat_gather_ = param.online_opt_stat_gather_;
|
||||
fast_heap_table_build_param.thread_idx_ = param.thread_idx_;
|
||||
ObDirectLoadFastHeapTableBuilder *fast_heap_table_builder = nullptr;
|
||||
if (OB_ISNULL(fast_heap_table_builder =
|
||||
table_builder_allocator_->alloc<ObDirectLoadFastHeapTableBuilder>())) {
|
||||
|
||||
@ -34,20 +34,19 @@ public:
|
||||
ObDirectLoadTableStoreParam();
|
||||
~ObDirectLoadTableStoreParam();
|
||||
bool is_valid() const;
|
||||
TO_STRING_KV(K_(snapshot_version), K_(table_data_desc), KP_(datum_utils), KP_(col_descs),
|
||||
KP_(cmp_funcs), KP_(file_mgr), K_(is_multiple_mode), K_(is_fast_heap_table),
|
||||
TO_STRING_KV(K_(snapshot_version), K_(thread_idx), K_(table_data_desc), KP_(datum_utils),
|
||||
KP_(col_descs), KP_(file_mgr), K_(is_multiple_mode), K_(is_fast_heap_table),
|
||||
KP_(insert_table_ctx), KP_(fast_heap_table_ctx), KP_(dml_row_handler),
|
||||
KP_(extra_buf), K_(extra_buf_size));
|
||||
public:
|
||||
int64_t snapshot_version_;
|
||||
int64_t thread_idx_;
|
||||
ObDirectLoadTableDataDesc table_data_desc_;
|
||||
const blocksstable::ObStorageDatumUtils *datum_utils_;
|
||||
const common::ObIArray<share::schema::ObColDesc> *col_descs_;
|
||||
const blocksstable::ObStoreCmpFuncs *cmp_funcs_;
|
||||
ObDirectLoadTmpFileManager *file_mgr_;
|
||||
bool is_multiple_mode_;
|
||||
bool is_fast_heap_table_;
|
||||
bool online_opt_stat_gather_;
|
||||
ObDirectLoadInsertTableContext *insert_table_ctx_;
|
||||
ObDirectLoadFastHeapTableContext *fast_heap_table_ctx_;
|
||||
ObDirectLoadDMLRowHandler *dml_row_handler_;
|
||||
|
||||
Reference in New Issue
Block a user