]>
Commit | Line | Data |
---|---|---|
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 | #ifndef ROCKSDB_LITE | |
7 | ||
8 | #pragma once | |
9 | #include <string> | |
10 | #include "rocksdb/env.h" | |
11 | #include "rocksdb/options.h" | |
12 | #include "rocksdb/table_properties.h" | |
13 | #include "rocksdb/types.h" | |
14 | ||
15 | namespace rocksdb { | |
16 | ||
17 | class Comparator; | |
18 | ||
19 | // ExternalSstFileInfo include information about sst files created | |
20 | // using SstFileWriter | |
21 | struct ExternalSstFileInfo { | |
22 | ExternalSstFileInfo() {} | |
23 | ExternalSstFileInfo(const std::string& _file_path, | |
24 | const std::string& _smallest_key, | |
25 | const std::string& _largest_key, | |
26 | SequenceNumber _sequence_number, uint64_t _file_size, | |
27 | int32_t _num_entries, int32_t _version) | |
28 | : file_path(_file_path), | |
29 | smallest_key(_smallest_key), | |
30 | largest_key(_largest_key), | |
31 | sequence_number(_sequence_number), | |
32 | file_size(_file_size), | |
33 | num_entries(_num_entries), | |
34 | version(_version) {} | |
35 | ||
36 | std::string file_path; // external sst file path | |
37 | std::string smallest_key; // smallest user key in file | |
38 | std::string largest_key; // largest user key in file | |
39 | SequenceNumber sequence_number; // sequence number of all keys in file | |
40 | uint64_t file_size; // file size in bytes | |
41 | uint64_t num_entries; // number of entries in file | |
42 | int32_t version; // file version | |
43 | }; | |
44 | ||
45 | // SstFileWriter is used to create sst files that can be added to database later | |
46 | // All keys in files generated by SstFileWriter will have sequence number = 0 | |
47 | class SstFileWriter { | |
48 | public: | |
49 | // User can pass `column_family` to specify that the the generated file will | |
50 | // be ingested into this column_family, note that passing nullptr means that | |
51 | // the column_family is unknown. | |
52 | // If invalidate_page_cache is set to true, SstFileWriter will give the OS a | |
53 | // hint that this file pages is not needed everytime we write 1MB to the file | |
54 | SstFileWriter(const EnvOptions& env_options, const Options& options, | |
55 | ColumnFamilyHandle* column_family = nullptr, | |
56 | bool invalidate_page_cache = true) | |
57 | : SstFileWriter(env_options, options, options.comparator, column_family, | |
58 | invalidate_page_cache) {} | |
59 | ||
60 | // Deprecated API | |
61 | SstFileWriter(const EnvOptions& env_options, const Options& options, | |
62 | const Comparator* user_comparator, | |
63 | ColumnFamilyHandle* column_family = nullptr, | |
64 | bool invalidate_page_cache = true); | |
65 | ||
66 | ~SstFileWriter(); | |
67 | ||
68 | // Prepare SstFileWriter to write into file located at "file_path". | |
69 | Status Open(const std::string& file_path); | |
70 | ||
71 | // Add key, value to currently opened file | |
72 | // REQUIRES: key is after any previously added key according to comparator. | |
73 | Status Add(const Slice& user_key, const Slice& value); | |
74 | ||
75 | // Finalize writing to sst file and close file. | |
76 | // | |
77 | // An optional ExternalSstFileInfo pointer can be passed to the function | |
78 | // which will be populated with information about the created sst file | |
79 | Status Finish(ExternalSstFileInfo* file_info = nullptr); | |
80 | ||
81 | // Return the current file size. | |
82 | uint64_t FileSize(); | |
83 | ||
84 | private: | |
85 | void InvalidatePageCache(bool closing); | |
86 | ||
87 | struct Rep; | |
88 | Rep* rep_; | |
89 | }; | |
90 | } // namespace rocksdb | |
91 | ||
92 | #endif // !ROCKSDB_LITE |