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

@ -1 +1 @@
sql_unittest(test_monitoring_dump)
# sql_unittest(test_monitoring_dump)

View File

@ -32,6 +32,7 @@
#include "sql/engine/basic/ob_monitoring_dump.h"
#include "sql/engine/test_engine_util.h"
using namespace oceanbase;
using namespace oceanbase::sql;
using namespace oceanbase::common;
@ -40,44 +41,42 @@ using namespace oceanbase::share;
int64_t row_size = 3;
static ObArenaAllocator alloc_;
class ObSingleChildOperatorFake : public ObSingleChildPhyOperator {
class ObSingleChildOperatorFake : public ObSingleChildPhyOperator
{
friend class ObPhyOperatorTest;
protected:
class ObSingleOpCtx : public ObPhyOperator::ObPhyOperatorCtx {
class ObSingleOpCtx : public ObPhyOperator::ObPhyOperatorCtx
{
public:
ObSingleOpCtx(ObExecContext& ctx) : ObPhyOperatorCtx(ctx)
{}
virtual void destroy()
{
return ObPhyOperatorCtx::destroy_base();
}
ObSingleOpCtx(ObExecContext &ctx)
: ObPhyOperatorCtx(ctx)
{
}
virtual void destroy() { return ObPhyOperatorCtx::destroy_base(); }
};
public:
ObSingleChildOperatorFake() : ObSingleChildPhyOperator(alloc_)
{}
ObSingleChildOperatorFake() : ObSingleChildPhyOperator(alloc_) {}
ObPhyOperatorType get_type() const
{
return static_cast<ObPhyOperatorType>(0);
}
int inner_open(ObExecContext& ctx) const
int inner_open(ObExecContext &ctx) const
{
int ret = OB_SUCCESS;
if (OB_SUCCESS != (ret = init_op_ctx(ctx))) {
_OB_LOG(WARN, "init operator context failed, ret=%d", ret);
} /* else {
ret = ObSingleChildPhyOperator::open(ctx);
}*/
}/* else {
ret = ObSingleChildPhyOperator::open(ctx);
}*/
return ret;
}
int inner_close(ObExecContext& ctx) const
int inner_close(ObExecContext &ctx) const
{
UNUSED(ctx);
int ret = OB_SUCCESS;
// ret = ObSingleChildPhyOperator::close(ctx);
//ret = ObSingleChildPhyOperator::close(ctx);
return ret;
}
@ -91,12 +90,12 @@ public:
*/
protected:
virtual int inner_get_next_row(ObExecContext& ctx, const ObNewRow*& row) const
virtual int inner_get_next_row(ObExecContext &ctx, const ObNewRow *&row) const
{
int ret = OB_SUCCESS;
const ObNewRow* input_row = NULL;
ObPhyOperator* child_op = NULL;
ObSingleOpCtx* phy_op_ctx = NULL;
const ObNewRow *input_row = NULL;
ObPhyOperator *child_op = NULL;
ObSingleOpCtx *phy_op_ctx = NULL;
if (NULL == (child_op = get_child(0))) {
ret = OB_ERR_UNEXPECTED;
@ -110,7 +109,7 @@ protected:
_OB_LOG(WARN, "get physical operator context failed, ret=%d", ret);
} else {
_OB_LOG(DEBUG, "inner_get_next_row, row=%s", to_cstring(*input_row));
ObNewRow& cur_row = phy_op_ctx->get_cur_row();
ObNewRow &cur_row = phy_op_ctx->get_cur_row();
OB_ASSERT(input_row->count_ <= cur_row.count_);
for (int64_t i = 0; i < input_row->count_; ++i) {
cur_row.cells_[i] = input_row->cells_[i];
@ -120,10 +119,10 @@ protected:
return ret;
}
virtual int init_op_ctx(ObExecContext& ctx) const
virtual int init_op_ctx(ObExecContext &ctx) const
{
int ret = OB_SUCCESS;
ObPhyOperatorCtx* op_ctx = NULL;
ObPhyOperatorCtx *op_ctx = NULL;
if (OB_SUCCESS != (ret = CREATE_PHY_OPERATOR_CTX(ObSingleOpCtx, ctx, get_id(), get_type(), op_ctx))) {
_OB_LOG(WARN, "create physical operator context failed, ret=%d", ret);
@ -133,27 +132,30 @@ protected:
return ret;
}
};
class ObTableScanFake : public ObNoChildrenPhyOperator {
class ObTableScanFake : public ObNoChildrenPhyOperator
{
protected:
class ObTableScanFakeCtx : public ObPhyOperatorCtx {
class ObTableScanFakeCtx : public ObPhyOperatorCtx
{
public:
ObTableScanFakeCtx(ObExecContext& ctx) : ObPhyOperatorCtx(ctx)
{}
virtual void destroy()
ObTableScanFakeCtx(ObExecContext &ctx)
: ObPhyOperatorCtx(ctx)
{
return ObPhyOperatorCtx::destroy_base();
}
virtual void destroy() { return ObPhyOperatorCtx::destroy_base(); }
};
public:
ObTableScanFake() : ObNoChildrenPhyOperator(alloc_), row_store_(NULL), store_size_(0), cur_index_(0)
{}
ObTableScanFake() : ObNoChildrenPhyOperator(alloc_),
row_store_(NULL), store_size_(0), cur_index_(0)
{
}
ObPhyOperatorType get_type() const
{
return static_cast<ObPhyOperatorType>(0);
}
int inner_open(ObExecContext& ctx) const
int inner_open(ObExecContext &ctx) const
{
int ret = OB_SUCCESS;
if (OB_SUCCESS != (ret = init_op_ctx(ctx))) {
@ -162,24 +164,24 @@ public:
return ret;
}
int inner_close(ObExecContext& ctx) const
int inner_close(ObExecContext &ctx) const
{
UNUSED(ctx);
return OB_SUCCESS;
}
void load_data_row(ObExecContext& ctx, int64_t store_size)
void load_data_row(ObExecContext &ctx, int64_t store_size)
{
int64_t cell_val = -1;
void* ptr = NULL;
void *ptr = NULL;
store_size_ = store_size;
ASSERT_GT(store_size_, 0);
ptr = ctx.get_allocator().alloc(store_size * sizeof(ObNewRow));
ASSERT_FALSE(NULL == ptr);
row_store_ = static_cast<ObNewRow*>(ptr);
row_store_ = static_cast<ObNewRow *>(ptr);
for (int64_t i = 0; i < store_size; ++i) {
void* cells = ctx.get_allocator().alloc(row_size * sizeof(ObObj));
void *cells = ctx.get_allocator().alloc(row_size * sizeof(ObObj));
ASSERT_FALSE(NULL == cells);
row_store_[i].cells_ = static_cast<ObObj*>(cells);
row_store_[i].count_ = row_size;
@ -188,9 +190,8 @@ public:
}
}
}
protected:
virtual int inner_get_next_row(ObExecContext& ctx, const ObNewRow*& row) const
virtual int inner_get_next_row(ObExecContext &ctx, const ObNewRow *&row) const
{
UNUSED(ctx);
int ret = OB_SUCCESS;
@ -202,34 +203,32 @@ protected:
return ret;
}
virtual int init_op_ctx(ObExecContext& ctx) const
virtual int init_op_ctx(ObExecContext &ctx) const
{
int ret = OB_SUCCESS;
ObPhyOperatorCtx* op_ctx = NULL;
ObPhyOperatorCtx *op_ctx = NULL;
ret = CREATE_PHY_OPERATOR_CTX(ObTableScanFakeCtx, ctx, get_id(), get_type(), op_ctx);
UNUSED(op_ctx);
return ret;
}
private:
ObNewRow* row_store_;
ObNewRow *row_store_;
int64_t store_size_;
mutable int64_t cur_index_;
};
class ObMonitoringDumpTest : public ::testing::Test {
class ObMonitoringDumpTest: public ::testing::Test
{
public:
ObMonitoringDumpTest(){};
ObMonitoringDumpTest() {};
virtual ~ObMonitoringDumpTest() = default;
virtual void SetUp(){};
virtual void SetUp() {};
virtual void TearDown(){};
void is_equal_content(const char* tmp_file, const char* result_file);
private:
// disallow copy
ObMonitoringDumpTest(const ObMonitoringDumpTest& other);
ObMonitoringDumpTest& operator=(const ObMonitoringDumpTest& other);
ObMonitoringDumpTest(const ObMonitoringDumpTest &other);
ObMonitoringDumpTest& operator=(const ObMonitoringDumpTest &other);
private:
// data members
};
@ -253,7 +252,7 @@ void ObMonitoringDumpTest::is_equal_content(const char* tmp_file, const char* re
fprintf(stdout, "emacs -q %s %s\n", result_file, tmp_file);
fprintf(stdout, "diff -u %s %s\n", result_file, tmp_file);
fprintf(stdout, "mv %s %s\n", tmp_file, result_file);
std::rename(tmp_file, result_file);
std::rename(tmp_file,result_file);
} else {
fprintf(stdout, "The result files mismatched, you can choose to\n");
fprintf(stdout, "diff -u %s %s\n", tmp_file, result_file);
@ -266,15 +265,15 @@ TEST_F(ObMonitoringDumpTest, test_get_next_row)
const char* tmp_file = "./test_monitoring_dump.tmp";
const char* result_file = "./test_monitoring_dump.result";
std::ofstream of_result(tmp_file);
const ObNewRow* row = NULL;
const ObNewRow *row = NULL;
ObExecContext ctx;
ObTableScanFake table_scan;
ObMonitoringDump root(ctx.get_allocator());
root.set_flags(OB_MONITOR_STAT | OB_MONITOR_TRACING);
root.set_flags(ObMonitorHint::OB_MONITOR_STAT | ObMonitorHint::OB_MONITOR_TRACING);
ObPhysicalPlan physical_plan;
int64_t op_size = 2;
ObSQLSessionInfo origin_session;
origin_session.test_init(0, 0, 0, NULL);
origin_session.test_init(0,0,0,NULL);
ASSERT_EQ(OB_SUCCESS, ObPreProcessSysVars::init_sys_var());
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
@ -318,10 +317,10 @@ TEST_F(ObMonitoringDumpTest, test_get_next_row)
ObMonitoringDumpTest::is_equal_content(tmp_file, result_file);
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
init_sql_factories();
::testing::InitGoogleTest(&argc, argv);
::testing::InitGoogleTest(&argc,argv);
OB_LOGGER.set_log_level("INFO");
return RUN_ALL_TESTS();
}