From 7730587120eb7f4b5cc5e0dc1630e63cca24319c Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Wed, 10 Apr 2013 08:37:03 -0700 Subject: [PATCH] Prevent segfault in OpenCompactionOutputFile Summary: The segfault was happening because the program was unable to open a new sst file (as part of the compaction) because the process ran out of file descriptors. The fix is to check the return status of the file creation before taking any other action. Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fabf03f9700 (LWP 29904)] leveldb::DBImpl::OpenCompactionOutputFile (this=this@entry=0x7fabf9011400, compact=compact@entry=0x7fabf741a2b0) at db/db_impl.cc:1399 1399 db/db_impl.cc: No such file or directory. (gdb) where Test Plan: make check Reviewers: MarkCallaghan, sheki Reviewed By: MarkCallaghan CC: leveldb Differential Revision: https://reviews.facebook.net/D10101 --- db/db_impl.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 4c2728c2f..a49d595c9 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1393,12 +1393,12 @@ Status DBImpl::OpenCompactionOutputFile(CompactionState* compact) { std::string fname = TableFileName(dbname_, file_number); Status s = env_->NewWritableFile(fname, &compact->outfile, storage_options_); - // Over-estimate slightly so we don't end up just barely crossing - // the threshold. - compact->outfile->SetPreallocationBlockSize( - 1.1 * versions_->MaxFileSizeForLevel(compact->compaction->level() + 1)); - if (s.ok()) { + // Over-estimate slightly so we don't end up just barely crossing + // the threshold. + compact->outfile->SetPreallocationBlockSize( + 1.1 * versions_->MaxFileSizeForLevel(compact->compaction->level() + 1)); + compact->builder.reset(new TableBuilder(options_, compact->outfile.get(), compact->compaction->level() + 1)); }