yiguolei commented on a change in pull request #454: Refactor Tablet and 
TabletMeta
URL: https://github.com/apache/incubator-doris/pull/454#discussion_r243494747
 
 

 ##########
 File path: be/src/olap/tablet.cpp
 ##########
 @@ -202,917 +63,145 @@ Tablet::~Tablet() {
     }
 
     // ensure that there is nobody using Tablet, like acquiring 
OLAPData(SegmentGroup)
-    obtain_header_wrlock();
-    for (auto& it : _data_sources) {
-        for (SegmentGroup* segment_group : it.second) {
-            SAFE_DELETE(segment_group);
-        }
-    }
-    _data_sources.clear();
-
-    // clear the transactions in memory
-    for (auto& it : _pending_data_sources) {
-        // false means can't remove the transaction from tablet_meta, also 
prevent the loading of tablet
-        for (SegmentGroup* segment_group : it.second) {
-            StorageEngine::get_instance()->delete_transaction(
-                    segment_group->partition_id(), 
segment_group->transaction_id(),
-                    _tablet_id, _schema_hash, false);
-            SAFE_DELETE(segment_group);
-        }
-    }
-    _pending_data_sources.clear();
-    release_header_lock();
-
-    SAFE_DELETE(_tablet_meta);
-
-    // 移动数据目录
-    if (_is_dropped) {
-        LOG(INFO) << "drop tablet:" << full_name() << ", tablet path:" << 
_tablet_path;
-        path table_path(_tablet_path);
-        std::string tablet_meta_path = _tablet_path + "/" + 
std::to_string(_tablet_id) + ".hdr";
-        OLAPStatus s = TabletMetaManager::dump_header(_store, _tablet_id, 
_schema_hash, tablet_meta_path);
-        LOG(INFO) << "dump tablet_meta to path:" << tablet_meta_path << ", 
status:" << s;
-        LOG(INFO) << "start to remove tablet tablet_meta:" << full_name();
-        s = TabletMetaManager::remove(_store, _tablet_id, _schema_hash);
-        LOG(INFO) << "finish remove tablet tablet_meta:" << full_name() << ", 
res:" << s;
-        if (move_to_trash(table_path, table_path) != OLAP_SUCCESS) {
-            LOG(WARNING) << "fail to delete tablet. [table_path=" << 
_tablet_path << "]";
-        }
-        LOG(INFO) << "finish drop tablet:" << full_name();
+    WriteLock wrlock(_meta_lock);
+    for (auto& it : _version_rowset_map) {
+        SAFE_DELETE(it.second);
     }
+    _version_rowset_map.clear();
 }
 
-OLAPStatus Tablet::load() {
+OLAPStatus Tablet::init_once() {
     OLAPStatus res = OLAP_SUCCESS;
-    MutexLock l(&_load_lock);
-
-    string one_schema_root = _tablet_path;
-    set<string> files;
-    set<string> index_files;
-    set<string> data_files;
-
-    if (_is_loaded) {
-        goto EXIT;
+    ReadLock rdlock(&_meta_lock);
+    for (int ser = 0; ser < _tablet_meta.rowset_size(); ++ser) {
+        const RowsetMeta* rs_meta = _tablet_meta.get_rs_meta(ser);
+        Version version = rs_meta->version();
+        Rowset* rowset = new Rowset(rs_meta);
+        _version_rowset_map[version] = rowset;
+        rowset->init();
     }
-
-    res = dir_walk(one_schema_root, NULL, &files);
-    // Disk Failure will triggered delete file in disk.
-    // IOError will drop object. File only deleted upon restart.
-    // TODO. Tablet should has a state to report to FE, delete tablet
-    //         request will get from FE.      
-    if (res == OLAP_ERR_DISK_FAILURE) {
-        LOG(WARNING) << "fail to walk schema root dir." 
-                     << "res=" << res << ", root=" << one_schema_root;
-        goto EXIT;
-    } else if (res != OLAP_SUCCESS) {
-        StorageEngine::get_instance()->drop_tablet(tablet_id(), schema_hash(), 
true);
-        return res;
-    }
-    res = load_indices();
-
-    if (res != OLAP_SUCCESS) {
-        LOG(FATAL) << "fail to load indices. [res=" << res << " tablet='" << 
_full_name << "']";
-        goto EXIT;
-    }
-
-    // delete unused files
-    obtain_header_rdlock();
-    list_index_files(&index_files);
-    list_data_files(&data_files);
-    if (remove_unused_files(one_schema_root,
-                            files,
-                            "",
-                            index_files,
-                            data_files) != OLAP_SUCCESS) {
-        LOG(WARNING) << "fail to remove unused files. [root='" << 
one_schema_root << "']";
-    }
-    release_header_lock();
-
-    _is_loaded = true;
-
-EXIT:
-    if (res != OLAP_SUCCESS) {
-        StorageEngine::get_instance()->drop_tablet(tablet_id(), schema_hash());
-    }
-
-    return res;
+    return OLAP_SUCCESS;
 }
 
 bool Tablet::can_do_compaction() {
     // 如果table正在做schema change,则通过选路判断数据是否转换完成
     // 如果选路成功,则转换完成,可以进行BE
     // 如果选路失败,则转换未完成,不能进行BE
-    this->obtain_header_rdlock();
-    const PDelta* lastest_version = this->lastest_version();
-    if (lastest_version == NULL) {
-        this->release_header_lock();
+    ReadLock rdlock(_meta_lock);
+    const Rowset* lastest_rowset = lastest_version();
+    if (lastest_rowset == NULL) {
+        return false;
+    }
+
+    Version test_version = Version(0, lastest_version->end_version());
+    vector<Version> path_versions;
+    if (OLAP_SUCCESS != _rs_graph->capture_consistent_versions(test_version, 
&path_versions)) {
+        LOG(WARNING) << "tablet has missed version. tablet=" << 
table->full_name();
         return false;
     }
 
-    if (this->is_schema_changing()) {
+    if (table->is_schema_changing()) {
 
 Review comment:
   what is table?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org
For additional commands, e-mail: dev-h...@doris.apache.org

Reply via email to