Fix delete records timestamp may be reordered (#27941)

Signed-off-by: yah01 <yah2er0ne@outlook.com>
pull/27983/head
yah01 2023-10-27 10:24:10 +08:00 committed by GitHub
parent 4a33391b8f
commit f212158d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 16 deletions

View File

@ -17,6 +17,7 @@
#include <thread>
#include <boost/iterator/counting_iterator.hpp>
#include <type_traits>
#include <variant>
#include "common/Consts.h"
#include "common/EasyAssert.h"
@ -236,19 +237,24 @@ SegmentGrowingImpl::Delete(int64_t reserved_begin,
ParsePksFromIDs(pks, field_meta.get_data_type(), *ids);
// filter out the deletions that the primary key not exists
auto end = std::remove_if(pks.begin(), pks.end(), [&](const PkType& pk) {
return !insert_record_.contain(pk);
});
size = end - pks.begin();
std::vector<std::tuple<Timestamp, PkType>> ordering(size);
for (int i = 0; i < size; i++) {
ordering[i] = std::make_tuple(timestamps_raw[i], pks[i]);
}
auto end =
std::remove_if(ordering.begin(),
ordering.end(),
[&](const std::tuple<Timestamp, PkType>& record) {
return !insert_record_.contain(std::get<1>(record));
});
size = end - ordering.begin();
ordering.resize(size);
if (size == 0) {
return SegcoreError::success();
}
// step 1: sort timestamp
std::vector<std::tuple<Timestamp, PkType>> ordering(size);
for (int i = 0; i < size; i++) {
ordering[i] = std::make_tuple(timestamps_raw[i], pks[i]);
}
std::sort(ordering.begin(), ordering.end());
std::vector<PkType> sort_pks(size);
std::vector<Timestamp> sort_timestamps(size);

View File

@ -1147,19 +1147,23 @@ SegmentSealedImpl::Delete(int64_t reserved_offset, // deprecated
ParsePksFromIDs(pks, field_meta.get_data_type(), *ids);
// filter out the deletions that the primary key not exists
auto end = std::remove_if(pks.begin(), pks.end(), [&](const PkType& pk) {
return !insert_record_.contain(pk);
});
size = end - pks.begin();
std::vector<std::tuple<Timestamp, PkType>> ordering(size);
for (int i = 0; i < size; i++) {
ordering[i] = std::make_tuple(timestamps_raw[i], pks[i]);
}
auto end =
std::remove_if(ordering.begin(),
ordering.end(),
[&](const std::tuple<Timestamp, PkType>& record) {
return !insert_record_.contain(std::get<1>(record));
});
size = end - ordering.begin();
ordering.resize(size);
if (size == 0) {
return SegcoreError::success();
}
// step 1: sort timestamp
std::vector<std::tuple<Timestamp, PkType>> ordering(size);
for (int i = 0; i < size; i++) {
ordering[i] = std::make_tuple(timestamps_raw[i], pks[i]);
}
std::sort(ordering.begin(), ordering.end());
std::vector<PkType> sort_pks(size);
std::vector<Timestamp> sort_timestamps(size);