We should fix the code to throw the exception immediately. Is there a way to check a Directory if it's old or not?
I agree – IW.open should fail immediately if any of the segments are too old.
Unfortunately, I don't see a simple way to do this. We can't just look at the version of the segments_N file, for example, because one segment could be from 2.9, and [say] 3.1 had last opened the index and written the 3.x file format for segments_N. See, IW does not go and open all SegmentReaders on open. It's only on merge, applying deletes, or opening an NRT reader, that we go and open segments for reading.
I think to do this correctly we should modify segments_N format to record the oldest segment in the index? Then IW can check this easily on open.
I don't mind if you continue w/ the fix to the test as you did, but IMO it just hides the real problem. I.e., allowing all merges caused by optimize() to finish is a correct fix.
There is already a pre-existing TODO in the test stating that we should fix IW to throw this exc on open. I'll also add a TODO to IW's ctor and go open an issue...