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

[c++] Improve exception-handling for query futures #2789

Merged
merged 2 commits into from
Jul 11, 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
2 changes: 1 addition & 1 deletion .github/workflows/libtiledb-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Build libTileDB-SOMA
run: TILEDBSOMA_COVERAGE="--coverage" ./scripts/bld --no-tiledb-deprecated=true
- name: Run libTileDB-SOMA unittests
run: ctest --test-dir build/libtiledbsoma -C Release --verbose --rerun-failed --output-on-failur
run: ctest --test-dir build/libtiledbsoma -C Release --verbose --rerun-failed --output-on-failure
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
21 changes: 17 additions & 4 deletions libtiledbsoma/src/soma/managed_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ ManagedQuery::ManagedQuery(
}

void ManagedQuery::close() {
if (query_future_.valid()) {
query_future_.get();
}
array_->close();
}

Expand Down Expand Up @@ -292,8 +289,13 @@ void ManagedQuery::submit_read() {
query_submitted_ = true;
query_future_ = std::async(std::launch::async, [&]() {
LOG_DEBUG("[ManagedQuery] submit thread start");
query_->submit();
try {
query_->submit();
} catch (const std::exception& e) {
return StatusAndException(false, e.what());
}
LOG_DEBUG("[ManagedQuery] submit thread done");
return StatusAndException(true, "success");
});
}

Expand All @@ -305,6 +307,17 @@ std::shared_ptr<ArrayBuffers> ManagedQuery::results() {
if (query_future_.valid()) {
LOG_DEBUG(fmt::format("[ManagedQuery] [{}] Waiting for query", name_));
query_future_.wait();
LOG_DEBUG(
fmt::format("[ManagedQuery] [{}] Done waiting for query", name_));

auto retval = query_future_.get();
if (!retval.succeeded()) {
throw TileDBSOMAError(fmt::format(
"[ManagedQuery] [{}] Query FAILED: {}",
name_,
retval.message()));
}

} else {
throw TileDBSOMAError(
fmt::format("[ManagedQuery] [{}] 'query_future_' invalid", name_));
Expand Down
22 changes: 21 additions & 1 deletion libtiledbsoma/src/soma/managed_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ namespace tiledbsoma {

using namespace tiledb;

// Probably we should just use a std::tuple here
class StatusAndException {
public:
StatusAndException(bool succeeded, std::string message)
: succeeded_(succeeded)
, message_(message) {
}

bool succeeded() {
return succeeded_;
}
std::string message() {
return message_;
}

private:
bool succeeded_;
std::string message_;
};

class ManagedQuery {
public:
//===================================================================
Expand Down Expand Up @@ -411,7 +431,7 @@ class ManagedQuery {
bool query_submitted_ = false;

// Future for asyncronous query
std::future<void> query_future_;
std::future<StatusAndException> query_future_;
};
}; // namespace tiledbsoma

Expand Down
Loading