Skip to content

Commit

Permalink
close the array through the ManagedQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
gspowley committed Oct 2, 2023
1 parent 8585eea commit 764a157
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
15 changes: 12 additions & 3 deletions libtiledbsoma/src/soma/managed_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ ManagedQuery::ManagedQuery(
reset();
}

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

void ManagedQuery::reset() {
query_ = std::make_unique<Query>(schema_->context(), *array_);
subarray_ = std::make_unique<Subarray>(schema_->context(), *array_);
Expand Down Expand Up @@ -160,9 +167,11 @@ void ManagedQuery::submit_read() {
if (!is_empty_query()) {
// Submit query in a separate thread, so we can return immediately
query_future_ = std::async(std::launch::async, [&]() {
LOG_DEBUG("[ManagedQuery] submit thread start");
LOG_DEBUG(
fmt::format("[ManagedQuery] [{}] submit thread start", name_));
query_->submit();
LOG_DEBUG("[ManagedQuery] submit thread done");
LOG_DEBUG(
fmt::format("[ManagedQuery] [{}] submit thread done", name_));
});
}
query_submitted_ = true;
Expand All @@ -180,7 +189,7 @@ std::shared_ptr<ArrayBuffers> ManagedQuery::results() {

if (!query_submitted_) {
throw TileDBSOMAError(fmt::format(
"[ManagedQuery][{}] submit query before reading results", name_));
"[ManagedQuery] [{}] submit query before reading results", name_));
}
query_submitted_ = false;

Expand Down
7 changes: 7 additions & 0 deletions libtiledbsoma/src/soma/managed_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class ManagedQuery {
ManagedQuery(ManagedQuery&&) = default;
~ManagedQuery() = default;

/**
* @brief Close the array after waiting for any asynchronous queries to
* complete.
*
*/
void close();

/**
* @brief Reset the state of this ManagedQuery object to prepare for a new
* query, while holding the array open.
Expand Down
4 changes: 3 additions & 1 deletion libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ void SOMAArray::open(
}

void SOMAArray::close() {
arr_->close();
// Close the array through the managed query to ensure any pending queries
// are completed.
mq_->close();
}

void SOMAArray::reset(
Expand Down

0 comments on commit 764a157

Please sign in to comment.