Skip to content

fix(rdf): resolve RdfRepository fresh to unblock 2.0 parallel IT lane (RdfGlossaryGraphIT 500s) - #34005

Merged
manerow merged 4 commits into
2.0from
fix/rdf-resource-stale-repo-2.0
Sep 25, 2026
Merged

manerow merged 4 commits into
2.0from
fix/rdf-resource-stale-repo-2.0

Conversation

@sonika-shah

Copy link
Copy Markdown
Collaborator

Problem

The Integration Test Lane (parallel) is red on the 2.0 branch across unrelated PRs. RdfGlossaryGraphIT fails 11/11 with 500 "An internal error occurred" from GET /v1/rdf/glossary/graph. It is order-dependent — it only fails when another RDF test runs before it in the same shared-app lane — so it also passes on retry, making CI flaky for everyone targeting 2.0.

Root cause

RdfResource pinned the repository:

private volatile RdfRepository rdfRepository;
private RdfRepository getRdfRepository() {
  if (rdfRepository == null) rdfRepository = RdfRepository.getInstanceOrNull();
  return rdfRepository;
}

RdfUpdater.initialize() calls RdfRepository.reset() (which close()s and nulls the static INSTANCE) and then rebuilds a fresh singleton — this is the durable single-writer live-projection / reindex path. After such a swap, RdfResource keeps returning the old, closed repository, so getGlossaryTermGraph(...) throws and the handler returns 500. getSemanticSearchEngine() had the same latent staleness (it caches an engine built on one repository instance).

Which PR introduced it

#33098 ("Backport single-writer RDF reindex pipeline to 2.0", Sep 10) added RdfLiveProjectionIT, which exercises the live-projection path that resets/rebuilds the RdfRepository singleton mid-lane. In the shared-app parallel lane, when it runs before RdfGlossaryGraphIT, the pinned repo is left closed. main does not hit this because #28042 resolves the repository fresh via a Supplier<RdfRepository> instead of pinning it. The pinning itself predates #33098; #33098 introduced the mid-lane reset that exposes it.

Fix

Mirror main's behaviour with a minimal change (no feature backport):

  • getRdfRepository() resolves RdfRepository.getInstanceOrNull() on every call; the pinned field is removed.
  • getSemanticSearchEngine() rebuilds when the underlying repository instance changes, so it can't hold a reference a reset() invalidated.

This is also correct beyond tests: in production any RdfUpdater.initialize() re-run (config reload / reindex) would otherwise leave the endpoints serving a dead store.

Verification

  • mvn -pl openmetadata-service -am install -DskipTests → BUILD SUCCESS.
  • The order-dependent cross-test poisoning reproduces only in the full shared-app parallel lane, so the deterministic gate is CI's Integration Test Lane (parallel) on this PR — the exact lane that is failing today.

…instance

RdfResource cached the first RdfRepository in a volatile field and never
refreshed it. RdfUpdater.initialize() calls RdfRepository.reset() (close + null
the static INSTANCE) and rebuilds it for durable live projection / reindex, so
after such a swap RdfResource kept serving the closed store and every RDF
endpoint 500'd.

This surfaced on 2.0 once #33098 added RdfLiveProjectionIT (single-writer live
projection) to the shared-app parallel IT lane: when it ran before
RdfGlossaryGraphIT in the same JVM it reset the singleton, and all 11
RdfGlossaryGraphIT cases got 500 from GET /v1/rdf/glossary/graph. main does not
hit this because #28042 resolves the repository fresh via a Supplier.

- getRdfRepository(): return RdfRepository.getInstanceOrNull() on every call;
  drop the pinned field.
- getSemanticSearchEngine(): rebuild when the underlying repository instance
  changes so it can't hold a reference the reset invalidated.
@sonika-shah
sonika-shah requested a review from a team as a code owner September 25, 2026 06:15
@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.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 25, 2026
Comment on lines +58 to +59
private volatile SemanticSearchEngine semanticSearchEngine;
private volatile RdfRepository semanticSearchEngineRepository;

@gitar-bot gitar-bot Bot Sep 25, 2026 •

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: Unlocked fast path can return engine bound to the old repository

Two separate volatile fields hold the engine/repository pair. Inside the lock, the writer sets semanticSearchEngine and then semanticSearchEngineRepository. The unlocked reader reads the engine into local first and checks the repository field second. A reader can therefore get the old engine, then see the new repository reference that matches repository, skip the rebuild, and return an engine still bound to the closed store. That is the same staleness this PR is trying to remove. Fix: publish the pair atomically in one volatile holder (a record) and compare against the holder's repository.

Publish engine and its repository atomically via a single volatile record:

private record EngineBinding(RdfRepository repository, SemanticSearchEngine engine) {}
private volatile EngineBinding engineBinding;

private SemanticSearchEngine getSemanticSearchEngine() {
  final RdfRepository repository = getRdfRepository();
  EngineBinding binding = engineBinding;
  if (repository != null && (binding == null || binding.repository() != repository)) {
    binding = new EngineBinding(
        repository, new SemanticSearchEngine(repository, Entity.getSearchRepository()));
    engineBinding = binding;
  }
  return repository == null ? null : binding.engine();
}

Was this helpful? React with 👍 / 👎

Addresses review: getRdfRepository() now resolves the live singleton on every
call, which RdfUpdater.reset() can transiently null, so reading it twice in a
handler (null/enabled check then use) could NPE if a reset lands between them.
Each handler now reads it once into a final local and uses that, matching main's
pattern. getSemanticSearchEngine() also resolves the repo once during
construction.

Reverted the getSemanticSearchEngine rebuild-on-repo-change change: it is not
needed to fix the failing RdfGlossaryGraphIT (which uses getRdfRepository()
directly) and kept /search/semantic exactly as it was.
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 1b3bfa9fee4f694b0f92a89cb2c96aba1b9faad4 in Playwright run 36119438539, attempt 1.

✅ 897 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking 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) 43m 16s

⏱️ Max setup 2m 49s · max shard execution 18m 0s · max shard-job elapsed before upload 21m 40s · reporting 6s

🌐 188.01 requests/attempt · 2.29 app boots/UI scenario · 24.26% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 24.26% (convergence target: at most 15%).
  • Application boot ratio was 2.29 per UI scenario (2107 boots / 919 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 136 0 0 0 0 0
✅ Shard chromium-02 151 0 0 0 0 0
✅ Shard chromium-03 143 0 0 0 0 0
✅ Shard chromium-04 156 0 0 0 0 0
✅ Shard chromium-05 153 0 0 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard ingestion-01 1 0 0 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 11 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@gitar-bot

gitar-bot Bot commented Sep 25, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 1 closed / 2 findings

🟡 Medium risk · RDF endpoints now resolve the live repository per request, changing backend behavior

Resolves stale repository references in RdfResource by fetching RdfRepository fresh on each call instead of pinning a single instance, unblocking the parallel IT lane. The fix mirrors main's approach and handles mid-lane repository resets correctly.

Consider atomically publishing the semantic search engine and repository pair in a single volatile holder to prevent an unlocked reader from obtaining an engine bound to a closed repository while the writer is updating the pair.

💡 Bug: Unlocked fast path can return engine bound to the old repository

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:58-59 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:82-96

Two separate volatile fields hold the engine/repository pair. Inside the lock, the writer sets semanticSearchEngine and then semanticSearchEngineRepository. The unlocked reader reads the engine into local first and checks the repository field second. A reader can therefore get the old engine, then see the new repository reference that matches repository, skip the rebuild, and return an engine still bound to the closed store. That is the same staleness this PR is trying to remove. Fix: publish the pair atomically in one volatile holder (a record) and compare against the holder's repository.

Publish engine and its repository atomically via a single volatile record
private record EngineBinding(RdfRepository repository, SemanticSearchEngine engine) {}
private volatile EngineBinding engineBinding;

private SemanticSearchEngine getSemanticSearchEngine() {
  final RdfRepository repository = getRdfRepository();
  EngineBinding binding = engineBinding;
  if (repository != null && (binding == null || binding.repository() != repository)) {
    binding = new EngineBinding(
        repository, new SemanticSearchEngine(repository, Entity.getSearchRepository()));
    engineBinding = binding;
  }
  return repository == null ? null : binding.engine();
}
✅ 1 closed
✅ Bug: Repeated getRdfRepository() calls can NPE during reset window

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:74-80 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:540
getRdfRepository() now reads the live static INSTANCE on every call. RdfUpdater.initialize() calls disable(), which runs RdfRepository.reset() and sets INSTANCE = null, and only rebuilds the singleton after that. Handlers call the getter several times in a row, e.g. if (getRdfRepository() == null || !getRdfRepository().isEnabled()) and then getRdfRepository().executeSparqlQuery(...), along with getRdfStatus, getEntityAsRdf, lineage and export. If a reset lands between those calls, a later call returns null and throws an NPE, so the request fails with a 500. The old pinned field never became null, so this failure path is new with this change. Fix: have each handler read the repository once into a final local and use that local for the null/enabled check and every later call.

🤖 Prompt for agents
Code Review: Resolves stale repository references in `RdfResource` by fetching `RdfRepository` fresh on each call instead of pinning a single instance, unblocking the parallel IT lane. The fix mirrors main's approach and handles mid-lane repository resets correctly.
  
  Consider atomically publishing the semantic search engine and repository pair in a single volatile holder to prevent an unlocked reader from obtaining an engine bound to a closed repository while the writer is updating the pair.

1. 💡 Bug: Unlocked fast path can return engine bound to the old repository
   Files: openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:58-59, openmetadata-service/src/main/java/org/openmetadata/service/resources/rdf/RdfResource.java:82-96

   Two separate volatile fields hold the engine/repository pair. Inside the lock, the writer sets `semanticSearchEngine` and then `semanticSearchEngineRepository`. The unlocked reader reads the engine into `local` first and checks the repository field second. A reader can therefore get the old engine, then see the new repository reference that matches `repository`, skip the rebuild, and return an engine still bound to the closed store. That is the same staleness this PR is trying to remove. Fix: publish the pair atomically in one volatile holder (a record) and compare against the holder's repository.

   Fix (Publish engine and its repository atomically via a single volatile record):
   private record EngineBinding(RdfRepository repository, SemanticSearchEngine engine) {}
   private volatile EngineBinding engineBinding;
   
   private SemanticSearchEngine getSemanticSearchEngine() {
     final RdfRepository repository = getRdfRepository();
     EngineBinding binding = engineBinding;
     if (repository != null && (binding == null || binding.repository() != repository)) {
       binding = new EngineBinding(
           repository, new SemanticSearchEngine(repository, Entity.getSearchRepository()));
       engineBinding = binding;
     }
     return repository == null ? null : binding.engine();
   }

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

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

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow merged commit 8749c67 into 2.0 Sep 25, 2026
122 of 136 checks passed
@manerow
manerow deleted the fix/rdf-resource-stale-repo-2.0 branch September 25, 2026 10:43

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.

2 participants