Repository navigation
Fixes #34689: version changes made from tag, glossary term, domain and data product Assets tabs - #34690
Fixes #34689: version changes made from tag, glossary term, domain and data product Assets tabs#34690manerow wants to merge 4 commits into
Conversation
| EntityUtil.populateEntityReferences(request.assets()); | ||
| List<BulkResponse> passed = new ArrayList<>(); | ||
| List<BulkResponse> failed = new ArrayList<>(); | ||
| for (EntityReference ref : request.assets()) { |
There was a problem hiding this comment.
When several columns of the same table are selected, the table gets saved once per column. A column isn't saved on its own: tagging it loads and saves its whole table, and this loop handles each selected column separately. So picking 50 columns of one table means 50 table saves, 50 versions, 50 "table updated" events in the feed and alerts, and all of the table's column docs reindexed 50 times.
The selected items should be grouped by the entity that actually gets saved (column → its table), with all edits applied together and saved once. AssetLabelEdits already edits in memory, so this should only touch editAssets.
A test with two columns of the same table would cover it: the version goes up once and there's one change event.
There was a problem hiding this comment.
Good catch, fixed in 8a94c38. Selected items are now grouped by the entity that gets saved: a column resolves to its table, all of that table's edits are applied to one copy, and the table is saved once, so 50 columns give one version and one change event.
If that save fails (say one column breaks a rule), the table's items are retried one by one, so one bad column doesn't block the rest. columnsOfOneTable_areSavedOnceWithOneEvent and aConflictingColumn_doesNotBlockTheOtherColumnsOfItsTable cover both cases.
| private static <T extends EntityInterface> void patchAndRecord( | ||
| EntityRepository<T> repository, UUID id, JsonPatch patch, ChangeActor actor) { | ||
| PatchResponse<T> response = | ||
| repository.patch(null, id, actor.userName(), patch, null, actor.impersonatedBy()); |
There was a problem hiding this comment.
This PR applies the tag/term through a separate PATCH call for each selected asset, so N selected assets = N PATCH calls. Today each asset already gets a light load, a tag_usage insert and a search update; with this change each one also does a full entity load, a diff and rule checks, an entity row write, a version row and a change event. So large selections will get noticeably slower, especially on the glossary endpoints, which run synchronously within the request.
Could we group that work, so the DB writes, search updates and events go out in batches, while still reusing the same PATCH steps so search and everything else stay in sync? Curious what you think, or if there's a simpler way to cut the per-asset cost.
There was a problem hiding this comment.
Agreed, done in 8a94c38 with a BulkPatch. It keeps the per-entity PATCH steps (the PATCH field load, prepareInternal, rule checks, owner and domain validation and the EntityUpdater), each entity in its own transaction, and batches the writes the way the bulk API does: entity rows and version history in one transaction, search in one bulk request through a new batch scope in the lifecycle dispatcher, and change events in one insert. Search is refreshed before the call returns, as single writes are, so the Assets tab and later update-by-query calls see the change straight away.
Median of three runs locally:
| Call | main |
this PR |
|---|---|---|
| Glossary term on 100 tables, add / remove | 4.2 s / 3.7 s | 0.8 s / 0.8 s |
| Glossary term on 50 columns of one table, add / remove | 1.6 s / 1.6 s | 0.3 s / 0.3 s |
| Domain on 100 tables, add / remove | 5.1 s / 4.5 s | 1.0 s / 1.0 s |
So it is now faster than main while also writing a version and an event per asset. The domain and data product Assets tabs go through the same path too, as you asked in Slack. One trade-off: like the bulk API, these edits are not merged into the user's previous version from the last 10 minutes.
✅ Playwright Results — workflow succeededValidated commit ✅ 3499 passed · ❌ 0 failed · 🟡 1 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) 1h 7m 29s ⏱️ Max setup 5m 1s · max shard execution 19m 59s · max shard-job elapsed before upload 24m 11s · reporting 11s 🌐 213.63 requests/attempt · 2.00 app boots/UI scenario · 31.78% common-shard skew Optimization targets still in progress:
🟡 1 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 |
Code Review ✅ Approved 1 closed / 1 findings🔴 High risk · Bulk edits alter persisted asset labels, domain membership, and data-product assignments. Fixes versioning and change events for Assets tab edits on tags, glossary terms, domains, and data products by routing each asset through the standard PATCH flow with rule checks, entity updates, version history, search, and change events. Resolves domain asset change event dropped on PARTIAL_SUCCESS. No issues found. ✅ 1 closed✅ Bug: Domain asset change event dropped on PARTIAL_SUCCESS
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 |
|
| // After commit, as in a single PATCH: each type's own post-update hooks still run, while the | ||
| // search updates they raise go out as one bulk request. Inherited fields are filled in first, so | ||
| // an asset that loses its own domain is indexed with the one it now inherits. | ||
| private void react(List<EntityRepository<T>.EntityUpdater> stored) { |
There was a problem hiding this comment.
With BulkPatch, the column docs in column_search_index stop being updated. Search now goes through onEntitiesUpdated → updateEntitiesIndex, and that path never calls syncTableColumns; only the single-entity path does (SearchRepository.java:1998).
So after a column is tagged from the Assets tab, the column won't show up on the tag's Assets tab, and a removed tag keeps showing. A table moved into a domain keeps the old domain on its column docs too. The first version of this PR handled it, since each PATCH went through the single path. Could the bulk path sync column docs for tables as well? A test checking a column's search doc after an Assets-tab add would catch this.
| // starts again from fresh copies, because the updater mutates what it is given. | ||
| private Optional<EntityRepository<T>.EntityUpdater> update(T original, Edit<T> edit) { | ||
| List<EntityRepository<T>.EntityUpdater> result = new ArrayList<>(1); | ||
| repository.flushInOneTransaction( |
There was a problem hiding this comment.
The tag and relationship rows are committed before the entity row and version are saved. update() runs the updater in its own transaction, which already writes the tag_usage and domain/data-product rows; the row and version history come later in storeBatch.
If that later step fails for an asset, the asset already shows the new tag or domain, but has no new version, no change event and no search update. On retry the label is already there, so the diff is empty and it's reported as a success. Running the per-entity writes and the store for a chunk in one transaction (like bulkRestoreSubtree) would avoid that, with a one-by-one fallback if it fails.
There was a problem hiding this comment.
This would also help performance: right now each asset gets its own transaction and commit, so 1,000 assets is 1,000 commits before the batched save. Running the checks first (no writes), then each chunk's updaters and the store in one transaction, gives ~10 commits per 1,000 assets and keeps the tags and version together. If the chunk fails, the existing one-by-one fallback still applies.
| bySavedEntity.forEach( | ||
| (id, selections) -> | ||
| edits.add(new BulkPatch.Edit<>(id, asset -> applyAll(asset, selections)))); | ||
| return new BulkPatch<>(repository, request.actor(), request.dryRun()).apply(edits); |
There was a problem hiding this comment.
Could we chunk the edits passed to BulkPatch.apply, say 100 entities at a time?
Right now every selected entity of a type goes into one BulkPatch. It loads them all at once, keeps several copies of each in memory until the end, and saves all rows and versions in one transaction. Roughly, 1,000 wide tables would hold about 3 GB in memory and keep 1,000 rows locked for the whole save.
The save is a plain UPDATE … WHERE id (EntityDAO.java:185) from the snapshot taken at the start. So an ingestion or user edit made during the call gets overwritten, and the window grows with the selection: about 1 s per 100 tables at the speed you measured. Chunking would keep each batch small and that window short.



Fixes #34689
Refs open-metadata/openmetadata-collate#1526
Problem
Adding or removing assets from the Assets tab of a tag, glossary term, domain or data product changed the assets but recorded nothing on them: no new version, no
updatedBy/updatedAtchange and no change event, so the activity feed, alerts, webhooks and audit log never saw it. The same edit on the asset's own page is recorded correctly.Why it happened
These endpoints wrote the relationship tables directly and refreshed search, RDF and lineage by hand. Versions only come from the entity update path, and change events only from the REST response filter, which never sees an entity from these calls.
What this PR changes
Each selected asset now goes through the steps a PATCH on its own page runs, as the requesting user: rule checks, the entity updater, version history, search, RDF, lineage and a change event.
AssetEditServiceholds this flow; each endpoint only says what to change on the loaded asset.BulkPatchbatches the work. Each entity still gets its own checks and updater in its own transaction, but entity rows and version history are written together, search goes out as one bulk request (refreshed before returning, like a single write), and change events are inserted together. Items saved as the same entity are grouped, so 50 columns of one table are one save, one version and one event. If a group fails, its items are retried one by one.What users will notice
PARTIAL_SUCCESS.No API or UI change.
Cost
Median of three runs on local MySQL and Elasticsearch, as a non-admin user. This PR also writes a version and an event per saved asset, which
maindoes not.mainHow it was tested
AssetLabelEditsTest,EntityLifecycleBatchUpdatesTest,SearchIndexHandlerTest,SearchRepositoryTest.AssetsTabVersioningIT(32 cases) fails onmainand passes here on MySQL and Postgres: all four tabs, add and remove, grouped columns, attribution, dry runs, partial failures and child fields of every type.