fixed leaking log::Writers

Summary: Fixes valgrind errors in column_family_test.

Test Plan: `make check`, `make valgrind_check`

Reviewers: igor, yhchiang

Reviewed By: yhchiang

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D41181
main
Yueh-Hsuan Chiang 10 years ago
parent 685582a0b4
commit 4ce5be4255
  1. 1
      db/column_family.cc
  2. 1
      db/db_impl.cc
  3. 1
      db/db_test.cc
  4. 1
      db/forward_iterator.cc
  5. 5
      db/job_context.h

@ -59,6 +59,7 @@ ColumnFamilyHandleImpl::~ColumnFamilyHandleImpl() {
if (job_context.HaveSomethingToDelete()) { if (job_context.HaveSomethingToDelete()) {
db_->PurgeObsoleteFiles(job_context); db_->PurgeObsoleteFiles(job_context);
} }
job_context.Clean();
} }
} }

@ -542,6 +542,7 @@ void DBImpl::FindObsoleteFiles(JobContext* job_context, bool force,
} }
// We're just cleaning up for DB::Write(). // We're just cleaning up for DB::Write().
assert(job_context->logs_to_free.empty());
job_context->logs_to_free = logs_to_free_; job_context->logs_to_free = logs_to_free_;
logs_to_free_.clear(); logs_to_free_.clear();

@ -12670,6 +12670,7 @@ TEST_F(DBTest, DontDeletePendingOutputs) {
dbfull()->FindObsoleteFiles(&job_context, true /*force*/); dbfull()->FindObsoleteFiles(&job_context, true /*force*/);
dbfull()->TEST_UnlockMutex(); dbfull()->TEST_UnlockMutex();
dbfull()->PurgeObsoleteFiles(job_context); dbfull()->PurgeObsoleteFiles(job_context);
job_context.Clean();
}; };
env_->table_write_callback_ = &purge_obsolete_files_function; env_->table_write_callback_ = &purge_obsolete_files_function;

@ -169,6 +169,7 @@ void ForwardIterator::Cleanup(bool release_sv) {
if (job_context.HaveSomethingToDelete()) { if (job_context.HaveSomethingToDelete()) {
db_->PurgeObsoleteFiles(job_context); db_->PurgeObsoleteFiles(job_context);
} }
job_context.Clean();
} }
} }
} }

@ -83,6 +83,10 @@ struct JobContext {
new_superversion = create_superversion ? new SuperVersion() : nullptr; new_superversion = create_superversion ? new SuperVersion() : nullptr;
} }
// For non-empty JobContext Clean() has to be called at least once before
// before destruction (see asserts in ~JobContext()). Should be called with
// unlocked DB mutex. Destructor doesn't call Clean() to avoid accidentally
// doing potentially slow Clean() with locked DB mutex.
void Clean() { void Clean() {
// free pending memtables // free pending memtables
for (auto m : memtables_to_free) { for (auto m : memtables_to_free) {
@ -109,6 +113,7 @@ struct JobContext {
assert(memtables_to_free.size() == 0); assert(memtables_to_free.size() == 0);
assert(superversions_to_free.size() == 0); assert(superversions_to_free.size() == 0);
assert(new_superversion == nullptr); assert(new_superversion == nullptr);
assert(logs_to_free.size() == 0);
} }
}; };

Loading…
Cancel
Save