diff --git a/deps/oblib/src/lib/task/ob_timer.cpp b/deps/oblib/src/lib/task/ob_timer.cpp index 219bd92a34..c448102b70 100644 --- a/deps/oblib/src/lib/task/ob_timer.cpp +++ b/deps/oblib/src/lib/task/ob_timer.cpp @@ -37,9 +37,18 @@ int ObTimer::init(const char* timer_name, const ObMemAttr &attr) if (is_inited_) { ret = OB_INIT_TWICE; } else { - is_inited_ = true; - is_stopped_ = false; - ObTimerUtil::copy_buff(timer_name_, sizeof(timer_name_), timer_name); + if (nullptr == timer_service_) { + timer_service_ = &(ObTimerService::get_instance()); + } + IRunWrapper *expect_wrapper = Threads::get_expect_run_wrapper(); + if (expect_wrapper != nullptr && expect_wrapper != run_wrapper_) { + ret = OB_ERR_UNEXPECTED; + OB_LOG(ERROR, "ObTimer::init tenant ctx not match", KP(expect_wrapper), KP(run_wrapper_)); + } else { + is_inited_ = true; + is_stopped_ = false; + ObTimerUtil::copy_buff(timer_name_, sizeof(timer_name_), timer_name); + } } return ret; } @@ -52,12 +61,7 @@ ObTimer::~ObTimer() int ObTimer::start() { int ret = OB_SUCCESS; - IRunWrapper *expect_wrapper = Threads::get_expect_run_wrapper(); - if (expect_wrapper != nullptr && expect_wrapper != run_wrapper_) { - ret = OB_ERR_UNEXPECTED; - OB_LOG(ERROR, "ObTimer::start tenant ctx not match", KP(expect_wrapper), KP(run_wrapper_)); - ob_abort(); - } else if (!is_inited_) { + if (!is_inited_) { ret = OB_NOT_INIT; OB_LOG(WARN, "timer is not yet initialized", K(ret)); } else if (is_stopped_) { @@ -97,15 +101,19 @@ void ObTimer::destroy() wait(); is_inited_ = false; timer_service_ = nullptr; + run_wrapper_ = nullptr; timer_name_[0] = '\0'; } } -int ObTimer::set_run_wrapper(lib::IRunWrapper *run_wrapper) +int ObTimer::set_run_wrapper_with_ret(lib::IRunWrapper *run_wrapper) { int ret = OB_SUCCESS; - if (nullptr != run_wrapper) - { + if (is_inited_) { + ret = OB_OP_NOT_ALLOW; + OB_LOG(ERROR, "can not set run_wrapper after init", K(ret)); + } + if (OB_SUCC(ret) && nullptr != run_wrapper) { ObTimerService *service = run_wrapper->get_timer_service(); if (nullptr == service) { ret = OB_ERR_UNEXPECTED; diff --git a/deps/oblib/src/lib/task/ob_timer.h b/deps/oblib/src/lib/task/ob_timer.h index 712c41743a..a9240238ed 100644 --- a/deps/oblib/src/lib/task/ob_timer.h +++ b/deps/oblib/src/lib/task/ob_timer.h @@ -42,7 +42,7 @@ public: void stop(); // only stop void wait(); // wait all running task finish void destroy(); - int set_run_wrapper(lib::IRunWrapper *run_wrapper); + int set_run_wrapper_with_ret(lib::IRunWrapper *run_wrapper); int64_t to_string(char *buf, const int64_t buf_len) const { int64_t pos = 0; diff --git a/deps/oblib/src/lib/task/ob_timer_service.h b/deps/oblib/src/lib/task/ob_timer_service.h index 25415b8d30..dfc2570f39 100644 --- a/deps/oblib/src/lib/task/ob_timer_service.h +++ b/deps/oblib/src/lib/task/ob_timer_service.h @@ -205,27 +205,6 @@ public: static constexpr int64_t DELAY_IN_PRI_QUEUE_THREASHOLD = 1L * 1000L * 1000L; // 1s }; -#define NEW_AND_SET_TIMER_SERVICE(id) \ -do { \ - uint64_t tid = (uint64_t) id; \ - int tmp_ret = OB_SUCCESS; \ - ObTimerService *timer_service = MTL(ObTimerService *); \ - if (nullptr == timer_service) { \ - ObTenantBase *tenant_base = MTL_CTX(); \ - if (nullptr == tenant_base) { \ - tmp_ret = OB_ERR_NULL_VALUE; \ - LOG_WARN("tenant_base is NULL", K(tid), K(tmp_ret)); \ - } else if (nullptr == (timer_service = OB_NEW(ObTimerService, "timer_service", tid))) { \ - tmp_ret = OB_ALLOCATE_MEMORY_FAILED; \ - LOG_WARN("failed to new timer service", K(tid), K(tmp_ret)); \ - } else if (OB_SUCCESS != (tmp_ret = timer_service->start())) { \ - LOG_WARN("failed to start timer service", K(tid), K(tmp_ret)); \ - } else { \ - tenant_base->set(timer_service); \ - } \ - } \ -} while (0) - } /* common */ } /* oceanbase */ diff --git a/deps/oblib/src/lib/thread/thread_mgr.h b/deps/oblib/src/lib/thread/thread_mgr.h index db14853f67..c9649dff89 100644 --- a/deps/oblib/src/lib/thread/thread_mgr.h +++ b/deps/oblib/src/lib/thread/thread_mgr.h @@ -797,7 +797,7 @@ public: ret = common::OB_ERR_UNEXPECTED; } else { timer_ = new (buf_) common::ObTimer(); - if (OB_FAIL(timer_->set_run_wrapper(tg_helper_))) { + if (OB_FAIL(timer_->set_run_wrapper_with_ret(tg_helper_))) { OB_LOG(WARN, "timer set run wrapper failed", K(ret)); } else if (OB_FAIL(timer_->init(attr_.name_, ObMemAttr(get_tenant_id(), "TGTimer")))) { diff --git a/deps/oblib/unittest/lib/task/test_timer.cpp b/deps/oblib/unittest/lib/task/test_timer.cpp index e44a72dc00..f6d99fd10b 100644 --- a/deps/oblib/unittest/lib/task/test_timer.cpp +++ b/deps/oblib/unittest/lib/task/test_timer.cpp @@ -219,6 +219,12 @@ TEST_F(TestTimer, task_service_stop) usleep(100000); // 100ms ASSERT_EQ(1, task1.task_run_count_); ASSERT_EQ(0, task2.task_run_count_); + timer1.stop(); + timer1.wait(); + timer1.destroy(); + timer2.stop(); + timer2.wait(); + timer2.destroy(); } TEST_F(TestTimer, task_run1_wait) @@ -265,6 +271,29 @@ TEST_F(TestTimer, schedule_after_stop) timer.destroy(); } +TEST_F(TestTimer, without_start) +{ + // ensure that the timer still works without calling start + TestTimerTask task; + task.exec_time_ = 10000; // 10ms + ObTimer timer; + ASSERT_EQ(OB_SUCCESS, timer.init()); + ASSERT_EQ(OB_SUCCESS, timer.schedule(task, 0, false, false)); + usleep(50000); // 50ms + ASSERT_EQ(1, task.task_run_count_); + timer.stop(); + timer.wait(); + timer.destroy(); + // ensure that the timer still works after destroy and re-init + ASSERT_EQ(OB_SUCCESS, timer.init()); + ASSERT_EQ(OB_SUCCESS, timer.schedule(task, 0, false, false)); + usleep(50000); // 50ms + ASSERT_EQ(2, task.task_run_count_); + timer.stop(); + timer.wait(); + timer.destroy(); +} + } // end namespace common } // end namespace oceanbase diff --git a/deps/oblib/unittest/lib/test_work_queue.cpp b/deps/oblib/unittest/lib/test_work_queue.cpp index 5921c330b8..20b07575ec 100644 --- a/deps/oblib/unittest/lib/test_work_queue.cpp +++ b/deps/oblib/unittest/lib/test_work_queue.cpp @@ -145,7 +145,6 @@ TEST_F(TestWorkQueue, async_task) ASSERT_EQ(OB_SUCCESS, wqueue.wait()); } -/* TEST_F(TestWorkQueue, on_shoot_timer_task) { ObWorkQueue wqueue; @@ -252,7 +251,6 @@ TEST_F(TestWorkQueue, immediate_task) ASSERT_EQ(OB_SUCCESS, wqueue.stop()); ASSERT_EQ(OB_SUCCESS, wqueue.wait()); } -*/ int main(int argc, char **argv) { diff --git a/src/logservice/logrouteservice/ob_log_route_service.cpp b/src/logservice/logrouteservice/ob_log_route_service.cpp index 7d6d3cebcc..30e446b846 100644 --- a/src/logservice/logrouteservice/ob_log_route_service.cpp +++ b/src/logservice/logrouteservice/ob_log_route_service.cpp @@ -114,8 +114,8 @@ int ObLogRouteService::init(ObISQLClient *proxy, } else if (OB_FAIL(LOG_ROUTE_TIMER_INIT_FAIL)) { LOG_ERROR("ERRSIM: LOG_ROUTE_TIMER_INIT_FAIL"); #endif - } else if (OB_FAIL(timer_.set_run_wrapper(MTL_CTX()))) { - LOG_WARN("timer set run wrapper failed", K(ret)); + } else if (OB_FAIL(timer_.set_run_wrapper_with_ret(MTL_CTX()))) { + LOG_ERROR("timer set run wrapper failed", K(ret)); } else if (OB_FAIL(timer_.init("LogRouter"))) { LOG_ERROR("fail to init itable gc timer", K(ret)); #ifdef ERRSIM diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index 7c9c71a270..51967e055b 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -239,15 +239,6 @@ int ObServer::init(const ObServerOptions &opts, const ObPLogWriterCfg &log_cfg) } #endif - // start ObTimerService first, because some timers depend on it - if (OB_SUCC(ret)) { - if (OB_FAIL(ObSimpleThreadPoolDynamicMgr::get_instance().init())) { - LOG_ERROR("init queue_thread dynamic mgr failed", KR(ret)); - } else if (OB_FAIL(ObTimerService::get_instance().start())) { - LOG_ERROR("start timer service failed", KR(ret)); - } - } - // server parameters be inited here. if (OB_SUCC(ret) && OB_FAIL(init_config())) { LOG_ERROR("init config failed", KR(ret)); @@ -265,6 +256,15 @@ int ObServer::init(const ObServerOptions &opts, const ObPLogWriterCfg &log_cfg) // set large page param ObLargePageHelper::set_param(config_.use_large_pages); + // start ObTimerService first, because some timers depend on it + if (OB_SUCC(ret)) { + if (OB_FAIL(ObSimpleThreadPoolDynamicMgr::get_instance().init())) { + LOG_ERROR("init queue_thread dynamic mgr failed", KR(ret)); + } else if (OB_FAIL(ObTimerService::get_instance().start())) { + LOG_ERROR("start timer service failed", KR(ret)); + } + } + if (is_arbitration_mode()) { #ifdef OB_BUILD_ARBITRATION FLOG_INFO("begin init observer in arbitration mode", KR(ret)); diff --git a/src/observer/table/group/ob_table_tenant_group.cpp b/src/observer/table/group/ob_table_tenant_group.cpp index dda8882b8f..73ed826d26 100644 --- a/src/observer/table/group/ob_table_tenant_group.cpp +++ b/src/observer/table/group/ob_table_tenant_group.cpp @@ -325,8 +325,9 @@ int ObTableGroupCommitMgr::start_timer() int ret = OB_SUCCESS; if (!timer_.inited()) { - timer_.set_run_wrapper(MTL_CTX()); - if (OB_FAIL(timer_.init("TableGroupCommitMgr"))) { + if (OB_FAIL(timer_.set_run_wrapper_with_ret(MTL_CTX()))) { + LOG_WARN("fail to set timer's run wrapper", KR(ret)); + } else if (OB_FAIL(timer_.init("TableGroupCommitMgr"))) { LOG_WARN("fail to init kv group commit timer", KR(ret)); } else if (OB_FAIL(timer_.schedule(group_trigger_task_, ObTableGroupTriggerTask::TASK_SCHEDULE_INTERVAL, diff --git a/src/observer/table_load/ob_table_load_service.cpp b/src/observer/table_load/ob_table_load_service.cpp index eeaf15aa3a..90ef74c843 100644 --- a/src/observer/table_load/ob_table_load_service.cpp +++ b/src/observer/table_load/ob_table_load_service.cpp @@ -894,7 +894,7 @@ int ObTableLoadService::start() ret = OB_NOT_INIT; LOG_WARN("ObTableLoadService not init", KR(ret), KP(this)); } else { - if (OB_FAIL(timer_.set_run_wrapper(MTL_CTX()))) { + if (OB_FAIL(timer_.set_run_wrapper_with_ret(MTL_CTX()))) { LOG_WARN("fail to set gc timer's run wrapper", KR(ret)); } else if (OB_FAIL(timer_.init("TLD_Timer", ObMemAttr(MTL_ID(), "TLD_TIMER")))) { LOG_WARN("fail to init gc timer", KR(ret)); diff --git a/src/share/redolog/ob_log_file_reader.cpp b/src/share/redolog/ob_log_file_reader.cpp index 0256f7b37c..68c01f9991 100644 --- a/src/share/redolog/ob_log_file_reader.cpp +++ b/src/share/redolog/ob_log_file_reader.cpp @@ -171,7 +171,7 @@ int ObLogFileReader2::init() LOG_WARN("already inited", K(ret)); } else if (OB_FAIL(quick_map_.create(MAP_BUCKET_INIT_CNT, "LogFileReaderM"))) { LOG_WARN("already inited", K(ret)); - } else if (OB_FAIL(timer_.set_run_wrapper(MTL_CTX()))) { + } else if (OB_FAIL(timer_.set_run_wrapper_with_ret(MTL_CTX()))) { LOG_WARN("timer set_run_wrapper fail", K(ret)); } else if (OB_FAIL(timer_.init("ObLogFileReader2"))) { LOG_WARN("init timer fail", K(ret)); diff --git a/src/sql/plan_cache/ob_plan_cache.cpp b/src/sql/plan_cache/ob_plan_cache.cpp index 4d1795525a..ca23cce3f3 100644 --- a/src/sql/plan_cache/ob_plan_cache.cpp +++ b/src/sql/plan_cache/ob_plan_cache.cpp @@ -403,11 +403,6 @@ int ObPlanCache::init(int64_t hash_bucket, uint64_t tenant_id) SQL_PC_LOG(WARN, "failed to init PlanCache", K(ret)); } else if (OB_FAIL(TG_CREATE_TENANT(lib::TGDefIDs::PlanCacheEvict, tg_id_))) { LOG_WARN("failed to create tg", K(ret)); - } else { - // just for unittest test_create_executor, do not set error code - NEW_AND_SET_TIMER_SERVICE(tenant_id); - } - if (OB_FAIL(ret)) { } else if (OB_FAIL(TG_START(tg_id_))) { LOG_WARN("failed to start tg", K(ret)); } else if (OB_FAIL(TG_SCHEDULE(tg_id_, evict_task_, GCONF.plan_cache_evict_interval, true))) { diff --git a/src/storage/blocksstable/ob_block_manager.cpp b/src/storage/blocksstable/ob_block_manager.cpp index 6875fbf05b..456f0675f9 100644 --- a/src/storage/blocksstable/ob_block_manager.cpp +++ b/src/storage/blocksstable/ob_block_manager.cpp @@ -145,10 +145,10 @@ int ObBlockManager::init(ObIODevice *io_device, const int64_t block_size) { ObServerSuperBlockHeader::OB_MAX_SUPER_BLOCK_SIZE)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument, ", K(ret), KP(io_device), K(block_size)); + } else if (OB_FAIL(timer_.set_run_wrapper_with_ret(MTL_CTX()))) { + LOG_WARN("fail to set_run_wrapper for timer", K(ret)); } else if (OB_FAIL(timer_.init("BlkMgr"))) { LOG_WARN("fail to init timer", K(ret)); - } else if (OB_FAIL(timer_.set_run_wrapper(MTL_CTX()))) { - LOG_WARN("fail to set_run_wrapper for timer", K(ret)); } else if (OB_FAIL(bucket_lock_.init(DEFAULT_LOCK_BUCKET_COUNT, ObLatchIds::BLOCK_MANAGER_LOCK))) { LOG_WARN("fail to init bucket lock", K(ret)); diff --git a/src/storage/ob_tenant_tablet_stat_mgr.cpp b/src/storage/ob_tenant_tablet_stat_mgr.cpp index 804cca55b5..7e2cb422f7 100644 --- a/src/storage/ob_tenant_tablet_stat_mgr.cpp +++ b/src/storage/ob_tenant_tablet_stat_mgr.cpp @@ -658,11 +658,6 @@ int ObTenantTabletStatMgr::init(const int64_t tenant_id) LOG_WARN("failed to init bucket lock", K(ret)); } else if (OB_FAIL(TG_CREATE_TENANT(lib::TGDefIDs::TabletStatRpt, report_tg_id_))) { LOG_WARN("failed to create TabletStatRpt thread", K(ret)); - } else { - // just for unittest test_tenant_tablet_stat_mgr, do not set error code - NEW_AND_SET_TIMER_SERVICE(tenant_id); - } - if (OB_FAIL(ret)) { } else if (OB_FAIL(TG_START(report_tg_id_))) { LOG_WARN("failed to start stat TabletStatRpt thread", K(ret)); } else if (OB_FAIL(TG_SCHEDULE(report_tg_id_, report_stat_task_, TABLET_STAT_PROCESS_INTERVAL, repeat))) { diff --git a/src/storage/slog_ckpt/ob_server_checkpoint_slog_handler.cpp b/src/storage/slog_ckpt/ob_server_checkpoint_slog_handler.cpp index e2f10690a7..23df4ee884 100644 --- a/src/storage/slog_ckpt/ob_server_checkpoint_slog_handler.cpp +++ b/src/storage/slog_ckpt/ob_server_checkpoint_slog_handler.cpp @@ -60,7 +60,7 @@ int ObServerCheckpointSlogHandler::init(ObStorageLogger *server_slogger) if (OB_UNLIKELY(is_inited_)) { ret = OB_INIT_TWICE; LOG_WARN("ObServerCheckpointSlogHandler has inited", K(ret)); - } else if (OB_FAIL(task_timer_.set_run_wrapper(MTL_CTX()))) { + } else if (OB_FAIL(task_timer_.set_run_wrapper_with_ret(MTL_CTX()))) { LOG_WARN("fail to set timer's run wrapper", K(ret)); } else if (OB_FAIL(task_timer_.init("ServerCkptSlogHandler"))) { LOG_WARN("fail to init task timer", K(ret)); diff --git a/src/storage/tx_storage/ob_checkpoint_service.cpp b/src/storage/tx_storage/ob_checkpoint_service.cpp index d5a7c0bfe8..c63eafee40 100644 --- a/src/storage/tx_storage/ob_checkpoint_service.cpp +++ b/src/storage/tx_storage/ob_checkpoint_service.cpp @@ -51,19 +51,19 @@ int ObCheckPointService::init(const int64_t tenant_id) int ObCheckPointService::start() { int ret = OB_SUCCESS; - if (OB_FAIL(checkpoint_timer_.set_run_wrapper(MTL_CTX()))) { + if (OB_FAIL(checkpoint_timer_.set_run_wrapper_with_ret(MTL_CTX()))) { STORAGE_LOG(ERROR, "fail to set checkpoint_timer's run wrapper", K(ret)); } else if (OB_FAIL(checkpoint_timer_.init("TxCkpt", ObMemAttr(MTL_ID(), "CheckPointTimer")))) { STORAGE_LOG(ERROR, "fail to init checkpoint_timer", K(ret)); } else if (OB_FAIL(checkpoint_timer_.schedule(checkpoint_task_, CHECKPOINT_INTERVAL, true))) { STORAGE_LOG(ERROR, "fail to schedule checkpoint task", K(ret)); - } else if (OB_FAIL(traversal_flush_timer_.set_run_wrapper(MTL_CTX()))) { + } else if (OB_FAIL(traversal_flush_timer_.set_run_wrapper_with_ret(MTL_CTX()))) { STORAGE_LOG(ERROR, "fail to set traversal_timer's run wrapper", K(ret)); } else if (OB_FAIL(traversal_flush_timer_.init("Flush", ObMemAttr(MTL_ID(), "FlushTimer")))) { STORAGE_LOG(ERROR, "fail to init traversal_timer", K(ret)); } else if (OB_FAIL(traversal_flush_timer_.schedule(traversal_flush_task_, TRAVERSAL_FLUSH_INTERVAL, true))) { STORAGE_LOG(ERROR, "fail to schedule traversal_flush task", K(ret)); - } else if (OB_FAIL(check_clog_disk_usage_timer_.set_run_wrapper(MTL_CTX()))) { + } else if (OB_FAIL(check_clog_disk_usage_timer_.set_run_wrapper_with_ret(MTL_CTX()))) { STORAGE_LOG(ERROR, "fail to set check_clog_disk_usage_timer's run wrapper", K(ret)); } else if (OB_FAIL(check_clog_disk_usage_timer_.init("CKClogDisk", ObMemAttr(MTL_ID(), "DiskUsageTimer")))) { STORAGE_LOG(ERROR, "fail to init check_clog_disk_usage_timer", K(ret)); diff --git a/src/storage/tx_storage/ob_tablet_gc_service.cpp b/src/storage/tx_storage/ob_tablet_gc_service.cpp index 8c9cf0859b..3f0fb79b15 100755 --- a/src/storage/tx_storage/ob_tablet_gc_service.cpp +++ b/src/storage/tx_storage/ob_tablet_gc_service.cpp @@ -62,23 +62,18 @@ int ObTabletGCService::start() { int ret = OB_SUCCESS; bool is_shared_storage = GCTX.is_shared_storage_mode(); -#ifdef OB_BUILD_SHARED_STORAGE - if (is_shared_storage) { - if (OB_FAIL(timer_for_private_block_gc_.set_run_wrapper(MTL_CTX()))) { - STORAGE_LOG(ERROR, "fail to set timer's run wrapper", KR(ret)); - } - } -#endif if (OB_FAIL(ret)) { - } else if (OB_FAIL(timer_for_tablet_change_.set_run_wrapper(MTL_CTX()))) { + } else if (OB_FAIL(timer_for_tablet_change_.set_run_wrapper_with_ret(MTL_CTX()))) { STORAGE_LOG(ERROR, "fail to set timer's run wrapper", KR(ret)); } else if (OB_FAIL(timer_for_tablet_change_.init())) { STORAGE_LOG(ERROR, "fail to init timer", KR(ret)); - } else if (OB_FAIL(timer_for_tablet_shell_.set_run_wrapper(MTL_CTX()))) { + } else if (OB_FAIL(timer_for_tablet_shell_.set_run_wrapper_with_ret(MTL_CTX()))) { STORAGE_LOG(ERROR, "fail to set timer's run wrapper", KR(ret)); } else if (OB_FAIL(timer_for_tablet_shell_.init("TabletShell", ObMemAttr(MTL_ID(), "TabletShell")))) { STORAGE_LOG(ERROR, "fail to init timer", KR(ret)); #ifdef OB_BUILD_SHARED_STORAGE + } else if (is_shared_storage && OB_FAIL(timer_for_private_block_gc_.set_run_wrapper_with_ret(MTL_CTX()))) { + STORAGE_LOG(ERROR, "fail to set timer's run wrapper", KR(ret)); } else if (is_shared_storage && OB_FAIL(timer_for_private_block_gc_.init("PvtBlkGCTimer", ObMemAttr(MTL_ID(), "PvtBlkGCTimer")))) { STORAGE_LOG(ERROR, "fail to init timer", KR(ret)); #endif diff --git a/unittest/observer/table/test_create_executor.cpp b/unittest/observer/table/test_create_executor.cpp index 4ae47017c0..487f140687 100644 --- a/unittest/observer/table/test_create_executor.cpp +++ b/unittest/observer/table/test_create_executor.cpp @@ -508,7 +508,11 @@ TEST_F(TestCreateExecutor, test_cache) { uint64_t tenant_id = 1; ObTenantBase tenant_ctx(tenant_id); + ObTimerService *timer_service = OB_NEW(ObTimerService, ObModIds::TEST, tenant_id); + ASSERT_NE(nullptr, timer_service); + tenant_ctx.set(timer_service); ObTenantEnv::set_tenant(&tenant_ctx); + ASSERT_EQ(OB_SUCCESS, timer_service->start()); // init plan cache ObPlanCache plan_cache; int ret = plan_cache.init(OB_PLAN_CACHE_BUCKET_NUMBER, tenant_id); @@ -558,6 +562,13 @@ TEST_F(TestCreateExecutor, test_cache) ASSERT_TRUE(nullptr != spec); ASSERT_EQ(TABLE_API_EXEC_INSERT, spec->type_); } + + if (nullptr != timer_service) { + timer_service->stop(); + timer_service->wait(); + timer_service->destroy(); + OB_DELETE(ObTimerService, ObModIds::TEST, timer_service); + } } } // end namespace oceanbase diff --git a/unittest/sql/test_sql_utils.cpp b/unittest/sql/test_sql_utils.cpp index b33f87cf67..e93bec7d61 100644 --- a/unittest/sql/test_sql_utils.cpp +++ b/unittest/sql/test_sql_utils.cpp @@ -166,7 +166,9 @@ TestSqlUtils::TestSqlUtils() memset(schema_file_path_, '\0', 128); exec_ctx_.set_sql_ctx(&sql_ctx_); + static ObTimerService timer_service(sys_tenant_id_); static ObTenantBase tenant_ctx(sys_tenant_id_); + tenant_ctx.set(&timer_service); ObTenantEnv::set_tenant(&tenant_ctx); auto& cluster_version = ObClusterVersion::get_instance(); diff --git a/unittest/storage/test_tenant_tablet_stat_mgr.cpp b/unittest/storage/test_tenant_tablet_stat_mgr.cpp index 1e2d5fd320..223d9cbe57 100644 --- a/unittest/storage/test_tenant_tablet_stat_mgr.cpp +++ b/unittest/storage/test_tenant_tablet_stat_mgr.cpp @@ -41,12 +41,14 @@ private: const uint64_t tenant_id_; ObTenantBase tenant_base_; ObTenantTabletStatMgr *stat_mgr_; + ObTimerService *timer_service_; }; TestTenantTabletStatMgr::TestTenantTabletStatMgr() : tenant_id_(1), tenant_base_(tenant_id_), - stat_mgr_(nullptr) + stat_mgr_(nullptr), + timer_service_(nullptr) { } @@ -65,7 +67,10 @@ void TestTenantTabletStatMgr::SetUp() ASSERT_TRUE(MockTenantModuleEnv::get_instance().is_inited()); int ret = OB_SUCCESS; - ObTenantEnv::set_tenant(&tenant_base_); + timer_service_ = OB_NEW(ObTimerService, ObModIds::TEST, tenant_id_); + ASSERT_NE(nullptr, timer_service_); + ASSERT_EQ(OB_SUCCESS, timer_service_->start()); + tenant_base_.set(timer_service_); stat_mgr_ = OB_NEW(ObTenantTabletStatMgr, ObModIds::TEST); ret = stat_mgr_->init(tenant_id_); ASSERT_EQ(OB_SUCCESS, ret); @@ -75,11 +80,18 @@ void TestTenantTabletStatMgr::SetUp() ASSERT_EQ(OB_SUCCESS, tenant_base_.init()); ASSERT_EQ(tenant_id_, MTL_ID()); ASSERT_EQ(stat_mgr_, MTL(ObTenantTabletStatMgr *)); + ASSERT_EQ(timer_service_, MTL(ObTimerService *)); } void TestTenantTabletStatMgr::TearDown() { stat_mgr_->destroy(); + if (nullptr != timer_service_) { + timer_service_->stop(); + timer_service_->wait(); + timer_service_->destroy(); + OB_DELETE(ObTimerService, ObModIds::TEST, timer_service_); + } ObTenantEnv::set_tenant(nullptr); }