1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
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).
5 
6 #pragma once
7 
8 #include <stdint.h>
9 
10 #include <limits>
11 #include <string>
12 #include <vector>
13 
14 #include "rocksdb/types.h"
15 
16 namespace ROCKSDB_NAMESPACE {
17 struct ColumnFamilyMetaData;
18 struct LevelMetaData;
19 struct SstFileMetaData;
20 
21 // The metadata that describes a column family.
22 struct ColumnFamilyMetaData {
ColumnFamilyMetaDataColumnFamilyMetaData23   ColumnFamilyMetaData() : size(0), file_count(0), name("") {}
ColumnFamilyMetaDataColumnFamilyMetaData24   ColumnFamilyMetaData(const std::string& _name, uint64_t _size,
25                        const std::vector<LevelMetaData>&& _levels)
26       : size(_size), name(_name), levels(_levels) {}
27 
28   // The size of this column family in bytes, which is equal to the sum of
29   // the file size of its "levels".
30   uint64_t size;
31   // The number of files in this column family.
32   size_t file_count;
33   // The name of the column family.
34   std::string name;
35   // The metadata of all levels in this column family.
36   std::vector<LevelMetaData> levels;
37 };
38 
39 // The metadata that describes a level.
40 struct LevelMetaData {
LevelMetaDataLevelMetaData41   LevelMetaData(int _level, uint64_t _size,
42                 const std::vector<SstFileMetaData>&& _files)
43       : level(_level), size(_size), files(_files) {}
44 
45   // The level which this meta data describes.
46   const int level;
47   // The size of this level in bytes, which is equal to the sum of
48   // the file size of its "files".
49   const uint64_t size;
50   // The metadata of all sst files in this level.
51   const std::vector<SstFileMetaData> files;
52 };
53 
54 // The metadata that describes a SST file.
55 struct SstFileMetaData {
SstFileMetaDataSstFileMetaData56   SstFileMetaData()
57       : size(0),
58         file_number(0),
59         smallest_seqno(0),
60         largest_seqno(0),
61         num_reads_sampled(0),
62         being_compacted(false),
63         num_entries(0),
64         num_deletions(0),
65         oldest_blob_file_number(0) {}
66 
SstFileMetaDataSstFileMetaData67   SstFileMetaData(const std::string& _file_name, uint64_t _file_number,
68                   const std::string& _path, size_t _size,
69                   SequenceNumber _smallest_seqno, SequenceNumber _largest_seqno,
70                   const std::string& _smallestkey,
71                   const std::string& _largestkey, uint64_t _num_reads_sampled,
72                   bool _being_compacted, uint64_t _oldest_blob_file_number,
73                   uint64_t _oldest_ancester_time, uint64_t _file_creation_time,
74                   std::string& _file_checksum,
75                   std::string& _file_checksum_func_name)
76       : size(_size),
77         name(_file_name),
78         file_number(_file_number),
79         db_path(_path),
80         smallest_seqno(_smallest_seqno),
81         largest_seqno(_largest_seqno),
82         smallestkey(_smallestkey),
83         largestkey(_largestkey),
84         num_reads_sampled(_num_reads_sampled),
85         being_compacted(_being_compacted),
86         num_entries(0),
87         num_deletions(0),
88         oldest_blob_file_number(_oldest_blob_file_number),
89         oldest_ancester_time(_oldest_ancester_time),
90         file_creation_time(_file_creation_time),
91         file_checksum(_file_checksum),
92         file_checksum_func_name(_file_checksum_func_name) {}
93 
94   // File size in bytes.
95   size_t size;
96   // The name of the file.
97   std::string name;
98   // The id of the file.
99   uint64_t file_number;
100   // The full path where the file locates.
101   std::string db_path;
102 
103   SequenceNumber smallest_seqno;  // Smallest sequence number in file.
104   SequenceNumber largest_seqno;   // Largest sequence number in file.
105   std::string smallestkey;        // Smallest user defined key in the file.
106   std::string largestkey;         // Largest user defined key in the file.
107   uint64_t num_reads_sampled;     // How many times the file is read.
108   bool being_compacted;  // true if the file is currently being compacted.
109 
110   uint64_t num_entries;
111   uint64_t num_deletions;
112 
113   uint64_t oldest_blob_file_number;  // The id of the oldest blob file
114                                      // referenced by the file.
115   // An SST file may be generated by compactions whose input files may
116   // in turn be generated by earlier compactions. The creation time of the
117   // oldest SST file that is the compaction ancester of this file.
118   // The timestamp is provided Env::GetCurrentTime().
119   // 0 if the information is not available.
120   uint64_t oldest_ancester_time;
121   // Timestamp when the SST file is created, provided by Env::GetCurrentTime().
122   // 0 if the information is not available.
123   uint64_t file_creation_time;
124 
125   // The checksum of a SST file, the value is decided by the file content and
126   // the checksum algorithm used for this SST file. The checksum function is
127   // identified by the file_checksum_func_name. If the checksum function is
128   // not specified, file_checksum is "0" by default.
129   std::string file_checksum;
130 
131   // The name of the checksum function used to generate the file checksum
132   // value. If file checksum is not enabled (e.g., sst_file_checksum_func is
133   // null), file_checksum_func_name is UnknownFileChecksumFuncName, which is
134   // "Unknown".
135   std::string file_checksum_func_name;
136 };
137 
138 // The full set of metadata associated with each SST file.
139 struct LiveFileMetaData : SstFileMetaData {
140   std::string column_family_name;  // Name of the column family
141   int level;                       // Level at which this file resides.
LiveFileMetaDataLiveFileMetaData142   LiveFileMetaData() : column_family_name(), level(0) {}
143 };
144 
145 // Metadata returned as output from ExportColumnFamily() and used as input to
146 // CreateColumnFamiliesWithImport().
147 struct ExportImportFilesMetaData {
148   std::string db_comparator_name;       // Used to safety check at import.
149   std::vector<LiveFileMetaData> files;  // Vector of file metadata.
150 };
151 }  // namespace ROCKSDB_NAMESPACE
152