]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/include/rocksdb/sst_file_writer.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / include / rocksdb / sst_file_writer.h
CommitLineData
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 24namespace ROCKSDB_NAMESPACE {
7c673cae
FG
25
26class Comparator;
27
28// ExternalSstFileInfo include information about sst files created
11fdf7f2 29// using SstFileWriter.
7c673cae 30struct ExternalSstFileInfo {
11fdf7f2
TL
31 ExternalSstFileInfo()
32 : file_path(""),
33 smallest_key(""),
34 largest_key(""),
35 smallest_range_del_key(""),
36 largest_range_del_key(""),
20effc67
TL
37 file_checksum(""),
38 file_checksum_func_name(""),
11fdf7f2
TL
39 sequence_number(0),
40 file_size(0),
41 num_entries(0),
42 num_range_del_entries(0),
43 version(0) {}
44
7c673cae
FG
45 ExternalSstFileInfo(const std::string& _file_path,
46 const std::string& _smallest_key,
47 const std::string& _largest_key,
48 SequenceNumber _sequence_number, uint64_t _file_size,
49 int32_t _num_entries, int32_t _version)
50 : file_path(_file_path),
51 smallest_key(_smallest_key),
52 largest_key(_largest_key),
11fdf7f2
TL
53 smallest_range_del_key(""),
54 largest_range_del_key(""),
20effc67
TL
55 file_checksum(""),
56 file_checksum_func_name(""),
7c673cae
FG
57 sequence_number(_sequence_number),
58 file_size(_file_size),
59 num_entries(_num_entries),
11fdf7f2 60 num_range_del_entries(0),
7c673cae
FG
61 version(_version) {}
62
11fdf7f2
TL
63 std::string file_path; // external sst file path
64 std::string smallest_key; // smallest user key in file
65 std::string largest_key; // largest user key in file
66 std::string
67 smallest_range_del_key; // smallest range deletion user key in file
68 std::string largest_range_del_key; // largest range deletion user key in file
20effc67
TL
69 std::string file_checksum; // sst file checksum;
70 std::string file_checksum_func_name; // The name of file checksum function
1e59de90
TL
71 SequenceNumber sequence_number; // sequence number of all keys in file
72 uint64_t file_size; // file size in bytes
73 uint64_t num_entries; // number of entries in file
11fdf7f2 74 uint64_t num_range_del_entries; // number of range deletion entries in file
7c673cae
FG
75 int32_t version; // file version
76};
77
78// SstFileWriter is used to create sst files that can be added to database later
11fdf7f2 79// All keys in files generated by SstFileWriter will have sequence number = 0.
7c673cae
FG
80class SstFileWriter {
81 public:
11fdf7f2 82 // User can pass `column_family` to specify that the generated file will
7c673cae
FG
83 // be ingested into this column_family, note that passing nullptr means that
84 // the column_family is unknown.
85 // If invalidate_page_cache is set to true, SstFileWriter will give the OS a
494da23a
TL
86 // hint that this file pages is not needed every time we write 1MB to the
87 // file. To use the rate limiter an io_priority smaller than IO_TOTAL can be
88 // passed.
1e59de90
TL
89 // The `skip_filters` option is DEPRECATED and could be removed in the
90 // future. Use `BlockBasedTableOptions::filter_policy` to control filter
91 // generation.
7c673cae
FG
92 SstFileWriter(const EnvOptions& env_options, const Options& options,
93 ColumnFamilyHandle* column_family = nullptr,
11fdf7f2
TL
94 bool invalidate_page_cache = true,
95 Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL,
96 bool skip_filters = false)
7c673cae 97 : SstFileWriter(env_options, options, options.comparator, column_family,
11fdf7f2 98 invalidate_page_cache, io_priority, skip_filters) {}
7c673cae
FG
99
100 // Deprecated API
101 SstFileWriter(const EnvOptions& env_options, const Options& options,
102 const Comparator* user_comparator,
103 ColumnFamilyHandle* column_family = nullptr,
11fdf7f2
TL
104 bool invalidate_page_cache = true,
105 Env::IOPriority io_priority = Env::IOPriority::IO_TOTAL,
106 bool skip_filters = false);
7c673cae
FG
107
108 ~SstFileWriter();
109
110 // Prepare SstFileWriter to write into file located at "file_path".
111 Status Open(const std::string& file_path);
112
11fdf7f2
TL
113 // Add a Put key with value to currently opened file (deprecated)
114 // REQUIRES: key is after any previously added key according to comparator.
1e59de90 115 // REQUIRES: comparator is *not* timestamp-aware.
11fdf7f2
TL
116 ROCKSDB_DEPRECATED_FUNC Status Add(const Slice& user_key, const Slice& value);
117
118 // Add a Put key with value to currently opened file
119 // REQUIRES: key is after any previously added key according to comparator.
1e59de90 120 // REQUIRES: comparator is *not* timestamp-aware.
11fdf7f2
TL
121 Status Put(const Slice& user_key, const Slice& value);
122
1e59de90
TL
123 // Add a Put (key with timestamp, value) to the currently opened file
124 // REQUIRES: key is after any previously added key according to the
125 // comparator.
126 // REQUIRES: the timestamp's size is equal to what is expected by
127 // the comparator.
128 Status Put(const Slice& user_key, const Slice& timestamp, const Slice& value);
129
11fdf7f2 130 // Add a Merge key with value to currently opened file
7c673cae 131 // REQUIRES: key is after any previously added key according to comparator.
1e59de90 132 // REQUIRES: comparator is *not* timestamp-aware.
11fdf7f2
TL
133 Status Merge(const Slice& user_key, const Slice& value);
134
135 // Add a deletion key to currently opened file
136 // REQUIRES: key is after any previously added key according to comparator.
1e59de90 137 // REQUIRES: comparator is *not* timestamp-aware.
11fdf7f2
TL
138 Status Delete(const Slice& user_key);
139
1e59de90
TL
140 // Add a deletion key with timestamp to the currently opened file
141 // REQUIRES: key is after any previously added key according to the
142 // comparator.
143 // REQUIRES: the timestamp's size is equal to what is expected by
144 // the comparator.
145 Status Delete(const Slice& user_key, const Slice& timestamp);
146
11fdf7f2 147 // Add a range deletion tombstone to currently opened file
1e59de90 148 // REQUIRES: comparator is *not* timestamp-aware.
11fdf7f2 149 Status DeleteRange(const Slice& begin_key, const Slice& end_key);
7c673cae 150
1e59de90
TL
151 // Add a range deletion tombstone to currently opened file.
152 // REQUIRES: begin_key and end_key are user keys without timestamp.
153 // REQUIRES: the timestamp's size is equal to what is expected by
154 // the comparator.
155 Status DeleteRange(const Slice& begin_key, const Slice& end_key,
156 const Slice& timestamp);
157
7c673cae
FG
158 // Finalize writing to sst file and close file.
159 //
160 // An optional ExternalSstFileInfo pointer can be passed to the function
11fdf7f2 161 // which will be populated with information about the created sst file.
7c673cae
FG
162 Status Finish(ExternalSstFileInfo* file_info = nullptr);
163
164 // Return the current file size.
165 uint64_t FileSize();
166
167 private:
168 void InvalidatePageCache(bool closing);
7c673cae 169 struct Rep;
11fdf7f2 170 std::unique_ptr<Rep> rep_;
7c673cae 171};
f67539c2 172} // namespace ROCKSDB_NAMESPACE
7c673cae
FG
173
174#endif // !ROCKSDB_LITE