Skip to content

Read legacy text index directory without probing consolidated entry when it exists#18919

Open
xiangfu0 wants to merge 1 commit into
apache:masterfrom
xiangfu0:fix-text-index-legacy-directory-probe
Open

Read legacy text index directory without probing consolidated entry when it exists#18919
xiangfu0 wants to merge 1 commit into
apache:masterfrom
xiangfu0:fix-text-index-legacy-directory-probe

Conversation

@xiangfu0

@xiangfu0 xiangfu0 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Problem

With storeInSegmentFile=true, TextIndexType.ReaderFactory probed the consolidated segment-file entry (segmentReader.getIndexFor(column, StandardIndexes.text())) unconditionally.

On a V1/V2 segment backed by FilePerIndexDirectory whose column still has the legacy Lucene text-index directory on disk, getFileFor resolves that directory (File.exists() is true for directories) and mapForReads rejects it with IllegalArgumentException: File: ... must be a regular file — killing the whole segment load before any fallback can run. This makes flipping storeInSegmentFile=true non-rolling-upgrade-safe for existing V1/V2 text segments.

TextIndexHandler cannot rescue these segments either: its combined-format conversion is v3-gated, so the reader factory must handle them.

This is the text-index twin of the vector index bug fixed in #18852.

Fix

Legacy-directory-first gate, same pattern as #18852: if SegmentDirectoryPaths.findTextIndexIndexFile finds a Lucene directory on disk (an unmigrated V3 segment, or any V1/V2 segment), construct the directory-based LuceneTextIndexReader directly and skip the consolidated probe entirely. The probe only runs when no legacy directory exists.

Tests

New TextIndexTypeTest mirrors the vector regression tests:

  • testReaderFactoryUsesLegacyTextDirectoryWithoutProbingConsolidatedEntry — builds a real legacy Lucene text index in the V1 root layout, stubs getIndexFor to throw IllegalArgumentException("... must be a regular file"), asserts the reader is constructed, serves queries, and the probe never runs.
  • testReaderFactoryUsesLegacyTextDirectoryInV3LayoutWithoutProbing — same for the v3/ subdirectory layout.

Both tests fail without the fix (verified by stashing the main change) and pass with it.

@xiangfu0
xiangfu0 force-pushed the fix-text-index-legacy-directory-probe branch from cb8749f to 12939e2 Compare July 5, 2026 19:25
@codecov-commenter

codecov-commenter commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.24%. Comparing base (fd772ee) to head (ccf0cb7).

Files with missing lines Patch % Lines
...egment/local/segment/index/text/TextIndexType.java 57.14% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18919      +/-   ##
============================================
+ Coverage     65.21%   65.24%   +0.02%     
  Complexity     1405     1405              
============================================
  Files          3418     3418              
  Lines        214651   214652       +1     
  Branches      33922    33923       +1     
============================================
+ Hits         139989   140041      +52     
+ Misses        63356    63335      -21     
+ Partials      11306    11276      -30     
Flag Coverage Δ
custom-integration1 100.00% <ø> (ø)
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 ?
java-21 65.24% <57.14%> (+0.02%) ⬆️
temurin 65.24% <57.14%> (+0.02%) ⬆️
unittests 65.23% <57.14%> (+0.02%) ⬆️
unittests1 56.88% <57.14%> (+0.02%) ⬆️
unittests2 37.74% <57.14%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xiangfu0
xiangfu0 force-pushed the fix-text-index-legacy-directory-probe branch 4 times, most recently from e7cf769 to 042febc Compare July 10, 2026 08:08

@xiangfu0 xiangfu0 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Found one high-signal SegmentDirectory correctness issue; see inline comment.

// directory and fails to map it (not a regular file), which would kill the segment load
// before any fallback could run. This keeps storeInSegmentFile=true rolling-upgrade-safe
// for existing text segments.
File legacyTextIndex = SegmentDirectoryPaths.findTextIndexIndexFile(segmentDir, metadata.getColumnName());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This probe needs the same local-directory guard used by the vector reader. SegmentDirectoryPaths.findTextIndexIndexFile() calls findFormatFile(), which requires segmentDir.isDirectory(). For a remote/tiered SegmentDirectory, getPath() can be a non-existent local path while getIndexFor() can still return the consolidated columns.psf buffer, so storeInSegmentFile=true can fail segment load before reading that buffer. Please guard the probe with segmentDir.isDirectory() and add a non-local consolidated-entry regression test like the vector reader has.

@xiangfu0
xiangfu0 force-pushed the fix-text-index-legacy-directory-probe branch from 042febc to b2c8049 Compare July 11, 2026 08:02

@xiangfu0 xiangfu0 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Found one high-signal issue; see inline comment.

// directory and fails to map it (not a regular file), which would kill the segment load
// before any fallback could run. This keeps storeInSegmentFile=true rolling-upgrade-safe
// for existing text segments.
File legacyTextIndex = SegmentDirectoryPaths.findTextIndexIndexFile(segmentDir, metadata.getColumnName());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This calls findTextIndexIndexFile() before trying the consolidated text-index entry, but that helper requires segmentDir to be a local directory. For non-local SegmentDirectory implementations, segment load can fail here before getIndexFor(..., text()) has a chance to read the valid columns.psf entry. The vector reader guards the same sidecar probe with segmentDir.isDirectory(); this path should do the same and add a non-local consolidated-entry regression test.

@xiangfu0
xiangfu0 force-pushed the fix-text-index-legacy-directory-probe branch 4 times, most recently from 4433c2f to ccf0cb7 Compare July 16, 2026 08:02
…hen it exists

With storeInSegmentFile=true, the text index reader factory probed the
consolidated segment-file entry (getIndexFor) unconditionally. On a V1/V2
segment backed by FilePerIndexDirectory, getIndexFor resolves the
still-present legacy Lucene text-index DIRECTORY and mapForReads rejects it
(IllegalArgumentException: must be a regular file), killing the segment load
before the legacy fallback could run — making the flag
non-rolling-upgrade-safe for existing text segments. TextIndexHandler cannot
rescue these segments because its combined-format conversion is v3-gated.

The factory now checks the on-disk artifact first: if it is a Lucene
directory (an unmigrated V3 segment, or any V1/V2 segment), read it directly
and skip the probe entirely. Same pattern as the vector index fix in apache#18852.

Tests cover both the V1 root layout and the v3/ subdirectory layout,
asserting the probe never runs while the legacy directory exists.
@xiangfu0
xiangfu0 force-pushed the fix-text-index-legacy-directory-probe branch from ccf0cb7 to 7b8c035 Compare July 17, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants