This is an automated email from the ASF dual-hosted git repository. lingbin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new 14c7720 Fix removing tablet bug from partition_map in TabletManager (#2842) 14c7720 is described below commit 14c772013b66e4e2b7360eed3a3199f8f6351a73 Author: LingBin <lingbi...@gmail.com> AuthorDate: Thu Feb 6 09:57:12 2020 +0800 Fix removing tablet bug from partition_map in TabletManager (#2842) When using an iterator of _tablet_map.tablet_arr(`std::list`) to remove a tablet, we should first remove tablet from _partition_map to avoid the iterator becoming invalid. --- be/src/olap/tablet.cpp | 2 +- be/src/olap/tablet.h | 2 +- be/src/olap/tablet_manager.cpp | 22 +++++++++++++--------- be/src/olap/tablet_manager.h | 2 ++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/be/src/olap/tablet.cpp b/be/src/olap/tablet.cpp index aa1ae61..dafcdfc 100644 --- a/be/src/olap/tablet.cpp +++ b/be/src/olap/tablet.cpp @@ -931,7 +931,7 @@ OLAPStatus Tablet::set_partition_id(int64_t partition_id) { return _tablet_meta->set_partition_id(partition_id); } -TabletInfo Tablet::get_tablet_info() { +TabletInfo Tablet::get_tablet_info() const { return TabletInfo(tablet_id(), schema_hash(), tablet_uid()); } diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h index e32075b..9f94637 100644 --- a/be/src/olap/tablet.h +++ b/be/src/olap/tablet.h @@ -223,7 +223,7 @@ public: OLAPStatus set_partition_id(int64_t partition_id); - TabletInfo get_tablet_info(); + TabletInfo get_tablet_info() const; void pick_candicate_rowsets_to_cumulative_compaction(std::vector<RowsetSharedPtr>* candidate_rowsets); void pick_candicate_rowsets_to_base_compaction(std::vector<RowsetSharedPtr>* candidate_rowsets); diff --git a/be/src/olap/tablet_manager.cpp b/be/src/olap/tablet_manager.cpp index 18d9ca0..41caa0a 100644 --- a/be/src/olap/tablet_manager.cpp +++ b/be/src/olap/tablet_manager.cpp @@ -569,11 +569,10 @@ OLAPStatus TabletManager::drop_tablets_on_error_root_path( for (list<TabletSharedPtr>::iterator it = _tablet_map[tablet_id].table_arr.begin(); it != _tablet_map[tablet_id].table_arr.end();) { if ((*it)->equal(tablet_id, schema_hash)) { + // We should first remove tablet from partition_map to avoid iterator + // becoming invalid. + _remove_tablet_from_partition_unlocked(*(*it)); it = _tablet_map[tablet_id].table_arr.erase(it); - _partition_tablet_map[(*it)->partition_id()].erase((*it)->get_tablet_info()); - if (_partition_tablet_map[(*it)->partition_id()].empty()) { - _partition_tablet_map.erase((*it)->partition_id()); - } } else { ++it; } @@ -1110,7 +1109,8 @@ void TabletManager::update_root_path_info(std::map<std::string, DataDirInfo>* pa } } // update_root_path_info -void TabletManager::get_partition_related_tablets(int64_t partition_id, std::set<TabletInfo>* tablet_infos) { +void TabletManager::get_partition_related_tablets(int64_t partition_id, + std::set<TabletInfo>* tablet_infos) { ReadLock rlock(&_tablet_map_lock); if (_partition_tablet_map.find(partition_id) != _partition_tablet_map.end()) { for (auto& tablet_info : _partition_tablet_map[partition_id]) { @@ -1332,10 +1332,7 @@ OLAPStatus TabletManager::_drop_tablet_directly_unlocked( it != _tablet_map[tablet_id].table_arr.end();) { if ((*it)->equal(tablet_id, schema_hash)) { TabletSharedPtr tablet = *it; - _partition_tablet_map[(*it)->partition_id()].erase((*it)->get_tablet_info()); - if (_partition_tablet_map[(*it)->partition_id()].empty()) { - _partition_tablet_map.erase((*it)->partition_id()); - } + _remove_tablet_from_partition_unlocked(*(*it)); it = _tablet_map[tablet_id].table_arr.erase(it); if (!keep_files) { // drop tablet will update tablet meta, should lock @@ -1395,4 +1392,11 @@ TabletSharedPtr TabletManager::_get_tablet_unlocked(TTabletId tablet_id, SchemaH return tablet; } +void TabletManager::_remove_tablet_from_partition_unlocked(const Tablet& tablet) { + _partition_tablet_map[tablet.partition_id()].erase(tablet.get_tablet_info()); + if (_partition_tablet_map[tablet.partition_id()].empty()) { + _partition_tablet_map.erase(tablet.partition_id()); + } +} + } // doris diff --git a/be/src/olap/tablet_manager.h b/be/src/olap/tablet_manager.h index 38d7e42..ac5c3d7 100644 --- a/be/src/olap/tablet_manager.h +++ b/be/src/olap/tablet_manager.h @@ -169,6 +169,8 @@ private: void _build_tablet_stat(); + void _remove_tablet_from_partition_unlocked(const Tablet& tablet); + private: // TODO(lingbin): should be TabletInstances? // should be removed after schema_hash be removed --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org