From 13a7fbd3608faa57d450f0071da812c1cba9baf3 Mon Sep 17 00:00:00 2001 From: fengdeyiji <546976189@qq.com> Date: Fri, 30 Jun 2023 07:42:18 +0000 Subject: [PATCH] [MDS] fix mds_ctx print LOG when destroy core-risk --- src/storage/multi_data_source/mds_ctx.cpp | 14 ++++++++++++-- src/storage/tablet/ob_i_tablet_mds_interface.ipp | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/storage/multi_data_source/mds_ctx.cpp b/src/storage/multi_data_source/mds_ctx.cpp index 849feaec3..17bcab203 100644 --- a/src/storage/multi_data_source/mds_ctx.cpp +++ b/src/storage/multi_data_source/mds_ctx.cpp @@ -30,13 +30,21 @@ state_(TwoPhaseCommitState::STATE_INIT) {} MdsCtx::~MdsCtx() { - if (!write_list_.empty()) { - MDS_LOG_RET(WARN, OB_ERR_UNEXPECTED, "nodes not commit or abort when mds ctx destroyed", K(*this)); + bool list_empty = false; + { + MdsWLockGuard lg(lock_); + bool list_empty = write_list_.empty(); + if (!list_empty) { + MDS_LOG_RET(INFO, OB_SUCCESS, "nodes not commit or abort when mds ctx destroyed", K(*this)); + } + } + if (!list_empty) { on_abort(share::SCN::max_scn()); } } int MdsCtx::assign(const MdsCtx &rhs) { + MdsWLockGuard lg(lock_); writer_ = rhs.writer_; state_ = rhs.state_; return OB_SUCCESS; @@ -46,6 +54,7 @@ const MdsWriter MdsCtx::get_writer() const { return writer_; } void MdsCtx::set_writer(const MdsWriter &writer) { + MdsWLockGuard lg(lock_); if (state_ != TwoPhaseCommitState::STATE_INIT) { MDS_LOG_RET(ERROR, OB_INVALID_ARGUMENT, "not allow set writer in non-init state", K(*this), K(writer)); } else { @@ -56,6 +65,7 @@ void MdsCtx::set_writer(const MdsWriter &writer) bool MdsCtx::can_write() const { + MdsRLockGuard lg(lock_); return state_ == TwoPhaseCommitState::STATE_INIT && writer_.is_valid(); } diff --git a/src/storage/tablet/ob_i_tablet_mds_interface.ipp b/src/storage/tablet/ob_i_tablet_mds_interface.ipp index 06d5b4ce1..5a0413d6b 100644 --- a/src/storage/tablet/ob_i_tablet_mds_interface.ipp +++ b/src/storage/tablet/ob_i_tablet_mds_interface.ipp @@ -490,7 +490,11 @@ int ObITabletMdsInterface::get_latest(OP &&read_op, bool &is_committed, const in ret = OB_ERR_UNEXPECTED; MDS_LOG_GET(WARN, "mds cannot be NULL"); } else if (CLICK_FAIL(handle.get_latest(read_op, is_committed, read_seq))) { - MDS_LOG_GET(WARN, "failed to get_latest"); + if (OB_SNAPSHOT_DISCARDED != ret) { + MDS_LOG_GET(WARN, "failed to get mds data"); + } else { + MDS_LOG_GET(TRACE, "failed to get mds data"); + } } if (CLICK_FAIL(ret)) { if (OB_ENTRY_NOT_EXIST == ret || OB_SNAPSHOT_DISCARDED == ret) { @@ -528,7 +532,9 @@ int ObITabletMdsInterface::get_snapshot(OP &&read_op, MDS_LOG_GET(WARN, "mds cannot be NULL"); } else if (CLICK_FAIL(handle.get_snapshot(read_op, snapshot, read_seq, timeout_us))) { if (OB_SNAPSHOT_DISCARDED != ret) { - MDS_LOG_GET(WARN, "failed to get_snapshot"); + MDS_LOG_GET(WARN, "failed to get mds data"); + } else { + MDS_LOG_GET(TRACE, "failed to get mds data"); } } if (CLICK_FAIL(ret)) { @@ -566,7 +572,11 @@ int ObITabletMdsInterface::get_snapshot(const Key &key, ret = OB_ERR_UNEXPECTED; MDS_LOG_GET(WARN, "mds cannot be NULL"); } else if (CLICK() && OB_SUCCESS != (ret = handle.get_snapshot(key, read_op, snapshot, read_seq, timeout_us))) { - MDS_LOG_GET(WARN, "failed to get_snapshot"); + if (OB_SNAPSHOT_DISCARDED != ret) { + MDS_LOG_GET(WARN, "failed to get mds data"); + } else { + MDS_LOG_GET(TRACE, "failed to get mds data"); + } } if (CLICK_FAIL(ret)) { if (OB_ENTRY_NOT_EXIST == ret || OB_SNAPSHOT_DISCARDED == ret) {