| 143 | } |
| 144 | |
| 145 | Status SharedJdbcConnection::Close(const extdatasource::TCloseParams& params, |
| 146 | extdatasource::TCloseResult* result) { |
| 147 | // Only the last active instance closes the shared JDBC connection. |
| 148 | if (ref_count_.fetch_sub(1, std::memory_order_acq_rel) == 1) { |
| 149 | // Guard against the case where Open() was never called or failed: only invoke |
| 150 | // executor_.Close() if the Java data source was successfully opened. |
| 151 | std::unique_lock<std::mutex> lk(open_mu_); |
| 152 | bool should_close = open_done_ && open_status_.ok(); |
| 153 | lk.unlock(); |
| 154 | if (should_close) return executor_.Close(params, result); |
| 155 | } |
| 156 | return Status::OK(); |
| 157 | } |
| 158 | |
| 159 | // DataSourceScanPlanNode |
| 160 | Status DataSourceScanPlanNode::CreateExecNode(RuntimeState* state, |