diff --git a/src/storage/memtable/mvcc/ob_query_engine.cpp b/src/storage/memtable/mvcc/ob_query_engine.cpp index f9bd61f2607c5284c87fb553ab352c5b0278c3a8..ae33a9434dbc0b220962e532da1c722ded5044cb 100644 --- a/src/storage/memtable/mvcc/ob_query_engine.cpp +++ b/src/storage/memtable/mvcc/ob_query_engine.cpp @@ -176,7 +176,7 @@ void ObQueryEngine::destroy() { if (IS_NOT_INIT) { // do nothing - } else if (OB_NOT_NULL(index_)) { + } else if (OB_NOT_NULL(index_) && NOT_PLACE_HOLDER(index_)) { index_->destroy(); memstore_allocator_.free(index_); index_ = nullptr; @@ -704,8 +704,9 @@ int ObQueryEngine::estimate_row_count(const ObMemtableKey *start_key, const int void ObQueryEngine::dump2text(FILE *fd) { - if (OB_NOT_NULL(index_)) { - index_->dump2text(fd); + TableIndex *index = ATOMIC_LOAD(&index_); + if (OB_NOT_NULL(index) && NOT_PLACE_HOLDER(index)) { + index->dump2text(fd); } } diff --git a/src/storage/memtable/mvcc/ob_query_engine.h b/src/storage/memtable/mvcc/ob_query_engine.h index 0b1bd4c210177639d097f23d4433d525749a12f2..9b325a8cd24402171f1c363a3016459cebeeb465 100644 --- a/src/storage/memtable/mvcc/ob_query_engine.h +++ b/src/storage/memtable/mvcc/ob_query_engine.h @@ -49,6 +49,8 @@ public: class ObQueryEngine { +#define NOT_PLACE_HOLDER(ptr) OB_UNLIKELY(PLACE_HOLDER != ptr) + public: enum { INIT_TABLE_INDEX_COUNT = (1 << 10), @@ -198,15 +200,37 @@ public: int estimate_row_count(const ObMemtableKey *start_key, const int start_exclude, const ObMemtableKey *end_key, const int end_exclude, int64_t &logical_row_count, int64_t &physical_row_count); - int dump_keyhash(FILE *fd) const { return OB_NOT_NULL(index_) ? index_->dump_keyhash(fd) : OB_SUCCESS; } - int64_t hash_size() const { return OB_NOT_NULL(index_) ? index_->hash_size() : 0; } - int64_t hash_alloc_memory() const { return OB_NOT_NULL(index_) ? index_->hash_alloc_memory() : 0; } - int dump_keybtree(FILE* fd) { return OB_NOT_NULL(index_) ? index_->dump_keybtree(fd) : OB_SUCCESS; } - int64_t btree_size() const { return OB_NOT_NULL(index_) ? index_->btree_size() : 0; } + int dump_keyhash(FILE *fd) const + { + TableIndex *index = ATOMIC_LOAD(&index_); + return OB_NOT_NULL(index) && NOT_PLACE_HOLDER(index) ? index->dump_keyhash(fd) : OB_SUCCESS; + } + int64_t hash_size() const + { + TableIndex *index = ATOMIC_LOAD(&index_); + return OB_NOT_NULL(index) && NOT_PLACE_HOLDER(index) ? index->hash_size() : 0; + } + int64_t hash_alloc_memory() const + { + TableIndex *index = ATOMIC_LOAD(&index_); + return OB_NOT_NULL(index) && NOT_PLACE_HOLDER(index) ? index->hash_alloc_memory() : 0; + } + int dump_keybtree(FILE *fd) + { + TableIndex *index = ATOMIC_LOAD(&index_); + return OB_NOT_NULL(index) && NOT_PLACE_HOLDER(index) ? index->dump_keybtree(fd) : OB_SUCCESS; + } + int64_t btree_size() const + { + TableIndex *index = ATOMIC_LOAD(&index_); + return OB_NOT_NULL(index) && NOT_PLACE_HOLDER(index) ? index->btree_size() : 0; + } int64_t btree_alloc_memory() const { - return OB_NOT_NULL(index_) ? - index_->btree_alloc_memory() + btree_allocator_.get_allocated() : 0; + TableIndex *index = ATOMIC_LOAD(&index_); + return OB_NOT_NULL(index) && NOT_PLACE_HOLDER(index) + ? index->btree_alloc_memory() + btree_allocator_.get_allocated() + : 0; } void dump2text(FILE *fd); int get_table_index(TableIndex *&return_ptr) const;