diff --git a/src/storage/memtable/mvcc/ob_mvcc_engine.cpp b/src/storage/memtable/mvcc/ob_mvcc_engine.cpp index 92f6df00b8..f9539d2fa3 100644 --- a/src/storage/memtable/mvcc/ob_mvcc_engine.cpp +++ b/src/storage/memtable/mvcc/ob_mvcc_engine.cpp @@ -223,6 +223,7 @@ int ObMvccEngine::estimate_scan_row_count( part_est.logical_row_count_, part_est.physical_row_count_))) { TRANS_LOG(WARN, "query engine estimate row count fail", K(ret)); } + return ret; } diff --git a/src/storage/memtable/mvcc/ob_mvcc_row.cpp b/src/storage/memtable/mvcc/ob_mvcc_row.cpp index cf4d116ed2..3909248cb1 100644 --- a/src/storage/memtable/mvcc/ob_mvcc_row.cpp +++ b/src/storage/memtable/mvcc/ob_mvcc_row.cpp @@ -286,8 +286,8 @@ void ObMvccRow::reset() index_ = NULL; total_trans_node_cnt_ = 0; last_compact_cnt_ = 0; - max_modify_count_ = UINT32_MAX; - min_modify_count_ = UINT32_MAX; + max_modify_scn_.set_invalid(); + min_modify_scn_.set_invalid(); } int64_t ObMvccRow::to_string(char *buf, const int64_t buf_len) const @@ -309,8 +309,8 @@ int64_t ObMvccRow::to_string(char *buf, const int64_t buf_len) const "latest_compact_ts=%ld " "last_compact_cnt=%ld " "total_trans_node_cnt=%ld " - "max_modify_count=%u " - "min_modify_count=%u}", + "max_modify_scn=%s " + "min_modify_scn=%s}", this, (latch_.is_locked() ? "locked" : "unlocked"), flag_, @@ -326,8 +326,8 @@ int64_t ObMvccRow::to_string(char *buf, const int64_t buf_len) const latest_compact_ts_, last_compact_cnt_, total_trans_node_cnt_, - max_modify_count_, - min_modify_count_); + to_cstring(max_modify_scn_), + to_cstring(min_modify_scn_)); return pos; } @@ -755,7 +755,7 @@ int ObMvccRow::trans_commit(const SCN commit_version, ObMvccTransNode &node) } update_dml_flag_(node.get_dml_flag(), - node.modify_count_); + node.get_scn()); update_max_trans_version(commit_version, node.tx_id_); update_max_elr_trans_version(commit_version, node.tx_id_); } @@ -763,23 +763,17 @@ int ObMvccRow::trans_commit(const SCN commit_version, ObMvccTransNode &node) return ret; } -void ObMvccRow::update_dml_flag_(blocksstable::ObDmlFlag flag, - uint32_t modify_count) +void ObMvccRow::update_dml_flag_(const blocksstable::ObDmlFlag flag, const share::SCN modify_scn) { if (blocksstable::ObDmlFlag::DF_LOCK != flag) { - if (max_modify_count_ == modify_count || min_modify_count_ == modify_count) { - // TODO(handora.qc): add it back later - // TRANS_LOG(ERROR, "mvcc row never trans commit twice", KPC(this), K(flag), K(modify_count)); - } else { - if (max_modify_count_ == UINT32_MAX || max_modify_count_ < modify_count) { - max_modify_count_ = modify_count; - last_dml_flag_ = flag; - } + if (!max_modify_scn_.is_valid() || max_modify_scn_ <= modify_scn) { + max_modify_scn_ = modify_scn; + last_dml_flag_ = flag; + } - if (min_modify_count_ == UINT32_MAX || min_modify_count_ > modify_count) { - min_modify_count_ = modify_count; - first_dml_flag_ = flag; - } + if (!min_modify_scn_.is_valid() || min_modify_scn_ > modify_scn) { + min_modify_scn_ = modify_scn; + first_dml_flag_ = flag; } } } diff --git a/src/storage/memtable/mvcc/ob_mvcc_row.h b/src/storage/memtable/mvcc/ob_mvcc_row.h index d82a943c0c..64c64d396a 100644 --- a/src/storage/memtable/mvcc/ob_mvcc_row.h +++ b/src/storage/memtable/mvcc/ob_mvcc_row.h @@ -247,27 +247,29 @@ struct ObMvccRow // Spin lock that protects row data. ObRowLatch latch_; - // Update count since last row compact. - int32_t update_since_compact_; uint8_t flag_; blocksstable::ObDmlFlag first_dml_flag_; blocksstable::ObDmlFlag last_dml_flag_; - ObMvccTransNode *list_head_; - transaction::ObTransID max_trans_id_; - share::SCN max_trans_version_; - transaction::ObTransID max_elr_trans_id_; - share::SCN max_elr_trans_version_; - ObMvccTransNode *latest_compact_node_; - // using for optimizing inserting trans node when replaying - ObMvccRowIndex *index_; + int32_t update_since_compact_; + int64_t total_trans_node_cnt_; int64_t latest_compact_ts_; int64_t last_compact_cnt_; - // TODO(handora.qc): remove it after link all nodes - uint32_t max_modify_count_; - uint32_t min_modify_count_; + share::SCN max_trans_version_; + share::SCN max_elr_trans_version_; + share::SCN max_modify_scn_; + share::SCN min_modify_scn_; + transaction::ObTransID max_trans_id_; + transaction::ObTransID max_elr_trans_id_; + ObMvccTransNode *list_head_; + ObMvccTransNode *latest_compact_node_; + ObMvccRowIndex *index_; - ObMvccRow() { reset(); } + ObMvccRow() + { + STATIC_ASSERT(sizeof(ObMvccRow) <= 120, "Size of ObMvccRow Overflow."); + reset(); + } void reset(); // ===================== ObMvccRow Operation Interface ===================== @@ -360,8 +362,8 @@ struct ObMvccRow bool is_valid_replay_queue_index(const int64_t index) const; // ======================== ObMvccRow Row Metas ======================== - // first dml and last dml is the important statistics for row estimation - void update_dml_flag_(blocksstable::ObDmlFlag flag, uint32_t modify_count); + // first dml and last dml is the importatnt statistics for row estimation + void update_dml_flag_(const blocksstable::ObDmlFlag flag, const share::SCN modify_count); blocksstable::ObDmlFlag get_first_dml_flag() const { return first_dml_flag_; } // max_trans_version/max_elr_trans_version is the max (elr) version on the row diff --git a/src/storage/memtable/mvcc/ob_mvcc_trans_ctx.cpp b/src/storage/memtable/mvcc/ob_mvcc_trans_ctx.cpp index bcc6d879b1..1130969b10 100644 --- a/src/storage/memtable/mvcc/ob_mvcc_trans_ctx.cpp +++ b/src/storage/memtable/mvcc/ob_mvcc_trans_ctx.cpp @@ -1733,6 +1733,8 @@ int ObMvccRowCallback::checkpoint_callback() TRANS_LOG(ERROR, "checkpoint never called on submitted callback", KPC(this)); } else if (OB_FAIL(value_.remove_callback(*this))) { TRANS_LOG(ERROR, "remove callback from trans node failed", K(ret), K(*this)); + } else if (OB_NOT_NULL(tnode_)) { + (void)value_.update_dml_flag_(get_dml_flag(), tnode_->get_scn()); } return ret; diff --git a/src/storage/memtable/mvcc/ob_query_engine.cpp b/src/storage/memtable/mvcc/ob_query_engine.cpp index efc2e48a66..34891b100e 100644 --- a/src/storage/memtable/mvcc/ob_query_engine.cpp +++ b/src/storage/memtable/mvcc/ob_query_engine.cpp @@ -405,6 +405,7 @@ int ObQueryEngine::sample_rows(Iterator *iter, const ObMemtabl } gap_size = 0; } + if (blocksstable::ObDmlFlag::DF_NOT_EXIST == value->first_dml_flag_ && blocksstable::ObDmlFlag::DF_NOT_EXIST == value->last_dml_flag_) { ObMvccTransNode *iter = value->get_list_head(); @@ -426,6 +427,7 @@ int ObQueryEngine::sample_rows(Iterator *iter, const ObMemtabl } else { // existent row, not change estimation total row count } + if (sample_row_count >= MAX_SAMPLE_ROW_COUNT) { break; } @@ -442,8 +444,6 @@ int ObQueryEngine::sample_rows(Iterator *iter, const ObMemtabl if (gap_size >= OB_SKIP_RANGE_LIMIT) { physical_row_count -= static_cast(static_cast(gap_size) * ratio); } - TRANS_LOG(DEBUG, "memtable after sample", KR(ret), K(sample_row_count), K(logical_row_count), - K(physical_row_count), K(gap_size), K(ratio)); return ret; } @@ -686,6 +686,7 @@ int ObQueryEngine::estimate_row_count(const transaction::ObTransID &tx_id, TRANS_LOG(WARN, "failed to sample rows", KR(ret), K(*start_key), K(*end_key)); } } + logical_row_count = log_row_count1 + log_row_count2; // since remaining_row_count actually includes phy_row_count1, so we don't // want to add it twice here