Skip to content

feat(search): keep tika out of tag updates and retry incomplete extractions - #4113

Merged
fschade merged 6 commits into
opencloud-eu:mainfrom
fschade:fix-search-extraction-state
Nov 24, 2026
Merged

fschade merged 6 commits into
opencloud-eu:mainfrom
fschade:fix-search-extraction-state

Conversation

@fschade

@fschade fschade commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Description

Files Tika cannot parse stay findable, and their content is retried a limited number of times.

  • A file Tika answers for but cannot parse (a container-exception in the metadata, or no metadata at all) is still indexed by name, path and tags.
  • Such a file carries an ExtractionFailure object (Count, RetryAt). It is retried after 1h, then after 24h. After the third failure the service logs a warning and stops trying until the file changes.
  • opencloud search index --force-rescan ignores the limit.
  • If Tika or the file is unreachable, a new or changed file is indexed by name as well. This is not counted, and every later space walk tries again. An entry that is already current for this version is left alone, so a rescan during an outage does not drop extracted content.
  • Entries without the field count as extracted. Old entries with empty content heal with --force-rescan, and there is no forced re-extraction on upgrade.
  • UpsertItem is no longer part of Searcher. UpdateMetadata stats the resource once and reuses one basic extractor.
  • Admins can list the files the service gave up on with extractionfailure.count>=3. The search README documents the limits.

How Has This Been Tested?

  • test environment
  • unit tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

@fschade fschade self-assigned this Nov 24, 2026
@github-project-automation github-project-automation Bot moved this to Qualification in OpenCloud Team Board Nov 24, 2026
@fschade fschade moved this from Qualification to In Progress in OpenCloud Team Board Nov 24, 2026
@fschade
fschade requested a review from aduffeck November 24, 2026 13:51
@codacy-production

codacy-production Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 71 complexity

Metric Results
Complexity 71

View in Codacy

🟢 Coverage 72.69% diff coverage · +0.23% coverage variation

Metric Results
Coverage variation ✅ +0.23% coverage variation (-1.00%)
Diff coverage ✅ 72.69% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (0b73e9e) 95037 29280 30.81%
Head commit (cf5a087) 95213 (+176) 29557 (+277) 31.04% (+0.23%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4113) 271 197 72.69%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@fschade
fschade requested a review from butonic November 24, 2026 15:00

@aduffeck aduffeck left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the change in general. But since existing index entries don't have Extracted set, every file in the index will go through Tika again on the next space walk after the upgrade. If that's fine it should be mentioned in the release notes, but maybe there's a way to avoid it? For example, flip the flag to something like ExtractionFailed, so entries written before this change count as extracted by default.

@fschade

fschade commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

I like the change in general. But since existing index entries don't have Extracted set, every file in the index will go through Tika again on the next space walk after the upgrade. If that's fine it should be mentioned in the release notes, but maybe there's a way to avoid it? For example, flip the flag to something like ExtractionFailed, so entries written before this change count as extracted by default.

good point, yes, inverting the field is a good idea, the only downside is that old failed resources are marked as ok!

@butonic butonic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keeping tika out of tag updates is the right idea 👍 but the error handling around Extracted loses files from the index, and the upgrade path re-extracts everything. Details inline.

Since the event handlers now call UpdateMetadata, UpsertItem has no production callers left. Only the Searcher interface, the mock and service_test.go still use it. I'd drop it from the interface, regenerate the mock and point the tests at UpdateMetadata / IndexSpace. Otherwise it is one more public entry point that does a full stat + extraction, which is exactly what this PR tries to get rid of.

Comment thread services/search/pkg/content/tika.go Resolved
Comment thread services/search/pkg/search/service.go Resolved
Comment thread services/search/pkg/bleve/backend.go Resolved
Comment thread services/search/pkg/search/service.go Resolved
@butonic

butonic commented Nov 24, 2026

Copy link
Copy Markdown
Member

the only downside is that old failed resources are marked as ok!

mostly not, AFAICT: before this PR a failed extraction did not index the resource at all, so isIndexed hits ErrResourceNotFound and retries it after the upgrade anyway. Only the ones the old code indexed as a success with empty content ([] and the container exceptions you now detect) stay as they are, and a forced rescan fixes those.

One thing left IMO: deterministic failures like an encrypted pdf are now retried on every IndexSpace of the space, which every upload triggers ... so each of them is downloaded and sent to tika again and again. Could we only retry when the mtime changed, or cap the retries? Not a blocker if you'd rather do that in a follow up.

butonic

This comment was marked as outdated.

@butonic

This comment was marked as outdated.

@butonic

butonic commented Nov 24, 2026

Copy link
Copy Markdown
Member

Changed my mind on the follow up: the counter changes what we store in the index, and if ExtractionFailed ships in a release we have to deal with both fields or migrate. Let's do ExtractionFailures (and ErrUnparsable) in this PR so the stored format is right from the start.

@butonic

butonic commented Nov 24, 2026

Copy link
Copy Markdown
Member

The retry delays are a lower bound: RetryAt is only checked when a walk of the space runs, and those are only triggered by events in that space or a manual opencloud search index. In a quiet space a failed file is never retried. Could you adjust the README so it says "tried again on the first reindex of its space after one hour / one day" instead of suggesting a timer?

Related: on a transient error (tika unreachable, 5xx, timeout, download failed) we now write nothing at all, so a new file uploaded while tika is down is not findable by name until a walk after tika is back. Tagging it does not help either, the UpdateMetadata fallback fails the same way. We could reuse the struct for that: if there is no entry yet, write the basic doc with ExtractionFailure{Count: 0, RetryAt: now + a few minutes}. isIndexed retries it once RetryAt is due, it does not count towards the cap, and the stored format stays the same. Existing entries keep their old content like now.

An actual timer could be a ticker that queries for entries whose RetryAt is due and upserts just those, without walking the space. It doesn't change what we store, so that is fine as a follow up IMO.

@fschade
fschade enabled auto-merge November 24, 2026 17:04
@fschade
fschade merged commit 93a514c into opencloud-eu:main Nov 24, 2026
61 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenCloud Team Board Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants