kangpinghuang commented on a change in pull request #567: Add publish version task URL: https://github.com/apache/incubator-doris/pull/567#discussion_r249662942
########## File path: be/src/olap/storage_engine.cpp ########## @@ -1002,4 +954,56 @@ OLAPStatus StorageEngine::load_header( return res; } + +OLAPStatus StorageEngine::execute_task(EngineTask* task) { + // 1. add wlock to related tablets + // 2. do prepare work + // 3. release wlock + { + vector<TabletInfo> tablet_infos; + task->get_related_tablets(&tablet_infos); + sort(tablet_infos.begin(), tablet_infos.end()); + for (TabletInfo& tablet_info : tablet_infos) { + TabletSharedPtr tablet = TabletManager::instance()->get_tablet(tablet_info.tablet_id, tablet_info.schema_hash, false); + tablet->obtain_header_wrlock(); + } + // add write lock to all related tablets + OLAPStatus prepare_status = task->prepare(); + for (TabletInfo& tablet_info : tablet_infos) { + TabletSharedPtr tablet = TabletManager::instance()->get_tablet(tablet_info.tablet_id, tablet_info.schema_hash, false); + tablet->release_header_lock(); + } + if (prepare_status != OLAP_SUCCESS) { + return prepare_status; + } + } + + // do execute work without lock + OLAPStatus exec_status = task->execute(); + if (exec_status != OLAP_SUCCESS) { + return exec_status; + } + + // 1. add wlock to related tablets + // 2. do finish work + // 3. release wlock + { + vector<TabletInfo> tablet_infos; + // related tablets may be changed after execute task, so that get them here again + task->get_related_tablets(&tablet_infos); + sort(tablet_infos.begin(), tablet_infos.end()); + for (TabletInfo& tablet_info : tablet_infos) { + TabletSharedPtr tablet = TabletManager::instance()->get_tablet(tablet_info.tablet_id, tablet_info.schema_hash, false); + tablet->obtain_header_wrlock(); + } + // add write lock to all related tablets + OLAPStatus fin_status = task->finish(); + for (TabletInfo& tablet_info : tablet_infos) { + TabletSharedPtr tablet = TabletManager::instance()->get_tablet(tablet_info.tablet_id, tablet_info.schema_hash, false); Review comment: the code seem to be the same with line 962-979, Is it possible the put them in a function? ---------------------------------------------------------------- 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