From a712c44f441f2edc98d33d98f74d88303a4f17f1 Mon Sep 17 00:00:00 2001 From: chaoyli Date: Sun, 23 Jun 2019 11:28:05 +0800 Subject: [PATCH] Check get_header status returned When performing storage_medium_migration, the header may be already droped. In this scenario, header returned will be null pointer. Saving data to a null pointer will cause core dump. --- be/src/olap/olap_define.h | 1 + be/src/olap/olap_snapshot.cpp | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/be/src/olap/olap_define.h b/be/src/olap/olap_define.h index 932ac5f67565cd..c8be0e9a78906d 100644 --- a/be/src/olap/olap_define.h +++ b/be/src/olap/olap_define.h @@ -332,6 +332,7 @@ enum OLAPStatus { OLAP_ERR_META_PUT = -3004, OLAP_ERR_META_ITERATOR = -3005, OLAP_ERR_META_DELETE = -3006, + OLAP_ERR_META_ALREADY_EXIST = -3007, }; enum ColumnFamilyIndex { diff --git a/be/src/olap/olap_snapshot.cpp b/be/src/olap/olap_snapshot.cpp index be18729bdca51a..ad1fed0101b052 100644 --- a/be/src/olap/olap_snapshot.cpp +++ b/be/src/olap/olap_snapshot.cpp @@ -718,6 +718,16 @@ OLAPStatus OLAPEngine::storage_medium_migrate( << "schema_hash_path=" << schema_hash_path; remove_all_dir(schema_hash_path); } + + OLAPHeader new_olap_header; + res = OlapHeaderManager::get_header(stores[0], tablet->tablet_id(), tablet->schema_hash(), &new_olap_header); + if (res != OLAP_ERR_META_KEY_NOT_FOUND) { + LOG(WARNING) << "olap_header already exists. " + << "data_dir:" << stores[0]->path() + << "tablet:" << tablet->full_name(); + return OLAP_ERR_META_ALREADY_EXIST; + } + create_dirs(schema_hash_path); // migrate all index and data files but header file @@ -727,21 +737,14 @@ OLAPStatus OLAPEngine::storage_medium_migrate( break; } - // generate new header file from the old - OLAPHeader* new_olap_header = new(std::nothrow) OLAPHeader(); - if (new_olap_header == NULL) { - OLAP_LOG_WARNING("new olap header failed"); - res = OLAP_ERR_BUFFER_OVERFLOW; - break; - } - res = _generate_new_header(stores[0], shard, tablet, version_entity_vec, new_olap_header); + res = _generate_new_header(stores[0], shard, tablet, version_entity_vec, &new_olap_header); if (res != OLAP_SUCCESS) { OLAP_LOG_WARNING("fail to generate new header file from the old. [res=%d]", res); break; } // load the new tablet into OLAPEngine - auto olap_table = OLAPTable::create_from_header(new_olap_header, stores[0]); + auto olap_table = OLAPTable::create_from_header(&new_olap_header, stores[0]); if (olap_table == NULL) { OLAP_LOG_WARNING("failed to create from header"); res = OLAP_ERR_TABLE_CREATE_FROM_HEADER_ERROR; @@ -793,7 +796,13 @@ OLAPStatus OLAPEngine::_generate_new_header( OlapStore* ref_store = OLAPEngine::get_instance()->get_store(tablet->storage_root_path_name()); - OlapHeaderManager::get_header(ref_store, tablet->tablet_id(), tablet->schema_hash(), new_olap_header); + res = OlapHeaderManager::get_header(ref_store, tablet->tablet_id(), tablet->schema_hash(), new_olap_header); + if (res == OLAP_ERR_META_KEY_NOT_FOUND) { + LOG(WARNING) << "olap_header has already been dropped. " + << "data_dir:" << ref_store->path() + << "tablet:" << tablet->full_name(); + return res; + } _update_header_file_info(version_entity_vec, new_olap_header); new_olap_header->set_shard(new_shard);