Skip to content

Commit

Permalink
Introduce CancelQuery override in DuckDBFlightSqlServer to release gl…
Browse files Browse the repository at this point in the history
…obal mutex upon query cancellation.
  • Loading branch information
prmoore77 committed Jul 17, 2023
1 parent a653e7a commit bf3cc0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/duckdb/duckdb_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,19 @@ namespace arrow {

Status ClosePreparedStatement(const ServerCallContext &context,
const ActionClosePreparedStatementRequest &request) {
// Unlock our mutex so that other threads can run queries...
global_mutex.unlock();

const std::string &prepared_statement_handle = request.prepared_statement_handle;

auto search = prepared_statements_.find(prepared_statement_handle);

if (search != prepared_statements_.end()) {
prepared_statements_.erase(prepared_statement_handle);
} else {
return Status::Invalid("Prepared statement not found");
}

// Unlock our mutex so that other threads can run queries...
global_mutex.unlock();

return Status::OK();
}

Expand Down Expand Up @@ -354,6 +355,14 @@ namespace arrow {
return std::unique_ptr<FlightInfo>(new FlightInfo(result));
}

arrow::Result<CancelResult> CancelQuery(
const ServerCallContext &context, const ActionCancelQueryRequest &request) {
// Release the global mutex
global_mutex.unlock();

return Status::OK();
}

};

DuckDBFlightSqlServer::DuckDBFlightSqlServer(std::shared_ptr<Impl> impl)
Expand Down Expand Up @@ -443,6 +452,10 @@ namespace arrow {
return impl_->DoPutPreparedStatementUpdate(context, command, reader);
}

arrow::Result<CancelResult> DuckDBFlightSqlServer::CancelQuery(
const ServerCallContext &context, const ActionCancelQueryRequest &request) {
return impl_->CancelQuery(context, request);
}

} // namespace sqlite
} // namespace sql
Expand Down
3 changes: 3 additions & 0 deletions src/duckdb/duckdb_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class DuckDBFlightSqlServer : public FlightSqlServerBase {
arrow::Result<std::unique_ptr<FlightDataStream>> DoGetTables(
const ServerCallContext& context, const GetTables& command) override;

arrow::Result<CancelResult> CancelQuery(
const ServerCallContext& context, const ActionCancelQueryRequest& request) override;

private:
class Impl;
std::shared_ptr<Impl> impl_;
Expand Down

0 comments on commit bf3cc0c

Please sign in to comment.