From eb03a78412a66d4a3ee659f27675e7fa83f58ddc Mon Sep 17 00:00:00 2001 From: meegoo Date: Thu, 9 Nov 2023 23:25:14 -0800 Subject: [PATCH] [BugFix] Fix automatic partition write data into wrong partition when many partition created concurrency (#34731) Signed-off-by: meegoo (cherry picked from commit 2095a85b420594d905619643b6f03376e8d42d28) # Conflicts: # be/src/runtime/lake_tablets_channel.cpp --- be/src/runtime/lake_tablets_channel.cpp | 14 ++++++++++++++ be/src/runtime/local_tablets_channel.cpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/be/src/runtime/lake_tablets_channel.cpp b/be/src/runtime/lake_tablets_channel.cpp index 48776ce8048f5..aba5a93694f4a 100644 --- a/be/src/runtime/lake_tablets_channel.cpp +++ b/be/src/runtime/lake_tablets_channel.cpp @@ -399,11 +399,25 @@ Status LakeTabletsChannel::_create_delta_writers(const PTabletWriterOpenRequest& _delta_writers.emplace(tablet.tablet_id(), std::move(writer)); tablet_ids.emplace_back(tablet.tablet_id()); } +<<<<<<< HEAD DCHECK_EQ(_delta_writers.size(), params.tablets_size()); // In order to get sorted index for each tablet std::sort(tablet_ids.begin(), tablet_ids.end()); for (size_t i = 0; i < tablet_ids.size(); ++i) { _tablet_id_to_sorted_indexes.emplace(tablet_ids[i], i); +======= + if (!tablet_ids.empty()) { // has new tablets added, need rebuild the sorted index + tablet_ids.reserve(tablet_ids.size() + _tablet_id_to_sorted_indexes.size()); + for (auto& iter : _tablet_id_to_sorted_indexes) { + tablet_ids.emplace_back(iter.first); + } + // In order to get sorted index for each tablet + std::sort(tablet_ids.begin(), tablet_ids.end()); + DCHECK_EQ(_delta_writers.size(), tablet_ids.size()); + for (size_t i = 0; i < tablet_ids.size(); ++i) { + _tablet_id_to_sorted_indexes[tablet_ids[i]] = i; + } +>>>>>>> 2095a85b42 ([BugFix] Fix automatic partition write data into wrong partition when many partition created concurrency (#34731)) } return Status::OK(); } diff --git a/be/src/runtime/local_tablets_channel.cpp b/be/src/runtime/local_tablets_channel.cpp index f5735b0c8a6f0..735cc11f14a5d 100644 --- a/be/src/runtime/local_tablets_channel.cpp +++ b/be/src/runtime/local_tablets_channel.cpp @@ -732,7 +732,7 @@ Status LocalTabletsChannel::incremental_open(const PTabletWriterOpenRequest& par DCHECK_EQ(_delta_writers.size(), tablet_ids.size()); std::sort(tablet_ids.begin(), tablet_ids.end()); for (size_t i = 0; i < tablet_ids.size(); ++i) { - _tablet_id_to_sorted_indexes.emplace(tablet_ids[i], i); + _tablet_id_to_sorted_indexes[tablet_ids[i]] = i; } }