imay commented on a change in pull request #1497: Add ALTER_TABLET task in be
URL: https://github.com/apache/incubator-doris/pull/1497#discussion_r304407797
 
 

 ##########
 File path: be/src/olap/schema_change.cpp
 ##########
 @@ -1121,6 +1121,207 @@ bool SchemaChangeWithSorting::_external_sorting(
     return true;
 }
 
+OLAPStatus SchemaChangeHandler::process_alter_tablet_v2(const 
TAlterTabletReqV2& request) {
+    LOG(INFO) << "begin to validate alter tablet request. base_tablet_id=" << 
request.base_tablet_id
+              << ", base_schema_hash" << request.base_schema_hash
+              << ", new_tablet_id=" << request.new_tablet_id
+              << ", new_schema_hash=" << request.new_schema_hash
+              << ", alter_version=" << request.alter_version
+              << ", alter_version_hash=" << request.alter_version_hash;
+
+    // Lock schema_change_lock util schema change info is stored in tablet 
header
+    if 
(!StorageEngine::instance()->tablet_manager()->try_schema_change_lock(request.base_tablet_id))
 {
+        LOG(WARNING) << "failed to obtain schema change lock. "
+                     << "base_tablet=" << request.base_tablet_id;
+        return OLAP_ERR_TRY_LOCK_FAILED;
+    }
+
+    OLAPStatus res = _do_process_alter_tablet_v2(request);
+    LOG(INFO) << "finished alter tablet process, res=" << res;
+    
StorageEngine::instance()->tablet_manager()->release_schema_change_lock(request.base_tablet_id);
+    return res;
+}
+
+OLAPStatus SchemaChangeHandler::_do_process_alter_tablet_v2(const 
TAlterTabletReqV2& request) {
+    OLAPStatus res = OLAP_SUCCESS;
+    TabletSharedPtr base_tablet = 
StorageEngine::instance()->tablet_manager()->get_tablet(
+            request.base_tablet_id, request.base_schema_hash);
+    if (base_tablet == nullptr) {
+        LOG(WARNING) << "fail to find base tablet. base_tablet=" << 
request.base_tablet_id
+                     << ", base_schema_hash=" << request.base_schema_hash;
+        return OLAP_ERR_TABLE_NOT_FOUND;
+    }
+
+    // new tablet has to exist
+    TabletSharedPtr new_tablet = 
StorageEngine::instance()->tablet_manager()->get_tablet(
+            request.new_tablet_id, request.new_schema_hash);
+    if (new_tablet == nullptr) {
+        LOG(WARNING) << "fail to find new tablet."
+                     << ", new_tablet=" << request.new_tablet_id
+                     << ", new_schema_hash=" << request.new_schema_hash;
+        return OLAP_ERR_TABLE_NOT_FOUND;
+    }
+
+    // check if tablet's state is not_ready, if it is ready, it means the 
tablet already finished 
+    // check whether the tablet's max continuous version == request.version
+    if (new_tablet->tablet_state() != TABLET_NOTREADY) {
+        res = _validate_alter_result(new_tablet, request);
+        LOG(INFO) << "tablet's state=" << new_tablet->tablet_state()
+                  << " the convert job alreay finished, check its version"
+                  << " res=" << res;
+        return res;
+    }
+
+    LOG(INFO) << "finish to validate alter tablet request. begin to convert 
data from base tablet to new tablet" 
+              << " base_tablet=" << base_tablet->full_name()
+              << " new_tablet=" << new_tablet->full_name();
+
+    ReadLock base_migration_rlock(base_tablet->get_migration_lock_ptr(), 
TRY_LOCK);
+    if (!base_migration_rlock.own_lock()) {
+        return OLAP_ERR_RWLOCK_ERROR;
+    }
+    ReadLock new_migration_rlock(new_tablet->get_migration_lock_ptr(), 
TRY_LOCK);
+    if (!new_migration_rlock.own_lock()) {
+        return OLAP_ERR_RWLOCK_ERROR;
+    }
+
+    // 2. Get version_to_be_changed and store into tablet header
+    base_tablet->obtain_push_lock();
+    base_tablet->obtain_header_wrlock();
+    new_tablet->obtain_header_wrlock();
+
+    // check if the tablet has alter task
+    // if it has alter task, it means it is under old alter process
+
+    vector<Version> versions_to_be_changed;
+    vector<RowsetReaderSharedPtr> rs_readers;
+    // delete handlers for new tablet
+    DeleteHandler delete_handler;
+    do {
+        // get history data to be converted and it will check if there is hold 
in base tablet
+        res = _get_versions_to_be_changed(base_tablet, versions_to_be_changed);
 
 Review comment:
   use pointer as output param

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