Skip to content

Commit

Permalink
[fix](cluster key) fix cluster key schema change (#45203)
Browse files Browse the repository at this point in the history
Problem Summary:
for schema change: add a key in the tail of all keys, may get:

```
F20241209 14:52:09.513403 3166619 segment_writer.cpp:1309] Check failed: key.compare(last_key) >= 0 key is not sorted! current key: ^A^B06olTqiL2rEn48nTpmP8, last key: ^B^@^OЭ^BxsmIHehvUnv
*** Check failure stack trace: ***
    @     0x563674f2dcc6  google::LogMessage::SendToLog()
    @     0x563674f2a710  google::LogMessage::Flush()
    @     0x563674f2e509  google::LogMessageFatal::~LogMessageFatal()
    @     0x56366a8a72c0  doris::segment_v2::SegmentWriter::_generate_short_key_index()
    @     0x56366a8a6032  doris::segment_v2::SegmentWriter::append_block()
    @     0x56366a7624c9  doris::SegmentCreator::add_block()
    @     0x56366a731d35  doris::BaseBetaRowsetWriter::add_block()
    @     0x56366a94a233  doris::VSchemaChangeDirectly::_inner_process()
    @     0x56366a95d558  doris::SchemaChange::process()
    @     0x56366a9511e5  doris::SchemaChangeJob::_convert_historical_rowsets()
    @     0x56366a94e5e2  doris::SchemaChangeJob::_do_process_alter_tablet()
    @     0x56366a94cf22  doris::SchemaChangeJob::process_alter_tablet()
    @     0x563669e9e857  doris::alter_tablet_callback()
```
  • Loading branch information
mymeiyi authored Dec 12, 2024
1 parent 5fcf945 commit e2c24e3
Show file tree
Hide file tree
Showing 7 changed files with 28,859 additions and 0 deletions.
9 changes: 9 additions & 0 deletions be/src/cloud/cloud_schema_change_job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ Status CloudSchemaChangeJob::process_alter_tablet(const TAlterTabletReqV2& reque
reader_context.batch_size = ALTER_TABLE_BATCH_SIZE;
reader_context.delete_bitmap = &_base_tablet->tablet_meta()->delete_bitmap();
reader_context.version = Version(0, start_resp.alter_version());
std::vector<uint32_t> cluster_key_idxes;
if (!_base_tablet_schema->cluster_key_uids().empty()) {
for (const auto& uid : _base_tablet_schema->cluster_key_uids()) {
cluster_key_idxes.emplace_back(_base_tablet_schema->field_index(uid));
}
reader_context.read_orderby_key_columns = &cluster_key_idxes;
reader_context.is_unique = false;
reader_context.sequence_id_idx = -1;
}

for (auto& split : rs_splits) {
RETURN_IF_ERROR(split.rs_reader->init(&reader_context));
Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/memtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "runtime/descriptors.h"
#include "runtime/exec_env.h"
#include "runtime/thread_context.h"
#include "util/debug_points.h"
#include "util/runtime_profile.h"
#include "util/stopwatch.hpp"
#include "vec/aggregate_functions/aggregate_function_reader.h"
Expand Down Expand Up @@ -589,6 +590,7 @@ void MemTable::shrink_memtable_by_agg() {
}

bool MemTable::need_flush() const {
DBUG_EXECUTE_IF("MemTable.need_flush", { return true; });
auto max_size = config::write_buffer_size;
if (_partial_update_mode == UniqueKeyUpdateModePB::UPDATE_FIXED_COLUMNS) {
auto update_columns_size = _num_columns;
Expand Down
9 changes: 9 additions & 0 deletions be/src/olap/schema_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ Status SchemaChangeJob::_do_process_alter_tablet(const TAlterTabletReqV2& reques
for (int i = 0; i < num_cols; ++i) {
return_columns[i] = i;
}
std::vector<uint32_t> cluster_key_idxes;

DBUG_EXECUTE_IF("SchemaChangeJob::_do_process_alter_tablet.block", DBUG_BLOCK);

Expand Down Expand Up @@ -982,6 +983,14 @@ Status SchemaChangeJob::_do_process_alter_tablet(const TAlterTabletReqV2& reques
reader_context.batch_size = ALTER_TABLE_BATCH_SIZE;
reader_context.delete_bitmap = &_base_tablet->tablet_meta()->delete_bitmap();
reader_context.version = Version(0, end_version);
if (!_base_tablet_schema->cluster_key_uids().empty()) {
for (const auto& uid : _base_tablet_schema->cluster_key_uids()) {
cluster_key_idxes.emplace_back(_base_tablet_schema->field_index(uid));
}
reader_context.read_orderby_key_columns = &cluster_key_idxes;
reader_context.is_unique = false;
reader_context.sequence_id_idx = -1;
}
for (auto& rs_split : rs_splits) {
res = rs_split.rs_reader->init(&reader_context);
if (!res) {
Expand Down
Loading

0 comments on commit e2c24e3

Please sign in to comment.