filename.h raw

   1  // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
   2  // Use of this source code is governed by a BSD-style license that can be
   3  // found in the LICENSE file. See the AUTHORS file for names of contributors.
   4  //
   5  // File names used by DB code
   6  
   7  #ifndef STORAGE_LEVELDB_DB_FILENAME_H_
   8  #define STORAGE_LEVELDB_DB_FILENAME_H_
   9  
  10  #include <stdint.h>
  11  
  12  #include <string>
  13  
  14  #include "leveldb/slice.h"
  15  #include "leveldb/status.h"
  16  #include "port/port.h"
  17  
  18  namespace leveldb {
  19  
  20  class Env;
  21  
  22  enum FileType {
  23    kLogFile,
  24    kDBLockFile,
  25    kTableFile,
  26    kDescriptorFile,
  27    kCurrentFile,
  28    kTempFile,
  29    kInfoLogFile  // Either the current one, or an old one
  30  };
  31  
  32  // Return the name of the log file with the specified number
  33  // in the db named by "dbname".  The result will be prefixed with
  34  // "dbname".
  35  std::string LogFileName(const std::string& dbname, uint64_t number);
  36  
  37  // Return the name of the sstable with the specified number
  38  // in the db named by "dbname".  The result will be prefixed with
  39  // "dbname".
  40  std::string TableFileName(const std::string& dbname, uint64_t number);
  41  
  42  // Return the legacy file name for an sstable with the specified number
  43  // in the db named by "dbname". The result will be prefixed with
  44  // "dbname".
  45  std::string SSTTableFileName(const std::string& dbname, uint64_t number);
  46  
  47  // Return the name of the descriptor file for the db named by
  48  // "dbname" and the specified incarnation number.  The result will be
  49  // prefixed with "dbname".
  50  std::string DescriptorFileName(const std::string& dbname, uint64_t number);
  51  
  52  // Return the name of the current file.  This file contains the name
  53  // of the current manifest file.  The result will be prefixed with
  54  // "dbname".
  55  std::string CurrentFileName(const std::string& dbname);
  56  
  57  // Return the name of the lock file for the db named by
  58  // "dbname".  The result will be prefixed with "dbname".
  59  std::string LockFileName(const std::string& dbname);
  60  
  61  // Return the name of a temporary file owned by the db named "dbname".
  62  // The result will be prefixed with "dbname".
  63  std::string TempFileName(const std::string& dbname, uint64_t number);
  64  
  65  // Return the name of the info log file for "dbname".
  66  std::string InfoLogFileName(const std::string& dbname);
  67  
  68  // Return the name of the old info log file for "dbname".
  69  std::string OldInfoLogFileName(const std::string& dbname);
  70  
  71  // If filename is a leveldb file, store the type of the file in *type.
  72  // The number encoded in the filename is stored in *number.  If the
  73  // filename was successfully parsed, returns true.  Else return false.
  74  bool ParseFileName(const std::string& filename, uint64_t* number,
  75                     FileType* type);
  76  
  77  // Make the CURRENT file point to the descriptor file with the
  78  // specified number.
  79  Status SetCurrentFile(Env* env, const std::string& dbname,
  80                        uint64_t descriptor_number);
  81  
  82  }  // namespace leveldb
  83  
  84  #endif  // STORAGE_LEVELDB_DB_FILENAME_H_
  85