Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion be/src/agent/task_worker_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ void TaskWorkerPool::_create_tablet_worker_thread_callback() {
tablet_info.row_count = 0;
tablet_info.data_size = 0;
tablet_info.__set_path_hash(tablet->data_dir()->path_hash());
tablet_info.__set_replica_id(tablet->replica_id());
finish_tablet_infos.push_back(tablet_info);
}

Expand Down Expand Up @@ -428,7 +429,7 @@ void TaskWorkerPool::_drop_tablet_worker_thread_callback() {
drop_tablet_req.tablet_id, false, &err);
if (dropped_tablet != nullptr) {
Status drop_status = StorageEngine::instance()->tablet_manager()->drop_tablet(
drop_tablet_req.tablet_id);
drop_tablet_req.tablet_id, drop_tablet_req.replica_id);
if (!drop_status.ok()) {
LOG(WARNING) << "drop table failed! signature: " << agent_task_req.signature;
error_msgs.push_back("drop table failed!");
Expand Down
9 changes: 7 additions & 2 deletions be/src/olap/base_tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class BaseTablet : public std::enable_shared_from_this<BaseTablet> {
const std::string full_name() const;
int64_t partition_id() const;
int64_t tablet_id() const;
int64_t replica_id() const;
int32_t schema_hash() const;
int16_t shard_id();
int16_t shard_id() const;
bool equal(int64_t tablet_id, int32_t schema_hash);

// properties encapsulated in TabletSchema
Expand Down Expand Up @@ -123,11 +124,15 @@ inline int64_t BaseTablet::tablet_id() const {
return _tablet_meta->tablet_id();
}

inline int64_t BaseTablet::replica_id() const {
return _tablet_meta->replica_id();
}

inline int32_t BaseTablet::schema_hash() const {
return _tablet_meta->schema_hash();
}

inline int16_t BaseTablet::shard_id() {
inline int16_t BaseTablet::shard_id() const {
return _tablet_meta->shard_id();
}

Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/snapshot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Status SnapshotManager::release_snapshot(const string& snapshot_path) {
// For now, alpha and beta rowset meta have same fields, so we can just use
// AlphaRowsetMeta here.
Status SnapshotManager::convert_rowset_ids(const FilePathDesc& clone_dir_desc, int64_t tablet_id,
const int32_t& schema_hash) {
int64_t replica_id, const int32_t& schema_hash) {
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
Status res = Status::OK();
// check clone dir existed
Expand Down Expand Up @@ -151,6 +151,7 @@ Status SnapshotManager::convert_rowset_ids(const FilePathDesc& clone_dir_desc, i
// should modify tablet id and schema hash because in restore process the tablet id is not
// equal to tablet id in meta
new_tablet_meta_pb.set_tablet_id(tablet_id);
new_tablet_meta_pb.set_replica_id(replica_id);
new_tablet_meta_pb.set_schema_hash(schema_hash);
TabletSchema tablet_schema;
tablet_schema.init_from_pb(new_tablet_meta_pb.schema());
Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/snapshot_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SnapshotManager {
static SnapshotManager* instance();

Status convert_rowset_ids(const FilePathDesc& clone_dir_desc, int64_t tablet_id,
const int32_t& schema_hash);
int64_t replica_id, const int32_t& schema_hash);

private:
SnapshotManager() : _snapshot_base_id(0) {
Expand Down
1 change: 1 addition & 0 deletions be/src/olap/tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ void Tablet::build_tablet_report_info(TTabletInfo* tablet_info,
tablet_info->__set_version_count(_tablet_meta->version_count());
tablet_info->__set_path_hash(_data_dir->path_hash());
tablet_info->__set_is_in_memory(_tablet_meta->tablet_schema().is_in_memory());
tablet_info->__set_replica_id(replica_id());
}

// should use this method to get a copy of current tablet meta
Expand Down
97 changes: 48 additions & 49 deletions be/src/olap/tablet_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "olap/tablet_manager.h"

#include <gen_cpp/Types_types.h>
#include <rapidjson/document.h>
#include <re2/re2.h>
#include <thrift/protocol/TDebugProtocol.h>
Expand Down Expand Up @@ -184,7 +185,8 @@ Status TabletManager::_add_tablet_to_map_unlocked(TTabletId tablet_id,
if (drop_old) {
// If the new tablet is fresher than the existing one, then replace
// the existing tablet with the new one.
RETURN_NOT_OK_LOG(_drop_tablet_unlocked(tablet_id, keep_files),
// Use default replica_id to ignore whether replica_id is match when drop tablet.
RETURN_NOT_OK_LOG(_drop_tablet_unlocked(tablet_id, /* replica_id */ 0, keep_files),
strings::Substitute("failed to drop old tablet when add new tablet. "
"tablet_id=$0",
tablet_id));
Expand Down Expand Up @@ -368,7 +370,7 @@ TabletSharedPtr TabletManager::_internal_create_tablet_unlocked(
}
// something is wrong, we need clear environment
if (is_tablet_added) {
Status status = _drop_tablet_unlocked(new_tablet_id, false);
Status status = _drop_tablet_unlocked(new_tablet_id, request.replica_id, false);
if (!status.ok()) {
LOG(WARNING) << "fail to drop tablet when create tablet failed. res=" << res;
}
Expand Down Expand Up @@ -446,22 +448,21 @@ TabletSharedPtr TabletManager::_create_tablet_meta_and_dir_unlocked(
return nullptr;
}

Status TabletManager::drop_tablet(TTabletId tablet_id, bool keep_files) {
std::lock_guard<std::shared_mutex> wrlock(_get_tablets_shard_lock(tablet_id));
Status TabletManager::drop_tablet(TTabletId tablet_id, TReplicaId replica_id, bool keep_files) {
auto& shard = _get_tablets_shard(tablet_id);
std::lock_guard wrlock(shard.lock);
if (shard.tablets_under_clone.count(tablet_id) > 0) {
LOG(INFO) << "tablet " << tablet_id << " is under clone, skip drop task";
return Status::OK();
}
SCOPED_SWITCH_THREAD_LOCAL_MEM_TRACKER(_mem_tracker);
return _drop_tablet_unlocked(tablet_id, keep_files);
return _drop_tablet_unlocked(tablet_id, replica_id, keep_files);
}

// Drop specified tablet, the main logical is as follows:
// 1. tablet not in schema change:
// drop specified tablet directly;
// 2. tablet in schema change:
// a. schema change not finished && the dropping tablet is a base-tablet:
// base-tablet cannot be dropped;
// b. other cases:
// drop specified tablet directly and clear schema change info.
Status TabletManager::_drop_tablet_unlocked(TTabletId tablet_id, bool keep_files) {
LOG(INFO) << "begin drop tablet. tablet_id=" << tablet_id;
// Drop specified tablet.
Status TabletManager::_drop_tablet_unlocked(TTabletId tablet_id, TReplicaId replica_id,
bool keep_files) {
LOG(INFO) << "begin drop tablet. tablet_id=" << tablet_id << ", replica_id=" << replica_id;
DorisMetrics::instance()->drop_tablet_requests_total->increment(1);

// Fetch tablet which need to be dropped
Expand All @@ -471,8 +472,39 @@ Status TabletManager::_drop_tablet_unlocked(TTabletId tablet_id, bool keep_files
<< "tablet_id=" << tablet_id;
return Status::OK();
}
// We should compare replica id to avoid dropping new cloned tablet.
// Iff request replica id is 0, FE may be an older release, then we drop this tablet as before.
if (to_drop_tablet->replica_id() != replica_id && replica_id != 0) {
LOG(WARNING) << "fail to drop tablet because replica id not match. "
<< "tablet_id=" << tablet_id << ", replica_id=" << to_drop_tablet->replica_id()
<< ", request replica_id=" << replica_id;
return Status::OK();
}

return _drop_tablet_directly_unlocked(tablet_id, keep_files);
_remove_tablet_from_partition(to_drop_tablet);
tablet_map_t& tablet_map = _get_tablet_map(tablet_id);
tablet_map.erase(tablet_id);
if (!keep_files) {
// drop tablet will update tablet meta, should lock
std::lock_guard<std::shared_mutex> wrlock(to_drop_tablet->get_header_lock());
LOG(INFO) << "set tablet to shutdown state and remove it from memory. "
<< "tablet_id=" << tablet_id
<< ", tablet_path=" << to_drop_tablet->tablet_path_desc().filepath;
// NOTE: has to update tablet here, but must not update tablet meta directly.
// because other thread may hold the tablet object, they may save meta too.
// If update meta directly here, other thread may override the meta
// and the tablet will be loaded at restart time.
// To avoid this exception, we first set the state of the tablet to `SHUTDOWN`.
to_drop_tablet->set_tablet_state(TABLET_SHUTDOWN);
to_drop_tablet->save_meta();
{
std::lock_guard<std::shared_mutex> wrdlock(_shutdown_tablets_lock);
_shutdown_tablets.push_back(to_drop_tablet);
}
}

to_drop_tablet->deregister_tablet_from_dir();
return Status::OK();
}

Status TabletManager::drop_tablets_on_error_root_path(
Expand Down Expand Up @@ -1220,39 +1252,6 @@ Status TabletManager::_create_tablet_meta_unlocked(const TCreateTabletReq& reque
return res;
}

Status TabletManager::_drop_tablet_directly_unlocked(TTabletId tablet_id, bool keep_files) {
TabletSharedPtr dropped_tablet = _get_tablet_unlocked(tablet_id);
if (dropped_tablet == nullptr) {
LOG(WARNING) << "fail to drop tablet because it does not exist. "
<< " tablet_id=" << tablet_id;
return Status::OLAPInternalError(OLAP_ERR_TABLE_NOT_FOUND);
}
_remove_tablet_from_partition(dropped_tablet);
tablet_map_t& tablet_map = _get_tablet_map(tablet_id);
tablet_map.erase(tablet_id);
if (!keep_files) {
// drop tablet will update tablet meta, should lock
std::lock_guard<std::shared_mutex> wrlock(dropped_tablet->get_header_lock());
LOG(INFO) << "set tablet to shutdown state and remove it from memory. "
<< "tablet_id=" << tablet_id
<< ", tablet_path=" << dropped_tablet->tablet_path_desc().filepath;
// NOTE: has to update tablet here, but must not update tablet meta directly.
// because other thread may hold the tablet object, they may save meta too.
// If update meta directly here, other thread may override the meta
// and the tablet will be loaded at restart time.
// To avoid this exception, we first set the state of the tablet to `SHUTDOWN`.
dropped_tablet->set_tablet_state(TABLET_SHUTDOWN);
dropped_tablet->save_meta();
{
std::lock_guard<std::shared_mutex> wrdlock(_shutdown_tablets_lock);
_shutdown_tablets.push_back(dropped_tablet);
}
}

dropped_tablet->deregister_tablet_from_dir();
return Status::OK();
}

TabletSharedPtr TabletManager::_get_tablet_unlocked(TTabletId tablet_id) {
VLOG_NOTICE << "begin to get tablet. tablet_id=" << tablet_id;
tablet_map_t& tablet_map = _get_tablet_map(tablet_id);
Expand Down
6 changes: 2 additions & 4 deletions be/src/olap/tablet_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class TabletManager {
// Return OLAP_SUCCESS, if run ok
// OLAP_ERR_TABLE_DELETE_NOEXIST_ERROR, if tablet not exist
// Status::OLAPInternalError(OLAP_ERR_NOT_INITED), if not inited
Status drop_tablet(TTabletId tablet_id, bool keep_files = false);
Status drop_tablet(TTabletId tablet_id, TReplicaId replica_id, bool keep_files = false);

Status drop_tablets_on_error_root_path(const std::vector<TabletInfo>& tablet_info_vec);

Expand Down Expand Up @@ -157,9 +157,7 @@ class TabletManager {

bool _check_tablet_id_exist_unlocked(TTabletId tablet_id);

Status _drop_tablet_directly_unlocked(TTabletId tablet_id, bool keep_files = false);

Status _drop_tablet_unlocked(TTabletId tablet_id, bool keep_files);
Status _drop_tablet_unlocked(TTabletId tablet_id, TReplicaId replica_id, bool keep_files);

TabletSharedPtr _get_tablet_unlocked(TTabletId tablet_id);
TabletSharedPtr _get_tablet_unlocked(TTabletId tablet_id, bool include_deleted,
Expand Down
10 changes: 7 additions & 3 deletions be/src/olap/tablet_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Status TabletMeta::create(const TCreateTabletReq& request, const TabletUid& tabl
const unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id,
TabletMetaSharedPtr* tablet_meta) {
tablet_meta->reset(new TabletMeta(
request.table_id, request.partition_id, request.tablet_id,
request.table_id, request.partition_id, request.tablet_id, request.replica_id,
request.tablet_schema.schema_hash, shard_id, request.tablet_schema, next_unique_id,
col_ordinal_to_unique_id, tablet_uid,
request.__isset.tablet_type ? request.tablet_type : TTabletType::TABLET_TYPE_DISK,
Expand All @@ -50,8 +50,8 @@ Status TabletMeta::create(const TCreateTabletReq& request, const TabletUid& tabl
TabletMeta::TabletMeta() : _tablet_uid(0, 0), _schema(new TabletSchema) {}

TabletMeta::TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id,
int32_t schema_hash, uint64_t shard_id, const TTabletSchema& tablet_schema,
uint32_t next_unique_id,
int64_t replica_id, int32_t schema_hash, uint64_t shard_id,
const TTabletSchema& tablet_schema, uint32_t next_unique_id,
const std::unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id,
TabletUid tablet_uid, TTabletType::type tabletType,
TStorageMedium::type t_storage_medium, const std::string& storage_name,
Expand All @@ -61,6 +61,7 @@ TabletMeta::TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id
tablet_meta_pb.set_table_id(table_id);
tablet_meta_pb.set_partition_id(partition_id);
tablet_meta_pb.set_tablet_id(tablet_id);
tablet_meta_pb.set_replica_id(replica_id);
tablet_meta_pb.set_schema_hash(schema_hash);
tablet_meta_pb.set_shard_id(shard_id);
// Persist the creation time, but it is not used
Expand Down Expand Up @@ -375,6 +376,7 @@ void TabletMeta::init_from_pb(const TabletMetaPB& tablet_meta_pb) {
_table_id = tablet_meta_pb.table_id();
_partition_id = tablet_meta_pb.partition_id();
_tablet_id = tablet_meta_pb.tablet_id();
_replica_id = tablet_meta_pb.replica_id();
_schema_hash = tablet_meta_pb.schema_hash();
_shard_id = tablet_meta_pb.shard_id();
_creation_time = tablet_meta_pb.creation_time();
Expand Down Expand Up @@ -443,6 +445,7 @@ void TabletMeta::to_meta_pb(TabletMetaPB* tablet_meta_pb) {
tablet_meta_pb->set_table_id(table_id());
tablet_meta_pb->set_partition_id(partition_id());
tablet_meta_pb->set_tablet_id(tablet_id());
tablet_meta_pb->set_replica_id(replica_id());
tablet_meta_pb->set_schema_hash(schema_hash());
tablet_meta_pb->set_shard_id(shard_id());
tablet_meta_pb->set_creation_time(creation_time());
Expand Down Expand Up @@ -683,6 +686,7 @@ bool operator==(const TabletMeta& a, const TabletMeta& b) {
if (a._table_id != b._table_id) return false;
if (a._partition_id != b._partition_id) return false;
if (a._tablet_id != b._tablet_id) return false;
if (a._replica_id != b._replica_id) return false;
if (a._schema_hash != b._schema_hash) return false;
if (a._shard_id != b._shard_id) return false;
if (a._creation_time != b._creation_time) return false;
Expand Down
11 changes: 9 additions & 2 deletions be/src/olap/tablet_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class TabletMeta {
TabletMeta();
// Only remote_storage_name is needed in meta, it is a key used to get remote params from fe.
// The config of storage is saved in fe.
TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id, int32_t schema_hash,
uint64_t shard_id, const TTabletSchema& tablet_schema, uint32_t next_unique_id,
TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id, int64_t replica_id,
int32_t schema_hash, uint64_t shard_id, const TTabletSchema& tablet_schema,
uint32_t next_unique_id,
const std::unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id,
TabletUid tablet_uid, TTabletType::type tabletType,
TStorageMedium::type t_storage_medium, const std::string& remote_storage_name,
Expand Down Expand Up @@ -112,6 +113,7 @@ class TabletMeta {
int64_t table_id() const;
int64_t partition_id() const;
int64_t tablet_id() const;
int64_t replica_id() const;
int32_t schema_hash() const;
int16_t shard_id() const;
void set_shard_id(int32_t shard_id);
Expand Down Expand Up @@ -188,6 +190,7 @@ class TabletMeta {
int64_t _table_id = 0;
int64_t _partition_id = 0;
int64_t _tablet_id = 0;
int64_t _replica_id = 0;
int32_t _schema_hash = 0;
int32_t _shard_id = 0;
int64_t _creation_time = 0;
Expand Down Expand Up @@ -232,6 +235,10 @@ inline int64_t TabletMeta::tablet_id() const {
return _tablet_id;
}

inline int64_t TabletMeta::replica_id() const {
return _replica_id;
}

inline int32_t TabletMeta::schema_hash() const {
return _schema_hash;
}
Expand Down
Loading