Skip to content

[YQL-17298] Fix data race on ICompare::TPtr #1213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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