Repository navigation
SEA metadata queries emit a redundant CloseStatement DELETE on a statement already returned state=CLOSED (#168) - #183
Conversation
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — the fix correctly mirrors the established regular-query path (statement/mutable.rs:366): close_id returns an empty id when status.state == Closed, and from_reader_with_close already skips the close guard for an empty id (result_stream.rs:571). Applied uniformly across all 8 metadata sites; two wiremock tests assert the skip and the non-CLOSED regression. One low note on test coverage being limited to list_catalogs.
Addresses: - #3626177132 at tests/v0_metadata_wiremock.rs:780 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
…ement already returned state=CLOSED (#168) Signed-off-by: peco-engineer-bot[bot] <3815206+peco-engineer-bot[bot]@users.noreply.github.com>
Addresses: - #3626177132 at tests/v0_metadata_wiremock.rs:780 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
22ed926 to
76ffa87
Compare
There was a problem hiding this comment.
Verdict: 1 Low
Clean, correctly-scoped fix. close_id() mirrors the regular-query path in statement/mutable.rs, and both from_reader_with_close and StatementCloseGuard::drop already no-op on an empty id, so the CLOSED-skip is sound at all 8 sites. One low: the wildcard fan-out path (fetch_tables_for_catalog) uses a bespoke close guard that the added tests don't exercise.
Addresses: - #3688886958 at src/metadata_v0.rs:688 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: 1 Nit
Looks good — clean, minimal fix. close_id() correctly maps a status.state == CLOSED ExecuteResult to an empty statement id, mirroring the established regular-query path (statement/mutable.rs:366); from_reader_with_close already skips the close guard on an empty id, and the fan-out path's explicit close_statement is now gated behind !stmt_id.is_empty(). The helper is applied consistently at all 8 metadata sites and the two new wiremock tests (plus the match-branch and wildcard-fanout regression guards) exercise both the skip and the still-close paths at the right tier. One nit on test-helper duplication.
Other findings
- ⚪ Nit — The wildcard-fanout test re-implements the poll loop from
wait_for_close_deleteinline (because that helper hardcodes thestmt-testpath and this test asserts onstmt-tables-comp-a). Consider generalizingwait_for_close_deleteto take the statement path so all four tests share one polling implementation. Minor test-only duplication — no behavioral impact.
Summary
Automated fix for #168 — SEA metadata queries emit a redundant CloseStatement DELETE on a statement already returned state=CLOSED.
Fixed the SEA metadata path in src/metadata_v0.rs to honor status.state==CLOSED from the ExecuteStatement response and skip the redundant CloseStatement DELETE, mirroring the regular-query path. Added a close_id() helper applied at all 8 metadata sites; the two pre-written wiremock tests are now green and the full 703-test suite plus clippy/fmt pass. This bug is client-side RPC-omission behavior anchored in the SEA API contract, so the wiremock tests asserting on wire traffic (expect(0)/expect(1) on the DELETE endpoint) are the correct anchor (offline carve-out).
Root cause & plan
Root cause: The SEA metadata path in src/metadata_v0.rs ignores the terminal StatementStatus returned by the transport. Every Metadata::list_* method does
let stmt_id = raw.statement_id.clone();and unconditionally callsResultStream::from_reader_with_close(reader, session, stmt_id), which installs a StatementCloseGuard that fires a fire-and-forgetDELETE /api/2.0/sql/statements/<id>(CloseStatement) on drop. When the ExecuteStatement response already reportedstatus.state == CLOSED(the common inline/direct-result case where the kernel omits wait_timeout — the server auto-closes and returns state=CLOSED), the statement is already closed server-side, so this DELETE is redundant (server responds 404 STATEMENT_NOT_FOUND, swallowed by best-effort close_statement). The regular-query path (src/statement/mutable.rs:~365) does NOT have this bug: it computesalready_closed = result.status.state == StatementState::Closedand pre-sets the sharedclosedflag so neither the handle nor its Drop fires the redundant CloseStatement. The metadata path simply never consults raw.status. Fix: mirror the regular path — at each metadata site, resolve the close-id to empty whenraw.status.state == StatementState::Closed(from_reader_with_close already skips the guard for an empty statement_id).Files:
src/metadata_v0.rs,tests/v0_metadata_wiremock.rsPlanned coverage:
Files changed
tests/v0_metadata_wiremock.rssrc/metadata_v0.rsTest plan
metadata_closed_response_skips_close_statement— fails (red) against the original code, passes (green) after the fixmetadata_succeeded_response_still_closes_statement— fails (red) against the original code, passes (green) after the fix🤖 Generated by engineer-bot (bug-fix flow) — review before merge.