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.
|
|
|
|
//
|
2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// File names used by DB code
|
|
|
|
|
2013-10-05 05:32:05 +00:00
|
|
|
#pragma once
|
2011-03-18 22:37:00 +00:00
|
|
|
#include <stdint.h>
|
2014-07-02 16:54:20 +00:00
|
|
|
#include <unordered_map>
|
2011-03-18 22:37:00 +00:00
|
|
|
#include <string>
|
2014-07-02 16:54:20 +00:00
|
|
|
#include <vector>
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/slice.h"
|
|
|
|
#include "rocksdb/status.h"
|
2013-10-24 06:39:23 +00:00
|
|
|
#include "rocksdb/transaction_log.h"
|
2011-03-18 22:37:00 +00:00
|
|
|
#include "port/port.h"
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
class Env;
|
2014-05-06 21:51:33 +00:00
|
|
|
class Directory;
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
enum FileType {
|
|
|
|
kLogFile,
|
|
|
|
kDBLockFile,
|
|
|
|
kTableFile,
|
|
|
|
kDescriptorFile,
|
|
|
|
kCurrentFile,
|
|
|
|
kTempFile,
|
2012-12-17 19:26:59 +00:00
|
|
|
kInfoLogFile, // Either the current one, or an old one
|
2013-10-18 21:50:54 +00:00
|
|
|
kMetaDatabase,
|
|
|
|
kIdentityFile
|
2011-03-18 22:37:00 +00:00
|
|
|
};
|
|
|
|
|
2014-07-02 16:54:20 +00:00
|
|
|
// map from file number to path ID.
|
|
|
|
typedef std::unordered_map<uint64_t, uint32_t> FileNumToPathIdMap;
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
// Return the name of the log file with the specified number
|
|
|
|
// in the db named by "dbname". The result will be prefixed with
|
|
|
|
// "dbname".
|
|
|
|
extern std::string LogFileName(const std::string& dbname, uint64_t number);
|
|
|
|
|
2012-12-08 00:30:22 +00:00
|
|
|
static const std::string ARCHIVAL_DIR = "archive";
|
|
|
|
|
|
|
|
extern std::string ArchivalDirectory(const std::string& dbname);
|
|
|
|
|
2012-11-30 01:28:37 +00:00
|
|
|
// 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,
|
|
|
|
uint64_t num);
|
|
|
|
|
2014-07-02 16:54:20 +00:00
|
|
|
extern std::string MakeTableFileName(const std::string& name, uint64_t number);
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
// Return the name of the sstable with the specified number
|
|
|
|
// in the db named by "dbname". The result will be prefixed with
|
|
|
|
// "dbname".
|
2014-07-14 22:34:30 +00:00
|
|
|
extern std::string TableFileName(const std::vector<DbPath>& db_paths,
|
2014-07-02 16:54:20 +00:00
|
|
|
uint64_t number, uint32_t path_id);
|
|
|
|
|
2014-08-13 18:57:40 +00:00
|
|
|
// Sufficient buffer size for FormatFileNumber.
|
|
|
|
extern const size_t kFormatFileNumberBufSize;
|
|
|
|
|
|
|
|
extern void FormatFileNumber(uint64_t number, uint32_t path_id, char* out_buf,
|
|
|
|
size_t out_buf_size);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
// Return the name of the descriptor file for the db named by
|
|
|
|
// "dbname" and the specified incarnation number. The result will be
|
|
|
|
// prefixed with "dbname".
|
|
|
|
extern std::string DescriptorFileName(const std::string& dbname,
|
|
|
|
uint64_t number);
|
|
|
|
|
|
|
|
// Return the name of the current file. This file contains the name
|
|
|
|
// of the current manifest file. The result will be prefixed with
|
|
|
|
// "dbname".
|
|
|
|
extern std::string CurrentFileName(const std::string& dbname);
|
|
|
|
|
|
|
|
// Return the name of the lock file for the db named by
|
|
|
|
// "dbname". The result will be prefixed with "dbname".
|
|
|
|
extern std::string LockFileName(const std::string& dbname);
|
|
|
|
|
|
|
|
// Return the name of a temporary file owned by the db named "dbname".
|
|
|
|
// The result will be prefixed with "dbname".
|
|
|
|
extern std::string TempFileName(const std::string& dbname, uint64_t number);
|
|
|
|
|
2014-08-14 17:05:16 +00:00
|
|
|
// A helper structure for prefix of info log names.
|
|
|
|
struct InfoLogPrefix {
|
|
|
|
char buf[260];
|
|
|
|
Slice prefix;
|
|
|
|
// Prefix with DB absolute path encoded
|
|
|
|
explicit InfoLogPrefix(bool has_log_dir, const std::string& db_absolute_path);
|
|
|
|
// Default Prefix
|
|
|
|
explicit InfoLogPrefix();
|
|
|
|
};
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
// Return the name of the info log file for "dbname".
|
2012-09-06 00:44:13 +00:00
|
|
|
extern std::string InfoLogFileName(const std::string& dbname,
|
|
|
|
const std::string& db_path="", const std::string& log_dir="");
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
// Return the name of the old info log file for "dbname".
|
2012-09-06 00:44:13 +00:00
|
|
|
extern std::string OldInfoLogFileName(const std::string& dbname, uint64_t ts,
|
|
|
|
const std::string& db_path="", const std::string& log_dir="");
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2012-12-17 19:26:59 +00:00
|
|
|
// Return the name to use for a metadatabase. The result will be prefixed with
|
|
|
|
// "dbname".
|
|
|
|
extern std::string MetaDatabaseName(const std::string& dbname,
|
|
|
|
uint64_t number);
|
|
|
|
|
2013-10-18 21:50:54 +00:00
|
|
|
// Return the name of the Identity file which stores a unique number for the db
|
|
|
|
// that will get regenerated if the db loses all its data and is recreated fresh
|
|
|
|
// either from a backup-image or empty
|
|
|
|
extern std::string IdentityFileName(const std::string& dbname);
|
|
|
|
|
2013-10-05 05:32:05 +00:00
|
|
|
// If filename is a rocksdb file, store the type of the file in *type.
|
2011-04-20 22:48:11 +00:00
|
|
|
// The number encoded in the filename is stored in *number. If the
|
|
|
|
// filename was successfully parsed, returns true. Else return false.
|
2014-08-14 17:05:16 +00:00
|
|
|
// info_log_name_prefix is the path of info logs.
|
|
|
|
extern bool ParseFileName(const std::string& filename, uint64_t* number,
|
|
|
|
const Slice& info_log_name_prefix, FileType* type,
|
2013-10-24 06:39:23 +00:00
|
|
|
WalFileType* log_type = nullptr);
|
2014-08-14 17:05:16 +00:00
|
|
|
// Same as previous function, but skip info log files.
|
|
|
|
extern bool ParseFileName(const std::string& filename, uint64_t* number,
|
|
|
|
FileType* type, WalFileType* log_type = nullptr);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
// Make the CURRENT file point to the descriptor file with the
|
|
|
|
// specified number.
|
|
|
|
extern Status SetCurrentFile(Env* env, const std::string& dbname,
|
2014-05-06 21:51:33 +00:00
|
|
|
uint64_t descriptor_number,
|
|
|
|
Directory* directory_to_fsync);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2013-10-18 21:50:54 +00:00
|
|
|
// Make the IDENTITY file for the db
|
|
|
|
extern Status SetIdentityFile(Env* env, const std::string& dbname);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|