Skip to content

Cache, cancel and simplify the Grafana table-model metadata lookups - #143

Open
PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:feat/grafana-metadata-followup
Open

PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:feat/grafana-metadata-followup

Conversation

@PDGGK

@PDGGK PDGGK commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #134 (comment): the metadata lookups behind the table-model pickers share the 8-session pool with panel queries, could not be cancelled, ran again on every editor mount, and issued an extra USE.

Statements. The table and column lookups now run SHOW TABLES FROM "<db>" and DESC "<db>"."<table>", each part quoted on its own, so a lookup issues no USE. Panel and variable queries still USE their database. Checked on IoTDB 2.0.11:

SHOW TABLES FROM "grafana-Demo"            -> weather-station
DESC "grafana-Demo"."Weather-Station"     -> time TIMESTAMP TIME / region STRING TAG / temperature FLOAT FIELD
SHOW TABLES FROM grafana-Demo              -> 700: mismatched input '-'

Cancellation. TablePicker gives each lookup an AbortController and aborts it when the picker unmounts or its database or table changes; the signal goes through getResource(..., { abortSignal }) and reaches the handler as r.Context(). On the backend, executeTableStatement checks the context before taking a pooled session and again after. One limit: TableSessionPool.GetSession() in iotdb-client-go takes no context and waits up to 60 s, so a cancelled lookup still waits for a session, but it then hands the session straight back without running anything. Making the wait itself cancellable needs a context-aware GetSession in the Go client. With all 8 sessions held, a lookup cancelled at 0.3 s returned context canceled once a session was freed at 1.5 s, and all 8 sessions could be taken again afterwards.

Cache. Successful lookups are reused for 30 s, keyed on the endpoint and the names; failures are not cached. Opening the DATABASE list still asks the server again, as before. The README notes the 30 s.

Panel and variable queries go through the same executor, so they now also return the context error instead of running when their request has already been cancelled.

Tests: Go 74 -> 79 top-level tests (122 -> 135 with subtests), Jest 38 -> 46, all passing; tsc --noEmit clean, no new ESLint findings. Removing the post-wait context check, the abort in the effect cleanup, the cache read, or the signal forwarding each makes the corresponding new test fail.

Follow-up to the review of apache#134. The table-model editor's database, table
and column pickers share the plugin's eight-session pool with panel
queries. Each lookup ran again on every editor mount, could not be
cancelled, and issued an extra USE.

- The lookups now run SHOW TABLES FROM <db> and DESC <db>.<table>, with
  each part of the name quoted on its own, so they issue no USE and leave
  no session state behind. Panel and variable queries still USE their
  database.
- The table-model executor checks the request context before it waits
  for a pooled session and again once it has one. The native client's
  GetSession takes no context and cannot be interrupted, so a request
  cancelled during the wait still waits, but it then hands the session
  straight back instead of running its statement.
- The datasource keeps successful lookups for 30 seconds, keyed on the
  database and table. Opening the database list still asks the server
  again, and failed lookups are not kept.
- The pickers pass an AbortSignal with each lookup and abort it when the
  picker unmounts or its database or table changes, which cancels the
  request.

Signed-off-by: Zihan Dai <1436286758@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant