|
|
@ -7,11 +7,13 @@ |
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#include "file/filename.h" |
|
|
|
#include "file/filename.h" |
|
|
|
#include <cinttypes> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <ctype.h> |
|
|
|
#include <ctype.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <cinttypes> |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
#include "file/writable_file_writer.h" |
|
|
|
#include "file/writable_file_writer.h" |
|
|
|
#include "rocksdb/env.h" |
|
|
|
#include "rocksdb/env.h" |
|
|
|
#include "test_util/sync_point.h" |
|
|
|
#include "test_util/sync_point.h" |
|
|
@ -42,10 +44,8 @@ static size_t GetInfoLogPrefix(const std::string& path, char* dest, int len) { |
|
|
|
while (i < src_len && write_idx < len - sizeof(suffix)) { |
|
|
|
while (i < src_len && write_idx < len - sizeof(suffix)) { |
|
|
|
if ((path[i] >= 'a' && path[i] <= 'z') || |
|
|
|
if ((path[i] >= 'a' && path[i] <= 'z') || |
|
|
|
(path[i] >= '0' && path[i] <= '9') || |
|
|
|
(path[i] >= '0' && path[i] <= '9') || |
|
|
|
(path[i] >= 'A' && path[i] <= 'Z') || |
|
|
|
(path[i] >= 'A' && path[i] <= 'Z') || path[i] == '-' || |
|
|
|
path[i] == '-' || |
|
|
|
path[i] == '.' || path[i] == '_') { |
|
|
|
path[i] == '.' || |
|
|
|
|
|
|
|
path[i] == '_'){ |
|
|
|
|
|
|
|
dest[write_idx++] = path[i]; |
|
|
|
dest[write_idx++] = path[i]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (i > 0) { |
|
|
|
if (i > 0) { |
|
|
@ -153,7 +153,8 @@ void FormatFileNumber(uint64_t number, uint32_t path_id, char* out_buf, |
|
|
|
if (path_id == 0) { |
|
|
|
if (path_id == 0) { |
|
|
|
snprintf(out_buf, out_buf_size, "%" PRIu64, number); |
|
|
|
snprintf(out_buf, out_buf_size, "%" PRIu64, number); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
snprintf(out_buf, out_buf_size, "%" PRIu64 |
|
|
|
snprintf(out_buf, out_buf_size, |
|
|
|
|
|
|
|
"%" PRIu64 |
|
|
|
"(path " |
|
|
|
"(path " |
|
|
|
"%" PRIu32 ")", |
|
|
|
"%" PRIu32 ")", |
|
|
|
number, path_id); |
|
|
|
number, path_id); |
|
|
@ -176,9 +177,7 @@ std::string CurrentFileName(const std::string& dbname) { |
|
|
|
return dbname + "/" + kCurrentFileName; |
|
|
|
return dbname + "/" + kCurrentFileName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string LockFileName(const std::string& dbname) { |
|
|
|
std::string LockFileName(const std::string& dbname) { return dbname + "/LOCK"; } |
|
|
|
return dbname + "/LOCK"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string TempFileName(const std::string& dbname, uint64_t number) { |
|
|
|
std::string TempFileName(const std::string& dbname, uint64_t number) { |
|
|
|
return MakeFileName(dbname, number, kTempFileNameSuffix.c_str()); |
|
|
|
return MakeFileName(dbname, number, kTempFileNameSuffix.c_str()); |
|
|
@ -199,7 +198,8 @@ InfoLogPrefix::InfoLogPrefix(bool has_log_dir, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string InfoLogFileName(const std::string& dbname, |
|
|
|
std::string InfoLogFileName(const std::string& dbname, |
|
|
|
const std::string& db_path, const std::string& log_dir) { |
|
|
|
const std::string& db_path, |
|
|
|
|
|
|
|
const std::string& log_dir) { |
|
|
|
if (log_dir.empty()) { |
|
|
|
if (log_dir.empty()) { |
|
|
|
return dbname + "/LOG"; |
|
|
|
return dbname + "/LOG"; |
|
|
|
} |
|
|
|
} |
|
|
@ -210,7 +210,8 @@ std::string InfoLogFileName(const std::string& dbname, |
|
|
|
|
|
|
|
|
|
|
|
// Return the name of the old info log file for "dbname".
|
|
|
|
// Return the name of the old info log file for "dbname".
|
|
|
|
std::string OldInfoLogFileName(const std::string& dbname, uint64_t ts, |
|
|
|
std::string OldInfoLogFileName(const std::string& dbname, uint64_t ts, |
|
|
|
const std::string& db_path, const std::string& log_dir) { |
|
|
|
const std::string& db_path, |
|
|
|
|
|
|
|
const std::string& log_dir) { |
|
|
|
char buf[50]; |
|
|
|
char buf[50]; |
|
|
|
snprintf(buf, sizeof(buf), "%llu", static_cast<unsigned long long>(ts)); |
|
|
|
snprintf(buf, sizeof(buf), "%llu", static_cast<unsigned long long>(ts)); |
|
|
|
|
|
|
|
|
|
|
@ -263,9 +264,7 @@ std::string IdentityFileName(const std::string& dbname) { |
|
|
|
// dbname/OPTIONS-[0-9]+
|
|
|
|
// dbname/OPTIONS-[0-9]+
|
|
|
|
// dbname/OPTIONS-[0-9]+.dbtmp
|
|
|
|
// dbname/OPTIONS-[0-9]+.dbtmp
|
|
|
|
// Disregards / at the beginning
|
|
|
|
// Disregards / at the beginning
|
|
|
|
bool ParseFileName(const std::string& fname, |
|
|
|
bool ParseFileName(const std::string& fname, uint64_t* number, FileType* type, |
|
|
|
uint64_t* number, |
|
|
|
|
|
|
|
FileType* type, |
|
|
|
|
|
|
|
WalFileType* log_type) { |
|
|
|
WalFileType* log_type) { |
|
|
|
return ParseFileName(fname, number, "", type, log_type); |
|
|
|
return ParseFileName(fname, number, "", type, log_type); |
|
|
|
} |
|
|
|
} |
|
|
|