kangpinghuang commented on a change in pull request #567: Add publish version 
task
URL: https://github.com/apache/incubator-doris/pull/567#discussion_r249743428
 
 

 ##########
 File path: be/src/olap/task/engine_publish_version_task.cpp
 ##########
 @@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "olap/task/engine_publish_version_task.h"
+#include "olap/data_dir.h"
+#include "olap/rowset/rowset_meta_manager.h"
+#include "olap/tablet_manager.h"
+#include <map>
+
+namespace doris {
+
+using std::map;
+
+EnginePublishVersionTask::EnginePublishVersionTask(TPublishVersionRequest& 
publish_version_req, 
+                                                   vector<TTabletId>* 
error_tablet_ids)
+    : _publish_version_req(publish_version_req), 
+      _error_tablet_ids(error_tablet_ids) {}
+
+OLAPStatus EnginePublishVersionTask::finish() {
+    LOG(INFO) << "begin to process publish version. transaction_id="
+        << _publish_version_req.transaction_id;
+
+    int64_t transaction_id = _publish_version_req.transaction_id;
+    OLAPStatus res = OLAP_SUCCESS;
+
+    // each partition
+    for (auto& partitionVersionInfo
+         : _publish_version_req.partition_version_infos) {
+
+        int64_t partition_id = partitionVersionInfo.partition_id;
+        map<TabletInfo, RowsetSharedPtr> tablet_related_rs;
+        TxnManager::instance()->get_txn_related_tablets(transaction_id, 
partition_id, &tablet_related_rs);
+
+        Version version(partitionVersionInfo.version, 
partitionVersionInfo.version);
+        VersionHash version_hash = partitionVersionInfo.version_hash;
+
+        // each tablet
+        for (auto& tablet_rs : tablet_related_rs) {
+            OLAPStatus publish_status = OLAP_SUCCESS;
+            TabletInfo tablet_info = tablet_rs.first;
+            RowsetSharedPtr rowset = tablet_rs.second;
+            LOG(INFO) << "begin to publish version on tablet. "
+                    << "tablet_id=" << tablet_info.tablet_id
+                    << ", schema_hash=" << tablet_info.schema_hash
+                    << ", version=" << version.first
+                    << ", version_hash=" << version_hash
+                    << ", transaction_id=" << transaction_id;
+            TabletSharedPtr tablet = 
TabletManager::instance()->get_tablet(tablet_info.tablet_id, 
tablet_info.schema_hash);
+
+            if (tablet.get() == NULL) {
+                LOG(WARNING) << "can't get tablet when publish version. 
tablet_id=" << tablet_info.tablet_id
+                             << "schema_hash=" << tablet_info.schema_hash;
+                _error_tablet_ids->push_back(tablet_info.tablet_id);
+                res = OLAP_ERR_PUSH_TABLE_NOT_EXIST;
+                continue;
+            }
+
+            // publish version, one tablet only has one rowset for a single txn
+            // if one tablet has more than one rowset for a single txn, 
+            // should consider part of rowset meta persist 
+            // failed, it is very difficault, so that not deal with this case
+            // get rowsets from txn manager according to tablet and txn id
+            // set rowset version 
+            // persist rowset meta
+            rowset->set_version(version);
+            rowset->set_version_hash(version_hash);
+            // TODO(ygl): currently, tablet meta will be persist when add a 
new rowset,
+            // so that not persist rowset meta here
+            /**
+            publish_status = RowsetMetaManager::save(
+                tablet->data_dir()->get_meta(),
+                rowset->rowset_id(),
+                rowset->rowset_meta());
+            if (publish_status != OLAP_SUCCESS) {
+                LOG(WARNING) << "save pending rowset failed. rowset_id:" << 
rowset->rowset_id() 
+                             << "tablet id: " << tablet_info.tablet_id
+                             << "txn id:" << transaction_id;
+                error_tablet_ids->push_back(tablet_info.tablet_id);
+                res = OLAP_ERR_ROWSET_SAVE_FAILED;
+                continue;
+            }
+            */
+            // add visible rowset to tablet
+            publish_status = tablet->add_inc_rowset(*rowset);
+            if (publish_status != OLAP_SUCCESS) {
+                LOG(WARNING) << "add visilbe rowset to tablet failed 
rowset_id:" << rowset->rowset_id()
+                             << "tablet id: " << tablet_info.tablet_id
+                             << "txn id:" << transaction_id;
+                _error_tablet_ids->push_back(tablet_info.tablet_id);
+                res = OLAP_ERR_ROWSET_SAVE_FAILED;
+                continue;
+            }
+
+            if (publish_status == OLAP_SUCCESS) {
+                LOG(INFO) << "publish version successfully on tablet. tablet=" 
<< tablet->full_name()
+                          << ", transaction_id=" << transaction_id << ", 
version=" << version.first;
+                // delete rowset from meta env
+                RowsetMetaManager::remove(tablet->data_dir()->get_meta(), 
rowset->rowset_id());
+                // delete txn info
+                TxnManager::instance()->delete_txn(partition_id, 
transaction_id, 
+                    tablet_info.tablet_id, tablet_info.schema_hash);
+            } else {
+                LOG(WARNING) << "fail to publish version on tablet. tablet=" 
<< tablet->full_name().c_str()
+                             << "transaction_id=" << transaction_id
 
 Review comment:
   add space to seperate from the front string? the same to the following lines

----------------------------------------------------------------
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