2013-10-16 21:59:46 +00:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2012-09-15 00:11:35 +00:00
|
|
|
// Copyright (c) 2012 Facebook.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
2012-11-29 00:42:36 +00:00
|
|
|
// found in the LICENSE file.
|
2012-09-15 00:11:35 +00:00
|
|
|
|
2014-04-15 20:39:26 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2014-09-05 06:14:37 +00:00
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
2014-04-03 23:04:10 +00:00
|
|
|
#define __STDC_FORMAT_MACROS
|
2014-09-05 06:14:37 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-03 23:04:10 +00:00
|
|
|
#include <inttypes.h>
|
2013-08-06 19:54:37 +00:00
|
|
|
#include <algorithm>
|
2012-09-15 00:11:35 +00:00
|
|
|
#include <string>
|
|
|
|
#include <stdint.h>
|
2013-08-06 19:54:37 +00:00
|
|
|
#include "db/db_impl.h"
|
|
|
|
#include "db/filename.h"
|
2014-11-14 23:43:10 +00:00
|
|
|
#include "db/job_context.h"
|
2012-09-15 00:11:35 +00:00
|
|
|
#include "db/version_set.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/env.h"
|
2012-09-15 00:11:35 +00:00
|
|
|
#include "port/port.h"
|
|
|
|
#include "util/mutexlock.h"
|
2014-03-24 04:49:14 +00:00
|
|
|
#include "util/sync_point.h"
|
2014-11-14 19:38:26 +00:00
|
|
|
#include "util/file_util.h"
|
2012-09-15 00:11:35 +00:00
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2012-09-15 00:11:35 +00:00
|
|
|
|
|
|
|
Status DBImpl::DisableFileDeletions() {
|
2015-02-05 05:39:45 +00:00
|
|
|
InstrumentedMutexLock l(&mutex_);
|
2014-01-02 11:33:42 +00:00
|
|
|
++disable_delete_obsolete_files_;
|
|
|
|
if (disable_delete_obsolete_files_ == 1) {
|
2014-10-29 21:06:14 +00:00
|
|
|
Log(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
|
|
|
|
"File Deletions Disabled");
|
2014-05-20 21:28:51 +00:00
|
|
|
} else {
|
2014-10-29 21:06:14 +00:00
|
|
|
Log(InfoLogLevel::WARN_LEVEL, db_options_.info_log,
|
2014-05-20 21:28:51 +00:00
|
|
|
"File Deletions Disabled, but already disabled. Counter: %d",
|
|
|
|
disable_delete_obsolete_files_);
|
2014-01-02 11:33:42 +00:00
|
|
|
}
|
2012-09-15 00:11:35 +00:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2014-01-02 11:33:42 +00:00
|
|
|
Status DBImpl::EnableFileDeletions(bool force) {
|
2015-02-12 17:54:48 +00:00
|
|
|
// Job id == 0 means that this is not our background process, but rather
|
|
|
|
// user thread
|
|
|
|
JobContext job_context(0);
|
2014-01-02 11:33:42 +00:00
|
|
|
bool should_purge_files = false;
|
2013-11-08 23:23:46 +00:00
|
|
|
{
|
2015-02-05 05:39:45 +00:00
|
|
|
InstrumentedMutexLock l(&mutex_);
|
2014-01-02 11:33:42 +00:00
|
|
|
if (force) {
|
|
|
|
// if force, we need to enable file deletions right away
|
|
|
|
disable_delete_obsolete_files_ = 0;
|
|
|
|
} else if (disable_delete_obsolete_files_ > 0) {
|
|
|
|
--disable_delete_obsolete_files_;
|
|
|
|
}
|
|
|
|
if (disable_delete_obsolete_files_ == 0) {
|
2014-10-29 21:06:14 +00:00
|
|
|
Log(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
|
|
|
|
"File Deletions Enabled");
|
2014-01-02 11:33:42 +00:00
|
|
|
should_purge_files = true;
|
2014-10-28 18:54:33 +00:00
|
|
|
FindObsoleteFiles(&job_context, true);
|
2014-05-20 21:28:51 +00:00
|
|
|
} else {
|
2014-10-29 21:06:14 +00:00
|
|
|
Log(InfoLogLevel::WARN_LEVEL, db_options_.info_log,
|
2014-05-20 21:28:51 +00:00
|
|
|
"File Deletions Enable, but not really enabled. Counter: %d",
|
|
|
|
disable_delete_obsolete_files_);
|
2014-01-02 11:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (should_purge_files) {
|
2014-10-28 18:54:33 +00:00
|
|
|
PurgeObsoleteFiles(job_context);
|
2013-11-08 23:23:46 +00:00
|
|
|
}
|
2014-11-15 00:57:17 +00:00
|
|
|
job_context.Clean();
|
2014-09-05 18:48:17 +00:00
|
|
|
LogFlush(db_options_.info_log);
|
2012-09-15 00:11:35 +00:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2014-08-26 23:26:29 +00:00
|
|
|
int DBImpl::IsFileDeletionsEnabled() const {
|
|
|
|
return disable_delete_obsolete_files_;
|
|
|
|
}
|
|
|
|
|
2012-11-29 00:42:36 +00:00
|
|
|
Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
|
2013-10-03 21:38:32 +00:00
|
|
|
uint64_t* manifest_file_size,
|
|
|
|
bool flush_memtable) {
|
2012-09-24 21:01:01 +00:00
|
|
|
|
|
|
|
*manifest_file_size = 0;
|
2012-09-15 00:11:35 +00:00
|
|
|
|
2014-02-25 21:16:59 +00:00
|
|
|
mutex_.Lock();
|
|
|
|
|
2013-10-03 21:38:32 +00:00
|
|
|
if (flush_memtable) {
|
|
|
|
// flush all dirty data to disk.
|
2014-02-25 21:16:59 +00:00
|
|
|
Status status;
|
|
|
|
for (auto cfd : *versions_->GetColumnFamilySet()) {
|
2015-03-20 00:04:29 +00:00
|
|
|
if (cfd->IsDropped()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-25 21:16:59 +00:00
|
|
|
cfd->Ref();
|
|
|
|
mutex_.Unlock();
|
|
|
|
status = FlushMemTable(cfd, FlushOptions());
|
|
|
|
mutex_.Lock();
|
2014-04-07 21:21:25 +00:00
|
|
|
cfd->Unref();
|
2014-02-25 21:16:59 +00:00
|
|
|
if (!status.ok()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-04-07 21:21:25 +00:00
|
|
|
versions_->GetColumnFamilySet()->FreeDeadColumnFamilies();
|
|
|
|
|
2013-10-03 21:38:32 +00:00
|
|
|
if (!status.ok()) {
|
2014-02-25 21:16:59 +00:00
|
|
|
mutex_.Unlock();
|
2014-10-29 21:06:14 +00:00
|
|
|
Log(InfoLogLevel::ERROR_LEVEL, db_options_.info_log,
|
|
|
|
"Cannot Flush data %s\n", status.ToString().c_str());
|
2013-10-03 21:38:32 +00:00
|
|
|
return status;
|
|
|
|
}
|
2012-09-15 00:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make a set of all of the live *.sst files
|
2014-07-02 16:54:20 +00:00
|
|
|
std::vector<FileDescriptor> live;
|
2014-02-07 22:47:16 +00:00
|
|
|
for (auto cfd : *versions_->GetColumnFamilySet()) {
|
2015-03-20 00:04:29 +00:00
|
|
|
if (cfd->IsDropped()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-07 22:47:16 +00:00
|
|
|
cfd->current()->AddLiveFiles(&live);
|
|
|
|
}
|
2012-09-15 00:11:35 +00:00
|
|
|
|
2013-08-29 21:30:52 +00:00
|
|
|
ret.clear();
|
|
|
|
ret.reserve(live.size() + 2); //*.sst + CURRENT + MANIFEST
|
2012-09-15 00:11:35 +00:00
|
|
|
|
|
|
|
// create names of the live files. The names are not absolute
|
|
|
|
// paths, instead they are relative to dbname_;
|
2013-08-29 21:30:52 +00:00
|
|
|
for (auto live_file : live) {
|
2014-07-02 16:54:20 +00:00
|
|
|
ret.push_back(MakeTableFileName("", live_file.GetNumber()));
|
2012-09-15 00:11:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 21:30:52 +00:00
|
|
|
ret.push_back(CurrentFileName(""));
|
2014-11-04 01:45:55 +00:00
|
|
|
ret.push_back(DescriptorFileName("", versions_->manifest_file_number()));
|
2012-09-15 00:11:35 +00:00
|
|
|
|
2012-09-24 21:01:01 +00:00
|
|
|
// find length of manifest file while holding the mutex lock
|
2014-11-04 01:45:55 +00:00
|
|
|
*manifest_file_size = versions_->manifest_file_size();
|
2012-09-24 21:01:01 +00:00
|
|
|
|
2014-02-25 21:16:59 +00:00
|
|
|
mutex_.Unlock();
|
2012-09-15 00:11:35 +00:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2013-08-06 19:54:37 +00:00
|
|
|
Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
|
2014-10-30 00:43:37 +00:00
|
|
|
return wal_manager_.GetSortedWalFiles(files);
|
2013-08-06 19:54:37 +00:00
|
|
|
}
|
2014-11-14 19:38:26 +00:00
|
|
|
|
2012-09-15 00:11:35 +00:00
|
|
|
}
|
2014-04-15 20:39:26 +00:00
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|