2012-09-15 02:11:35 +02:00
|
|
|
// Copyright (c) 2012 Facebook.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
2012-11-29 01:42:36 +01:00
|
|
|
// found in the LICENSE file.
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2013-08-06 21:54:37 +02:00
|
|
|
#include <algorithm>
|
2012-09-15 02:11:35 +02:00
|
|
|
#include <string>
|
|
|
|
#include <stdint.h>
|
2013-08-06 21:54:37 +02:00
|
|
|
#include "db/db_impl.h"
|
|
|
|
#include "db/filename.h"
|
2012-09-15 02:11:35 +02:00
|
|
|
#include "db/version_set.h"
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/env.h"
|
2012-09-15 02:11:35 +02:00
|
|
|
#include "port/port.h"
|
|
|
|
#include "util/mutexlock.h"
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2012-09-15 02:11:35 +02:00
|
|
|
|
|
|
|
Status DBImpl::DisableFileDeletions() {
|
|
|
|
MutexLock l(&mutex_);
|
2012-11-29 01:42:36 +01:00
|
|
|
disable_delete_obsolete_files_ = true;
|
2013-06-05 19:48:24 +02:00
|
|
|
Log(options_.info_log, "File Deletions Disabled");
|
2012-09-15 02:11:35 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DBImpl::EnableFileDeletions() {
|
|
|
|
MutexLock l(&mutex_);
|
2012-11-29 01:42:36 +01:00
|
|
|
disable_delete_obsolete_files_ = false;
|
2013-06-05 19:48:24 +02:00
|
|
|
Log(options_.info_log, "File Deletions Enabled");
|
2012-09-15 02:11:35 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2012-11-29 01:42:36 +01:00
|
|
|
Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
|
2013-10-03 23:38:32 +02:00
|
|
|
uint64_t* manifest_file_size,
|
|
|
|
bool flush_memtable) {
|
2012-09-24 23:01:01 +02:00
|
|
|
|
|
|
|
*manifest_file_size = 0;
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2013-10-03 23:38:32 +02:00
|
|
|
if (flush_memtable) {
|
|
|
|
// flush all dirty data to disk.
|
|
|
|
Status status = Flush(FlushOptions());
|
|
|
|
if (!status.ok()) {
|
|
|
|
Log(options_.info_log, "Cannot Flush data %s\n",
|
|
|
|
status.ToString().c_str());
|
|
|
|
return status;
|
|
|
|
}
|
2012-09-15 02:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MutexLock l(&mutex_);
|
|
|
|
|
|
|
|
// Make a set of all of the live *.sst files
|
2012-11-29 01:42:36 +01:00
|
|
|
std::set<uint64_t> live;
|
2012-09-15 02:11:35 +02:00
|
|
|
versions_->AddLiveFilesCurrentVersion(&live);
|
|
|
|
|
2013-08-29 23:30:52 +02:00
|
|
|
ret.clear();
|
|
|
|
ret.reserve(live.size() + 2); //*.sst + CURRENT + MANIFEST
|
2012-09-15 02:11:35 +02:00
|
|
|
|
|
|
|
// create names of the live files. The names are not absolute
|
|
|
|
// paths, instead they are relative to dbname_;
|
2013-08-29 23:30:52 +02:00
|
|
|
for (auto live_file : live) {
|
|
|
|
ret.push_back(TableFileName("", live_file));
|
2012-09-15 02:11:35 +02:00
|
|
|
}
|
|
|
|
|
2013-08-29 23:30:52 +02:00
|
|
|
ret.push_back(CurrentFileName(""));
|
|
|
|
ret.push_back(DescriptorFileName("", versions_->ManifestFileNumber()));
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2012-09-24 23:01:01 +02:00
|
|
|
// find length of manifest file while holding the mutex lock
|
|
|
|
*manifest_file_size = versions_->ManifestFileSize();
|
|
|
|
|
2012-09-15 02:11:35 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2013-08-06 21:54:37 +02:00
|
|
|
Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
|
|
|
|
// First get sorted files in archive dir, then append sorted files from main
|
|
|
|
// dir to maintain sorted order
|
|
|
|
|
2013-08-29 23:30:52 +02:00
|
|
|
// list wal files in archive dir.
|
2013-08-06 21:54:37 +02:00
|
|
|
Status s;
|
2013-10-01 23:46:52 +02:00
|
|
|
std::string archivedir = ArchivalDirectory(options_.wal_dir);
|
2013-08-06 21:54:37 +02:00
|
|
|
if (env_->FileExists(archivedir)) {
|
|
|
|
s = AppendSortedWalsOfType(archivedir, files, kArchivedLogFile);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// list wal files in main db dir.
|
2013-10-01 23:46:52 +02:00
|
|
|
return AppendSortedWalsOfType(options_.wal_dir, files, kAliveLogFile);
|
2013-08-06 21:54:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Status DBImpl::DeleteWalFiles(const VectorLogPtr& files) {
|
|
|
|
Status s;
|
2013-10-01 23:46:52 +02:00
|
|
|
std::string archivedir = ArchivalDirectory(options_.wal_dir);
|
2013-08-06 21:54:37 +02:00
|
|
|
std::string files_not_deleted;
|
|
|
|
for (const auto& wal : files) {
|
2013-08-29 23:30:52 +02:00
|
|
|
/* Try deleting in the dir that pathname points to for the logfile.
|
|
|
|
This may fail if we try to delete a log file which was live when captured
|
|
|
|
but is archived now. Try deleting it from archive also
|
2013-08-06 21:54:37 +02:00
|
|
|
*/
|
2013-10-01 23:46:52 +02:00
|
|
|
Status st = env_->DeleteFile(options_.wal_dir + "/" + wal->PathName());
|
2013-08-29 23:30:52 +02:00
|
|
|
if (!st.ok()) {
|
|
|
|
if (wal->Type() == kAliveLogFile &&
|
|
|
|
env_->DeleteFile(LogFileName(archivedir, wal->LogNumber())).ok()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
files_not_deleted.append(wal->PathName());
|
2013-08-06 21:54:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!files_not_deleted.empty()) {
|
|
|
|
return Status::IOError("Deleted all requested files except: " +
|
|
|
|
files_not_deleted);
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2012-09-15 02:11:35 +02:00
|
|
|
}
|