Skip to content

Commit

Permalink
[fix](meger-on-write) fix query result wrong when schema change (apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoxin01 committed Aug 27, 2023
1 parent 475f984 commit 4cb4b1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
36 changes: 23 additions & 13 deletions be/src/olap/delta_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ Status DeltaWriter::init() {
if (_tablet->enable_unique_key_merge_on_write()) {
std::lock_guard<std::shared_mutex> lck(_tablet->get_header_lock());
_cur_max_version = _tablet->max_version_unlocked().second;
_rowset_ids = _tablet->all_rs_id(_cur_max_version);
// tablet is under alter process. The delete bitmap will be calculated after conversion.
if (_tablet->tablet_state() == TABLET_NOTREADY &&
SchemaChangeHandler::tablet_in_converting(_tablet->tablet_id())) {
_rowset_ids.clear();
} else {
_rowset_ids = _tablet->all_rs_id(_cur_max_version);
}
}

// check tablet version number
Expand Down Expand Up @@ -399,22 +405,26 @@ Status DeltaWriter::close_wait(const PSlaveTabletNodes& slave_tablet_nodes,
return res;
}
if (_tablet->enable_unique_key_merge_on_write()) {
auto beta_rowset = reinterpret_cast<BetaRowset*>(_cur_rowset.get());
std::vector<segment_v2::SegmentSharedPtr> segments;
RETURN_IF_ERROR(beta_rowset->load_segments(&segments));
// tablet is under alter process. The delete bitmap will be calculated after conversion.
if (_tablet->tablet_state() == TABLET_NOTREADY &&
SchemaChangeHandler::tablet_in_converting(_tablet->tablet_id())) {
return Status::OK();
}
if (segments.size() > 1) {
RETURN_IF_ERROR(_tablet->calc_delete_bitmap(beta_rowset->rowset_id(), segments, nullptr,
_delete_bitmap, _cur_max_version, true));
}
LOG(INFO) << "tablet is under alter process, delete bitmap will be calculated later, "
"tablet_id: "
<< _tablet->tablet_id() << " txn_id: " << _req.txn_id;
} else {
auto beta_rowset = reinterpret_cast<BetaRowset*>(_cur_rowset.get());
std::vector<segment_v2::SegmentSharedPtr> segments;
RETURN_IF_ERROR(beta_rowset->load_segments(&segments));
if (segments.size() > 1) {
RETURN_IF_ERROR(_tablet->calc_delete_bitmap(beta_rowset->rowset_id(), segments,
nullptr, _delete_bitmap,
_cur_max_version, true));
}

_storage_engine->txn_manager()->set_txn_related_delete_bitmap(
_req.partition_id, _req.txn_id, _tablet->tablet_id(), _tablet->schema_hash(),
_tablet->tablet_uid(), true, _delete_bitmap, _rowset_ids);
_storage_engine->txn_manager()->set_txn_related_delete_bitmap(
_req.partition_id, _req.txn_id, _tablet->tablet_id(), _tablet->schema_hash(),
_tablet->tablet_uid(), true, _delete_bitmap, _rowset_ids);
}
}

_delta_written_success = true;
Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/schema_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ Status SchemaChangeHandler::_do_process_alter_tablet_v2(const TAlterTabletReqV2&
std::lock_guard<std::mutex> rwlock(new_tablet->get_rowset_update_lock());
std::lock_guard<std::shared_mutex> new_wlock(new_tablet->get_header_lock());
SCOPED_SIMPLE_TRACE_IF_TIMEOUT(TRACE_TABLET_LOCK_THRESHOLD);
int64_t new_max_version = new_tablet->max_version().second;
int64_t new_max_version = new_tablet->max_version_unlocked().second;
rowsets.clear();
if (max_version < new_max_version) {
LOG(INFO)
Expand Down

0 comments on commit 4cb4b1f

Please sign in to comment.