Make doc values skip index extensible and add DocValuesField/SkipStat<T> API#16358
Make doc values skip index extensible and add DocValuesField/SkipStat<T> API#16358sgup432 wants to merge 6 commits into
Conversation
|
Example of how the data layout on the disk changes after this PR: Before (fixed schema, version ≤ 2): After (stats-based, version 3): After, with a future stat (sum) added: |
|
@romseygeek Looking for your suggestion on this. In a nutshell, this change is to allow anyone to add bits of information in skip index with more ease without having to bump version everytime, recalculate the jump table and add more version checks during read (all of which looks very painful). |
|
Thanks for opening @sgup432! My main worry around extending skip indexes is actually on the read side - it's really not obvious to me yet how we can make it clear which stats are available on an index, and indeed how those stats should be accessed without polluting the API. I sent a message to the dev list a few days ago about making Codec-specific data structures available on LeafReader with a possible solution. |
|
@romseygeek Yeah I agree on the read side of things and that we have been polluting doc values skipper interface. I do remember the email you sent out. I did think about it, and have had few ideas to solve it, maybe we will follow up with another PR. |
|
@romseygeek I have opened a draft PR here - sgup432#1 on top of this PR. Basically showcasing how we can read the stats available for a field, building on top of this PR nicely. Essentially it exposes two API:
Also did some did integration in some places(for reference) to fetch stats from DocValuesField without opening the skip index file. |
|
@romseygeek I have added above mentioned change here ie for the read side. Namely the APIs - DocValueField, SkipStat. Makes it easier for anyone to extend the current lucene codecs, and write their own pretty easily without changing lucene core. |
Description
As of today, if someone needs to add a new metadata or stats in the skip index, it requires a version bump every time, changing the skip index jump table value to the updated value which takes into account of the size from new changes, and then accordingly during read, add version checks to read those extra values. This is because the skip index uses a fixed schema where every byte position is predetermined, so the reader navigates purely by precomputed offsets and any new field invalidates them. For example, PR #15737 adds pre-aggregated sum and value count per interval to the skip index, which required a backward compatibility commit, recalculating the fixed byte offsets, and gating reads behind version checks.
I feel this is pretty cumbersome and error prone if we need to add new metadata every time. With this PR, I have replaced the fixed-schema layout with length-prefixed, type-tagged entries. Each stat is identified by a type byte, and the reader uses stored lengths to skip over anything it doesn't recognize. This means future stats can be appended by simply writing a new type tag in the writer and adding a case in the reader's switch, with no version bump, no jump table recalculation, and older readers that don't know about the new stat will just skip past it harmlessly.
For example, adding a new stats(eg: sum like mentioned above) after this PR: