@@ -461,26 +461,38 @@ public boolean commit(final int commitLeastPages) {
461
461
*/
462
462
public MappedFile findMappedFileByOffset (final long offset , final boolean returnFirstOnNotFound ) {
463
463
try {
464
- MappedFile mappedFile = this .getFirstMappedFile ();
465
- if (mappedFile != null ) {
466
- int index = (int ) ((offset / this .mappedFileSize ) - (mappedFile .getFileFromOffset () / this .mappedFileSize ));
464
+ MappedFile firstMappedFile = this .getFirstMappedFile ();
465
+ if (firstMappedFile != null ) {
466
+ int index = (int ) ((offset / this .mappedFileSize ) - (firstMappedFile .getFileFromOffset () / this .mappedFileSize ));
467
467
if (index < 0 || index >= this .mappedFiles .size ()) {
468
- LOG_ERROR .warn ("Offset for {} not matched. Request offset: {}, index: {}, " +
469
- "mappedFileSize: {}, mappedFiles count: {}" ,
470
- mappedFile ,
468
+ LOG_ERROR .warn ("Offset for {} not matched. Request offset: {}, index: {}, mappedFileSize: {}, mappedFiles count: {}" ,
469
+ firstMappedFile ,
471
470
offset ,
472
471
index ,
473
472
this .mappedFileSize ,
474
473
this .mappedFiles .size ());
475
- }
474
+ } else {
475
+ MappedFile targetFile = null ;
476
+ try {
477
+ targetFile = this .mappedFiles .get (index );
478
+ } catch (Exception ignored ) {
479
+ }
476
480
477
- try {
478
- return this .mappedFiles .get (index );
479
- } catch (Exception e ) {
480
- if (returnFirstOnNotFound ) {
481
- return mappedFile ;
481
+ if (targetFile != null && offset >= targetFile .getFileFromOffset ()
482
+ && offset < targetFile .getFileFromOffset () + this .mappedFileSize ) {
483
+ return targetFile ;
482
484
}
483
- LOG_ERROR .warn ("findMappedFileByOffset failure. " , e );
485
+
486
+ for (MappedFile tmpMappedFile : this .mappedFiles ) {
487
+ if (offset >= tmpMappedFile .getFileFromOffset ()
488
+ && offset < tmpMappedFile .getFileFromOffset () + this .mappedFileSize ) {
489
+ return tmpMappedFile ;
490
+ }
491
+ }
492
+ }
493
+
494
+ if (returnFirstOnNotFound ) {
495
+ return firstMappedFile ;
484
496
}
485
497
}
486
498
} catch (Exception e ) {
0 commit comments