File tree 3 files changed +35
-1
lines changed
java/org/apache/lucene/misc/store
test/org/apache/lucene/misc/store
3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,8 @@ Bug Fixes
133
133
134
134
* GITHUB#14215: Fix degenerate case in HNSW where all vectors have the same score. (Ben Trent)
135
135
136
+ * GITHUB#14320: Fix DirectIOIndexInput seek to not read when position is within buffer (Chris Hegarty)
137
+
136
138
Changes in Runtime Behavior
137
139
---------------------
138
140
* GITHUB#14189: Bump floor segment size to 16MB in TieredMergePolicy and
Original file line number Diff line number Diff line change @@ -373,7 +373,13 @@ public long getFilePointer() {
373
373
@ Override
374
374
public void seek (long pos ) throws IOException {
375
375
if (pos != getFilePointer ()) {
376
- seekInternal (pos );
376
+ final long absolutePos = pos + offset ;
377
+ if (absolutePos >= filePos && absolutePos <= filePos + buffer .limit ()) {
378
+ // the new position is within the existing buffer
379
+ buffer .position (Math .toIntExact (absolutePos - filePos ));
380
+ } else {
381
+ seekInternal (pos ); // do an actual seek/read
382
+ }
377
383
}
378
384
assert pos == getFilePointer ();
379
385
}
Original file line number Diff line number Diff line change @@ -209,4 +209,30 @@ public void testUseDirectIODefaults() throws Exception {
209
209
OptionalLong .of (largeSize )));
210
210
}
211
211
}
212
+
213
+ // Ping-pong seeks should be really fast, since the position should be within buffer.
214
+ // The test should complete within sub-second times, not minutes.
215
+ public void testSeekSmall () throws IOException {
216
+ Path tmpDir = createTempDir ("testSeekSmall" );
217
+ try (Directory dir = getDirectory (tmpDir )) {
218
+ int len = atLeast (100 );
219
+ try (IndexOutput o = dir .createOutput ("out" , newIOContext (random ()))) {
220
+ byte [] b = new byte [len ];
221
+ for (int i = 0 ; i < len ; i ++) {
222
+ b [i ] = (byte ) i ;
223
+ }
224
+ o .writeBytes (b , 0 , len );
225
+ }
226
+ try (IndexInput in = dir .openInput ("out" , newIOContext (random ()))) {
227
+ for (int i = 0 ; i < 100_000 ; i ++) {
228
+ in .seek (2 );
229
+ assertEquals (2 , in .readByte ());
230
+ in .seek (1 );
231
+ assertEquals (1 , in .readByte ());
232
+ in .seek (0 );
233
+ assertEquals (0 , in .readByte ());
234
+ }
235
+ }
236
+ }
237
+ }
212
238
}
You can’t perform that action at this time.
0 commit comments