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_r261939518
 
 

 ##########
 File path: be/src/olap/snapshot_manager.cpp
 ##########
 @@ -208,84 +206,114 @@ OLAPStatus SnapshotManager::_create_snapshot_files(
         remove_all_dir(schema_full_path);
     }
     create_dirs(schema_full_path);
-
     path boost_path(snapshot_id_path);
     string snapshot_id = canonical(boost_path).string();
-
-    bool header_locked = false;
-    ref_tablet->obtain_header_rdlock();
-    header_locked = true;
-
-    TabletMeta* new_tablet_meta = nullptr;
     do {
-        // get latest version
-        const RowsetSharedPtr lastest_version = 
ref_tablet->rowset_with_max_version();
-        if (lastest_version == NULL) {
-            OLAP_LOG_WARNING("tablet has not any version. [path='%s']",
-                    ref_tablet->full_name().c_str());
-            res = OLAP_ERR_VERSION_NOT_EXIST;
+        DataDir* data_dir = ref_tablet->data_dir();
+        std::unique_ptr<TabletMeta> new_tablet_meta(new(nothrow) 
TabletMeta(data_dir));
+        if (new_tablet_meta.get() == NULL) {
+            OLAP_LOG_WARNING("fail to malloc TabletMeta.");
+            res = OLAP_ERR_MALLOC_ERROR;
             break;
         }
-
-        // get snapshot version, use request.version if specified
-        int32_t version = lastest_version->end_version();
-        if (request.__isset.version) {
-            if (lastest_version->end_version() < request.version
-                    || (lastest_version->start_version() == 
lastest_version->end_version()
-                    && lastest_version->end_version() == request.version
-                    && lastest_version->version_hash() != 
request.version_hash)) {
-                OLAP_LOG_WARNING("invalid make snapshot request. "
-                        "[version=%d version_hash=%ld req_version=%d 
req_version_hash=%ld]",
-                        lastest_version->end_version(), 
lastest_version->version_hash(),
-                        request.version, request.version_hash);
-                res = OLAP_ERR_INPUT_PARAMETER_ERROR;
+        vector<RowsetSharedPtr> consistent_rowsets;
+        if (request.__isset.missing_version) {
+            ReadLock rdlock(ref_tablet->get_header_lock_ptr());
+            for (int64_t missed_version : request.missing_version) {
+                Version version = { missed_version, missed_version };
+                const RowsetSharedPtr rowset = 
ref_tablet->get_rowset_by_version(version);
+                if (rowset != nullptr) {
+                    consistent_rowsets.push_back(rowset);
+                } else {
+                    LOG(WARNING) << "failed to find missed version when 
snapshot. "
+                                << "tablet=" << request.tablet_id
+                                << ", schema_hash=" << request.schema_hash
+                                << ", version=" << version.first << "-" << 
version.second;
+                    res = OLAP_ERR_VERSION_NOT_EXIST;
+                    break;
+                }
+            }
+            res = TabletMetaManager::get_header(data_dir, 
ref_tablet->tablet_id(), ref_tablet->schema_hash(), new_tablet_meta.get());
+            if (res != OLAP_SUCCESS) {
+                LOG(WARNING) << "fail to load header. res=" << res
+                        << " tablet_id=" << ref_tablet->tablet_id() 
+                        << " , schema_hash=" << ref_tablet->schema_hash();
+                break;
+            }
+        } else {
+            ReadLock rdlock(ref_tablet->get_header_lock_ptr());
+            // get latest version
+            const RowsetSharedPtr lastest_version = 
ref_tablet->rowset_with_max_version();
+            if (lastest_version == NULL) {
+                OLAP_LOG_WARNING("tablet has not any version. [path='%s']",
+                        ref_tablet->full_name().c_str());
+                res = OLAP_ERR_VERSION_NOT_EXIST;
+                break;
+            }
+            // get snapshot version, use request.version if specified
+            int32_t version = lastest_version->end_version();
+            if (request.__isset.version) {
+                if (lastest_version->end_version() < request.version
+                        || (lastest_version->start_version() == 
lastest_version->end_version()
+                        && lastest_version->end_version() == request.version
+                        && lastest_version->version_hash() != 
request.version_hash)) {
+                    OLAP_LOG_WARNING("invalid make snapshot request. "
+                            "[version=%d version_hash=%ld req_version=%d 
req_version_hash=%ld]",
+                            lastest_version->end_version(), 
lastest_version->version_hash(),
+                            request.version, request.version_hash);
+                    res = OLAP_ERR_INPUT_PARAMETER_ERROR;
+                    break;
+                }
+                version = request.version;
+            }
+            // get shortest version path
+            res = ref_tablet->capture_consistent_rowsets(Version(0, version), 
&consistent_rowsets);
+            if (res != OLAP_SUCCESS) {
+                OLAP_LOG_WARNING("fail to select versions to span. [res=%d]", 
res);
                 break;
             }
 
-            version = request.version;
-        }
-
-        // get shortest version path
-        vector<RowsetSharedPtr> consistent_rowsets;
-        res = ref_tablet->capture_consistent_rowsets(Version(0, version), 
&consistent_rowsets);
-        if (res != OLAP_SUCCESS) {
-            OLAP_LOG_WARNING("fail to select versions to span. [res=%d]", res);
-            break;
+            res = TabletMetaManager::get_header(data_dir, 
ref_tablet->tablet_id(), ref_tablet->schema_hash(), new_tablet_meta.get());
 
 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