Repository navigation
Fixes 33353: Batch table custom-metric and column-extension reads - #33355
Conversation
Table detail reads fetched custom metrics once per column and column extensions once per column, so a 100-column table with customMetrics cost 101 entity_extension queries per request. TableMetadataLoader now loads table and column metrics for a whole batch of tables with one prefix query, and column extensions with one keyed query, keeping the per-request count independent of column width. The paginated column endpoints share the same loader. Part of #32946 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
#33539 landed SqlQueryCounter on main, and this PR carried its own, so the two collided add/add. This PR's copy is dropped in favour of main's. That is a pure dedup rather than a compromise: TableMetadataReadIT only calls the two-argument forRequests and the public constructor, both of which main's copy has with the same semantics - calling-thread scope for the constructor, "a request is in flight" for forRequests. Nothing here used the three-argument forRequests, deadlockOnce or afterFirst that the dropped copy also carried, so this does not depend on #33642. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Review feedback, and it caught a false claim of mine. This PR's description
said "the paginated path already read by key". It did not: getTableColumns
still read column extensions with getExtensionsByJsonSchema, filtering on
jsonschema = 'columnExtension', while the entity read (setFields) and the
single-column read resolve by the exact persisted key through
TableMetadataLoader. A column-extension row written under an older schema name
was therefore returned by two reads and silently dropped by
GET /v1/tables/{id}/columns?fields=extension.
The branch now calls metadataLoader.loadColumnExtensions, so all three reads
agree. It is cheaper as well: the old read fetched every column-extension row
on the table and filtered in memory, where the loader fetches only the page's
keys. Per-record deserialisation failures are still caught individually, so one
bad row does not blank the rest of the page.
Nothing tested this path, which is how the inconsistency and the claim both
survived - the legacy-key test went through the entity read only, and the
paginated test checked customMetrics only.
paginatedColumnExtensionsPreserveLegacyKeys covers it. Run locally against
MySQL/Elasticsearch: 9/9 with this change; against the previous code the new
test is the only failure, with "expected: <{note=legacy}> but was: <null>".
Out of scope and unchanged: searchTableColumnsInternal has no extension branch
at all. That is true on main as well, so it is a pre-existing gap in the search
endpoint rather than something this PR introduced.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Code Review ✅ Approved 1 closed / 1 findings🟡 Medium risk · Batches table metadata extension reads and changes repository hydration behavior. Batches table custom-metric and column-extension reads through a new ✅ 1 closed✅ Bug: Paginated /columns extension read not routed through loader
OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
✅ Playwright Results — workflow succeededValidated commit ✅ 4553 passed · ❌ 0 failed · 🟡 5 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 55m 23s ⏱️ Max setup 4m 59s · max shard execution 23m 24s · max shard-job elapsed before upload 27m 9s · reporting 19s 🌐 224.33 requests/attempt · 2.23 app boots/UI scenario · 43.66% common-shard skew Optimization targets still in progress:
🟡 5 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
…text> (open-metadata#33642) * Scope the JDBI test decorators on Predicate<StatementContext> Three PRs in the open-metadata#32946 stack each carry their own copy of these decorators and now collide with the versions open-metadata#33539 landed on main: CONFLICT (add/add) SqlQueryCounter.java open-metadata#33344, open-metadata#33355 CONFLICT (add/add) SqlFailureProbe.java open-metadata#33362 Their copies are not gratuitous - they scope on Predicate<StatementContext> rather than the BooleanSupplier that merged, and open-metadata#33344 and open-metadata#33355 already call the three-argument forRequests and deadlockOnce. This makes main's copy the one they call, so the dedup on rebase is a deletion rather than a rewrite. Predicate<StatementContext> is also the better answer to the review on open-metadata#33539 that forRequests was too broad. A fragment alone cannot tell the request under test apart from a concurrent one running the same SQL; the caller needs a look at each candidate statement. SqlFailureProbe.forRequests therefore returns, but requiring the caller's predicate rather than matching any in-flight request. SqlFailureProbe.deadlockOnce covers open-metadata#33344's SqlQueryCounter.deadlockOnce so EntityRepositoryGoldenIT becomes a one-line swap. Injection stays in the probe rather than moving into the counter: a counter that also throws is two jobs in one class, and the probe's one-shot claim is already a compareAndSet. 16 unit tests, both guards verified to fail without the code that satisfies them - dropping the predicate gate gives "a matching statement the predicate rejects must not be counted", and replacing the CAS with a check-then-act gives "both threads were past the guard at once ... expected: <1> but was: <2>". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Cover the request-scoped overloads, which nothing exercised Review feedback, and correct: forRequests was called by nothing but itself. The unit tests injected predicates through the package-private constructor and SqlTestDecoratorsIT only used the calling-thread ones, so the composed scope - "a request is in flight AND the caller's predicate accepts" - was the one line in these classes with no coverage. It is also the line where a regression is silent: get it wrong and every REST-driven statement is rejected, or every one is accepted, and a test supplying its own predicate would never notice. RequestLatencyContext.startRequest and clearContext are public statics, so the composition is testable without a server. Four tests, two per class: a matching statement outside any request is not counted or claimed, the same statement inside one is, and a caller predicate that rejects still wins while a request is in flight. Each half is independently guarded. Dropping the request check fails with "no request in flight, so there is nothing to attribute the statement to"; dropping the caller predicate fails with "a request is in flight but the caller's predicate rejects this statement". Verified both ways. 20 unit tests total. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Replace deadlockOnce with a scope-free deadlock() supplier Review follow-up from @manerow, and the trap is real. deadlockOnce built its probe through the calling-thread constructor, while the open-metadata#33344 factory it was meant to replace is request-scoped. Its only call site, EntityRepositoryGoldenIT, drives a PATCH over REST, so the statement runs on a Jetty worker: a calling-thread probe never fires, and the replay test goes green without ever exercising the replay. Silent false pass, in the one place whose job is to prove a deadlock is retried. A convenience that has to guess a scope will keep guessing wrong, so there is no longer one. deadlock() returns the failure shape DeadlockRetry replays and composes with either scope, which makes the mistake impossible to make by accident: new SqlFailureProbe(jdbi, fragment, deadlock()) // this thread SqlFailureProbe.forRequests(jdbi, fragment, deadlock(), mine::match) // a request Two claims in this PR were also wrong and are corrected in the description. The open-metadata#33344 call site counts as well as injects - assertEquals(2, writes.count()) - and no factory here does both, so the swap is not one line; it nests a counter around a probe. And SqlQueryCounter.afterFirst is still not provided, so open-metadata#33344 cannot delete its copy outright either. A new test pins the nesting: the probe sits outermost while both are open, closing it hands the logger back to the counter rather than the application, and the chain unwinds to the original. 21 unit tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Move the composition test to the IT, where it can assert behaviour Review feedback, and correct: assertSame on the SqlLogger chain is wiring, not behaviour, and passes even if delegation stops invoking the inner decorator - the one failure it needed to catch. I had justified it by saying a real StatementContext could not be built here. That was wrong twice over. StatementContext is not final; it has a private constructor that reflection can reach. But the signature is not stable: this module resolves jdbi3-core 3.37.1, whose constructor takes (ConfigRegistry, ExtensionMethod), while 3.47.0 takes a third Type argument. A unit test built on that would break on a minor dependency bump. So the test moves to SqlTestDecoratorsIT, where real statements produce real contexts and no reflection is needed. It now asserts what one statement does to both decorators: the outer probe fires, the inner counter still sees the same statement, and once the probe is spent the counter keeps counting through it. The unit-level wiring assertion is deleted rather than kept alongside. 20 unit tests; the composition case runs in the IT lane. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Describe your changes:
Fixes #33353
Part of #32946, shipped on its own as the reviewer suggested: this is the "505 → 5 statements on table metrics" win from #33248, ported onto the unchanged
EntityRepositoryso it can merge and cherry-pick today.Table detail reads fetched custom metrics once per column and column extensions once per column, so
GET /v1/tables/{id}?fields=columns,customMetricson a 100-column table ran 101entity_extensionqueries.TableMetadataLoadernow loads table and column metrics for a whole batch of tables with one prefix query, and column extensions with one keyed query (getExtensionsByKeys, chunked like the otherINlists), so the per-request count no longer depends on column width. The paginated column endpoints and the single-column read share the same loader, andTableRepositoryloses its four per-column readers.Type of change:
High-level design:
TableMetadataLoader(new,jdbi3): three read operations, one query each:loadMetrics(tables, includeColumns),loadColumnMetrics(tableId, columns),loadColumnExtensions(tableId, columns). It takes aSupplier<EntityExtensionDAO>so the reads join whatever transaction the caller already holds.EntityExtensionDAO.getExtensionsByKeys:WHERE id = :id AND extension IN (<keys>), chunked throughEntityDAO.queryInChunks. Column extensions are looked up by their exact persisted key, so legacy rows stored under anotherjsonSchemaare still returned — by the entity read, the single-column read and the paginated/columnsread alike.Correction: an earlier revision of this description said "the paginated path already read by key". It did not —
getTableColumnsstill filtered onjsonschema = 'columnExtension', so a legacy row was returned by two reads and dropped byGET /v1/tables/{id}/columns?fields=extension. Caught in review; that branch now goes through the same loader, andTableMetadataReadIT.paginatedColumnExtensionsPreserveLegacyKeyscovers it (fails on the previous code withexpected: <{note=legacy}> but was: <null>).TableRepository:setFields,fetchAndSetCustomMetrics, the two paginated column reads and the single-column read call the loader;getCustomMetrics,batchFetchCustomMetrics,batchFetchCustomMetricsByColumnandgetColumnExtensionare deleted. The public constants keep their values (they now alias the loader's).No public/protected repository API changes; Collate compiles unchanged. Response JSON is unchanged: metric order per column is still the extension-name order, and absent metrics still serialize as
[].SqlQueryCounter(test util) is byte-identical to the one in Fixes 32946: Pin entity repository lifecycle and cache contracts (1/7) #33344 so the two PRs merge in either order.Tests:
Use cases covered
GET /v1/tables/{id}?fields=columns,customMetricsat 3, 100 and 1,000 columns: one extension query, table metric and column metric both present, unrelatedcustomMetrics.table.tableish.*rows ignored.fields=columns,extension: one table-extension query plus one keyed query; a legacy column-extension row stored under anotherjsonSchemais returned.fields=columnsalone runs zero extension queries and leavescustomMetricsnull.setFieldsInBulkacross two tables with the same column names: one query, metrics not mixed across tables.GET /v1/tables/{id}/columns?fields=customMetrics&limit=3: one extension query, counted only inside the HTTP request.Unit tests
TableMetadataLoaderTest(8 tests, no database): absent inputs need no DAO, selected-column filtering, table-only reads do not decode column metrics, overlapping column names across tables stay distinct, malformed or unresolvable keys do not stop later columns, DAO failure clears stale values.Backend integration tests
TableMetadataReadIT(8 tests, real SQL statement counter,@Isolated).main'sTableRepository(PostgreSQL): 5 of 8 fail on the query budget alone: 3 columns → 4 queries, 100 → 101, 1,000 → 1,001;fields=columns,extension→ 101; two-table bulk read → 202. The three that pass before (fields=columnsruns zero queries, the paginated page already ran one, the transaction check) are regression guards.TableResourceIT(294 cases, includingcreateUpdateDelete_tableCustomMetrics_200andtest_getTableColumnsWithCustomMetrics_200) andColumnCustomPropertiesIT(65 cases): 364 run, 0 failures, 0 errors, 9 pre-existing skips.Ingestion integration tests
Not applicable (no ingestion changes).
Playwright (UI) tests
Not applicable (no UI changes).
Manual testing performed
None beyond the automated runs above; all evidence is from the integration tests listed.
UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.The PR appears safe to merge; no actionable correctness, security, or repository-rule violations remain.
Summary
This PR replaces per-column custom-metric and extension reads with transaction-aware batched loading.
EntityExtensionDAO.TableMetadataLoaderto hydrate table metrics, column metrics, and column extensions in bounded query batches.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Table read request] --> B[TableRepository] B --> C{Requested fields} C -->|customMetrics| D[TableMetadataLoader.loadMetrics] C -->|column customMetrics| E[TableMetadataLoader.loadColumnMetrics] C -->|column extension| F[TableMetadataLoader.loadColumnExtensions] D --> G[Prefix-based batch query] E --> H[Column metric prefix query] F --> I[Chunked exact-key query] G --> J[(entity_extension)] H --> J I --> J D --> K[Hydrated tables and columns] E --> K F --> KReviews (2) · Last reviewed commit: "Route the paginated /columns extension r..."