Skip to content

Commit 71eb4af

Browse files
committed
LevelDB: use PosixWriteableFile only on MacOS X
mmap is proven on the other platforms, we are not changing it at the last moment before release.
1 parent 00aff76 commit 71eb4af

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/leveldb/util/env_posix.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ class PosixMmapFile : public WritableFile {
377377
}
378378
};
379379

380+
#if defined(OS_MACOSX)
380381
class PosixWriteableFile : public WritableFile {
381382
private:
382383
std::string filename_;
@@ -461,6 +462,7 @@ class PosixWriteableFile : public WritableFile {
461462
return s;
462463
}
463464
};
465+
#endif
464466

465467
static int LockOrUnlock(int fd, bool lock) {
466468
errno = 0;
@@ -524,6 +526,23 @@ class PosixEnv : public Env {
524526
int fd = open(fname.c_str(), O_RDONLY);
525527
if (fd < 0) {
526528
s = IOError(fname, errno);
529+
#if !defined(OS_MACOSX)
530+
} else if (mmap_limit_.Acquire()) {
531+
uint64_t size;
532+
s = GetFileSize(fname, &size);
533+
if (s.ok()) {
534+
void* base = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
535+
if (base != MAP_FAILED) {
536+
*result = new PosixMmapReadableFile(fname, base, size, &mmap_limit_);
537+
} else {
538+
s = IOError(fname, errno);
539+
}
540+
}
541+
close(fd);
542+
if (!s.ok()) {
543+
mmap_limit_.Release();
544+
}
545+
#endif
527546
} else {
528547
*result = new PosixRandomAccessFile(fname, fd);
529548
}
@@ -538,7 +557,11 @@ class PosixEnv : public Env {
538557
*result = NULL;
539558
s = IOError(fname, errno);
540559
} else {
560+
#if defined(OS_MACOSX)
541561
*result = new PosixWriteableFile(fname, fd);
562+
#else
563+
*result = new PosixMmapFile(fname, fd, page_size_);
564+
#endif
542565
}
543566
return s;
544567
}

0 commit comments

Comments
 (0)