google / google/leveldb

PosixMmapFile which using ftruncate+mmap may crash on Append() while the disk have no enough space

Open
#150 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
39.4k
Forks
8.2k
PR merge metrics
No merged PRs in 30d

Description

Original [issue 144](https://code.google.com/p/leveldb/issues/detail?id=144) created by xjason.li on 2013-02-05T06:21:07.000Z:

What steps will reproduce the problem?
1. Write to a leveldb DB on a almost full disk.
2. Continue Writing to DB until there is no space for *.log file to append to, or no space for a *.sst to compact.

What is the expected output? What do you see instead?

EXPECTED: `DB::Wirte()/DB::Put()` interface should return `Status::IOError()` with message like "No space left on device".
But the process crashed, with SIGBUS signal. The backtrace was(on linux):

```
#0 0x00000036b6936f47 in __memcpy_ssse3 () from /lib64/libc.so.6
#1 0x00007f5f56f70232 in leveldb::(anonymous namespace)::PosixMmapFile::Append (this=0x10185a0, data=) at util/env_posix.cc:227
```

What version of the product are you using? On what operating system?
Version: 1.5.0 ( version 1.6 & 1.7 also have this problem as the implementation of PosixMmapFile was not changed)
OS: Linux x86_64 2.6.32 (CentOS 6.2), FreeBSD 7.2

Please provide any additional information below.
We have encountered this problem on our data storage server.

If you want to reproduce this bug, an easy way is to use tmpfs to create a small in-memory filesystem, and write the DB to it.

I understand why this happen: When ftruncate() is called, the filesystem will not actually allocate blocks for the file. After the file is mmaped to the vm, the read/write operation will cause os to load the non-exists blocks. Finally, OS treat this operation as a invalid memory access.

I'm wondering is there a good way to avoid this bug when using ftruncate+mmap.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.