From dfe96c72c3a8a99e446c4b0613aed1374355ab9c Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Thu, 3 Mar 2016 18:25:07 -0800 Subject: [PATCH] Fix WriteLevel0TableForRecovery file delete protection Summary: The call to ``` CaptureCurrentFileNumberInPendingOutputs() ``` should be before ``` versions_->NewFileNumber() ``` Right now we are not actually protecting the file from being deleted Test Plan: make check Reviewers: sdong, anthony, yhchiang Reviewed By: yhchiang Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D54645 --- db/db_impl.cc | 2 +- db/db_impl.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index eb46811ae..153b605a8 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1386,9 +1386,9 @@ Status DBImpl::WriteLevel0TableForRecovery(int job_id, ColumnFamilyData* cfd, mutex_.AssertHeld(); const uint64_t start_micros = env_->NowMicros(); FileMetaData meta; - meta.fd = FileDescriptor(versions_->NewFileNumber(), 0, 0); auto pending_outputs_inserted_elem = CaptureCurrentFileNumberInPendingOutputs(); + meta.fd = FileDescriptor(versions_->NewFileNumber(), 0, 0); ReadOptions ro; ro.total_order_seek = true; Arena arena; diff --git a/db/db_impl.h b/db/db_impl.h index e0d10e99e..f068fe084 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -494,10 +494,11 @@ class DBImpl : public DB { // Background process needs to call // auto x = CaptureCurrentFileNumberInPendingOutputs() + // auto file_num = versions_->NewFileNumber(); // // ReleaseFileNumberFromPendingOutputs(x) - // This will protect any temporary files created while is - // executing from being deleted. + // This will protect any file with number `file_num` or greater from being + // deleted while is running. // ----------- // This function will capture current file number and append it to // pending_outputs_. This will prevent any background process to delete any