/Users/deen/code/yugabyte-db/src/yb/rocksdb/sst_file_writer.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | |
21 | | #ifndef ROCKSDB_INCLUDE_ROCKSDB_SST_FILE_WRITER_H |
22 | | #define ROCKSDB_INCLUDE_ROCKSDB_SST_FILE_WRITER_H |
23 | | |
24 | | #include <string> |
25 | | #include "yb/rocksdb/env.h" |
26 | | #include "yb/rocksdb/immutable_options.h" |
27 | | #include "yb/rocksdb/types.h" |
28 | | |
29 | | namespace rocksdb { |
30 | | |
31 | | class Comparator; |
32 | | |
33 | | // Table Properties that are specific to tables created by SstFileWriter. |
34 | | struct ExternalSstFilePropertyNames { |
35 | | // value of this property is a fixed int32 number. |
36 | | static const char kVersion[]; |
37 | | }; |
38 | | |
39 | | // ExternalSstFileInfo include information about sst files created |
40 | | // using SstFileWriter |
41 | | struct ExternalSstFileInfo { |
42 | 10.2k | ExternalSstFileInfo() {} |
43 | | ExternalSstFileInfo(const std::string& _file_path, |
44 | | const std::string& _smallest_key, |
45 | | const std::string& _largest_key, |
46 | | SequenceNumber _sequence_number, uint64_t _file_size, |
47 | | uint64_t _base_file_size, bool _is_split_sst, int32_t _num_entries, |
48 | | int32_t _version) |
49 | | : file_path(_file_path), |
50 | | smallest_key(_smallest_key), |
51 | | largest_key(_largest_key), |
52 | | sequence_number(_sequence_number), |
53 | | file_size(_file_size), |
54 | | base_file_size(_base_file_size), |
55 | | is_split_sst(_is_split_sst), |
56 | | num_entries(_num_entries), |
57 | 0 | version(_version) {} |
58 | | |
59 | | std::string file_path; // external sst file path |
60 | | std::string smallest_key; // smallest user key in file |
61 | | std::string largest_key; // largest user key in file |
62 | | SequenceNumber sequence_number; // sequence number of all keys in file |
63 | | uint64_t file_size; // total file(s) size in bytes |
64 | | uint64_t base_file_size; // base file size in bytes |
65 | | bool is_split_sst; // is SST split into metadata and data file(s) |
66 | | uint64_t num_entries; // number of entries in file |
67 | | int32_t version; // file version |
68 | | }; |
69 | | |
70 | | // SstFileWriter is used to create sst files that can be added to database later |
71 | | // All keys in files generated by SstFileWriter will have sequence number = 0 |
72 | | class SstFileWriter { |
73 | | public: |
74 | | SstFileWriter(const EnvOptions& env_options, |
75 | | const ImmutableCFOptions& ioptions, |
76 | | const Comparator* user_comparator); |
77 | | |
78 | | ~SstFileWriter(); |
79 | | |
80 | | // Prepare SstFileWriter to write into file located at "file_path". |
81 | | Status Open(const std::string& file_path); |
82 | | |
83 | | // Add key, value to currently opened file |
84 | | // REQUIRES: key is after any previously added key according to comparator. |
85 | | Status Add(const Slice& user_key, const Slice& value); |
86 | | |
87 | | // Finalize writing to sst file and close file. |
88 | | // |
89 | | // An optional ExternalSstFileInfo pointer can be passed to the function |
90 | | // which will be populated with information about the created sst file |
91 | | Status Finish(ExternalSstFileInfo* file_info = nullptr); |
92 | | |
93 | | private: |
94 | | class SstFileWriterPropertiesCollectorFactory; |
95 | | class SstFileWriterPropertiesCollector; |
96 | | struct Rep; |
97 | | Rep* rep_; |
98 | | }; |
99 | | } // namespace rocksdb |
100 | | |
101 | | #endif // ROCKSDB_INCLUDE_ROCKSDB_SST_FILE_WRITER_H |