@@ -63,7 +63,9 @@ EngineCloneTask::EngineCloneTask(const TCloneReq& clone_req, const TMasterInfo&
6363Status EngineCloneTask::execute () {
6464 // register the tablet to avoid it is deleted by gc thread during clone process
6565 SCOPED_ATTACH_TASK (_mem_tracker);
66- StorageEngine::instance ()->tablet_manager ()->register_clone_tablet (_clone_req.tablet_id );
66+ if (StorageEngine::instance ()->tablet_manager ()->register_clone_tablet (_clone_req.tablet_id )) {
67+ return Status::InternalError (" tablet {} is under clone" , _clone_req.tablet_id );
68+ }
6769 Status st = _do_clone ();
6870 StorageEngine::instance ()->tablet_manager ()->unregister_clone_tablet (_clone_req.tablet_id );
6971 return st;
@@ -81,6 +83,13 @@ Status EngineCloneTask::_do_clone() {
8183 std::vector<Version> missed_versions;
8284 // try to repair a tablet with missing version
8385 if (tablet != nullptr ) {
86+ if (tablet->replica_id () != _clone_req.replica_id ) {
87+ // `tablet` may be a dropped replica in FE, e.g: BE1 migrates replica of tablet_1 to BE2,
88+ // but before BE1 drop this replica, another new replica of tablet_1 is migrated to BE1.
89+ // If we allow to clone success on dropped replica, replica id may never be consistent between FE and BE.
90+ return Status::InternalError (" replica_id not match({} vs {})" , tablet->replica_id (),
91+ _clone_req.replica_id );
92+ }
8493 std::shared_lock migration_rlock (tablet->get_migration_lock (), std::try_to_lock);
8594 if (!migration_rlock.owns_lock ()) {
8695 return Status::OLAPInternalError (OLAP_ERR_RWLOCK_ERROR );
@@ -96,23 +105,23 @@ Status EngineCloneTask::_do_clone() {
96105 // completed. Or remote be will just return header not the rowset files. clone will failed.
97106 if (missed_versions.empty ()) {
98107 LOG (INFO ) << " missed version size = 0, skip clone and return success. tablet_id="
99- << _clone_req.tablet_id ;
108+ << _clone_req.tablet_id << " replica_id= " << _clone_req. replica_id ;
100109 _set_tablet_info (is_new_tablet);
101110 return Status::OK ();
102111 }
103112
104113 LOG (INFO ) << " clone to existed tablet. missed_versions_size=" << missed_versions.size ()
105114 << " , allow_incremental_clone=" << allow_incremental_clone
106115 << " , signature=" << _signature << " , tablet_id=" << _clone_req.tablet_id
107- << " , committed_version=" << _clone_req.committed_version ;
116+ << " , committed_version=" << _clone_req.committed_version
117+ << " , replica_id=" << _clone_req.replica_id ;
108118
109119 // try to download missing version from src backend.
110120 // if tablet on src backend does not contains missing version, it will download all versions,
111121 // and set allow_incremental_clone to false
112122 RETURN_IF_ERROR (_make_and_download_snapshots (*(tablet->data_dir ()), local_data_path,
113123 &src_host, &src_file_path, missed_versions,
114124 &allow_incremental_clone));
115-
116125 RETURN_IF_ERROR (_finish_clone (tablet.get (), local_data_path, _clone_req.committed_version ,
117126 allow_incremental_clone));
118127 } else {
0 commit comments