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

Pass exception to promise when failing to decode chunk. #32445

Merged
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
37 changes: 31 additions & 6 deletions searchlib/src/vespa/searchlib/docstore/filechunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ appendChunks(FixedParams * args, Chunk::UP chunk)
}
}

/*
* Wrapper for future unique pointer to chunk that drains the
* pending task if the future is still valid at destruction time.
*/
class FutureChunk {
std::future<std::unique_ptr<Chunk>> _future;
public:
FutureChunk(std::future<std::unique_ptr<Chunk>> future)
: _future(std::move(future))
{
}
FutureChunk(const FutureChunk&) = delete;
FutureChunk(FutureChunk&&) = default;
~FutureChunk() {
if (_future.valid()) {
_future.wait();
}
}
std::unique_ptr<Chunk> get() { return _future.get(); }
};

}

void
Expand All @@ -308,15 +329,19 @@ FileChunk::appendTo(vespalib::Executor & executor, const IGetLid & db, IWriteDat
assert(numChunks <= getNumChunks());
FixedParams fixedParams = {db, dest, lidReadGuard, getFileId().getId(), visitorProgress};
size_t limit = std::thread::hardware_concurrency();
vespalib::ArrayQueue<std::future<Chunk::UP>> queue;
vespalib::ArrayQueue<FutureChunk> queue;
for (size_t chunkId(0); chunkId < numChunks; chunkId++) {
std::promise<Chunk::UP> promisedChunk;
std::future<Chunk::UP> futureChunk = promisedChunk.get_future();
FutureChunk futureChunk(promisedChunk.get_future());
auto task = vespalib::makeLambdaTask([promise = std::move(promisedChunk), chunkId, this]() mutable {
const ChunkInfo & cInfo(_chunkInfo[chunkId]);
vespalib::DataBuffer whole(0ul, ALIGNMENT);
FileRandRead::FSP keepAlive(_file->read(cInfo.getOffset(), whole, cInfo.getSize()));
promise.set_value(std::make_unique<Chunk>(chunkId, whole.getData(), whole.getDataLen()));
try {
const ChunkInfo & cInfo(_chunkInfo[chunkId]);
vespalib::DataBuffer whole(0ul, ALIGNMENT);
FileRandRead::FSP keepAlive(_file->read(cInfo.getOffset(), whole, cInfo.getSize()));
promise.set_value(std::make_unique<Chunk>(chunkId, whole.getData(), whole.getDataLen()));
} catch (...) {
promise.set_exception(std::current_exception());
}
});
executor.execute(CpuUsage::wrap(std::move(task), cpu_category));

Expand Down