diff --git a/be/src/olap/data_dir.cpp b/be/src/olap/data_dir.cpp index e47bfa640f4004..661e8eaa826601 100755 --- a/be/src/olap/data_dir.cpp +++ b/be/src/olap/data_dir.cpp @@ -959,7 +959,7 @@ void DataDir::perform_path_gc_by_rowsetid() { RowsetId rowset_id = -1; bool is_rowset_file = _tablet_manager->get_rowset_id_from_path(path, &rowset_id); if (is_rowset_file) { - TabletSharedPtr tablet = _tablet_manager->get_tablet(tablet_id, schema_hash, true); + TabletSharedPtr tablet = _tablet_manager->get_tablet(tablet_id, schema_hash); if (tablet != nullptr) { bool valid = tablet->check_rowset_id(rowset_id); if (!valid) { @@ -968,13 +968,9 @@ void DataDir::perform_path_gc_by_rowsetid() { // and the rowsetid is not in committed rowsets // then delete the path. if (rowset_id < tablet->initial_end_rowset_id() - && !StorageEngine::instance()->check_rowset_id_in_unused_rowsets(rowset_id)) { - RowsetMetaSharedPtr rowset_meta = nullptr; - OLAPStatus status = RowsetMetaManager::get_rowset_meta( - _meta, tablet->tablet_uid(), rowset_id, rowset_meta); - if (status == OLAP_ERR_META_KEY_NOT_FOUND) { - _process_garbage_path(path); - } + && !StorageEngine::instance()->check_rowset_id_in_unused_rowsets(rowset_id) + && !RowsetMetaManager::check_rowset_meta(_meta, tablet->tablet_uid(), rowset_id)) { + _process_garbage_path(path); } } } diff --git a/be/src/olap/rowset/rowset_meta_manager.cpp b/be/src/olap/rowset/rowset_meta_manager.cpp index 3fc3faf951119a..abc6792e293a54 100644 --- a/be/src/olap/rowset/rowset_meta_manager.cpp +++ b/be/src/olap/rowset/rowset_meta_manager.cpp @@ -33,6 +33,16 @@ namespace doris { const std::string ROWSET_PREFIX = "rst_"; +bool RowsetMetaManager::check_rowset_meta(OlapMeta* meta, TabletUid tablet_uid, int64_t rowset_id) { + std::string key = ROWSET_PREFIX + tablet_uid.to_string() + "_" + std::to_string(rowset_id); + std::string value; + OLAPStatus s = meta->get(META_COLUMN_FAMILY_INDEX, key, &value); + if (s != OLAP_SUCCESS) { + return false; + } + return true; +} + OLAPStatus RowsetMetaManager::get_rowset_meta(OlapMeta* meta, TabletUid tablet_uid, int64_t rowset_id, RowsetMetaSharedPtr rowset_meta) { std::string key = ROWSET_PREFIX + tablet_uid.to_string() + "_" + std::to_string(rowset_id); std::string value; diff --git a/be/src/olap/rowset/rowset_meta_manager.h b/be/src/olap/rowset/rowset_meta_manager.h index 8a1f3dd13b1be4..0411243d7bbadb 100644 --- a/be/src/olap/rowset/rowset_meta_manager.h +++ b/be/src/olap/rowset/rowset_meta_manager.h @@ -31,6 +31,8 @@ namespace doris { // Helper class for managing rowset meta of one root path. class RowsetMetaManager { public: + static bool check_rowset_meta(OlapMeta* meta, TabletUid tablet_uid, int64_t rowset_id); + static OLAPStatus get_rowset_meta(OlapMeta* meta, TabletUid tablet_uid, int64_t rowset_id, RowsetMetaSharedPtr rowset_meta); static OLAPStatus get_json_rowset_meta(OlapMeta* meta, TabletUid tablet_uid, int64_t rowset_id, std::string* json_rowset_meta); diff --git a/be/src/olap/tablet_manager.cpp b/be/src/olap/tablet_manager.cpp index aa374f5ebf9fea..5abd653947ec2f 100755 --- a/be/src/olap/tablet_manager.cpp +++ b/be/src/olap/tablet_manager.cpp @@ -609,6 +609,7 @@ TabletSharedPtr TabletManager::_get_tablet(TTabletId tablet_id, SchemaHash schem tablet = _get_tablet_with_no_lock(tablet_id, schema_hash); if (tablet == nullptr && include_deleted) { for (auto& deleted_tablet : _shutdown_tablets) { + CHECK(deleted_tablet != nullptr) << "deleted tablet in nullptr"; if (deleted_tablet->tablet_id() == tablet_id && deleted_tablet->schema_hash() == schema_hash) { tablet = deleted_tablet; break; @@ -1350,6 +1351,7 @@ TabletSharedPtr TabletManager::_get_tablet_with_no_lock(TTabletId tablet_id, Sch tablet_map_t::iterator it = _tablet_map.find(tablet_id); if (it != _tablet_map.end()) { for (TabletSharedPtr tablet : it->second.table_arr) { + CHECK(tablet != nullptr) << "tablet is nullptr:" << tablet; if (tablet->equal(tablet_id, schema_hash)) { VLOG(3) << "get tablet success. tablet_id=" << tablet_id << ", schema_hash=" << schema_hash; diff --git a/be/test/olap/rowset/rowset_meta_manager_test.cpp b/be/test/olap/rowset/rowset_meta_manager_test.cpp index 6fbf9db523be27..63c5125d49e370 100644 --- a/be/test/olap/rowset/rowset_meta_manager_test.cpp +++ b/be/test/olap/rowset/rowset_meta_manager_test.cpp @@ -80,12 +80,14 @@ TEST_F(RowsetMetaManagerTest, TestSaveAndGetAndRemove) { ASSERT_EQ(rowset_meta.rowset_id(), rowset_id); OLAPStatus status = RowsetMetaManager::save(_meta, _tablet_uid, rowset_id, &rowset_meta); ASSERT_TRUE(status == OLAP_SUCCESS); + ASSERT_TRUE(RowsetMetaManager::check_rowset_meta(_meta, _tablet_uid, rowset_id)); std::string json_rowset_meta_read; status = RowsetMetaManager::get_json_rowset_meta(_meta, _tablet_uid, rowset_id, &json_rowset_meta_read); ASSERT_TRUE(status == OLAP_SUCCESS); ASSERT_EQ(_json_rowset_meta, json_rowset_meta_read); status = RowsetMetaManager::remove(_meta, _tablet_uid, rowset_id); ASSERT_TRUE(status == OLAP_SUCCESS); + ASSERT_FALSE(RowsetMetaManager::check_rowset_meta(_meta, _tablet_uid, rowset_id)); RowsetMetaSharedPtr rowset_meta_read(new RowsetMeta()); status = RowsetMetaManager::get_rowset_meta(_meta, _tablet_uid, rowset_id, rowset_meta_read); ASSERT_TRUE(status != OLAP_SUCCESS); @@ -95,6 +97,7 @@ TEST_F(RowsetMetaManagerTest, TestLoad) { uint64_t rowset_id = 10000; OLAPStatus status = RowsetMetaManager::load_json_rowset_meta(_meta, rowset_meta_path); ASSERT_TRUE(status == OLAP_SUCCESS); + ASSERT_TRUE(RowsetMetaManager::check_rowset_meta(_meta, _tablet_uid, rowset_id)); std::string json_rowset_meta_read; status = RowsetMetaManager::get_json_rowset_meta(_meta, _tablet_uid, rowset_id, &json_rowset_meta_read); ASSERT_TRUE(status == OLAP_SUCCESS);