]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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 | |
7c673cae FG |
7 | |
8 | #ifndef ROCKSDB_LITE | |
9 | ||
11fdf7f2 | 10 | #include <memory> |
7c673cae | 11 | #include <string> |
11fdf7f2 | 12 | |
7c673cae FG |
13 | #include "rocksdb/env.h" |
14 | #include "rocksdb/options.h" | |
15 | #include "rocksdb/table_properties.h" | |
16 | #include "rocksdb/types.h" | |
17 | ||
11fdf7f2 TL |
18 | #if defined(__GNUC__) || defined(__clang__) |
19 | #define ROCKSDB_DEPRECATED_FUNC __attribute__((__deprecated__)) | |
20 | #elif _WIN32 | |
21 | #define ROCKSDB_DEPRECATED_FUNC __declspec(deprecated) | |
22 | #endif | |
23 | ||
f67539c2 | 24 | namespace ROCKSDB_NAMESPACE { |
7c673cae FG |
25 | |
26 | class Comparator; | |
27 | ||
28 | // ExternalSstFileInfo include information about sst files created | |
11fdf7f2 | 29 | // using SstFileWriter. |
7c673cae | 30 | struct ExternalSstFileInfo { |
11fdf7f2 TL |
31 | ExternalSstFileInfo() |
32 | : file_path(""), | |
33 | smallest_key(""), | |
34 | largest_key(""), | |
35 | smallest_range_del_key(""), | |
36 | largest_range_del_key(""), | |
37 | sequence_number(0), | |
38 | file_size(0), | |
39 | num_entries(0), | |
40 | num_range_del_entries(0), | |
41 | version(0) {} | |
42 | ||
7c673cae FG |
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 | int32_t _num_entries, int32_t _version) | |
48 | : file_path(_file_path), | |
49 | smallest_key(_smallest_key), | |
50 | largest_key(_largest_key), | |
11fdf7f2 TL |
51 | smallest_range_del_key(""), |
52 | largest_range_del_key(""), | |
7c673cae FG |
53 | sequence_number(_sequence_number), |
54 | file_size(_file_size), | |
55 | num_entries(_num_entries), | |
11fdf7f2 | 56 | num_range_del_entries(0), |
7c673cae FG |
57 | version(_version) {} |
58 | ||
11fdf7f2 TL |
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 | std::string | |
63 | smallest_range_del_key; // smallest range deletion user key in file | |
64 | std::string largest_range_del_key; // largest range deletion user key in file | |
65 | SequenceNumber sequence_number; // sequence number of all keys in file | |
66 | uint64_t file_size; // file size in bytes | |
67 | uint64_t num_entries; // number of entries in file | |
68 | uint64_t num_range_del_entries; // number of range deletion entries in file | |
7c673cae FG |
69 | int32_t version; // file version |
70 | }; | |
71 | ||
72 | // SstFileWriter is used to create sst files that can be added to database later | |
11fdf7f2 | 73 | // All keys in files generated by SstFileWriter will have sequence number = 0. |
7c673cae FG |
74 | class SstFileWriter { |
75 | public: | |
11fdf7f2 | 76 | // User can pass `column_family` to specify that the generated file will |
7c673cae FG |
77 | // be ingested into this column_family, note that passing nullptr means that |
78 | // the column_family is unknown. | |
79 | // If invalidate_page_cache is set to true, SstFileWriter will give the OS a | |
494da23a TL |
80 | // hint that this file pages is not needed every time we write 1MB to the |
81 | // file. To use the rate limiter an io_priority smaller than IO_TOTAL can be | |
82 | // passed. | |
7c673cae FG |
83 | SstFileWriter(const EnvOptions& env_options, const Options& options, |
84 | ColumnFamilyHandle* column_family = nullptr, | |
11fdf7f2 TL |
85 | bool invalidate_page_cache = true, |
86 | Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL, | |
87 | bool skip_filters = false) | |
7c673cae | 88 | : SstFileWriter(env_options, options, options.comparator, column_family, |
11fdf7f2 | 89 | invalidate_page_cache, io_priority, skip_filters) {} |
7c673cae FG |
90 | |
91 | // Deprecated API | |
92 | SstFileWriter(const EnvOptions& env_options, const Options& options, | |
93 | const Comparator* user_comparator, | |
94 | ColumnFamilyHandle* column_family = nullptr, | |
11fdf7f2 TL |
95 | bool invalidate_page_cache = true, |
96 | Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL, | |
97 | bool skip_filters = false); | |
7c673cae FG |
98 | |
99 | ~SstFileWriter(); | |
100 | ||
101 | // Prepare SstFileWriter to write into file located at "file_path". | |
102 | Status Open(const std::string& file_path); | |
103 | ||
11fdf7f2 TL |
104 | // Add a Put key with value to currently opened file (deprecated) |
105 | // REQUIRES: key is after any previously added key according to comparator. | |
106 | ROCKSDB_DEPRECATED_FUNC Status Add(const Slice& user_key, const Slice& value); | |
107 | ||
108 | // Add a Put key with value to currently opened file | |
109 | // REQUIRES: key is after any previously added key according to comparator. | |
110 | Status Put(const Slice& user_key, const Slice& value); | |
111 | ||
112 | // Add a Merge key with value to currently opened file | |
7c673cae | 113 | // REQUIRES: key is after any previously added key according to comparator. |
11fdf7f2 TL |
114 | Status Merge(const Slice& user_key, const Slice& value); |
115 | ||
116 | // Add a deletion key to currently opened file | |
117 | // REQUIRES: key is after any previously added key according to comparator. | |
118 | Status Delete(const Slice& user_key); | |
119 | ||
120 | // Add a range deletion tombstone to currently opened file | |
121 | Status DeleteRange(const Slice& begin_key, const Slice& end_key); | |
7c673cae FG |
122 | |
123 | // Finalize writing to sst file and close file. | |
124 | // | |
125 | // An optional ExternalSstFileInfo pointer can be passed to the function | |
11fdf7f2 | 126 | // which will be populated with information about the created sst file. |
7c673cae FG |
127 | Status Finish(ExternalSstFileInfo* file_info = nullptr); |
128 | ||
129 | // Return the current file size. | |
130 | uint64_t FileSize(); | |
131 | ||
132 | private: | |
133 | void InvalidatePageCache(bool closing); | |
7c673cae | 134 | struct Rep; |
11fdf7f2 | 135 | std::unique_ptr<Rep> rep_; |
7c673cae | 136 | }; |
f67539c2 | 137 | } // namespace ROCKSDB_NAMESPACE |
7c673cae FG |
138 | |
139 | #endif // !ROCKSDB_LITE |