Skip to content

Fix infostream_to_segments.py to parse compact segment descriptors#597

Merged
mikemccand merged 1 commit into
mikemccand:mainfrom
jerinthomas1404:fix/parse-compact-segment-descriptors
Jul 23, 2026
Merged

Fix infostream_to_segments.py to parse compact segment descriptors#597
mikemccand merged 1 commit into
mikemccand:mainfrom
jerinthomas1404:fix/parse-compact-segment-descriptors

Conversation

@jerinthomas1404

@jerinthomas1404 jerinthomas1404 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

The parser fails with RuntimeError: failed to parse the expected N number of sogments when InfoStream logs contain compact segment descriptors like _4(10.4.0):C8782/109 instead of the verbose form with the full :[diagnostics={...}]:[attributes={...}] :id=... trailer.

Two changes:

  1. Make the verbose trailer optional in re_segment_desc by wrapping it in a non-capturing group (?:...)?. Group numbering (1-8) is preserved so all downstream consumers work unchanged.

This needs to be discussed with @mikemccand

  1. Handle empty diagnostics in parse_seg_details() by defaulting to source = "flush" instead of raising. This is correct for the common case (writer starting from empty index) where the real flush/merge origin is derived from flush postings as segment and merge seg= events independently.

Fixes #596

@mikemccand

Copy link
Copy Markdown
Owner

Phew, good catch, thank you @jerinthomas1404 -- this is from recent optimizations to reduce the insane verbosity of IndexWriter InfoStream logs: apache/lucene#15885

That change logs the verbose details for a segment exactly once, when the segment is born, and skips it thereafter. We don't lose any information because those verbose details never change for a segment. The one place we do lose just a bit is when there is a pre-existing index when IndexWriter first inits -- in that case the verbose details (carryover from prior IndexWriter that created those segments) are lost -- I think that's the case leading to your 2nd question above. That's fine -- we really should extend this tool to stitch together N InfoStreams.

@mikemccand mikemccand left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you @jerinthomas1404!

Comment thread src/python/infostream_to_segments.py Outdated
Comment thread src/python/infostream_to_segments.py
Comment thread src/python/infostream_to_segments.py Outdated
@jerinthomas1404
jerinthomas1404 force-pushed the fix/parse-compact-segment-descriptors branch from 87d6097 to e927ca0 Compare July 20, 2026 16:45
Comment thread src/python/infostream_to_segments.py Outdated


# When diagnostics are unavailable (compact segment descriptors from pre-existing
# index segments), we assume "merge" as the default source since long-lived

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Actually, from your response to my first comment on my last review it looks like Lucene should include the full verbose diagnostics of those initial segments? Let's fix the comment -- maybe change to something like "compact segment descriptors because the verbose version was already logged once for this segment" or so?

Or are you seeing pre-existing segments failing to have verbosity in a new IndexWriter?

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.

@mikemccand , you're correct, I have verified the upstream code and the init verbose log runs unconditionally.

I have rephrased the comment as below

Fallback when parsing a log that doesn't contain the verbose segment details
(e.g. truncated log missing the init/flush/merge birth line). We assume
"merge" since long-lived indices are dominated by merged segments

@jerinthomas1404
jerinthomas1404 force-pushed the fix/parse-compact-segment-descriptors branch 2 times, most recently from 735d5e4 to 06414b1 Compare July 22, 2026 20:26
Since apache/lucene#15885, IndexWriter emits verbose segment details
(diagnostics, attributes, id) only once at segment creation using
write-once semantics.  Subsequent references use a compact form like
`_4(10.4.0):C8782/109` with no trailing metadata.

Two changes:

1. Make the verbose trailer optional in `re_segment_desc` by wrapping
   it in a non-capturing group `(?:...)?`.  Group numbering (1-8) is
   preserved so all downstream consumers work unchanged.

2. Handle empty `diagnostics` in `parse_seg_details()` by defaulting
   to `DEFAULT_SEGMENT_SOURCE = ("merge", [])` — long-lived indices
   are dominated by merged segments, making merge the better heuristic
   for pre-existing segments whose origin is unknown.

Fixes mikemccand#596
@jerinthomas1404
jerinthomas1404 force-pushed the fix/parse-compact-segment-descriptors branch from 06414b1 to 3c83552 Compare July 22, 2026 20:34

@mikemccand mikemccand left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks great! Thank you @jerinthomas1404 -- I'll merge.

@mikemccand
mikemccand merged commit 50f41d3 into mikemccand:main Jul 23, 2026
1 check passed
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.

Infostream_to_segments.py fails to parse compact segment descriptors

2 participants