Skip to content

Commit

Permalink
[c++] Improve exception-handling for query futures (#2789)
Browse files Browse the repository at this point in the history
* [c++] Improve exception-handling for query futures

* why did this break now
  • Loading branch information
johnkerl authored Jul 11, 2024
1 parent b6b1cd4 commit 0634b54
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
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

0 comments on commit 0634b54

Please sign in to comment.