Skip to content
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

Fix a subtle bug in CompressedExternalIdTableSorter #1328

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/engine/idTable/CompressedExternalIdTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,9 @@ class CompressedExternalIdTableSorter
// requested for the output, and the single block is larger than this
// blocksize, we manually have to split it into chunks.
auto& block = this->currentBlock_;
if (block.empty()) {
co_return;
}
const auto blocksizeOutput = blocksize.value_or(block.numRows());
if (block.numRows() <= blocksizeOutput) {
if (this->moveResultOnMerge_) {
Expand Down Expand Up @@ -735,7 +738,9 @@ class CompressedExternalIdTableSorter
}
}
numPopped += result.numRows();
co_yield std::move(result).template toStatic<N>();
if (!result.empty()) {
co_yield std::move(result).template toStatic<N>();
}
AD_CORRECTNESS_CHECK(numPopped == this->numElementsPushed_);
}

Expand Down
5 changes: 5 additions & 0 deletions src/index/IndexImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ std::unique_ptr<ExternalSorter<SortByPSO, 5>> IndexImpl::buildOspWithPatterns(
// S P O PatternOfS PatternOfO, sorted by OPS.
auto blockGenerator =
[](auto& queue) -> cppcoro::generator<IdTableStatic<0>> {
// If an exception occurs in the block that is consuming the blocks yielded
// from this generator, we have to explicitly finish the `queue`, otherwise
// there will be a deadlock because the threads involved in the queue can
// never join.
absl::Cleanup cl{[&queue]() { queue.finish(); }};
while (auto block = queue.pop()) {
co_yield fixBlockAfterPatternJoin(std::move(block));
}
Expand Down
7 changes: 6 additions & 1 deletion test/engine/idTable/CompressedExternalIdTableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ void testExternalSorterImpl(size_t numDynamicColumns, size_t numRows,
}

for (size_t k = 0; k < 5; ++k) {
auto generator = writer.sortedView();
// Also test the case that the blocksize does not exactly divides the
// number of inputs.
auto blocksize = k == 1 ? 1 : 17;
using namespace ::testing;
auto generator = k == 0 ? std::views::join(ad_utility::OwningView{
writer.getSortedBlocks(blocksize)})
: writer.sortedView();
if (mergeMultipleTimes || k == 0) {
auto result = idTableFromRowGenerator<NumStaticColumns>(
generator, numDynamicColumns);
Expand Down
Loading