mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
Refactor GetArchivalDirectoryName to filename.h
Summary: filename.h has functions to do similar things. Moving code away from db_impl.cc Test Plan: make check Reviewers: dhruba Reviewed By: dhruba Differential Revision: https://reviews.facebook.net/D7251
This commit is contained in:
parent
38671c4d54
commit
1c6742e32f
|
@ -44,8 +44,6 @@ namespace leveldb {
|
|||
|
||||
void dumpLeveldbBuildVersion(Logger * log);
|
||||
|
||||
const std::string DBImpl::ARCHIVAL_DIR = "archive";
|
||||
|
||||
static Status NewLogger(const std::string& dbname,
|
||||
const std::string& db_log_dir,
|
||||
Env* env,
|
||||
|
@ -334,13 +332,9 @@ void DBImpl::MaybeIgnoreError(Status* s) const {
|
|||
}
|
||||
}
|
||||
|
||||
std::string DBImpl::GetArchivalDirectoryName() {
|
||||
return dbname_ + "/" + ARCHIVAL_DIR;
|
||||
}
|
||||
|
||||
const Status DBImpl::CreateArchivalDirectory() {
|
||||
if (options_.WAL_ttl_seconds > 0) {
|
||||
std::string archivalPath = GetArchivalDirectoryName();
|
||||
std::string archivalPath = ArchivalDirectory(dbname_);
|
||||
return env_->CreateDirIfMissing(archivalPath);
|
||||
}
|
||||
return Status::OK();
|
||||
|
@ -424,7 +418,6 @@ void DBImpl::PurgeObsoleteFiles(DeletionState& state) {
|
|||
}
|
||||
|
||||
if (!keep) {
|
||||
const std::string currentFile = state.allfiles[i];
|
||||
if (type == kTableFile) {
|
||||
// record the files to be evicted from the cache
|
||||
state.files_to_evict.push_back(number);
|
||||
|
@ -433,16 +426,15 @@ void DBImpl::PurgeObsoleteFiles(DeletionState& state) {
|
|||
int(type),
|
||||
static_cast<unsigned long long>(number));
|
||||
if (type == kLogFile && options_.WAL_ttl_seconds > 0) {
|
||||
Status st = env_->RenameFile(dbname_ + "/" + currentFile,
|
||||
dbname_ + "/" + ARCHIVAL_DIR + "/" + currentFile);
|
||||
|
||||
Status st = env_->RenameFile(LogFileName(dbname_, number),
|
||||
ArchivedLogFileName(dbname_, number));
|
||||
if (!st.ok()) {
|
||||
Log(options_.info_log, "RenameFile type=%d #%lld FAILED\n",
|
||||
int(type),
|
||||
static_cast<unsigned long long>(number));
|
||||
}
|
||||
} else {
|
||||
Status st = env_->DeleteFile(dbname_ + "/" + currentFile);
|
||||
Status st = env_->DeleteFile(dbname_ + "/" + state.allfiles[i]);
|
||||
if(!st.ok()) {
|
||||
Log(options_.info_log, "Delete type=%d #%lld FAILED\n",
|
||||
int(type),
|
||||
|
@ -485,7 +477,7 @@ void DBImpl::DeleteObsoleteFiles() {
|
|||
void DBImpl::PurgeObsoleteWALFiles() {
|
||||
if (options_.WAL_ttl_seconds != ULONG_MAX && options_.WAL_ttl_seconds > 0) {
|
||||
std::vector<std::string> WALFiles;
|
||||
std::string archivalDir = GetArchivalDirectoryName();
|
||||
std::string archivalDir = ArchivalDirectory(dbname_);
|
||||
env_->GetChildren(archivalDir, &WALFiles);
|
||||
int64_t currentTime;
|
||||
const Status status = env_->GetCurrentTime(¤tTime);
|
||||
|
@ -900,7 +892,7 @@ Status DBImpl::GetUpdatesSince(SequenceNumber seq,
|
|||
return s;
|
||||
}
|
||||
// list wal files in archive dir.
|
||||
s = ListAllWALFiles(GetArchivalDirectoryName(), &walFiles, kArchivedLogFile);
|
||||
s = ListAllWALFiles(ArchivalDirectory(dbname_), &walFiles, kArchivedLogFile);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -57,8 +57,6 @@ class DBImpl : public DB {
|
|||
uint64_t* manifest_file_size);
|
||||
virtual Status GetUpdatesSince(SequenceNumber seq_number,
|
||||
TransactionLogIterator ** iter);
|
||||
// Return's the path of the archival directory.
|
||||
std::string GetArchivalDirectoryName();
|
||||
|
||||
// Extra methods (for testing) that are not in the public DB interface
|
||||
|
||||
|
@ -316,7 +314,6 @@ protected:
|
|||
CompactionStats* stats_;
|
||||
|
||||
static const int KEEP_LOG_FILE_NUM = 1000;
|
||||
static const std::string ARCHIVAL_DIR;
|
||||
std::string db_absolute_path_;
|
||||
|
||||
// count of the number of contiguous delaying writes
|
||||
|
|
|
@ -2225,7 +2225,7 @@ TEST(DBTest, WALArchival) {
|
|||
// Re-open db. Causes deletion/archival to take place.
|
||||
// Assert that the files moved under "/archive".
|
||||
|
||||
std::string archiveDir = dbfull()->GetArchivalDirectoryName();
|
||||
std::string archiveDir = ArchivalDirectory(dbname_);
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
|
||||
|
|
|
@ -57,6 +57,9 @@ std::string LogFileName(const std::string& name, uint64_t number) {
|
|||
return MakeFileName(name, number, "log");
|
||||
}
|
||||
|
||||
std::string ArchivalDirectory(const std::string& dbname) {
|
||||
return dbname + "/" + ARCHIVAL_DIR;
|
||||
}
|
||||
std::string ArchivedLogFileName(const std::string& name, uint64_t number) {
|
||||
assert(number > 0);
|
||||
return MakeFileName(name + "/archive", number, "log");
|
||||
|
|
|
@ -32,6 +32,10 @@ enum FileType {
|
|||
// "dbname".
|
||||
extern std::string LogFileName(const std::string& dbname, uint64_t number);
|
||||
|
||||
static const std::string ARCHIVAL_DIR = "archive";
|
||||
|
||||
extern std::string ArchivalDirectory(const std::string& dbname);
|
||||
|
||||
// Return the name of the archived log file with the specified number
|
||||
// in the db named by "dbname". The result will be prefixed with "dbname".
|
||||
extern std::string ArchivedLogFileName(const std::string& dbname,
|
||||
|
|
Loading…
Reference in a new issue