Skip to content

Fixes #36437: Compact the RDF store on a schedule and pause writes during maintenance (backport 2.0 #36471) - #36660

Merged
manerow merged 20 commits into
2.0from
fix/36437-rdf-storage-maintenance-2.0
Nov 1, 2026
Merged

manerow merged 20 commits into
2.0from
fix/36437-rdf-storage-maintenance-2.0

Conversation

@manerow

@manerow manerow commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36437

Backport of PR #36471 to the 2.0 release branch, adapted to 2.0: it has no inference runs to keep maintenance away from, the reindex lock DAO lives in CollectionDAO, and the migration goes in the 2.0.8 folder. PR #36471 explains the problem and why it happened.

What this PR changes

  • Scheduled compaction. One server compacts the serving dataset every 24 hours (RDF_COMPACTION_INTERVAL_HOURS), never during a reindex. One Fuseki could not start is retried after 15 minutes; one it started and that did not succeed waits for the next interval, so a copy the volume cannot hold is not retried.
  • A write pause during maintenance. Every server holds back serving writes during a compaction or reindex clear. Queued writes wait in SQL without using retries or tripping the breaker; other writers wait up to RDF_REQUEST_TIMEOUT_MS, then get 503 with Retry-After. Pipeline run statuses now use the queue.
  • A stopped schedule is visible. Each successful maintenance compaction is recorded in rdf_projection_health.lastCompactedAt. Once none has succeeded for two intervals, whatever the reason, every check logs an error and /v1/rdf/status reports DEGRADED until one does.
  • A reindex clear that cannot time out. It gets a maintenance budget (RDF_MAINTENANCE_MAX_DURATION_MINUTES, 240). Compaction always follows; a failed clear then fails the run.
  • The dataset a blue/green promotion retires is emptied and compacted. Abandoned builds stay for inspection.
  • Honest compaction results. Success means Fuseki reported success: true; a task it forgets is unknown. Compactions are timed in ontology.rdf.compaction, with a last-success gauge.
  • Fixed: two servers taking over one expired reindex lock.

Leases use rdf_reindex_lock; the only migration adds the lastCompactedAt column in the 2.0.8 folder; 2.1.0 adds it too, guarded, for servers that skip 2.0.8. Decision record: ADR:2026-10-28-rdf-storage-maintenance-pauses-serving-writes-and-compacts-on-a-schedule.

How it was tested on 2.0

Type of change:

  • Bug fix

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: the new configuration block has defaults; lastCompactedAt comes with its 2.0.8 migration.
  • I have added tests (unit / integration) and listed them above.
  • Decision check: docs/decisions/2026-10-28-rdf-storage-maintenance-pauses-serving-writes-and-compacts-on-a-schedule.md.

Release refresh 2aa97215dfe: merged the current 2.0 branch. Both schema-generation entrypoints now resolve the same pinned quicktype CLI as upstream (20.0.27), so the lightweight workflow no longer depends on root node_modules. bash -n passed for both scripts; full generation completed with 898 nonempty TypeScript files, including the previously missing RDF storage-maintenance types. No generated outputs were lost; ten other generated diffs only rewrap comments. Independent review found no important issues. The combined 2.0 guard stack also packages the backend and passes 47 targeted RDF unit tests.

Review follow-up: compaction recovery and rolling upgrades

  • Serving compaction retains its shared write pause beyond the maintenance budget and keeps polling the same task. Malformed or unavailable status replies do not release it. A lost start response waits for an explicit idle task list; it does not submit another compaction.
  • The release migration retires the legacy drain consumer fence before enabling drain-v2, waiting for an old delivery in progress. Old servers can still enqueue their supported payloads; upgraded consumers deliver pipelineExecution. RDF startup rejects a database missing the new fence.
  • Compaction health starts before the first attempt and continues reporting while the worker waits, so a stalled first attempt eventually reports overdue/degraded.

Validation at 650f8861445: 106 focused unit tests and 10 recovery integration cases passed. The recovery cases use real MySQL/PostgreSQL plus an HTTP Fuseki boundary, and cover pause retention, malformed start/poll replies, resumption without dead letters, legacy consumer exclusion, an in-flight consumer during migration, and health degradation during a pause. Spotless passed. Independent review has no unanswered important findings.

Run the release migrations before deploying upgraded RDF servers. After the consumer-fence transfer, keep an upgraded RDF server available; an old-only rollback leaves queued writes pending. Never enable both consumer fences together.

… pause, compactions are tracked to the end, pipeline runs go through the queue
…ause holder each write through their own handle
@manerow manerow added safe to test Add this label to run secure Github workflows on PRs backend labels Oct 30, 2026
@manerow
manerow requested a review from a team as a code owner October 30, 2026 08:40
@manerow
manerow requested review from mohityadav766 and removed request for a team October 30, 2026 08:40
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

Comment on lines +916 to +930
// A compaction this server did not pause for (a lost pause lease, an operator, an older
// server) blocks the write until it ends: retry it without counting a failure.
if (RdfWriteRetry.isUncertain(exception)) {
throw new RdfWriteOutcomeUnknownException(description, exception);
throw isCompacting()
? new RdfStorageMaintenanceException(
"compaction (" + description + " waited)", COMPACTION_RETRY_AFTER)
: new RdfWriteOutcomeUnknownException(description, exception);
}
throw exception;
}
}

private boolean isCompacting() {
final DatasetEndpoint info = parseDatasetEndpoint(endpoint);
return info != null

@gitar-bot gitar-bot Bot Oct 30, 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: Server-wide isCompacting turns uncertain writes into 'nothing applied'

When a write times out, runWriteWithTimeout calls isCompacting(). That method goes through FusekiCompaction.anyRunningCompaction, which checks /$/tasks for a running Compact task on any dataset on the Fuseki server, not just the dataset this handle writes to. A true answer replaces RdfWriteOutcomeUnknownException with RdfStorageMaintenanceException.

This drops the uncertain-outcome handling that callers depend on:

  • RdfRebuildStore.withBuildLock only quarantines a build dataset (UNCERTAIN_WRITE) when RdfWriteOutcomeUnknownException.isPresent.
  • writeProbe only removes its probe triple on that exception type.
  • RdfBatchProcessor classifies on it too.
  • RdfLiveWriteStore.deferForMaintenance assumes "nothing reached the store".

Here is a reachable case. A maintenance compaction or prepareBuildDataset compaction returns TIMED_OUT but keeps running on Fuseki. A reindex then writes to openmetadata_b, and one of those writes times out for an unrelated reason. That write is reported as held by maintenance and is not quarantined, so Fuseki can apply it late after the dataset has been reused. A write held up by a compaction can also still be applied once the compaction ends, so its outcome really is unknown.

Fix: limit the check to compactions of this handle's dataset (Fuseki task bodies identify the dataset). Also keep the uncertainty, for example by making the maintenance exception carry or extend the outcome-unknown signal, so build quarantine and probe cleanup still happen.

Only treat the timeout as maintenance when the compaction targets this dataset, and keep the outcome-unknown cause so build quarantine still triggers.:

if (RdfWriteRetry.isUncertain(exception)) {
  final RdfWriteOutcomeUnknownException uncertain =
      new RdfWriteOutcomeUnknownException(description, exception);
  if (isCompacting(datasetName)) {
    // keep uncertain as the cause so RdfWriteOutcomeUnknownException.isPresent() stays true
    throw new RdfStorageMaintenanceException("compaction (" + description + " waited)", COMPACTION_RETRY_AFTER, uncertain);
  }
  throw uncertain;
}

Was this helpful? React with 👍 / 👎

Resolve the pinned quicktype CLI without root node_modules so the lightweight PR workflow can regenerate the release schemas. Regenerate the committed TypeScript models, including RDF storage maintenance.
@pmbrull
pmbrull requested a review from a team as a code owner October 30, 2026 10:32
@pmbrull
pmbrull removed the request for review from a team October 30, 2026 10:32
Keep the serving pause while Fuseki tasks outlive their budget or return unreadable responses. Transfer the queue consumer fence to upgraded servers before emitting pipeline execution payloads.

Refs #36437
Start the compaction health clock before contacting Fuseki and keep scheduled health reporting independent of the compaction worker. Keep consumer migration statements in the RDF schema section.
@gitar-bot

gitar-bot Bot commented Oct 30, 2026

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

🔴 High risk · Scheduled RDF compaction and cluster-wide write pausing alter data-maintenance and delivery paths; lease or recovery errors could delay writes or degrade projections.

Scheduled RDF compaction and serving-write pause during maintenance are added, with a fix for a non-JSON Fuseki reply that previously threw, now reported instead. Changes requested before merge: a server-wide compaction check in the Fuseki write-timeout path can replace an uncertain-write outcome with a maintenance exception, dropping build quarantine and probe cleanup, and should be limited to this handle's dataset while keeping the outcome-unknown signal. Also, the npx fallback for quicktype in json2ts.sh and json2ts-generate-all.sh bypasses the root lockfile's stream-json security override and should prefer the locked local binary.

⚠️ Bug: Server-wide isCompacting turns uncertain writes into 'nothing applied'

📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/JenaFusekiStorage.java:916-930 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/FusekiCompaction.java:83-97

When a write times out, runWriteWithTimeout calls isCompacting(). That method goes through FusekiCompaction.anyRunningCompaction, which checks /$/tasks for a running Compact task on any dataset on the Fuseki server, not just the dataset this handle writes to. A true answer replaces RdfWriteOutcomeUnknownException with RdfStorageMaintenanceException.

This drops the uncertain-outcome handling that callers depend on:

  • RdfRebuildStore.withBuildLock only quarantines a build dataset (UNCERTAIN_WRITE) when RdfWriteOutcomeUnknownException.isPresent.
  • writeProbe only removes its probe triple on that exception type.
  • RdfBatchProcessor classifies on it too.
  • RdfLiveWriteStore.deferForMaintenance assumes "nothing reached the store".

Here is a reachable case. A maintenance compaction or prepareBuildDataset compaction returns TIMED_OUT but keeps running on Fuseki. A reindex then writes to openmetadata_b, and one of those writes times out for an unrelated reason. That write is reported as held by maintenance and is not quarantined, so Fuseki can apply it late after the dataset has been reused. A write held up by a compaction can also still be applied once the compaction ends, so its outcome really is unknown.

Fix: limit the check to compactions of this handle's dataset (Fuseki task bodies identify the dataset). Also keep the uncertainty, for example by making the maintenance exception carry or extend the outcome-unknown signal, so build quarantine and probe cleanup still happen.

Only treat the timeout as maintenance when the compaction targets this dataset, and keep the outcome-unknown cause so build quarantine still triggers.
if (RdfWriteRetry.isUncertain(exception)) {
  final RdfWriteOutcomeUnknownException uncertain =
      new RdfWriteOutcomeUnknownException(description, exception);
  if (isCompacting(datasetName)) {
    // keep uncertain as the cause so RdfWriteOutcomeUnknownException.isPresent() stays true
    throw new RdfStorageMaintenanceException("compaction (" + description + " waited)", COMPACTION_RETRY_AFTER, uncertain);
  }
  throw uncertain;
}
💡 Security: npx-resolved quicktype skips the root stream-json security override

📄 openmetadata-ui/src/main/resources/ui/json2ts.sh:68-72 📄 openmetadata-ui/src/main/resources/ui/json2ts-generate-all.sh:130-134

Root package.json pins [email protected] and adds a resolutions override that forces stream-json 3.5.0 to pick up the GHSA-528h-pc64-c93x DoS fix. npx --yes -p [email protected] runs outside that lockfile whenever the local project lacks quicktype, which covers json2ts.sh run from the UI dir (its own package.json) and CI without a root install. In that case npm installs into its cache with quicktype's exact stream-json 1.7.5 pin and unlocked transitive versions, so the override the repo documents no longer applies. The impact is limited because this only runs at codegen time on local schemas. To fix it, prefer the locked binary ($ROOT/node_modules/.bin/quicktype) when it exists and fall back to npx only when it doesn't, or install quicktype from the root lockfile (yarn install --frozen-lockfile at root) in the lightweight CI job.

Prefer the lockfile-installed binary and fall back to npx only when it is missing
ROOT_QUICKTYPE="$(git rev-parse --show-toplevel 2>/dev/null)/node_modules/.bin/quicktype"
if [[ -x "$ROOT_QUICKTYPE" ]]; then
    QUICKTYPE="$ROOT_QUICKTYPE"
else
    QUICKTYPE=$(npx --yes -p [email protected] -c 'command -v quicktype' 2>/dev/null) || {
        echo "Failed to resolve quicktype via npx" >&2
        exit 1
    }
fi
✅ 1 closed
✅ Edge Case: Non-JSON Fuseki reply makes compact() throw instead of reporting

📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/FusekiCompaction.java:94-103 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/FusekiCompaction.java:125 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/FusekiCompaction.java:168-182 📄 openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/FusekiCompaction.java:211-215
FusekiCompaction.field and anyRunningCompaction call JsonUtils.readTree, which throws JsonParsingException. compact and taskState only catch IOException and InterruptedException, even though RdfStorageInterface says the compaction outcome "is reported, never thrown". So a 200 reply with a non-JSON body (for example an HTML page from a proxy, or a truncated reply) makes compact throw while Fuseki is still copying.

In RdfStorageMaintenanceService this leaves result null. retryAtNextCheck then releases the slot and the write pause ends. The next 15-minute check starts a second compaction, which breaks the rule that "one it started keeps the lease". In isCompacting, the parse error is raised inside the write's catch block and hides the original timeout.

Fix: catch JsonParsingException while parsing. Treat a bad poll reply as still running (null outcome), and a bad start reply as FAILED with the HTTP detail.

🤖 Prompt for agents
Code Review: Scheduled RDF compaction and serving-write pause during maintenance are added, with a fix for a non-JSON Fuseki reply that previously threw, now reported instead. Changes requested before merge: a server-wide compaction check in the Fuseki write-timeout path can replace an uncertain-write outcome with a maintenance exception, dropping build quarantine and probe cleanup, and should be limited to this handle's dataset while keeping the outcome-unknown signal. Also, the npx fallback for quicktype in json2ts.sh and json2ts-generate-all.sh bypasses the root lockfile's stream-json security override and should prefer the locked local binary.

1. ⚠️ Bug: Server-wide isCompacting turns uncertain writes into 'nothing applied'
   Files: openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/JenaFusekiStorage.java:916-930, openmetadata-service/src/main/java/org/openmetadata/service/rdf/storage/FusekiCompaction.java:83-97

   When a write times out, `runWriteWithTimeout` calls `isCompacting()`. That method goes through `FusekiCompaction.anyRunningCompaction`, which checks `/$/tasks` for a running `Compact` task on any dataset on the Fuseki server, not just the dataset this handle writes to. A `true` answer replaces `RdfWriteOutcomeUnknownException` with `RdfStorageMaintenanceException`.
   
   This drops the uncertain-outcome handling that callers depend on:
   - `RdfRebuildStore.withBuildLock` only quarantines a build dataset (`UNCERTAIN_WRITE`) when `RdfWriteOutcomeUnknownException.isPresent`.
   - `writeProbe` only removes its probe triple on that exception type.
   - `RdfBatchProcessor` classifies on it too.
   - `RdfLiveWriteStore.deferForMaintenance` assumes "nothing reached the store".
   
   Here is a reachable case. A maintenance compaction or `prepareBuildDataset` compaction returns `TIMED_OUT` but keeps running on Fuseki. A reindex then writes to `openmetadata_b`, and one of those writes times out for an unrelated reason. That write is reported as held by maintenance and is not quarantined, so Fuseki can apply it late after the dataset has been reused. A write held up by a compaction can also still be applied once the compaction ends, so its outcome really is unknown.
   
   Fix: limit the check to compactions of this handle's dataset (Fuseki task bodies identify the dataset). Also keep the uncertainty, for example by making the maintenance exception carry or extend the outcome-unknown signal, so build quarantine and probe cleanup still happen.

   Fix (Only treat the timeout as maintenance when the compaction targets this dataset, and keep the outcome-unknown cause so build quarantine still triggers.):
   if (RdfWriteRetry.isUncertain(exception)) {
     final RdfWriteOutcomeUnknownException uncertain =
         new RdfWriteOutcomeUnknownException(description, exception);
     if (isCompacting(datasetName)) {
       // keep uncertain as the cause so RdfWriteOutcomeUnknownException.isPresent() stays true
       throw new RdfStorageMaintenanceException("compaction (" + description + " waited)", COMPACTION_RETRY_AFTER, uncertain);
     }
     throw uncertain;
   }

2. 💡 Security: npx-resolved quicktype skips the root stream-json security override
   Files: openmetadata-ui/src/main/resources/ui/json2ts.sh:68-72, openmetadata-ui/src/main/resources/ui/json2ts-generate-all.sh:130-134

   Root `package.json` pins `[email protected]` and adds a `resolutions` override that forces `stream-json` 3.5.0 to pick up the GHSA-528h-pc64-c93x DoS fix. `npx --yes -p [email protected]` runs outside that lockfile whenever the local project lacks quicktype, which covers `json2ts.sh` run from the UI dir (its own package.json) and CI without a root install. In that case npm installs into its cache with quicktype's exact `stream-json` 1.7.5 pin and unlocked transitive versions, so the override the repo documents no longer applies. The impact is limited because this only runs at codegen time on local schemas. To fix it, prefer the locked binary (`$ROOT/node_modules/.bin/quicktype`) when it exists and fall back to npx only when it doesn't, or install quicktype from the root lockfile (`yarn install --frozen-lockfile` at root) in the lightweight CI job.

   Fix (Prefer the lockfile-installed binary and fall back to npx only when it is missing):
   ROOT_QUICKTYPE="$(git rev-parse --show-toplevel 2>/dev/null)/node_modules/.bin/quicktype"
   if [[ -x "$ROOT_QUICKTYPE" ]]; then
       QUICKTYPE="$ROOT_QUICKTYPE"
   else
       QUICKTYPE=$(npx --yes -p [email protected] -c 'command -v quicktype' 2>/dev/null) || {
           echo "Failed to resolve quicktype via npx" >&2
           exit 1
       }
   fi

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

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow merged commit 6c1c0b8 into 2.0 Nov 1, 2026
76 of 78 checks passed
@manerow
manerow deleted the fix/36437-rdf-storage-maintenance-2.0 branch November 1, 2026 18:33

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.

Fuseki disk grows until full because the RDF store is only compacted by the reindex app

2 participants