Skip to content

Commit

Permalink
[fix](merge-on-write) fix duplicate keys occur when be restart (#22437)
Browse files Browse the repository at this point in the history
For mow table, delete bitmap of stale rowsets has not been persisted. When be restart, duplicate keys will occur if read stale rowsets.
Therefore, for the mow table, we do not allow reading the stale rowsets. Although this may result in VERSION_ALREADY_MERGED error when query after be restart, its probability of occurrence is relatively low.
  • Loading branch information
liaoxin01 authored Aug 1, 2023
1 parent 26737dd commit f842067
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions be/src/olap/tablet_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,26 @@ void TabletMeta::init_from_pb(const TabletMetaPB& tablet_meta_pb) {
// init _schema
_schema->init_from_pb(tablet_meta_pb.schema());

if (tablet_meta_pb.has_enable_unique_key_merge_on_write()) {
_enable_unique_key_merge_on_write = tablet_meta_pb.enable_unique_key_merge_on_write();
}

// init _rs_metas
for (auto& it : tablet_meta_pb.rs_metas()) {
RowsetMetaSharedPtr rs_meta(new RowsetMeta());
rs_meta->init_from_pb(it);
_rs_metas.push_back(std::move(rs_meta));
}

for (auto& it : tablet_meta_pb.stale_rs_metas()) {
RowsetMetaSharedPtr rs_meta(new RowsetMeta());
rs_meta->init_from_pb(it);
_stale_rs_metas.push_back(std::move(rs_meta));
// For mow table, delete bitmap of stale rowsets has not been persisted.
// When be restart, query should not read the stale rowset, otherwise duplicate keys
// will be read out. Therefore, we don't add them to _stale_rs_meta for mow table.
if (!_enable_unique_key_merge_on_write) {
for (auto& it : tablet_meta_pb.stale_rs_metas()) {
RowsetMetaSharedPtr rs_meta(new RowsetMeta());
rs_meta->init_from_pb(it);
_stale_rs_metas.push_back(std::move(rs_meta));
}
}

if (tablet_meta_pb.has_in_restore_mode()) {
Expand All @@ -533,10 +542,6 @@ void TabletMeta::init_from_pb(const TabletMetaPB& tablet_meta_pb) {
_cooldown_meta_id = tablet_meta_pb.cooldown_meta_id();
}

if (tablet_meta_pb.has_enable_unique_key_merge_on_write()) {
_enable_unique_key_merge_on_write = tablet_meta_pb.enable_unique_key_merge_on_write();
}

if (tablet_meta_pb.has_delete_bitmap()) {
int rst_ids_size = tablet_meta_pb.delete_bitmap().rowset_ids_size();
int seg_ids_size = tablet_meta_pb.delete_bitmap().segment_ids_size();
Expand Down

0 comments on commit f842067

Please sign in to comment.