From 5ce81574faf8c8451738113044be6844a0e2e6eb Mon Sep 17 00:00:00 2001 From: obdev Date: Tue, 8 Nov 2022 10:35:26 +0000 Subject: [PATCH] Wait till statement timeout in refresh_and_protect_table --- src/storage/ls/ob_ls_tablet_service.cpp | 2 +- src/storage/ob_storage_table_guard.cpp | 23 ++++++++----------- src/storage/ob_storage_table_guard.h | 2 +- src/storage/tablet/ob_tablet.cpp | 2 +- src/storage/tablet/ob_tablet_memtable_mgr.cpp | 2 +- src/storage/tx/ob_tx_replay_executor.cpp | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/storage/ls/ob_ls_tablet_service.cpp b/src/storage/ls/ob_ls_tablet_service.cpp index 3c96a97b7..1a20b9421 100644 --- a/src/storage/ls/ob_ls_tablet_service.cpp +++ b/src/storage/ls/ob_ls_tablet_service.cpp @@ -1798,7 +1798,7 @@ int ObLSTabletService::create_memtable( const bool for_replay) { int ret = OB_SUCCESS; - ObTimeGuard time_guard("ObLSTabletService::create_memtable", 1 * 1000 * 1000); + ObTimeGuard time_guard("ObLSTabletService::create_memtable", 10 * 1000); ObTabletHandle handle; if (OB_UNLIKELY(!is_inited_)) { ret = OB_NOT_INIT; diff --git a/src/storage/ob_storage_table_guard.cpp b/src/storage/ob_storage_table_guard.cpp index 6a06f7b56..0f137c9ce 100644 --- a/src/storage/ob_storage_table_guard.cpp +++ b/src/storage/ob_storage_table_guard.cpp @@ -109,12 +109,8 @@ int ObStorageTableGuard::refresh_and_protect_table(ObRelativeTable &relative_tab ret = OB_ERR_UNEXPECTED; LOG_WARN("ls is null", K(ret), K(ls_id)); } - bool bool_ret = false; - while (OB_SUCC(ret) && need_to_refresh_table(iter.table_iter_, ret)) { - // it's ok that get_read_tables cover the ret code returned by need_to_refresh_table - // because need_to_refresh_table return false and stop the loop if refresh too much times - // the last ret code will be passed to upper levels + while (OB_SUCC(ret) && need_to_refresh_table(iter.table_iter_)) { if (OB_FAIL(store_ctx_.ls_->get_tablet_svr()->get_read_tables( tablet_id, store_ctx_.mvcc_acc_ctx_.get_snapshot_version(), @@ -125,6 +121,13 @@ int ObStorageTableGuard::refresh_and_protect_table(ObRelativeTable &relative_tab } else { // no worry. iter will hold tablet reference and its life cycle is longer than guard tablet_ = iter.tablet_handle_.get_obj(); + // TODO: check if seesion is killed + if (store_ctx_.timeout_ > 0) { + const int64_t query_left_time = store_ctx_.timeout_ - ObTimeUtility::current_time(); + if (query_left_time <= 0) { + ret = OB_TRANS_STMT_TIMEOUT; + } + } } } @@ -189,9 +192,6 @@ int ObStorageTableGuard::refresh_and_protect_memtable() TRANS_LOG(WARN, "refresh replay table too much times", K(ret), K(ls_id), K(tablet_id), K(cost_time)); } - if (cost_time > LOG_INTERVAL_US) { - ret = OB_TIMEOUT; - } } } while ((OB_SUCC(ret) || OB_ENTRY_NOT_EXIST == ret) && bool_ret); } @@ -316,9 +316,9 @@ int ObStorageTableGuard::check_freeze_to_inc_write_ref(ObITable *table, bool &bo return ret; } -bool ObStorageTableGuard::need_to_refresh_table(ObTableStoreIterator &iter, int &ret) +bool ObStorageTableGuard::need_to_refresh_table(ObTableStoreIterator &iter) { - ret = OB_SUCCESS; + int ret = OB_SUCCESS; bool bool_ret = false; int exit_flag = -1; @@ -361,9 +361,6 @@ bool ObStorageTableGuard::need_to_refresh_table(ObTableStoreIterator &iter, int } else { LOG_WARN("unexpect exit_flag", K(exit_flag), K(ret), K(ls_id), K(tablet_id)); } - if (OB_FAIL(ret)) { - bool_ret = false; - } } return bool_ret; diff --git a/src/storage/ob_storage_table_guard.h b/src/storage/ob_storage_table_guard.h index 7278d0be2..82238608a 100644 --- a/src/storage/ob_storage_table_guard.h +++ b/src/storage/ob_storage_table_guard.h @@ -57,7 +57,7 @@ private: memtable::ObIMemtable *memtable, bool &bool_ret); int check_freeze_to_inc_write_ref(ObITable *table, bool &bool_ret); - bool need_to_refresh_table(ObTableStoreIterator &iter, int &ret); + bool need_to_refresh_table(ObTableStoreIterator &iter); bool check_if_need_log(); private: static const int64_t LOG_INTERVAL_US = 10 * 1000 * 1000; diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index 3e6516237..4f8a86756 100644 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -1539,7 +1539,7 @@ int ObTablet::create_memtable(const int64_t schema_version, const bool for_replay) { int ret = OB_SUCCESS; - ObTimeGuard time_guard("ObTablet::create_memtable", 1 * 1000 * 1000); + ObTimeGuard time_guard("ObTablet::create_memtable", 10 * 1000); TCWLockGuard guard(table_store_lock_); time_guard.click("lock"); const int64_t clog_checkpoint_ts = tablet_meta_.clog_checkpoint_ts_; diff --git a/src/storage/tablet/ob_tablet_memtable_mgr.cpp b/src/storage/tablet/ob_tablet_memtable_mgr.cpp index 978ee2da3..f7c762636 100644 --- a/src/storage/tablet/ob_tablet_memtable_mgr.cpp +++ b/src/storage/tablet/ob_tablet_memtable_mgr.cpp @@ -141,7 +141,7 @@ int ObTabletMemtableMgr::create_memtable(const int64_t clog_checkpoint_ts, const int64_t schema_version, const bool for_replay) { - ObTimeGuard time_guard("ObTabletMemtableMgr::create_memtable", 1 * 1000 * 1000); + ObTimeGuard time_guard("ObTabletMemtableMgr::create_memtable", 10 * 1000); // Write lock SpinWLockGuard lock_guard(lock_); time_guard.click("lock"); diff --git a/src/storage/tx/ob_tx_replay_executor.cpp b/src/storage/tx/ob_tx_replay_executor.cpp index 828b3e507..fc7d80a9a 100644 --- a/src/storage/tx/ob_tx_replay_executor.cpp +++ b/src/storage/tx/ob_tx_replay_executor.cpp @@ -725,7 +725,7 @@ int ObTxReplayExecutor::get_compat_mode_(const ObTabletID &tablet_id, lib::Worke void ObTxReplayExecutor::rewrite_replay_retry_code_(int &ret_code) { if (ret_code == OB_MINOR_FREEZE_NOT_ALLOW || ret_code == OB_LOG_TS_OUT_OF_BOUND || - ret_code == OB_ALLOCATE_MEMORY_FAILED || ret_code == OB_TIMEOUT) { + ret_code == OB_ALLOCATE_MEMORY_FAILED) { TRANS_LOG(INFO, "rewrite replay error_code as OB_EAGAIN for retry", K(ret_code), K(ls_->get_ls_id()), K(log_ts_ns_)); ret_code = OB_EAGAIN;