]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
2 | // This source code is licensed under both the GPLv2 (found in the |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
7c673cae FG |
5 | // |
6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | |
7 | // Use of this source code is governed by a BSD-style license that can be | |
8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. | |
9 | // | |
10 | // File names used by DB code | |
11 | ||
12 | #pragma once | |
13 | #include <stdint.h> | |
1e59de90 | 14 | |
7c673cae | 15 | #include <string> |
1e59de90 | 16 | #include <unordered_map> |
7c673cae FG |
17 | #include <vector> |
18 | ||
19 | #include "options/db_options.h" | |
20 | #include "port/port.h" | |
20effc67 | 21 | #include "rocksdb/file_system.h" |
7c673cae FG |
22 | #include "rocksdb/options.h" |
23 | #include "rocksdb/slice.h" | |
24 | #include "rocksdb/status.h" | |
25 | #include "rocksdb/transaction_log.h" | |
26 | ||
f67539c2 | 27 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
28 | |
29 | class Env; | |
30 | class Directory; | |
1e59de90 | 31 | class SystemClock; |
7c673cae FG |
32 | class WritableFileWriter; |
33 | ||
20effc67 | 34 | #ifdef OS_WIN |
1e59de90 | 35 | constexpr char kFilePathSeparator = '\\'; |
20effc67 | 36 | #else |
1e59de90 | 37 | constexpr char kFilePathSeparator = '/'; |
20effc67 | 38 | #endif |
7c673cae FG |
39 | |
40 | // Return the name of the log file with the specified number | |
41 | // in the db named by "dbname". The result will be prefixed with | |
42 | // "dbname". | |
43 | extern std::string LogFileName(const std::string& dbname, uint64_t number); | |
44 | ||
f67539c2 TL |
45 | extern std::string LogFileName(uint64_t number); |
46 | ||
20effc67 TL |
47 | extern std::string BlobFileName(uint64_t number); |
48 | ||
7c673cae FG |
49 | extern std::string BlobFileName(const std::string& bdirname, uint64_t number); |
50 | ||
11fdf7f2 TL |
51 | extern std::string BlobFileName(const std::string& dbname, |
52 | const std::string& blob_dir, uint64_t number); | |
53 | ||
7c673cae FG |
54 | extern std::string ArchivalDirectory(const std::string& dbname); |
55 | ||
56 | // Return the name of the archived log file with the specified number | |
57 | // in the db named by "dbname". The result will be prefixed with "dbname". | |
1e59de90 | 58 | extern std::string ArchivedLogFileName(const std::string& dbname, uint64_t num); |
7c673cae FG |
59 | |
60 | extern std::string MakeTableFileName(const std::string& name, uint64_t number); | |
61 | ||
f67539c2 TL |
62 | extern std::string MakeTableFileName(uint64_t number); |
63 | ||
7c673cae FG |
64 | // Return the name of sstable with LevelDB suffix |
65 | // created from RocksDB sstable suffixed name | |
66 | extern std::string Rocks2LevelTableFileName(const std::string& fullname); | |
67 | ||
68 | // the reverse function of MakeTableFileName | |
69 | // TODO(yhchiang): could merge this function with ParseFileName() | |
70 | extern uint64_t TableFileNameToNumber(const std::string& name); | |
71 | ||
72 | // Return the name of the sstable with the specified number | |
73 | // in the db named by "dbname". The result will be prefixed with | |
74 | // "dbname". | |
75 | extern std::string TableFileName(const std::vector<DbPath>& db_paths, | |
76 | uint64_t number, uint32_t path_id); | |
77 | ||
78 | // Sufficient buffer size for FormatFileNumber. | |
79 | const size_t kFormatFileNumberBufSize = 38; | |
80 | ||
81 | extern void FormatFileNumber(uint64_t number, uint32_t path_id, char* out_buf, | |
82 | size_t out_buf_size); | |
83 | ||
84 | // Return the name of the descriptor file for the db named by | |
85 | // "dbname" and the specified incarnation number. The result will be | |
86 | // prefixed with "dbname". | |
87 | extern std::string DescriptorFileName(const std::string& dbname, | |
88 | uint64_t number); | |
89 | ||
1e59de90 TL |
90 | extern std::string DescriptorFileName(uint64_t number); |
91 | ||
92 | extern const std::string kCurrentFileName; // = "CURRENT" | |
93 | ||
7c673cae FG |
94 | // Return the name of the current file. This file contains the name |
95 | // of the current manifest file. The result will be prefixed with | |
96 | // "dbname". | |
97 | extern std::string CurrentFileName(const std::string& dbname); | |
98 | ||
99 | // Return the name of the lock file for the db named by | |
100 | // "dbname". The result will be prefixed with "dbname". | |
101 | extern std::string LockFileName(const std::string& dbname); | |
102 | ||
103 | // Return the name of a temporary file owned by the db named "dbname". | |
104 | // The result will be prefixed with "dbname". | |
105 | extern std::string TempFileName(const std::string& dbname, uint64_t number); | |
106 | ||
107 | // A helper structure for prefix of info log names. | |
108 | struct InfoLogPrefix { | |
109 | char buf[260]; | |
110 | Slice prefix; | |
111 | // Prefix with DB absolute path encoded | |
112 | explicit InfoLogPrefix(bool has_log_dir, const std::string& db_absolute_path); | |
113 | // Default Prefix | |
114 | explicit InfoLogPrefix(); | |
115 | }; | |
116 | ||
117 | // Return the name of the info log file for "dbname". | |
118 | extern std::string InfoLogFileName(const std::string& dbname, | |
119 | const std::string& db_path = "", | |
120 | const std::string& log_dir = ""); | |
121 | ||
122 | // Return the name of the old info log file for "dbname". | |
123 | extern std::string OldInfoLogFileName(const std::string& dbname, uint64_t ts, | |
124 | const std::string& db_path = "", | |
125 | const std::string& log_dir = ""); | |
126 | ||
1e59de90 TL |
127 | extern const std::string kOptionsFileNamePrefix; // = "OPTIONS-" |
128 | extern const std::string kTempFileNameSuffix; // = "dbtmp" | |
7c673cae FG |
129 | |
130 | // Return a options file name given the "dbname" and file number. | |
131 | // Format: OPTIONS-[number].dbtmp | |
132 | extern std::string OptionsFileName(const std::string& dbname, | |
133 | uint64_t file_num); | |
1e59de90 | 134 | extern std::string OptionsFileName(uint64_t file_num); |
7c673cae FG |
135 | |
136 | // Return a temp options file name given the "dbname" and file number. | |
137 | // Format: OPTIONS-[number] | |
138 | extern std::string TempOptionsFileName(const std::string& dbname, | |
139 | uint64_t file_num); | |
140 | ||
141 | // Return the name to use for a metadatabase. The result will be prefixed with | |
142 | // "dbname". | |
1e59de90 | 143 | extern std::string MetaDatabaseName(const std::string& dbname, uint64_t number); |
7c673cae FG |
144 | |
145 | // Return the name of the Identity file which stores a unique number for the db | |
146 | // that will get regenerated if the db loses all its data and is recreated fresh | |
147 | // either from a backup-image or empty | |
148 | extern std::string IdentityFileName(const std::string& dbname); | |
149 | ||
150 | // If filename is a rocksdb file, store the type of the file in *type. | |
151 | // The number encoded in the filename is stored in *number. If the | |
152 | // filename was successfully parsed, returns true. Else return false. | |
153 | // info_log_name_prefix is the path of info logs. | |
154 | extern bool ParseFileName(const std::string& filename, uint64_t* number, | |
155 | const Slice& info_log_name_prefix, FileType* type, | |
156 | WalFileType* log_type = nullptr); | |
157 | // Same as previous function, but skip info log files. | |
158 | extern bool ParseFileName(const std::string& filename, uint64_t* number, | |
159 | FileType* type, WalFileType* log_type = nullptr); | |
160 | ||
161 | // Make the CURRENT file point to the descriptor file with the | |
1e59de90 TL |
162 | // specified number. On its success and when dir_contains_current_file is not |
163 | // nullptr, the function will fsync the directory containing the CURRENT file | |
164 | // when | |
20effc67 TL |
165 | extern IOStatus SetCurrentFile(FileSystem* fs, const std::string& dbname, |
166 | uint64_t descriptor_number, | |
1e59de90 | 167 | FSDirectory* dir_contains_current_file); |
7c673cae FG |
168 | |
169 | // Make the IDENTITY file for the db | |
f67539c2 TL |
170 | extern Status SetIdentityFile(Env* env, const std::string& dbname, |
171 | const std::string& db_id = {}); | |
7c673cae FG |
172 | |
173 | // Sync manifest file `file`. | |
1e59de90 | 174 | extern IOStatus SyncManifest(const ImmutableDBOptions* db_options, |
20effc67 | 175 | WritableFileWriter* file); |
7c673cae | 176 | |
f67539c2 TL |
177 | // Return list of file names of info logs in `file_names`. |
178 | // The list only contains file name. The parent directory name is stored | |
179 | // in `parent_dir`. | |
180 | // `db_log_dir` should be the one as in options.db_log_dir | |
1e59de90 TL |
181 | extern Status GetInfoLogFiles(const std::shared_ptr<FileSystem>& fs, |
182 | const std::string& db_log_dir, | |
f67539c2 TL |
183 | const std::string& dbname, |
184 | std::string* parent_dir, | |
185 | std::vector<std::string>* file_names); | |
20effc67 TL |
186 | |
187 | extern std::string NormalizePath(const std::string& path); | |
f67539c2 | 188 | } // namespace ROCKSDB_NAMESPACE |