diff --git a/db/table_cache.cc b/db/table_cache.cc index 852d048a3..2e7c58957 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -98,7 +98,11 @@ Status TableCache::GetTableReader( RecordTick(ioptions_.statistics, NO_FILE_OPENS); if (s.ok()) { - if (readahead > 0) { + if (readahead > 0 && !env_options.use_mmap_reads) { + // Not compatible with mmap files since ReadaheadRandomAccessFile requires + // its wrapped file's Read() to copy data into the provided scratch + // buffer, which mmap files don't use. + // TODO(ajkr): try madvise for mmap files in place of buffered readahead. file = NewReadaheadRandomAccessFile(std::move(file), readahead); } if (!sequential_mode && ioptions_.advise_random_on_open) { diff --git a/util/file_reader_writer.cc b/util/file_reader_writer.cc index 9d4298b1e..aa8ca30b0 100644 --- a/util/file_reader_writer.cc +++ b/util/file_reader_writer.cc @@ -622,6 +622,7 @@ class ReadaheadRandomAccessFile : public RandomAccessFile { if (s.ok()) { buffer_offset_ = offset; buffer_len_ = result.size(); + assert(buffer_.BufferStart() == result.data()); } return s; }