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