1179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Use of this source code is governed by a BSD-style license that can be
3179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// found in the LICENSE file. See the AUTHORS file for names of contributors.
4179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org//
5179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// File names used by DB code
6179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
7179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#ifndef STORAGE_LEVELDB_DB_FILENAME_H_
8179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#define STORAGE_LEVELDB_DB_FILENAME_H_
9179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
10179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include <stdint.h>
11179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include <string>
12fbd97aa4c5325eace57d24b89845b9581bac9324jorlow@chromium.org#include "leveldb/slice.h"
13fbd97aa4c5325eace57d24b89845b9581bac9324jorlow@chromium.org#include "leveldb/status.h"
14179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#include "port/port.h"
15179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
16179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgnamespace leveldb {
17179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
18179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgclass Env;
19179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
20179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgenum FileType {
21179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org  kLogFile,
22179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org  kDBLockFile,
23179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org  kTableFile,
24179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org  kDescriptorFile,
25179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org  kCurrentFile,
26179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org  kTempFile,
2751f892d349df9ed408f5a0e6e012667e5eae5f8bgabor@google.com  kInfoLogFile  // Either the current one, or an old one
28179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org};
29179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
30179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of the log file with the specified number
31179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// in the db named by "dbname".  The result will be prefixed with
32179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// "dbname".
33179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string LogFileName(const std::string& dbname, uint64_t number);
34179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
35179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of the sstable with the specified number
36179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// in the db named by "dbname".  The result will be prefixed with
37179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// "dbname".
38179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string TableFileName(const std::string& dbname, uint64_t number);
39179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
402d749ea62f0e47281e82794c8e00eb588cd66616dgrogan@chromium.org// Return the legacy file name for an sstable with the specified number
412d749ea62f0e47281e82794c8e00eb588cd66616dgrogan@chromium.org// in the db named by "dbname". The result will be prefixed with
422d749ea62f0e47281e82794c8e00eb588cd66616dgrogan@chromium.org// "dbname".
432d749ea62f0e47281e82794c8e00eb588cd66616dgrogan@chromium.orgextern std::string SSTTableFileName(const std::string& dbname, uint64_t number);
442d749ea62f0e47281e82794c8e00eb588cd66616dgrogan@chromium.org
45179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of the descriptor file for the db named by
46179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// "dbname" and the specified incarnation number.  The result will be
47179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// prefixed with "dbname".
48179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string DescriptorFileName(const std::string& dbname,
49179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org                                      uint64_t number);
50179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
51179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of the current file.  This file contains the name
52179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// of the current manifest file.  The result will be prefixed with
53179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// "dbname".
54179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string CurrentFileName(const std::string& dbname);
55179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
56179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of the lock file for the db named by
57179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// "dbname".  The result will be prefixed with "dbname".
58179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string LockFileName(const std::string& dbname);
59179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
60179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of a temporary file owned by the db named "dbname".
61179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// The result will be prefixed with "dbname".
62179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string TempFileName(const std::string& dbname, uint64_t number);
63179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
64179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of the info log file for "dbname".
65179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string InfoLogFileName(const std::string& dbname);
66179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
67179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Return the name of the old info log file for "dbname".
68179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern std::string OldInfoLogFileName(const std::string& dbname);
69179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
70179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// If filename is a leveldb file, store the type of the file in *type.
711511be6edb54b6ade2bfad94256f76bc191e92ecdgrogan@chromium.org// The number encoded in the filename is stored in *number.  If the
721511be6edb54b6ade2bfad94256f76bc191e92ecdgrogan@chromium.org// filename was successfully parsed, returns true.  Else return false.
73179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern bool ParseFileName(const std::string& filename,
74179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org                          uint64_t* number,
75179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org                          FileType* type);
76179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
77179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// Make the CURRENT file point to the descriptor file with the
78179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org// specified number.
79179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.orgextern Status SetCurrentFile(Env* env, const std::string& dbname,
80179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org                             uint64_t descriptor_number);
81179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
82179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
8345b9940be332834440bd5299419f396e38085ebehans@chromium.org}  // namespace leveldb
84179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org
85179be588c25dccaa963df9c9c104fc6229435483jorlow@chromium.org#endif  // STORAGE_LEVELDB_DB_FILENAME_H_
86