Skip to content

Commit

Permalink
[YQL-17298] Fix data race on ICompare::TPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
nepal committed Jan 22, 2024
1 parent d856b1b commit 2794c99
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions ydb/library/yql/minikql/comp_nodes/mkql_wide_top_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,31 @@ struct TKeyInfo {
bool IsOptional;
NUdf::ICompare::TPtr Compare;
TType* PresortType = nullptr;
std::optional<TGenericPresortEncoder> LeftPacker;
std::optional<TGenericPresortEncoder> RightPacker;
};

struct TRuntimeKeyInfo {
TRuntimeKeyInfo(const TKeyInfo& keyInfo)
: Slot(keyInfo.Slot)
, IsOptional(keyInfo.IsOptional)
, Compare(keyInfo.Compare.Get())
{
if (keyInfo.PresortType) {
LeftPacker = keyInfo.PresortType;
RightPacker = keyInfo.PresortType;
}
}

const NUdf::EDataSlot Slot;
const bool IsOptional;
const NUdf::ICompare* const Compare;
mutable std::optional<TGenericPresortEncoder> LeftPacker;
mutable std::optional<TGenericPresortEncoder> RightPacker;
};

struct TMyValueCompare {
TMyValueCompare(const std::vector<TKeyInfo>& keys)
: Keys(keys)
: Keys(keys.cbegin(), keys.cend())
{
for (auto& key : Keys) {
if (key.PresortType) {
key.LeftPacker.emplace(key.PresortType);
key.RightPacker.emplace(key.PresortType);
}
}
}

int operator()(const bool* directions, const NUdf::TUnboxedValuePod* left, const NUdf::TUnboxedValuePod* right) const {
Expand Down Expand Up @@ -64,7 +75,7 @@ struct TMyValueCompare {
return 0;
}

mutable std::vector<TKeyInfo> Keys;
const std::vector<TRuntimeKeyInfo> Keys;
};

using TComparePtr = int(*)(const bool*, const NUdf::TUnboxedValuePod*, const NUdf::TUnboxedValuePod*);
Expand Down

0 comments on commit 2794c99

Please sign in to comment.