kangpinghuang commented on a change in pull request #596: Add implementation to 
tablet
URL: https://github.com/apache/incubator-doris/pull/596#discussion_r252124749
 
 

 ##########
 File path: be/src/olap/tablet.cpp
 ##########
 @@ -54,8 +56,62 @@ using std::vector;
 
 namespace doris {
 
-Tablet::Tablet(TabletMeta* tablet_meta, DataDir* data_dir) {
-    _data_dir = data_dir;
+TabletSharedPtr Tablet::create_from_tablet_meta_file(
+            const string& file_path, DataDir* data_dir) {
+    TabletMeta* tablet_meta = NULL;
+    tablet_meta = new(nothrow) TabletMeta();
+    if (tablet_meta == nullptr) {
+        LOG(WARNING) << "fail to malloc TabletMeta.";
+        return NULL;
+    }
+
+    if (tablet_meta->create_from_file(file_path) != OLAP_SUCCESS) {
+        LOG(WARNING) << "fail to load tablet_meta. file_path=" << file_path;
+        delete tablet_meta;
+        return nullptr;
+    }
+
+    // add new fields
+    boost::filesystem::path file_path_path(file_path);
+    std::string shard_path = 
file_path_path.parent_path().parent_path().parent_path().string();
+    std::string shard_str = shard_path.substr(shard_path.find_last_of('/') + 
1);
+    uint64_t shard = stol(shard_str);
+    tablet_meta->set_shard_id(shard);
+
+    // save tablet_meta info to kv db
+    // tablet_meta key format: tablet_id + "_" + schema_hash
+    OLAPStatus res = TabletMetaManager::save(data_dir, 
tablet_meta->tablet_id(),
+                                             tablet_meta->schema_hash(), 
tablet_meta);
+    if (res != OLAP_SUCCESS) {
+        OLAP_LOG_WARNING("fail to save tablet_meta to db. [file_path=%s]", 
file_path.c_str());
 
 Review comment:
   LOG(WARNING)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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