yiguolei commented on a change in pull request #669: Convert old files when 
start be
URL: https://github.com/apache/incubator-doris/pull/669#discussion_r261939726
 
 

 ##########
 File path: be/src/olap/storage_engine.cpp
 ##########
 @@ -117,8 +119,179 @@ StorageEngine::~StorageEngine() {
     clear();
 }
 
+// convert old tablet and its files to new tablet meta and rowset format
+OLAPStatus StorageEngine::_convert_old_tablet(DataDir* data_dir) {
+    auto convert_tablet_func = [this, data_dir](long tablet_id,
+        long schema_hash, const std::string& value) -> bool {
+        OlapSnapshotConverter converter;
+        // convert olap header and files
+        OLAPHeaderMessage olap_header_msg;
+        TabletMetaPB tablet_meta_pb;
+        vector<RowsetMetaPB> pending_rowsets;
+        bool parsed = olap_header_msg.ParseFromString(value);
+        if (!parsed) {
+            LOG(WARNING) << "convert olap header to tablet meta failed when 
load olap header tablet=" 
+                         << tablet_id << "." << schema_hash;
+            return false;
+        }
+        string old_data_path_prefix = 
data_dir->get_absolute_tablet_path(olap_header_msg, true);
+        OLAPStatus status = converter.to_new_snapshot(olap_header_msg, 
old_data_path_prefix, 
+            &tablet_meta_pb, old_data_path_prefix, *data_dir, 
&pending_rowsets);
+        if (status != OLAP_SUCCESS) {
+            LOG(WARNING) << "convert olap header to tablet meta failed when 
convert header and files tablet=" 
+                         << tablet_id << "." << schema_hash;
+            return false;
+        }
+
+        // write pending rowset to olap meta
+        for (auto& rowset_pb : pending_rowsets) {
+            string meta_binary;
+            rowset_pb.SerializeToString(&meta_binary);
+            status = RowsetMetaManager::save(data_dir->get_meta(), 
rowset_pb.rowset_id() , meta_binary);
+            if (status != OLAP_SUCCESS) {
+                LOG(WARNING) << "convert olap header to tablet meta failed 
when save rowset meta tablet=" 
+                             << tablet_id << "." << schema_hash;
+                return false;
+            }
+        }
+
+        // write converted tablet meta to olap meta
+        string meta_binary;
+        tablet_meta_pb.SerializeToString(&meta_binary);
+        status = TabletMetaManager::save(data_dir, tablet_meta_pb.tablet_id(), 
tablet_meta_pb.schema_hash(), meta_binary);
+        if (status != OLAP_SUCCESS) {
+            LOG(WARNING) << "convert olap header to tablet meta failed when 
save tablet meta tablet=" 
+                        << tablet_id << "." << schema_hash;
+            return false;
+        }
+        return true;
+    };
+    OLAPStatus convert_tablet_status = 
TabletMetaManager::traverse_headers(data_dir->get_meta(), convert_tablet_func, 
OLD_HEADER_PREFIX);
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to