From 6e08916eb390c8c6d7486098079836e6804e9ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=8F=E4=B9=8B=E7=AB=A0?= Date: Fri, 25 May 2018 10:47:56 -0700 Subject: [PATCH] Fix Fadvise on closed file when reads use mmap Summary: ```PosixMmapReadableFile::fd_``` is closed after created, but needs to remain open for the lifetime of `PosixMmapReadableFile` since it is used whenever `InvalidateCache` is called. Closes https://github.com/facebook/rocksdb/pull/2764 Differential Revision: D8152515 Pulled By: ajkr fbshipit-source-id: b738a6a55ba4e392f9b0f374ff396a1e61c64f65 --- env/env_posix.cc | 2 +- env/io_posix.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/env/env_posix.cc b/env/env_posix.cc index 660b3cf07a..e04eb5bf4d 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -241,9 +241,9 @@ class PosixEnv : public Env { size, options)); } else { s = IOError("while mmap file for read", fname, errno); + close(fd); } } - close(fd); } else { if (options.use_direct_reads && !options.use_mmap_reads) { #ifdef OS_MACOSX diff --git a/env/io_posix.cc b/env/io_posix.cc index 0e067b4e83..216fc897ee 100644 --- a/env/io_posix.cc +++ b/env/io_posix.cc @@ -456,6 +456,7 @@ PosixMmapReadableFile::~PosixMmapReadableFile() { fprintf(stdout, "failed to munmap %p length %" ROCKSDB_PRIszt " \n", mmapped_region_, length_); } + close(fd_); } Status PosixMmapReadableFile::Read(uint64_t offset, size_t n, Slice* result,