Skip to content

Fixes #35879: Keep search in sync after entity writes (2.0 backport of #35888) - #36255

Merged
mohityadav766 merged 1 commit into
2.0from
backport/2.0/search-sync
Oct 26, 2026
Merged

mohityadav766 merged 1 commit into
2.0from
backport/2.0/search-sync

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

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:

  • Retain the 2.0 repository APIs and imports when resolving conflicts.
  • Add the test-only TeamHierarchyTestFactory required by ReferenceLabelSearchIT.
  • Adapt ML-feature tag merging to 2.0's updater, matching existing features by name and retaining the returned tag list. The original hunk depended on ML-feature update code absent on 2.0.

Validation:

  • Scoped spotless:apply and git diff --check passed.
  • 1,923 search unit tests passed, zero failures/errors/skips, covering search core, index builders, Elasticsearch and OpenSearch. Container-backed ImmenseTermReproTest and UpdateChildrenAsyncPropagationTest were excluded because Docker is unresponsive.
  • Full reactor package through openmetadata-integration-tests passed with tests skipped and spring-boot.repackage.skip=true; all integration tests compile. An earlier packaging attempt exhausted local disk building the unrelated Kubernetes operator boot jar.
  • Full MySQL/Elasticsearch and PostgreSQL/OpenSearch integration workflows dispatched on this branch. Integration results are pending.

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.

RetriggerView in GreptileConfidence Score: 4/5

No concrete behavioral blocker was established, but the explicit Java requirements must be satisfied before merging.

Findings

  1. P2 Too many parameters ▶
  2. P2 Backend matching logic is duplicated ▶
  3. P2 Utility class is not final ▶
  4. P2 New helpers use early returns ▶
  5. P2 Test labels repeat raw strings ▶
  6. P2 Class reference skips required import ▶
  7. P2 Fixed bindings lack final modifiers ▶

Summary

Backports search synchronization after entity writes to 2.0.

  • PUT requests keep stored tags visible in search.
  • Renames and moves refresh descendant labels and copied references in search.
  • Team membership changes refresh users and teams in search.
  • Direct writes and recursive entity operations keep search current.

mohityadav766 explicitly 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 --> G
Loading

Reviews (1) · Last reviewed commit: "Fixes #35879: Keep search in sync after ..." · Reviewed by Greptile

…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)
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 26, 2026
@mohityadav766
mohityadav766 marked this pull request as ready for review October 26, 2026 13:20
@mohityadav766
mohityadav766 requested a review from a team as a code owner October 26, 2026 13:20
@mohityadav766
mohityadav766 requested review from yan-3005 and removed request for a team October 26, 2026 13:20
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 skip-pr-checks label.

@mohityadav766 mohityadav766 self-assigned this Oct 26, 2026
Comment on lines 546 to +560
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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 0 closed / 1 findings

🟡 Medium risk · Reworking search synchronization across entity writes, renames, memberships, and deletes could leave stale or incomplete indexed records when cascades diverge.

Backports the merged search-sync fixes to 2.0, covering PUT tag retention, glossary and tag renames, label and team-membership updates, and vote, dbt, delete and restore paths. Changes are requested because ML-feature tag updates write tag_usage rows that 2.0 never creates or cleans up, so tag counts and usage lookups become inconsistent. Merge stored feature tags into the updated feature in memory on PUT and skip the tag_usage writes, or add feature-tag handling on create and removal.

⚠️ Bug: ML-feature updateTags writes tag_usage rows 2.0 never creates or cleans

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MlModelRepository.java:546-560

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.

🤖 Prompt for agents
Code Review: Backports the merged search-sync fixes to 2.0, covering PUT tag retention, glossary and tag renames, label and team-membership updates, and vote, dbt, delete and restore paths. Changes are requested because ML-feature tag updates write `tag_usage` rows that 2.0 never creates or cleans up, so tag counts and usage lookups become inconsistent. Merge stored feature tags into the updated feature in memory on PUT and skip the `tag_usage` writes, or add feature-tag handling on create and removal.

1. ⚠️ Bug: ML-feature updateTags writes tag_usage rows 2.0 never creates or cleans
   Files: openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MlModelRepository.java:546-560

   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.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@mohityadav766
mohityadav766 merged commit 6d8691a into 2.0 Oct 26, 2026
103 of 115 checks passed
@mohityadav766
mohityadav766 deleted the backport/2.0/search-sync branch October 26, 2026 13:25
Comment on lines +162 to +168
default void updateReferenceCopies(
List<String> indexNames,
List<String> nestedPaths,
List<String> objectPaths,
String field,
List<String> values,
Pair<String, Map<String, Object>> updates)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Too many parameters

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!

Comment on lines +592 to +604
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)))));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Utility class is not final

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.

Suggested change
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!

Comment on lines +2880 to +2887
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 New helpers use early returns

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()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Comment on lines +665 to +667
l.builtin(
os.org.opensearch.client.opensearch._types
.BuiltinScriptLanguage.Painless))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Comment on lines +2888 to +2889
String id = entity.getId().toString();
Map<String, Object> label = new HashMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants