Repository navigation
Fixes #35879: Keep search in sync after entity writes (2.0 backport of #35888) - #36255
Conversation
…and direct writes (#35888) * Fixes #35879: Keep entity tags in search after a PUT that omits them A PUT merges the stored tags into the request's. When the request carried no tags, updateTags did that merge in a new list that the entity never saw. The database kept the tags, but the entity that gets indexed had none. The full-document search update then dropped them, and the Tier with them. Since #28155, connectors send every entity as a PUT, mostly through /bulk, and let the server skip the unchanged ones. Before, they PATCHed the ones that changed. Connectors send tags only when the source has some. So every ingestion run that changes an entity drops the tags users applied in OpenMetadata from its search document, until the next reindex. Tags on topic and API endpoint schema fields and on ML features are lost the same way, because those lists default to null too. updateTags now returns the tags the entity or field ends up with, and every caller keeps that list. Topics, API endpoints and search indexes also lost their field tags on the bulk path for a second reason. A PUT loads the stored entity with its PUT fields, and their bulk loaders read nested field tags only when the schema or fields are requested. These repositories listed no PUT fields, so the stored fields carried no tags to merge. They now list messageSchema, requestSchema/responseSchema and fields, as tables already list columns. * Keep renamed and moved tags and glossary terms in sync in search Renames and moves rewrote descendant FQNs in the database without re-indexing the descendants, and the asset-side rewrite missed or damaged some copies: - Renaming or moving a glossary term, tag or classification now re-indexes the descendant terms and tags (by the ids captured before the rewrite), so their documents no longer keep the old FQN (Kpler 21758). - Moving a tag to another parent now rewrites the tag FQN on tagged assets, as a rename already did. - The post-commit rename pass substring-replaced the FQN of every tagged asset (a table whose FQN contained the tag's FQN was renamed with it) and the classification rewrite did the same to sibling classifications sharing a name prefix. Both are gone: each repository rewrites its assets inline with the boundary-safe script. - Tag renames and deletes also reach the tag labels nested in columns, data model columns, schema fields, search-index fields, ML features and tasks. - A tag's or glossary term's display name or style change now reaches the label copies on assets, including nested ones, and clearing a value removes it. * Relabel the copies of renamed users, teams, domains and data products in search Documents copy the name and display name of the users, teams, domains and data products they reference, and nothing rewrote those copies: - A user's or team's display-name change, or a domain's or data product's rename or display-name change, now relabels every copy by id: owners and the ownerDisplayName list, reviewers, experts, domains, dataProducts, a user's teams and a team's parents, across the global alias and the user and team indexes. - A domain's display-name change ran a child script that wrote a "domain" field its children do not have. The script failed, and took down the owners propagated to data products in the same update. Domains and data products now leave their labels to the relabel pass, and a domain's own child propagation runs synchronously, so that it does not race the relabel pass over the same data products. - Adding or removing members through /teams/{id}/users made no search write, so the users' teams and the team's user count went stale. Both documents are rebuilt now. - A user's team change re-indexed each team from a read of only its id and user count, which blanked the owners and domains in the team's document. The teams are re-indexed from full reads, and the user count is part of a team document. * Keep search documents complete on writes outside the update path - A recursive soft delete or restore re-indexed the descendants from what the bulk updater had loaded. That leaves out what a PUT does not touch and what a descendant inherits, so a restored table lost its inherited owners and domains in search. The dispatched entities now load their search fields first. - A vote re-indexed the entity from a bare read, blanking owners, domains and tags. The vote change now travels with the entity, so only the votes and their total are rewritten. - Adding a dbt data model to a table wrote its tags, owners and column tags to the database only. The table is re-indexed afterwards. - deleteStale skipped the post-delete steps, so a hard-deleted stale entity kept its search document. (cherry picked from commit 361a62f)
❌ 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 |
| for (MlFeature updatedFeature : listOrEmpty(updatedModel.getMlFeatures())) { | ||
| MlFeature storedFeature = | ||
| listOrEmpty(origModel.getMlFeatures()).stream() | ||
| .filter(feature -> mlFeatureMatch.test(feature, updatedFeature)) | ||
| .filter(feature -> feature.getName().equals(updatedFeature.getName())) | ||
| .findAny() | ||
| .orElse(null); | ||
| if (storedFeature == null) { | ||
| continue; | ||
| } | ||
|
|
||
| updateMlFeatureDescription(storedFeature, updatedFeature); | ||
| updatedFeature.setTags( | ||
| updateTags( | ||
| storedFeature.getFullyQualifiedName(), | ||
| EntityUtil.getFieldName("mlFeatures", updatedFeature.getName(), Entity.FIELD_TAGS), |
There was a problem hiding this comment.
⚠️ Bug: ML-feature updateTags writes tag_usage rows 2.0 never creates or cleans
On 2.0, ML-feature tags live only in the model JSON. MlModelRepository has no applyTags override, and neither create nor setFields reads or writes tag_usage for feature FQNs. The new updateTags(storedFeature.getFullyQualifiedName(), ...) call runs deleteTagsByTarget plus applyTags against the feature FQN on every update. Feature tags therefore end up in tag_usage only for models updated after this change; models that were only created never get those rows, so tag asset counts and usage lookups disagree depending on whether a model was ever PUT or PATCHed. Nothing deletes these rows when a feature is later dropped from the model, so orphaned rows remain until the model is deleted. Each changed feature is also recorded twice: once by the mlFeatures list change (since mlFeatureMatch is equals) and again as mlFeatures.<name>.tags. To keep the backport's PUT-merge behaviour without changing storage, merge the stored feature tags into the updated feature in memory (EntityUtil.mergeTags) on PUT and skip the tag_usage writes. The alternative is to also apply feature tags on create and clean them up when a feature is removed.
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
| default void updateReferenceCopies( | ||
| List<String> indexNames, | ||
| List<String> nestedPaths, | ||
| List<String> objectPaths, | ||
| String field, | ||
| List<String> values, | ||
| Pair<String, Map<String, Object>> updates) |
There was a problem hiding this comment.
updateReferenceCopies takes six parameters, exceeding the Java guide's limit of five. Group the index targets and matching fields into a request object so callers cannot mix up the three string lists. This repository requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| List<FieldValue> fieldValues = values.stream().map(FieldValue::of).toList(); | ||
| List<Query> matches = new ArrayList<>(); | ||
| for (String path : nestedPaths) { | ||
| Query terms = | ||
| Query.of( | ||
| q -> q.terms(t -> t.field(path + "." + field).terms(tv -> tv.value(fieldValues)))); | ||
| matches.add(Query.of(q -> q.nested(n -> n.path(path).ignoreUnmapped(true).query(terms)))); | ||
| } | ||
| for (String path : objectPaths) { | ||
| matches.add( | ||
| Query.of( | ||
| q -> q.terms(t -> t.field(path + "." + field).terms(tv -> tv.value(fieldValues))))); | ||
| } |
There was a problem hiding this comment.
Backend matching logic is duplicated
The new updateReferenceCopies methods repeat the same query-building steps in Elasticsearch and OpenSearch. The Java guide requires near-identical backend methods to share their common logic. Extract the matching plan and leave only the client-specific query construction in each backend. This requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| * Builds the multi-level team hierarchies the inherited-role, inherited-domain and authorization | ||
| * tests need. Every name is namespaced, so the tests using these stay safe to run concurrently. | ||
| */ | ||
| public class TeamHierarchyTestFactory { |
There was a problem hiding this comment.
TeamHierarchyTestFactory has only static methods and a private constructor, but it is not final. The Java guide requires utility classes to be final. Add the modifier before merging to satisfy that requirement.
| public class TeamHierarchyTestFactory { | |
| public final class TeamHierarchyTestFactory { |
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| List<String> fields = REFERENCE_COPY_FIELDS.get(entityType); | ||
| if (fields == null) { | ||
| return; | ||
| } | ||
| Set<String> changedFields = getChangedFieldNames(changeDescription); | ||
| if (!changedFields.contains(FIELD_NAME) && !changedFields.contains(FIELD_DISPLAY_NAME)) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
relabelReferenceCopies adds two early returns. The Java guide requires one return at the end and explicitly forbids early-return guards. Put the work behind a named eligibility check. The same pattern appears in reindexRenamedDescendants and reindexMembership. These helpers must meet the requirement before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| TABLE_INDEX, | ||
| table.getId(), | ||
| d -> | ||
| "Shown Label".equals(findTag(d.path("tags"), tagFqn).path("displayName").asText())); |
There was a problem hiding this comment.
Test labels repeat raw strings
The new tests repeat label strings and use raw strings in .equals(), such as "Shown Label". The Java guide requires named constants for both cases. Define constants for the writes and checks, including the same pattern in ReferenceLabelSearchIT. This requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| l.builtin( | ||
| os.org.opensearch.client.opensearch._types | ||
| .BuiltinScriptLanguage.Painless)) |
There was a problem hiding this comment.
Class reference skips required import
The new method spells out os.org.opensearch.client.opensearch._types.BuiltinScriptLanguage in its body. The Java guide requires importing classes instead of using fully qualified names. Import BuiltinScriptLanguage and use its short name before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| String id = entity.getId().toString(); | ||
| Map<String, Object> label = new HashMap<>(); |
There was a problem hiding this comment.
Fixed bindings lack final modifiers
The new helpers omit final on locals that are never reassigned, including fields, changedFields, id, and label in relabelReferenceCopies. The Java guide requires final on unchanged locals and parameters. Apply this requirement to the added helpers and backend methods before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Fixes #35879
Backports merged PR #35888 (361a62f) to 2.0.
PUTs that omit tags retain stored tags in search. Glossary-term/tag renames and moves refresh descendant documents and asset labels; reference label and team-membership changes update their copies; vote, dbt data-model, recursive delete/restore and stale-delete paths keep search synchronized.
Compatibility adjustments for 2.0:
Validation:
This backport preserves the merged PR's scope. Local-only follow-up fixes, async cascade task reconciliation, and cluster-wide staged-index routing are separate work.
No concrete behavioral blocker was established, but the explicit Java requirements must be satisfied before merging.
Findings
Summary
Backports search synchronization after entity writes to 2.0.
mohityadav766explicitly deferred async cascade task reconciliation and cluster-wide staged-index routing in the PR description as separate work; these are not reported.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Entity write] --> B[Metadata database] B --> C[Committed rename or update] C --> D[Read fields needed by search] D --> E[Rebuild changed documents] C --> F[Refresh copied labels] E --> G[Elasticsearch or OpenSearch] F --> GReviews (1) · Last reviewed commit: "Fixes #35879: Keep search in sync after ..." · Reviewed by Greptile