diff --git a/src/storage/access/ob_single_merge.cpp b/src/storage/access/ob_single_merge.cpp index 4a696cbc80..4abefa7f2a 100644 --- a/src/storage/access/ob_single_merge.cpp +++ b/src/storage/access/ob_single_merge.cpp @@ -324,7 +324,7 @@ int ObSingleMerge::inner_get_next_row(ObDatumRow &row) access_ctx_->defensive_check_record_.query_flag_ = access_ctx_->query_flag_; transaction::ObTransService *trx = MTL(transaction::ObTransService *); bool trx_id_valid = (NULL != access_ctx_->store_ctx_ - && access_ctx_->store_ctx_->mvcc_acc_ctx_.tx_id_.is_valid()); + && access_ctx_->store_ctx_->mvcc_acc_ctx_.snapshot_.is_valid()); if (OB_NOT_NULL(trx) && trx_id_valid && NULL != trx->get_defensive_check_mgr()) { diff --git a/src/storage/tx/ob_tx_api.cpp b/src/storage/tx/ob_tx_api.cpp index 4549557e1d..4e2775905b 100644 --- a/src/storage/tx/ob_tx_api.cpp +++ b/src/storage/tx/ob_tx_api.cpp @@ -559,18 +559,18 @@ int ObTransService::get_read_snapshot(ObTxDesc &tx, if (OB_SUCC(ret)) { snapshot.source_ = ObTxReadSnapshot::SRC::GLOBAL; snapshot.parts_.reset(); - if (tx.state_ != ObTxDesc::State::IDLE) { + // If tx id is valid , record tx_id and scn + if (tx.tx_id_.is_valid()) { snapshot.core_.tx_id_ = tx.tx_id_; snapshot.core_.scn_ = ObSequence::get_max_seq_no(); + } + if (tx.state_ != ObTxDesc::State::IDLE) { ARRAY_FOREACH(tx.parts_, i) { if (!tx.parts_[i].is_clean() && OB_FAIL(snapshot.parts_.push_back(ObTxLSEpochPair(tx.parts_[i].id_, tx.parts_[i].epoch_)))) { TRANS_LOG(WARN, "push snapshot parts fail", K(ret), K(tx), K(snapshot)); } } - } else { - snapshot.core_.tx_id_.reset(); - snapshot.core_.scn_ = 0; } snapshot.valid_ = true; } @@ -611,9 +611,12 @@ int ObTransService::get_ls_read_snapshot(ObTxDesc &tx, snapshot.snapshot_lsid_ = lsid; snapshot.uncertain_bound_ = 0; snapshot.parts_.reset(); - if (tx.state_ != ObTxDesc::State::IDLE) { + // If tx id is valid , record tx_id and scn + if (tx.tx_id_.is_valid()) { snapshot.core_.tx_id_ = tx.tx_id_; snapshot.core_.scn_ = ObSequence::get_max_seq_no(); + } + if (tx.state_ != ObTxDesc::State::IDLE) { ARRAY_FOREACH(tx.parts_, i) { if (tx.parts_[i].id_ == lsid && !tx.parts_[i].is_clean()) { if (OB_FAIL(snapshot.parts_.push_back(ObTxLSEpochPair(lsid, tx.parts_[i].epoch_)))) { @@ -621,9 +624,6 @@ int ObTransService::get_ls_read_snapshot(ObTxDesc &tx, } } } - } else { - snapshot.core_.tx_id_.reset(); - snapshot.core_.scn_ = 0; } snapshot.valid_ = true; } else { diff --git a/src/storage/tx/ob_tx_data_functor.cpp b/src/storage/tx/ob_tx_data_functor.cpp index c0d3843f13..bb52dc03d5 100644 --- a/src/storage/tx/ob_tx_data_functor.cpp +++ b/src/storage/tx/ob_tx_data_functor.cpp @@ -264,7 +264,7 @@ int LockForReadFunctor::inner_lock_for_read(const ObTxData &tx_data, ObTxCCCtx * } else { // Only dml statement can read elr data if (ObTxData::ELR_COMMIT == state - && lock_for_read_arg_.mvcc_acc_ctx_.get_tx_id().is_valid()) { + && lock_for_read_arg_.mvcc_acc_ctx_.snapshot_.tx_id_.is_valid()) { can_read_ = !tx_data.undo_status_list_.is_contain(data_sql_sequence); trans_version_ = commit_version; } else {