]>
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). | |
7c673cae FG |
5 | // |
6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | |
7 | // Use of this source code is governed by a BSD-style license that can be | |
8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. | |
9 | ||
10 | #ifndef ROCKSDB_LITE | |
11 | ||
12 | #include "rocksdb/c.h" | |
13 | ||
1e59de90 TL |
14 | #include <cstdlib> |
15 | #include <map> | |
16 | #include <unordered_set> | |
17 | #include <vector> | |
18 | ||
7c673cae FG |
19 | #include "port/port.h" |
20 | #include "rocksdb/cache.h" | |
21 | #include "rocksdb/compaction_filter.h" | |
22 | #include "rocksdb/comparator.h" | |
23 | #include "rocksdb/convenience.h" | |
24 | #include "rocksdb/db.h" | |
25 | #include "rocksdb/env.h" | |
1e59de90 | 26 | #include "rocksdb/experimental.h" |
7c673cae FG |
27 | #include "rocksdb/filter_policy.h" |
28 | #include "rocksdb/iterator.h" | |
11fdf7f2 | 29 | #include "rocksdb/memtablerep.h" |
7c673cae FG |
30 | #include "rocksdb/merge_operator.h" |
31 | #include "rocksdb/options.h" | |
1e59de90 | 32 | #include "rocksdb/perf_context.h" |
11fdf7f2 | 33 | #include "rocksdb/rate_limiter.h" |
7c673cae | 34 | #include "rocksdb/slice_transform.h" |
11fdf7f2 TL |
35 | #include "rocksdb/statistics.h" |
36 | #include "rocksdb/status.h" | |
7c673cae | 37 | #include "rocksdb/table.h" |
11fdf7f2 | 38 | #include "rocksdb/universal_compaction.h" |
1e59de90 | 39 | #include "rocksdb/utilities/backup_engine.h" |
11fdf7f2 TL |
40 | #include "rocksdb/utilities/checkpoint.h" |
41 | #include "rocksdb/utilities/db_ttl.h" | |
42 | #include "rocksdb/utilities/memory_util.h" | |
43 | #include "rocksdb/utilities/optimistic_transaction_db.h" | |
1e59de90 TL |
44 | #include "rocksdb/utilities/options_util.h" |
45 | #include "rocksdb/utilities/table_properties_collectors.h" | |
11fdf7f2 TL |
46 | #include "rocksdb/utilities/transaction.h" |
47 | #include "rocksdb/utilities/transaction_db.h" | |
7c673cae | 48 | #include "rocksdb/utilities/write_batch_with_index.h" |
11fdf7f2 | 49 | #include "rocksdb/write_batch.h" |
7c673cae FG |
50 | #include "utilities/merge_operators.h" |
51 | ||
f67539c2 | 52 | using ROCKSDB_NAMESPACE::BackupEngine; |
1e59de90 | 53 | using ROCKSDB_NAMESPACE::BackupEngineOptions; |
f67539c2 TL |
54 | using ROCKSDB_NAMESPACE::BackupID; |
55 | using ROCKSDB_NAMESPACE::BackupInfo; | |
56 | using ROCKSDB_NAMESPACE::BatchResult; | |
57 | using ROCKSDB_NAMESPACE::BlockBasedTableOptions; | |
58 | using ROCKSDB_NAMESPACE::BottommostLevelCompaction; | |
59 | using ROCKSDB_NAMESPACE::BytewiseComparator; | |
60 | using ROCKSDB_NAMESPACE::Cache; | |
61 | using ROCKSDB_NAMESPACE::Checkpoint; | |
62 | using ROCKSDB_NAMESPACE::ColumnFamilyDescriptor; | |
63 | using ROCKSDB_NAMESPACE::ColumnFamilyHandle; | |
1e59de90 | 64 | using ROCKSDB_NAMESPACE::ColumnFamilyMetaData; |
f67539c2 TL |
65 | using ROCKSDB_NAMESPACE::ColumnFamilyOptions; |
66 | using ROCKSDB_NAMESPACE::CompactionFilter; | |
f67539c2 TL |
67 | using ROCKSDB_NAMESPACE::CompactionFilterFactory; |
68 | using ROCKSDB_NAMESPACE::CompactionOptionsFIFO; | |
69 | using ROCKSDB_NAMESPACE::CompactRangeOptions; | |
70 | using ROCKSDB_NAMESPACE::Comparator; | |
71 | using ROCKSDB_NAMESPACE::CompressionType; | |
72 | using ROCKSDB_NAMESPACE::CuckooTableOptions; | |
73 | using ROCKSDB_NAMESPACE::DB; | |
74 | using ROCKSDB_NAMESPACE::DBOptions; | |
75 | using ROCKSDB_NAMESPACE::DbPath; | |
76 | using ROCKSDB_NAMESPACE::Env; | |
77 | using ROCKSDB_NAMESPACE::EnvOptions; | |
78 | using ROCKSDB_NAMESPACE::FileLock; | |
79 | using ROCKSDB_NAMESPACE::FilterPolicy; | |
80 | using ROCKSDB_NAMESPACE::FlushOptions; | |
81 | using ROCKSDB_NAMESPACE::InfoLogLevel; | |
82 | using ROCKSDB_NAMESPACE::IngestExternalFileOptions; | |
83 | using ROCKSDB_NAMESPACE::Iterator; | |
1e59de90 | 84 | using ROCKSDB_NAMESPACE::LevelMetaData; |
f67539c2 TL |
85 | using ROCKSDB_NAMESPACE::LiveFileMetaData; |
86 | using ROCKSDB_NAMESPACE::Logger; | |
1e59de90 TL |
87 | using ROCKSDB_NAMESPACE::LRUCacheOptions; |
88 | using ROCKSDB_NAMESPACE::MemoryAllocator; | |
f67539c2 TL |
89 | using ROCKSDB_NAMESPACE::MemoryUtil; |
90 | using ROCKSDB_NAMESPACE::MergeOperator; | |
f67539c2 | 91 | using ROCKSDB_NAMESPACE::NewBloomFilterPolicy; |
1e59de90 | 92 | using ROCKSDB_NAMESPACE::NewCompactOnDeletionCollectorFactory; |
f67539c2 TL |
93 | using ROCKSDB_NAMESPACE::NewGenericRateLimiter; |
94 | using ROCKSDB_NAMESPACE::NewLRUCache; | |
1e59de90 | 95 | using ROCKSDB_NAMESPACE::NewRibbonFilterPolicy; |
f67539c2 TL |
96 | using ROCKSDB_NAMESPACE::OptimisticTransactionDB; |
97 | using ROCKSDB_NAMESPACE::OptimisticTransactionOptions; | |
98 | using ROCKSDB_NAMESPACE::Options; | |
99 | using ROCKSDB_NAMESPACE::PerfContext; | |
100 | using ROCKSDB_NAMESPACE::PerfLevel; | |
101 | using ROCKSDB_NAMESPACE::PinnableSlice; | |
1e59de90 | 102 | using ROCKSDB_NAMESPACE::PrepopulateBlobCache; |
f67539c2 TL |
103 | using ROCKSDB_NAMESPACE::RandomAccessFile; |
104 | using ROCKSDB_NAMESPACE::Range; | |
105 | using ROCKSDB_NAMESPACE::RateLimiter; | |
106 | using ROCKSDB_NAMESPACE::ReadOptions; | |
107 | using ROCKSDB_NAMESPACE::RestoreOptions; | |
108 | using ROCKSDB_NAMESPACE::SequentialFile; | |
109 | using ROCKSDB_NAMESPACE::Slice; | |
110 | using ROCKSDB_NAMESPACE::SliceParts; | |
111 | using ROCKSDB_NAMESPACE::SliceTransform; | |
112 | using ROCKSDB_NAMESPACE::Snapshot; | |
1e59de90 | 113 | using ROCKSDB_NAMESPACE::SstFileMetaData; |
f67539c2 TL |
114 | using ROCKSDB_NAMESPACE::SstFileWriter; |
115 | using ROCKSDB_NAMESPACE::Status; | |
1e59de90 | 116 | using ROCKSDB_NAMESPACE::TablePropertiesCollectorFactory; |
f67539c2 TL |
117 | using ROCKSDB_NAMESPACE::Transaction; |
118 | using ROCKSDB_NAMESPACE::TransactionDB; | |
119 | using ROCKSDB_NAMESPACE::TransactionDBOptions; | |
120 | using ROCKSDB_NAMESPACE::TransactionLogIterator; | |
121 | using ROCKSDB_NAMESPACE::TransactionOptions; | |
122 | using ROCKSDB_NAMESPACE::WALRecoveryMode; | |
123 | using ROCKSDB_NAMESPACE::WritableFile; | |
124 | using ROCKSDB_NAMESPACE::WriteBatch; | |
125 | using ROCKSDB_NAMESPACE::WriteBatchWithIndex; | |
126 | using ROCKSDB_NAMESPACE::WriteOptions; | |
7c673cae | 127 | |
11fdf7f2 | 128 | using std::unordered_set; |
1e59de90 | 129 | using std::vector; |
7c673cae FG |
130 | |
131 | extern "C" { | |
132 | ||
1e59de90 TL |
133 | struct rocksdb_t { |
134 | DB* rep; | |
135 | }; | |
136 | struct rocksdb_backup_engine_t { | |
137 | BackupEngine* rep; | |
138 | }; | |
139 | struct rocksdb_backup_engine_info_t { | |
140 | std::vector<BackupInfo> rep; | |
141 | }; | |
142 | struct rocksdb_restore_options_t { | |
143 | RestoreOptions rep; | |
144 | }; | |
145 | struct rocksdb_iterator_t { | |
146 | Iterator* rep; | |
147 | }; | |
148 | struct rocksdb_writebatch_t { | |
149 | WriteBatch rep; | |
150 | }; | |
151 | struct rocksdb_writebatch_wi_t { | |
152 | WriteBatchWithIndex* rep; | |
153 | }; | |
154 | struct rocksdb_snapshot_t { | |
155 | const Snapshot* rep; | |
156 | }; | |
157 | struct rocksdb_flushoptions_t { | |
158 | FlushOptions rep; | |
159 | }; | |
160 | struct rocksdb_fifo_compaction_options_t { | |
161 | CompactionOptionsFIFO rep; | |
162 | }; | |
7c673cae | 163 | struct rocksdb_readoptions_t { |
1e59de90 TL |
164 | ReadOptions rep; |
165 | // stack variables to set pointers to in ReadOptions | |
166 | Slice upper_bound; | |
167 | Slice lower_bound; | |
168 | Slice timestamp; | |
169 | Slice iter_start_ts; | |
170 | }; | |
171 | struct rocksdb_writeoptions_t { | |
172 | WriteOptions rep; | |
173 | }; | |
174 | struct rocksdb_options_t { | |
175 | Options rep; | |
7c673cae | 176 | }; |
7c673cae FG |
177 | struct rocksdb_compactoptions_t { |
178 | CompactRangeOptions rep; | |
1e59de90 TL |
179 | Slice full_history_ts_low; |
180 | }; | |
181 | struct rocksdb_block_based_table_options_t { | |
182 | BlockBasedTableOptions rep; | |
183 | }; | |
184 | struct rocksdb_cuckoo_table_options_t { | |
185 | CuckooTableOptions rep; | |
186 | }; | |
187 | struct rocksdb_seqfile_t { | |
188 | SequentialFile* rep; | |
189 | }; | |
190 | struct rocksdb_randomfile_t { | |
191 | RandomAccessFile* rep; | |
192 | }; | |
193 | struct rocksdb_writablefile_t { | |
194 | WritableFile* rep; | |
195 | }; | |
196 | struct rocksdb_wal_iterator_t { | |
197 | TransactionLogIterator* rep; | |
198 | }; | |
199 | struct rocksdb_wal_readoptions_t { | |
200 | TransactionLogIterator::ReadOptions rep; | |
201 | }; | |
202 | struct rocksdb_filelock_t { | |
203 | FileLock* rep; | |
7c673cae | 204 | }; |
494da23a TL |
205 | struct rocksdb_logger_t { |
206 | std::shared_ptr<Logger> rep; | |
207 | }; | |
1e59de90 TL |
208 | struct rocksdb_lru_cache_options_t { |
209 | LRUCacheOptions rep; | |
210 | }; | |
211 | struct rocksdb_memory_allocator_t { | |
212 | std::shared_ptr<MemoryAllocator> rep; | |
213 | }; | |
494da23a TL |
214 | struct rocksdb_cache_t { |
215 | std::shared_ptr<Cache> rep; | |
216 | }; | |
1e59de90 TL |
217 | struct rocksdb_livefiles_t { |
218 | std::vector<LiveFileMetaData> rep; | |
219 | }; | |
220 | struct rocksdb_column_family_handle_t { | |
221 | ColumnFamilyHandle* rep; | |
222 | }; | |
223 | struct rocksdb_column_family_metadata_t { | |
224 | ColumnFamilyMetaData rep; | |
225 | }; | |
226 | struct rocksdb_level_metadata_t { | |
227 | const LevelMetaData* rep; | |
228 | }; | |
229 | struct rocksdb_sst_file_metadata_t { | |
230 | const SstFileMetaData* rep; | |
231 | }; | |
232 | struct rocksdb_envoptions_t { | |
233 | EnvOptions rep; | |
234 | }; | |
235 | struct rocksdb_ingestexternalfileoptions_t { | |
236 | IngestExternalFileOptions rep; | |
237 | }; | |
238 | struct rocksdb_sstfilewriter_t { | |
239 | SstFileWriter* rep; | |
240 | }; | |
494da23a TL |
241 | struct rocksdb_ratelimiter_t { |
242 | std::shared_ptr<RateLimiter> rep; | |
243 | }; | |
1e59de90 TL |
244 | struct rocksdb_perfcontext_t { |
245 | PerfContext* rep; | |
246 | }; | |
11fdf7f2 TL |
247 | struct rocksdb_pinnableslice_t { |
248 | PinnableSlice rep; | |
249 | }; | |
250 | struct rocksdb_transactiondb_options_t { | |
251 | TransactionDBOptions rep; | |
252 | }; | |
253 | struct rocksdb_transactiondb_t { | |
254 | TransactionDB* rep; | |
255 | }; | |
256 | struct rocksdb_transaction_options_t { | |
257 | TransactionOptions rep; | |
258 | }; | |
259 | struct rocksdb_transaction_t { | |
260 | Transaction* rep; | |
261 | }; | |
1e59de90 TL |
262 | struct rocksdb_backup_engine_options_t { |
263 | BackupEngineOptions rep; | |
20effc67 | 264 | }; |
11fdf7f2 TL |
265 | struct rocksdb_checkpoint_t { |
266 | Checkpoint* rep; | |
267 | }; | |
268 | struct rocksdb_optimistictransactiondb_t { | |
269 | OptimisticTransactionDB* rep; | |
270 | }; | |
271 | struct rocksdb_optimistictransaction_options_t { | |
272 | OptimisticTransactionOptions rep; | |
273 | }; | |
7c673cae FG |
274 | |
275 | struct rocksdb_compactionfiltercontext_t { | |
276 | CompactionFilter::Context rep; | |
277 | }; | |
278 | ||
279 | struct rocksdb_compactionfilter_t : public CompactionFilter { | |
280 | void* state_; | |
281 | void (*destructor_)(void*); | |
1e59de90 TL |
282 | unsigned char (*filter_)(void*, int level, const char* key, size_t key_length, |
283 | const char* existing_value, size_t value_length, | |
284 | char** new_value, size_t* new_value_length, | |
285 | unsigned char* value_changed); | |
7c673cae FG |
286 | const char* (*name_)(void*); |
287 | unsigned char ignore_snapshots_; | |
288 | ||
494da23a | 289 | ~rocksdb_compactionfilter_t() override { (*destructor_)(state_); } |
7c673cae | 290 | |
494da23a TL |
291 | bool Filter(int level, const Slice& key, const Slice& existing_value, |
292 | std::string* new_value, bool* value_changed) const override { | |
7c673cae FG |
293 | char* c_new_value = nullptr; |
294 | size_t new_value_length = 0; | |
295 | unsigned char c_value_changed = 0; | |
1e59de90 TL |
296 | unsigned char result = |
297 | (*filter_)(state_, level, key.data(), key.size(), existing_value.data(), | |
298 | existing_value.size(), &c_new_value, &new_value_length, | |
299 | &c_value_changed); | |
7c673cae FG |
300 | if (c_value_changed) { |
301 | new_value->assign(c_new_value, new_value_length); | |
302 | *value_changed = true; | |
303 | } | |
304 | return result; | |
305 | } | |
306 | ||
494da23a | 307 | const char* Name() const override { return (*name_)(state_); } |
7c673cae | 308 | |
494da23a | 309 | bool IgnoreSnapshots() const override { return ignore_snapshots_; } |
7c673cae FG |
310 | }; |
311 | ||
312 | struct rocksdb_compactionfilterfactory_t : public CompactionFilterFactory { | |
313 | void* state_; | |
314 | void (*destructor_)(void*); | |
315 | rocksdb_compactionfilter_t* (*create_compaction_filter_)( | |
316 | void*, rocksdb_compactionfiltercontext_t* context); | |
317 | const char* (*name_)(void*); | |
318 | ||
494da23a | 319 | ~rocksdb_compactionfilterfactory_t() override { (*destructor_)(state_); } |
7c673cae | 320 | |
494da23a | 321 | std::unique_ptr<CompactionFilter> CreateCompactionFilter( |
7c673cae FG |
322 | const CompactionFilter::Context& context) override { |
323 | rocksdb_compactionfiltercontext_t ccontext; | |
324 | ccontext.rep = context; | |
325 | CompactionFilter* cf = (*create_compaction_filter_)(state_, &ccontext); | |
326 | return std::unique_ptr<CompactionFilter>(cf); | |
327 | } | |
328 | ||
494da23a | 329 | const char* Name() const override { return (*name_)(state_); } |
7c673cae FG |
330 | }; |
331 | ||
332 | struct rocksdb_comparator_t : public Comparator { | |
333 | void* state_; | |
334 | void (*destructor_)(void*); | |
1e59de90 TL |
335 | int (*compare_)(void*, const char* a, size_t alen, const char* b, |
336 | size_t blen); | |
7c673cae | 337 | const char* (*name_)(void*); |
1e59de90 TL |
338 | int (*compare_ts_)(void*, const char* a_ts, size_t a_tslen, const char* b_ts, |
339 | size_t b_tslen); | |
340 | int (*compare_without_ts_)(void*, const char* a, size_t alen, | |
341 | unsigned char a_has_ts, const char* b, size_t blen, | |
342 | unsigned char b_has_ts); | |
343 | ||
344 | rocksdb_comparator_t() : Comparator() {} | |
345 | ||
346 | rocksdb_comparator_t(size_t ts_size) : Comparator(ts_size) {} | |
7c673cae | 347 | |
494da23a | 348 | ~rocksdb_comparator_t() override { (*destructor_)(state_); } |
7c673cae | 349 | |
494da23a | 350 | int Compare(const Slice& a, const Slice& b) const override { |
7c673cae FG |
351 | return (*compare_)(state_, a.data(), a.size(), b.data(), b.size()); |
352 | } | |
353 | ||
1e59de90 TL |
354 | int CompareTimestamp(const Slice& a_ts, const Slice& b_ts) const override { |
355 | if (compare_ts_ == nullptr) { | |
356 | return 0; | |
357 | } | |
358 | return (*compare_ts_)(state_, a_ts.data(), a_ts.size(), b_ts.data(), | |
359 | b_ts.size()); | |
360 | } | |
361 | ||
362 | int CompareWithoutTimestamp(const Slice& a, bool a_has_ts, const Slice& b, | |
363 | bool b_has_ts) const override { | |
364 | if (compare_without_ts_ == nullptr) { | |
365 | return Compare(a, b); | |
366 | } | |
367 | return (*compare_without_ts_)(state_, a.data(), a.size(), a_has_ts, | |
368 | b.data(), b.size(), b_has_ts); | |
369 | } | |
370 | ||
494da23a | 371 | const char* Name() const override { return (*name_)(state_); } |
7c673cae FG |
372 | |
373 | // No-ops since the C binding does not support key shortening methods. | |
494da23a TL |
374 | void FindShortestSeparator(std::string*, const Slice&) const override {} |
375 | void FindShortSuccessor(std::string* /*key*/) const override {} | |
7c673cae FG |
376 | }; |
377 | ||
378 | struct rocksdb_filterpolicy_t : public FilterPolicy { | |
379 | void* state_; | |
380 | void (*destructor_)(void*); | |
381 | const char* (*name_)(void*); | |
7c673cae | 382 | |
494da23a | 383 | ~rocksdb_filterpolicy_t() override { (*destructor_)(state_); } |
7c673cae | 384 | |
494da23a | 385 | const char* Name() const override { return (*name_)(state_); } |
7c673cae FG |
386 | }; |
387 | ||
388 | struct rocksdb_mergeoperator_t : public MergeOperator { | |
389 | void* state_; | |
390 | void (*destructor_)(void*); | |
391 | const char* (*name_)(void*); | |
1e59de90 TL |
392 | char* (*full_merge_)(void*, const char* key, size_t key_length, |
393 | const char* existing_value, size_t existing_value_length, | |
394 | const char* const* operands_list, | |
395 | const size_t* operands_list_length, int num_operands, | |
396 | unsigned char* success, size_t* new_value_length); | |
7c673cae FG |
397 | char* (*partial_merge_)(void*, const char* key, size_t key_length, |
398 | const char* const* operands_list, | |
399 | const size_t* operands_list_length, int num_operands, | |
400 | unsigned char* success, size_t* new_value_length); | |
1e59de90 | 401 | void (*delete_value_)(void*, const char* value, size_t value_length); |
7c673cae | 402 | |
494da23a | 403 | ~rocksdb_mergeoperator_t() override { (*destructor_)(state_); } |
7c673cae | 404 | |
494da23a | 405 | const char* Name() const override { return (*name_)(state_); } |
7c673cae | 406 | |
494da23a TL |
407 | bool FullMergeV2(const MergeOperationInput& merge_in, |
408 | MergeOperationOutput* merge_out) const override { | |
7c673cae FG |
409 | size_t n = merge_in.operand_list.size(); |
410 | std::vector<const char*> operand_pointers(n); | |
411 | std::vector<size_t> operand_sizes(n); | |
412 | for (size_t i = 0; i < n; i++) { | |
413 | Slice operand(merge_in.operand_list[i]); | |
414 | operand_pointers[i] = operand.data(); | |
415 | operand_sizes[i] = operand.size(); | |
416 | } | |
417 | ||
418 | const char* existing_value_data = nullptr; | |
419 | size_t existing_value_len = 0; | |
420 | if (merge_in.existing_value != nullptr) { | |
421 | existing_value_data = merge_in.existing_value->data(); | |
422 | existing_value_len = merge_in.existing_value->size(); | |
423 | } | |
424 | ||
425 | unsigned char success; | |
426 | size_t new_value_len; | |
427 | char* tmp_new_value = (*full_merge_)( | |
428 | state_, merge_in.key.data(), merge_in.key.size(), existing_value_data, | |
429 | existing_value_len, &operand_pointers[0], &operand_sizes[0], | |
430 | static_cast<int>(n), &success, &new_value_len); | |
431 | merge_out->new_value.assign(tmp_new_value, new_value_len); | |
432 | ||
433 | if (delete_value_ != nullptr) { | |
434 | (*delete_value_)(state_, tmp_new_value, new_value_len); | |
435 | } else { | |
436 | free(tmp_new_value); | |
437 | } | |
438 | ||
439 | return success; | |
440 | } | |
441 | ||
494da23a TL |
442 | bool PartialMergeMulti(const Slice& key, |
443 | const std::deque<Slice>& operand_list, | |
444 | std::string* new_value, | |
445 | Logger* /*logger*/) const override { | |
7c673cae FG |
446 | size_t operand_count = operand_list.size(); |
447 | std::vector<const char*> operand_pointers(operand_count); | |
448 | std::vector<size_t> operand_sizes(operand_count); | |
449 | for (size_t i = 0; i < operand_count; ++i) { | |
450 | Slice operand(operand_list[i]); | |
451 | operand_pointers[i] = operand.data(); | |
452 | operand_sizes[i] = operand.size(); | |
453 | } | |
454 | ||
455 | unsigned char success; | |
456 | size_t new_value_len; | |
457 | char* tmp_new_value = (*partial_merge_)( | |
458 | state_, key.data(), key.size(), &operand_pointers[0], &operand_sizes[0], | |
459 | static_cast<int>(operand_count), &success, &new_value_len); | |
460 | new_value->assign(tmp_new_value, new_value_len); | |
461 | ||
462 | if (delete_value_ != nullptr) { | |
463 | (*delete_value_)(state_, tmp_new_value, new_value_len); | |
464 | } else { | |
465 | free(tmp_new_value); | |
466 | } | |
467 | ||
468 | return success; | |
469 | } | |
470 | }; | |
471 | ||
11fdf7f2 TL |
472 | struct rocksdb_dbpath_t { |
473 | DbPath rep; | |
474 | }; | |
475 | ||
7c673cae FG |
476 | struct rocksdb_env_t { |
477 | Env* rep; | |
478 | bool is_default; | |
479 | }; | |
480 | ||
481 | struct rocksdb_slicetransform_t : public SliceTransform { | |
482 | void* state_; | |
483 | void (*destructor_)(void*); | |
484 | const char* (*name_)(void*); | |
1e59de90 TL |
485 | char* (*transform_)(void*, const char* key, size_t length, |
486 | size_t* dst_length); | |
487 | unsigned char (*in_domain_)(void*, const char* key, size_t length); | |
488 | unsigned char (*in_range_)(void*, const char* key, size_t length); | |
7c673cae | 489 | |
494da23a | 490 | ~rocksdb_slicetransform_t() override { (*destructor_)(state_); } |
7c673cae | 491 | |
494da23a | 492 | const char* Name() const override { return (*name_)(state_); } |
7c673cae | 493 | |
494da23a | 494 | Slice Transform(const Slice& src) const override { |
7c673cae FG |
495 | size_t len; |
496 | char* dst = (*transform_)(state_, src.data(), src.size(), &len); | |
497 | return Slice(dst, len); | |
498 | } | |
499 | ||
494da23a | 500 | bool InDomain(const Slice& src) const override { |
7c673cae FG |
501 | return (*in_domain_)(state_, src.data(), src.size()); |
502 | } | |
503 | ||
494da23a | 504 | bool InRange(const Slice& src) const override { |
7c673cae FG |
505 | return (*in_range_)(state_, src.data(), src.size()); |
506 | } | |
507 | }; | |
508 | ||
509 | struct rocksdb_universal_compaction_options_t { | |
f67539c2 | 510 | ROCKSDB_NAMESPACE::CompactionOptionsUniversal* rep; |
7c673cae FG |
511 | }; |
512 | ||
513 | static bool SaveError(char** errptr, const Status& s) { | |
514 | assert(errptr != nullptr); | |
515 | if (s.ok()) { | |
516 | return false; | |
517 | } else if (*errptr == nullptr) { | |
518 | *errptr = strdup(s.ToString().c_str()); | |
519 | } else { | |
520 | // TODO(sanjay): Merge with existing error? | |
521 | // This is a bug if *errptr is not created by malloc() | |
522 | free(*errptr); | |
523 | *errptr = strdup(s.ToString().c_str()); | |
524 | } | |
525 | return true; | |
526 | } | |
527 | ||
528 | static char* CopyString(const std::string& str) { | |
529 | char* result = reinterpret_cast<char*>(malloc(sizeof(char) * str.size())); | |
530 | memcpy(result, str.data(), sizeof(char) * str.size()); | |
531 | return result; | |
532 | } | |
533 | ||
1e59de90 TL |
534 | rocksdb_t* rocksdb_open(const rocksdb_options_t* options, const char* name, |
535 | char** errptr) { | |
7c673cae FG |
536 | DB* db; |
537 | if (SaveError(errptr, DB::Open(options->rep, std::string(name), &db))) { | |
538 | return nullptr; | |
539 | } | |
540 | rocksdb_t* result = new rocksdb_t; | |
541 | result->rep = db; | |
542 | return result; | |
543 | } | |
544 | ||
1e59de90 TL |
545 | rocksdb_t* rocksdb_open_with_ttl(const rocksdb_options_t* options, |
546 | const char* name, int ttl, char** errptr) { | |
f67539c2 TL |
547 | ROCKSDB_NAMESPACE::DBWithTTL* db; |
548 | if (SaveError(errptr, ROCKSDB_NAMESPACE::DBWithTTL::Open( | |
549 | options->rep, std::string(name), &db, ttl))) { | |
11fdf7f2 TL |
550 | return nullptr; |
551 | } | |
552 | rocksdb_t* result = new rocksdb_t; | |
553 | result->rep = db; | |
554 | return result; | |
555 | } | |
556 | ||
20effc67 TL |
557 | rocksdb_t* rocksdb_open_for_read_only(const rocksdb_options_t* options, |
558 | const char* name, | |
559 | unsigned char error_if_wal_file_exists, | |
560 | char** errptr) { | |
7c673cae | 561 | DB* db; |
20effc67 TL |
562 | if (SaveError(errptr, DB::OpenForReadOnly(options->rep, std::string(name), |
563 | &db, error_if_wal_file_exists))) { | |
7c673cae FG |
564 | return nullptr; |
565 | } | |
566 | rocksdb_t* result = new rocksdb_t; | |
567 | result->rep = db; | |
568 | return result; | |
569 | } | |
570 | ||
f67539c2 TL |
571 | rocksdb_t* rocksdb_open_as_secondary(const rocksdb_options_t* options, |
572 | const char* name, | |
573 | const char* secondary_path, | |
574 | char** errptr) { | |
575 | DB* db; | |
576 | if (SaveError(errptr, | |
577 | DB::OpenAsSecondary(options->rep, std::string(name), | |
578 | std::string(secondary_path), &db))) { | |
579 | return nullptr; | |
580 | } | |
581 | rocksdb_t* result = new rocksdb_t; | |
582 | result->rep = db; | |
583 | return result; | |
584 | } | |
585 | ||
7c673cae FG |
586 | rocksdb_backup_engine_t* rocksdb_backup_engine_open( |
587 | const rocksdb_options_t* options, const char* path, char** errptr) { | |
588 | BackupEngine* be; | |
1e59de90 TL |
589 | if (SaveError(errptr, BackupEngine::Open( |
590 | options->rep.env, | |
591 | BackupEngineOptions(path, nullptr, true, | |
592 | options->rep.info_log.get()), | |
593 | &be))) { | |
7c673cae FG |
594 | return nullptr; |
595 | } | |
596 | rocksdb_backup_engine_t* result = new rocksdb_backup_engine_t; | |
597 | result->rep = be; | |
598 | return result; | |
599 | } | |
600 | ||
20effc67 | 601 | rocksdb_backup_engine_t* rocksdb_backup_engine_open_opts( |
1e59de90 | 602 | const rocksdb_backup_engine_options_t* options, rocksdb_env_t* env, |
20effc67 TL |
603 | char** errptr) { |
604 | BackupEngine* be; | |
605 | if (SaveError(errptr, BackupEngine::Open(options->rep, env->rep, &be))) { | |
606 | return nullptr; | |
607 | } | |
608 | rocksdb_backup_engine_t* result = new rocksdb_backup_engine_t; | |
609 | result->rep = be; | |
610 | return result; | |
611 | } | |
612 | ||
7c673cae | 613 | void rocksdb_backup_engine_create_new_backup(rocksdb_backup_engine_t* be, |
1e59de90 | 614 | rocksdb_t* db, char** errptr) { |
7c673cae FG |
615 | SaveError(errptr, be->rep->CreateNewBackup(db->rep)); |
616 | } | |
617 | ||
1e59de90 TL |
618 | void rocksdb_backup_engine_create_new_backup_flush( |
619 | rocksdb_backup_engine_t* be, rocksdb_t* db, | |
620 | unsigned char flush_before_backup, char** errptr) { | |
11fdf7f2 TL |
621 | SaveError(errptr, be->rep->CreateNewBackup(db->rep, flush_before_backup)); |
622 | } | |
623 | ||
7c673cae FG |
624 | void rocksdb_backup_engine_purge_old_backups(rocksdb_backup_engine_t* be, |
625 | uint32_t num_backups_to_keep, | |
626 | char** errptr) { | |
627 | SaveError(errptr, be->rep->PurgeOldBackups(num_backups_to_keep)); | |
628 | } | |
629 | ||
630 | rocksdb_restore_options_t* rocksdb_restore_options_create() { | |
631 | return new rocksdb_restore_options_t; | |
632 | } | |
633 | ||
634 | void rocksdb_restore_options_destroy(rocksdb_restore_options_t* opt) { | |
635 | delete opt; | |
636 | } | |
637 | ||
638 | void rocksdb_restore_options_set_keep_log_files(rocksdb_restore_options_t* opt, | |
639 | int v) { | |
640 | opt->rep.keep_log_files = v; | |
641 | } | |
642 | ||
11fdf7f2 | 643 | void rocksdb_backup_engine_verify_backup(rocksdb_backup_engine_t* be, |
1e59de90 | 644 | uint32_t backup_id, char** errptr) { |
11fdf7f2 TL |
645 | SaveError(errptr, be->rep->VerifyBackup(static_cast<BackupID>(backup_id))); |
646 | } | |
647 | ||
7c673cae FG |
648 | void rocksdb_backup_engine_restore_db_from_latest_backup( |
649 | rocksdb_backup_engine_t* be, const char* db_dir, const char* wal_dir, | |
650 | const rocksdb_restore_options_t* restore_options, char** errptr) { | |
651 | SaveError(errptr, be->rep->RestoreDBFromLatestBackup(std::string(db_dir), | |
652 | std::string(wal_dir), | |
653 | restore_options->rep)); | |
654 | } | |
655 | ||
20effc67 TL |
656 | void rocksdb_backup_engine_restore_db_from_backup( |
657 | rocksdb_backup_engine_t* be, const char* db_dir, const char* wal_dir, | |
658 | const rocksdb_restore_options_t* restore_options, const uint32_t backup_id, | |
659 | char** errptr) { | |
660 | SaveError(errptr, be->rep->RestoreDBFromBackup(backup_id, std::string(db_dir), | |
661 | std::string(wal_dir), | |
662 | restore_options->rep)); | |
663 | } | |
664 | ||
7c673cae FG |
665 | const rocksdb_backup_engine_info_t* rocksdb_backup_engine_get_backup_info( |
666 | rocksdb_backup_engine_t* be) { | |
667 | rocksdb_backup_engine_info_t* result = new rocksdb_backup_engine_info_t; | |
668 | be->rep->GetBackupInfo(&result->rep); | |
669 | return result; | |
670 | } | |
671 | ||
672 | int rocksdb_backup_engine_info_count(const rocksdb_backup_engine_info_t* info) { | |
673 | return static_cast<int>(info->rep.size()); | |
674 | } | |
675 | ||
676 | int64_t rocksdb_backup_engine_info_timestamp( | |
677 | const rocksdb_backup_engine_info_t* info, int index) { | |
678 | return info->rep[index].timestamp; | |
679 | } | |
680 | ||
681 | uint32_t rocksdb_backup_engine_info_backup_id( | |
682 | const rocksdb_backup_engine_info_t* info, int index) { | |
683 | return info->rep[index].backup_id; | |
684 | } | |
685 | ||
686 | uint64_t rocksdb_backup_engine_info_size( | |
687 | const rocksdb_backup_engine_info_t* info, int index) { | |
688 | return info->rep[index].size; | |
689 | } | |
690 | ||
691 | uint32_t rocksdb_backup_engine_info_number_files( | |
692 | const rocksdb_backup_engine_info_t* info, int index) { | |
693 | return info->rep[index].number_files; | |
694 | } | |
695 | ||
696 | void rocksdb_backup_engine_info_destroy( | |
697 | const rocksdb_backup_engine_info_t* info) { | |
698 | delete info; | |
699 | } | |
700 | ||
701 | void rocksdb_backup_engine_close(rocksdb_backup_engine_t* be) { | |
702 | delete be->rep; | |
703 | delete be; | |
704 | } | |
705 | ||
1e59de90 | 706 | rocksdb_backup_engine_options_t* rocksdb_backup_engine_options_create( |
20effc67 | 707 | const char* backup_dir) { |
1e59de90 TL |
708 | return new rocksdb_backup_engine_options_t{ |
709 | BackupEngineOptions(std::string(backup_dir))}; | |
20effc67 TL |
710 | } |
711 | ||
1e59de90 TL |
712 | void rocksdb_backup_engine_options_set_backup_dir( |
713 | rocksdb_backup_engine_options_t* options, const char* backup_dir) { | |
20effc67 TL |
714 | options->rep.backup_dir = std::string(backup_dir); |
715 | } | |
716 | ||
1e59de90 TL |
717 | void rocksdb_backup_engine_options_set_env( |
718 | rocksdb_backup_engine_options_t* options, rocksdb_env_t* env) { | |
20effc67 TL |
719 | options->rep.backup_env = (env ? env->rep : nullptr); |
720 | } | |
721 | ||
1e59de90 TL |
722 | void rocksdb_backup_engine_options_set_share_table_files( |
723 | rocksdb_backup_engine_options_t* options, unsigned char val) { | |
20effc67 TL |
724 | options->rep.share_table_files = val; |
725 | } | |
726 | ||
1e59de90 TL |
727 | unsigned char rocksdb_backup_engine_options_get_share_table_files( |
728 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
729 | return options->rep.share_table_files; |
730 | } | |
731 | ||
1e59de90 TL |
732 | void rocksdb_backup_engine_options_set_sync( |
733 | rocksdb_backup_engine_options_t* options, unsigned char val) { | |
20effc67 TL |
734 | options->rep.sync = val; |
735 | } | |
736 | ||
1e59de90 TL |
737 | unsigned char rocksdb_backup_engine_options_get_sync( |
738 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
739 | return options->rep.sync; |
740 | } | |
741 | ||
1e59de90 TL |
742 | void rocksdb_backup_engine_options_set_destroy_old_data( |
743 | rocksdb_backup_engine_options_t* options, unsigned char val) { | |
20effc67 TL |
744 | options->rep.destroy_old_data = val; |
745 | } | |
746 | ||
1e59de90 TL |
747 | unsigned char rocksdb_backup_engine_options_get_destroy_old_data( |
748 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
749 | return options->rep.destroy_old_data; |
750 | } | |
751 | ||
1e59de90 TL |
752 | void rocksdb_backup_engine_options_set_backup_log_files( |
753 | rocksdb_backup_engine_options_t* options, unsigned char val) { | |
20effc67 TL |
754 | options->rep.backup_log_files = val; |
755 | } | |
756 | ||
1e59de90 TL |
757 | unsigned char rocksdb_backup_engine_options_get_backup_log_files( |
758 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
759 | return options->rep.backup_log_files; |
760 | } | |
761 | ||
1e59de90 TL |
762 | void rocksdb_backup_engine_options_set_backup_rate_limit( |
763 | rocksdb_backup_engine_options_t* options, uint64_t limit) { | |
20effc67 TL |
764 | options->rep.backup_rate_limit = limit; |
765 | } | |
766 | ||
1e59de90 TL |
767 | uint64_t rocksdb_backup_engine_options_get_backup_rate_limit( |
768 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
769 | return options->rep.backup_rate_limit; |
770 | } | |
771 | ||
1e59de90 TL |
772 | void rocksdb_backup_engine_options_set_restore_rate_limit( |
773 | rocksdb_backup_engine_options_t* options, uint64_t limit) { | |
20effc67 TL |
774 | options->rep.restore_rate_limit = limit; |
775 | } | |
776 | ||
1e59de90 TL |
777 | uint64_t rocksdb_backup_engine_options_get_restore_rate_limit( |
778 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
779 | return options->rep.restore_rate_limit; |
780 | } | |
781 | ||
1e59de90 TL |
782 | void rocksdb_backup_engine_options_set_max_background_operations( |
783 | rocksdb_backup_engine_options_t* options, int val) { | |
20effc67 TL |
784 | options->rep.max_background_operations = val; |
785 | } | |
786 | ||
1e59de90 TL |
787 | int rocksdb_backup_engine_options_get_max_background_operations( |
788 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
789 | return options->rep.max_background_operations; |
790 | } | |
791 | ||
1e59de90 TL |
792 | void rocksdb_backup_engine_options_set_callback_trigger_interval_size( |
793 | rocksdb_backup_engine_options_t* options, uint64_t size) { | |
20effc67 TL |
794 | options->rep.callback_trigger_interval_size = size; |
795 | } | |
796 | ||
1e59de90 TL |
797 | uint64_t rocksdb_backup_engine_options_get_callback_trigger_interval_size( |
798 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
799 | return options->rep.callback_trigger_interval_size; |
800 | } | |
801 | ||
1e59de90 TL |
802 | void rocksdb_backup_engine_options_set_max_valid_backups_to_open( |
803 | rocksdb_backup_engine_options_t* options, int val) { | |
20effc67 TL |
804 | options->rep.max_valid_backups_to_open = val; |
805 | } | |
806 | ||
1e59de90 TL |
807 | int rocksdb_backup_engine_options_get_max_valid_backups_to_open( |
808 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
809 | return options->rep.max_valid_backups_to_open; |
810 | } | |
811 | ||
1e59de90 TL |
812 | void rocksdb_backup_engine_options_set_share_files_with_checksum_naming( |
813 | rocksdb_backup_engine_options_t* options, int val) { | |
20effc67 | 814 | options->rep.share_files_with_checksum_naming = |
1e59de90 | 815 | static_cast<BackupEngineOptions::ShareFilesNaming>(val); |
20effc67 TL |
816 | } |
817 | ||
1e59de90 TL |
818 | int rocksdb_backup_engine_options_get_share_files_with_checksum_naming( |
819 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
820 | return static_cast<int>(options->rep.share_files_with_checksum_naming); |
821 | } | |
822 | ||
1e59de90 TL |
823 | void rocksdb_backup_engine_options_destroy( |
824 | rocksdb_backup_engine_options_t* options) { | |
20effc67 TL |
825 | delete options; |
826 | } | |
827 | ||
11fdf7f2 TL |
828 | rocksdb_checkpoint_t* rocksdb_checkpoint_object_create(rocksdb_t* db, |
829 | char** errptr) { | |
830 | Checkpoint* checkpoint; | |
831 | if (SaveError(errptr, Checkpoint::Create(db->rep, &checkpoint))) { | |
832 | return nullptr; | |
833 | } | |
834 | rocksdb_checkpoint_t* result = new rocksdb_checkpoint_t; | |
835 | result->rep = checkpoint; | |
836 | return result; | |
837 | } | |
838 | ||
839 | void rocksdb_checkpoint_create(rocksdb_checkpoint_t* checkpoint, | |
840 | const char* checkpoint_dir, | |
841 | uint64_t log_size_for_flush, char** errptr) { | |
842 | SaveError(errptr, checkpoint->rep->CreateCheckpoint( | |
843 | std::string(checkpoint_dir), log_size_for_flush)); | |
844 | } | |
845 | ||
846 | void rocksdb_checkpoint_object_destroy(rocksdb_checkpoint_t* checkpoint) { | |
847 | delete checkpoint->rep; | |
848 | delete checkpoint; | |
849 | } | |
850 | ||
7c673cae FG |
851 | void rocksdb_close(rocksdb_t* db) { |
852 | delete db->rep; | |
853 | delete db; | |
854 | } | |
855 | ||
856 | void rocksdb_options_set_uint64add_merge_operator(rocksdb_options_t* opt) { | |
f67539c2 TL |
857 | opt->rep.merge_operator = |
858 | ROCKSDB_NAMESPACE::MergeOperators::CreateUInt64AddOperator(); | |
7c673cae FG |
859 | } |
860 | ||
1e59de90 TL |
861 | rocksdb_t* rocksdb_open_and_trim_history( |
862 | const rocksdb_options_t* db_options, const char* name, | |
863 | int num_column_families, const char* const* column_family_names, | |
864 | const rocksdb_options_t* const* column_family_options, | |
865 | rocksdb_column_family_handle_t** column_family_handles, char* trim_ts, | |
866 | size_t trim_tslen, char** errptr) { | |
867 | std::vector<ColumnFamilyDescriptor> column_families; | |
868 | for (int i = 0; i < num_column_families; i++) { | |
869 | column_families.push_back(ColumnFamilyDescriptor( | |
870 | std::string(column_family_names[i]), | |
871 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
872 | } | |
873 | ||
874 | std::string trim_ts_(trim_ts, trim_tslen); | |
875 | ||
876 | DB* db; | |
877 | std::vector<ColumnFamilyHandle*> handles; | |
878 | if (SaveError(errptr, DB::OpenAndTrimHistory( | |
879 | DBOptions(db_options->rep), std::string(name), | |
880 | column_families, &handles, &db, trim_ts_))) { | |
881 | return nullptr; | |
882 | } | |
883 | ||
884 | for (size_t i = 0; i < handles.size(); i++) { | |
885 | rocksdb_column_family_handle_t* c_handle = | |
886 | new rocksdb_column_family_handle_t; | |
887 | c_handle->rep = handles[i]; | |
888 | column_family_handles[i] = c_handle; | |
889 | } | |
890 | rocksdb_t* result = new rocksdb_t; | |
891 | result->rep = db; | |
892 | return result; | |
893 | } | |
894 | ||
7c673cae | 895 | rocksdb_t* rocksdb_open_column_families( |
f67539c2 TL |
896 | const rocksdb_options_t* db_options, const char* name, |
897 | int num_column_families, const char* const* column_family_names, | |
898 | const rocksdb_options_t* const* column_family_options, | |
899 | rocksdb_column_family_handle_t** column_family_handles, char** errptr) { | |
7c673cae FG |
900 | std::vector<ColumnFamilyDescriptor> column_families; |
901 | for (int i = 0; i < num_column_families; i++) { | |
902 | column_families.push_back(ColumnFamilyDescriptor( | |
903 | std::string(column_family_names[i]), | |
904 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
905 | } | |
906 | ||
907 | DB* db; | |
908 | std::vector<ColumnFamilyHandle*> handles; | |
1e59de90 TL |
909 | if (SaveError(errptr, DB::Open(DBOptions(db_options->rep), std::string(name), |
910 | column_families, &handles, &db))) { | |
7c673cae FG |
911 | return nullptr; |
912 | } | |
913 | ||
914 | for (size_t i = 0; i < handles.size(); i++) { | |
1e59de90 TL |
915 | rocksdb_column_family_handle_t* c_handle = |
916 | new rocksdb_column_family_handle_t; | |
7c673cae FG |
917 | c_handle->rep = handles[i]; |
918 | column_family_handles[i] = c_handle; | |
919 | } | |
920 | rocksdb_t* result = new rocksdb_t; | |
921 | result->rep = db; | |
922 | return result; | |
923 | } | |
924 | ||
20effc67 TL |
925 | rocksdb_t* rocksdb_open_column_families_with_ttl( |
926 | const rocksdb_options_t* db_options, const char* name, | |
927 | int num_column_families, const char* const* column_family_names, | |
928 | const rocksdb_options_t* const* column_family_options, | |
929 | rocksdb_column_family_handle_t** column_family_handles, const int* ttls, | |
930 | char** errptr) { | |
931 | std::vector<int32_t> ttls_vec; | |
932 | std::vector<ColumnFamilyDescriptor> column_families; | |
933 | for (int i = 0; i < num_column_families; i++) { | |
934 | ttls_vec.push_back(ttls[i]); | |
935 | ||
936 | column_families.push_back(ColumnFamilyDescriptor( | |
937 | std::string(column_family_names[i]), | |
938 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
939 | } | |
940 | ||
941 | ROCKSDB_NAMESPACE::DBWithTTL* db; | |
942 | std::vector<ColumnFamilyHandle*> handles; | |
943 | if (SaveError(errptr, ROCKSDB_NAMESPACE::DBWithTTL::Open( | |
944 | DBOptions(db_options->rep), std::string(name), | |
945 | column_families, &handles, &db, ttls_vec))) { | |
946 | return nullptr; | |
947 | } | |
948 | ||
949 | for (size_t i = 0; i < handles.size(); i++) { | |
950 | rocksdb_column_family_handle_t* c_handle = | |
951 | new rocksdb_column_family_handle_t; | |
952 | c_handle->rep = handles[i]; | |
953 | column_family_handles[i] = c_handle; | |
954 | } | |
955 | rocksdb_t* result = new rocksdb_t; | |
956 | result->rep = db; | |
957 | return result; | |
958 | } | |
959 | ||
7c673cae | 960 | rocksdb_t* rocksdb_open_for_read_only_column_families( |
f67539c2 TL |
961 | const rocksdb_options_t* db_options, const char* name, |
962 | int num_column_families, const char* const* column_family_names, | |
963 | const rocksdb_options_t* const* column_family_options, | |
7c673cae | 964 | rocksdb_column_family_handle_t** column_family_handles, |
20effc67 | 965 | unsigned char error_if_wal_file_exists, char** errptr) { |
7c673cae FG |
966 | std::vector<ColumnFamilyDescriptor> column_families; |
967 | for (int i = 0; i < num_column_families; i++) { | |
968 | column_families.push_back(ColumnFamilyDescriptor( | |
969 | std::string(column_family_names[i]), | |
970 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
971 | } | |
972 | ||
973 | DB* db; | |
974 | std::vector<ColumnFamilyHandle*> handles; | |
20effc67 TL |
975 | if (SaveError(errptr, |
976 | DB::OpenForReadOnly(DBOptions(db_options->rep), | |
977 | std::string(name), column_families, | |
978 | &handles, &db, error_if_wal_file_exists))) { | |
7c673cae FG |
979 | return nullptr; |
980 | } | |
981 | ||
982 | for (size_t i = 0; i < handles.size(); i++) { | |
1e59de90 TL |
983 | rocksdb_column_family_handle_t* c_handle = |
984 | new rocksdb_column_family_handle_t; | |
7c673cae FG |
985 | c_handle->rep = handles[i]; |
986 | column_family_handles[i] = c_handle; | |
987 | } | |
988 | rocksdb_t* result = new rocksdb_t; | |
989 | result->rep = db; | |
990 | return result; | |
991 | } | |
992 | ||
f67539c2 TL |
993 | rocksdb_t* rocksdb_open_as_secondary_column_families( |
994 | const rocksdb_options_t* db_options, const char* name, | |
995 | const char* secondary_path, int num_column_families, | |
996 | const char* const* column_family_names, | |
997 | const rocksdb_options_t* const* column_family_options, | |
998 | rocksdb_column_family_handle_t** column_family_handles, char** errptr) { | |
999 | std::vector<ColumnFamilyDescriptor> column_families; | |
1000 | for (int i = 0; i != num_column_families; ++i) { | |
1001 | column_families.emplace_back( | |
1002 | std::string(column_family_names[i]), | |
1003 | ColumnFamilyOptions(column_family_options[i]->rep)); | |
1004 | } | |
1005 | DB* db; | |
1006 | std::vector<ColumnFamilyHandle*> handles; | |
1007 | if (SaveError(errptr, DB::OpenAsSecondary(DBOptions(db_options->rep), | |
1008 | std::string(name), | |
1009 | std::string(secondary_path), | |
1010 | column_families, &handles, &db))) { | |
1011 | return nullptr; | |
1012 | } | |
1013 | for (size_t i = 0; i != handles.size(); ++i) { | |
1014 | rocksdb_column_family_handle_t* c_handle = | |
1015 | new rocksdb_column_family_handle_t; | |
1016 | c_handle->rep = handles[i]; | |
1017 | column_family_handles[i] = c_handle; | |
1018 | } | |
1019 | rocksdb_t* result = new rocksdb_t; | |
1020 | result->rep = db; | |
1021 | return result; | |
1022 | } | |
1023 | ||
1e59de90 TL |
1024 | char** rocksdb_list_column_families(const rocksdb_options_t* options, |
1025 | const char* name, size_t* lencfs, | |
1026 | char** errptr) { | |
7c673cae | 1027 | std::vector<std::string> fams; |
1e59de90 TL |
1028 | SaveError(errptr, DB::ListColumnFamilies(DBOptions(options->rep), |
1029 | std::string(name), &fams)); | |
7c673cae FG |
1030 | |
1031 | *lencfs = fams.size(); | |
1e59de90 TL |
1032 | char** column_families = |
1033 | static_cast<char**>(malloc(sizeof(char*) * fams.size())); | |
7c673cae FG |
1034 | for (size_t i = 0; i < fams.size(); i++) { |
1035 | column_families[i] = strdup(fams[i].c_str()); | |
1036 | } | |
1037 | return column_families; | |
1038 | } | |
1039 | ||
1040 | void rocksdb_list_column_families_destroy(char** list, size_t len) { | |
1041 | for (size_t i = 0; i < len; ++i) { | |
1042 | free(list[i]); | |
1043 | } | |
1044 | free(list); | |
1045 | } | |
1046 | ||
1047 | rocksdb_column_family_handle_t* rocksdb_create_column_family( | |
1e59de90 TL |
1048 | rocksdb_t* db, const rocksdb_options_t* column_family_options, |
1049 | const char* column_family_name, char** errptr) { | |
7c673cae | 1050 | rocksdb_column_family_handle_t* handle = new rocksdb_column_family_handle_t; |
1e59de90 TL |
1051 | SaveError(errptr, db->rep->CreateColumnFamily( |
1052 | ColumnFamilyOptions(column_family_options->rep), | |
1053 | std::string(column_family_name), &(handle->rep))); | |
7c673cae FG |
1054 | return handle; |
1055 | } | |
1056 | ||
20effc67 TL |
1057 | rocksdb_column_family_handle_t* rocksdb_create_column_family_with_ttl( |
1058 | rocksdb_t* db, const rocksdb_options_t* column_family_options, | |
1059 | const char* column_family_name, int ttl, char** errptr) { | |
1060 | ROCKSDB_NAMESPACE::DBWithTTL* db_with_ttl = | |
1061 | static_cast<ROCKSDB_NAMESPACE::DBWithTTL*>(db->rep); | |
1062 | rocksdb_column_family_handle_t* handle = new rocksdb_column_family_handle_t; | |
1063 | SaveError(errptr, db_with_ttl->CreateColumnFamilyWithTtl( | |
1064 | ColumnFamilyOptions(column_family_options->rep), | |
1065 | std::string(column_family_name), &(handle->rep), ttl)); | |
1066 | return handle; | |
1067 | } | |
1068 | ||
1e59de90 TL |
1069 | void rocksdb_drop_column_family(rocksdb_t* db, |
1070 | rocksdb_column_family_handle_t* handle, | |
1071 | char** errptr) { | |
7c673cae FG |
1072 | SaveError(errptr, db->rep->DropColumnFamily(handle->rep)); |
1073 | } | |
1074 | ||
1e59de90 TL |
1075 | uint32_t rocksdb_column_family_handle_get_id( |
1076 | rocksdb_column_family_handle_t* handle) { | |
1077 | return handle->rep->GetID(); | |
1078 | } | |
1079 | ||
1080 | char* rocksdb_column_family_handle_get_name( | |
1081 | rocksdb_column_family_handle_t* handle, size_t* name_len) { | |
1082 | auto name = handle->rep->GetName(); | |
1083 | *name_len = name.size(); | |
1084 | return CopyString(name); | |
1085 | } | |
1086 | ||
1087 | void rocksdb_column_family_handle_destroy( | |
1088 | rocksdb_column_family_handle_t* handle) { | |
7c673cae FG |
1089 | delete handle->rep; |
1090 | delete handle; | |
1091 | } | |
1092 | ||
1e59de90 TL |
1093 | void rocksdb_put(rocksdb_t* db, const rocksdb_writeoptions_t* options, |
1094 | const char* key, size_t keylen, const char* val, size_t vallen, | |
1095 | char** errptr) { | |
7c673cae FG |
1096 | SaveError(errptr, |
1097 | db->rep->Put(options->rep, Slice(key, keylen), Slice(val, vallen))); | |
1098 | } | |
1099 | ||
1e59de90 TL |
1100 | void rocksdb_put_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options, |
1101 | rocksdb_column_family_handle_t* column_family, | |
1102 | const char* key, size_t keylen, const char* val, | |
1103 | size_t vallen, char** errptr) { | |
1104 | SaveError(errptr, db->rep->Put(options->rep, column_family->rep, | |
1105 | Slice(key, keylen), Slice(val, vallen))); | |
1106 | } | |
1107 | ||
1108 | void rocksdb_put_with_ts(rocksdb_t* db, const rocksdb_writeoptions_t* options, | |
1109 | const char* key, size_t keylen, const char* ts, | |
1110 | size_t tslen, const char* val, size_t vallen, | |
1111 | char** errptr) { | |
1112 | SaveError(errptr, db->rep->Put(options->rep, Slice(key, keylen), | |
1113 | Slice(ts, tslen), Slice(val, vallen))); | |
1114 | } | |
1115 | ||
1116 | void rocksdb_put_cf_with_ts(rocksdb_t* db, | |
1117 | const rocksdb_writeoptions_t* options, | |
1118 | rocksdb_column_family_handle_t* column_family, | |
1119 | const char* key, size_t keylen, const char* ts, | |
1120 | size_t tslen, const char* val, size_t vallen, | |
1121 | char** errptr) { | |
7c673cae | 1122 | SaveError(errptr, |
1e59de90 TL |
1123 | db->rep->Put(options->rep, column_family->rep, Slice(key, keylen), |
1124 | Slice(ts, tslen), Slice(val, vallen))); | |
7c673cae FG |
1125 | } |
1126 | ||
1e59de90 TL |
1127 | void rocksdb_delete(rocksdb_t* db, const rocksdb_writeoptions_t* options, |
1128 | const char* key, size_t keylen, char** errptr) { | |
7c673cae FG |
1129 | SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen))); |
1130 | } | |
1131 | ||
1e59de90 TL |
1132 | void rocksdb_delete_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options, |
1133 | rocksdb_column_family_handle_t* column_family, | |
1134 | const char* key, size_t keylen, char** errptr) { | |
1135 | SaveError(errptr, db->rep->Delete(options->rep, column_family->rep, | |
1136 | Slice(key, keylen))); | |
1137 | } | |
1138 | ||
1139 | void rocksdb_delete_with_ts(rocksdb_t* db, | |
1140 | const rocksdb_writeoptions_t* options, | |
1141 | const char* key, size_t keylen, const char* ts, | |
1142 | size_t tslen, char** errptr) { | |
1143 | SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen), | |
1144 | Slice(ts, tslen))); | |
1145 | } | |
1146 | ||
1147 | void rocksdb_delete_cf_with_ts(rocksdb_t* db, | |
1148 | const rocksdb_writeoptions_t* options, | |
1149 | rocksdb_column_family_handle_t* column_family, | |
1150 | const char* key, size_t keylen, const char* ts, | |
1151 | size_t tslen, char** errptr) { | |
7c673cae | 1152 | SaveError(errptr, db->rep->Delete(options->rep, column_family->rep, |
1e59de90 TL |
1153 | Slice(key, keylen), Slice(ts, tslen))); |
1154 | } | |
1155 | ||
1156 | void rocksdb_singledelete(rocksdb_t* db, const rocksdb_writeoptions_t* options, | |
1157 | const char* key, size_t keylen, char** errptr) { | |
1158 | SaveError(errptr, db->rep->SingleDelete(options->rep, Slice(key, keylen))); | |
1159 | } | |
1160 | ||
1161 | void rocksdb_singledelete_cf(rocksdb_t* db, | |
1162 | const rocksdb_writeoptions_t* options, | |
1163 | rocksdb_column_family_handle_t* column_family, | |
1164 | const char* key, size_t keylen, char** errptr) { | |
1165 | SaveError(errptr, db->rep->SingleDelete(options->rep, column_family->rep, | |
1166 | Slice(key, keylen))); | |
1167 | } | |
1168 | ||
1169 | void rocksdb_singledelete_with_ts(rocksdb_t* db, | |
1170 | const rocksdb_writeoptions_t* options, | |
1171 | const char* key, size_t keylen, | |
1172 | const char* ts, size_t tslen, char** errptr) { | |
1173 | SaveError(errptr, db->rep->SingleDelete(options->rep, Slice(key, keylen), | |
1174 | Slice(ts, tslen))); | |
1175 | } | |
1176 | ||
1177 | void rocksdb_singledelete_cf_with_ts( | |
1178 | rocksdb_t* db, const rocksdb_writeoptions_t* options, | |
1179 | rocksdb_column_family_handle_t* column_family, const char* key, | |
1180 | size_t keylen, const char* ts, size_t tslen, char** errptr) { | |
1181 | SaveError(errptr, | |
1182 | db->rep->SingleDelete(options->rep, column_family->rep, | |
1183 | Slice(key, keylen), Slice(ts, tslen))); | |
1184 | } | |
1185 | ||
1186 | void rocksdb_increase_full_history_ts_low( | |
1187 | rocksdb_t* db, rocksdb_column_family_handle_t* column_family, | |
1188 | const char* ts_low, size_t ts_lowlen, char** errptr) { | |
1189 | std::string ts(ts_low, ts_lowlen); | |
1190 | SaveError(errptr, db->rep->IncreaseFullHistoryTsLow(column_family->rep, ts)); | |
1191 | } | |
1192 | ||
1193 | char* rocksdb_get_full_history_ts_low( | |
1194 | rocksdb_t* db, rocksdb_column_family_handle_t* column_family, | |
1195 | size_t* ts_len, char** errptr) { | |
1196 | char* result = nullptr; | |
1197 | std::string tmp; | |
1198 | Status s = db->rep->GetFullHistoryTsLow(column_family->rep, &tmp); | |
1199 | if (s.ok()) { | |
1200 | *ts_len = tmp.size(); | |
1201 | result = CopyString(tmp); | |
1202 | } else { | |
1203 | *ts_len = 0; | |
1204 | SaveError(errptr, s); | |
1205 | } | |
1206 | return result; | |
7c673cae FG |
1207 | } |
1208 | ||
f67539c2 TL |
1209 | void rocksdb_delete_range_cf(rocksdb_t* db, |
1210 | const rocksdb_writeoptions_t* options, | |
1211 | rocksdb_column_family_handle_t* column_family, | |
1212 | const char* start_key, size_t start_key_len, | |
1213 | const char* end_key, size_t end_key_len, | |
1214 | char** errptr) { | |
1215 | SaveError(errptr, db->rep->DeleteRange(options->rep, column_family->rep, | |
1216 | Slice(start_key, start_key_len), | |
1217 | Slice(end_key, end_key_len))); | |
1218 | } | |
1219 | ||
1e59de90 TL |
1220 | void rocksdb_merge(rocksdb_t* db, const rocksdb_writeoptions_t* options, |
1221 | const char* key, size_t keylen, const char* val, | |
1222 | size_t vallen, char** errptr) { | |
1223 | SaveError(errptr, db->rep->Merge(options->rep, Slice(key, keylen), | |
1224 | Slice(val, vallen))); | |
7c673cae FG |
1225 | } |
1226 | ||
1e59de90 TL |
1227 | void rocksdb_merge_cf(rocksdb_t* db, const rocksdb_writeoptions_t* options, |
1228 | rocksdb_column_family_handle_t* column_family, | |
1229 | const char* key, size_t keylen, const char* val, | |
1230 | size_t vallen, char** errptr) { | |
1231 | SaveError(errptr, db->rep->Merge(options->rep, column_family->rep, | |
1232 | Slice(key, keylen), Slice(val, vallen))); | |
7c673cae FG |
1233 | } |
1234 | ||
1e59de90 TL |
1235 | void rocksdb_write(rocksdb_t* db, const rocksdb_writeoptions_t* options, |
1236 | rocksdb_writebatch_t* batch, char** errptr) { | |
7c673cae FG |
1237 | SaveError(errptr, db->rep->Write(options->rep, &batch->rep)); |
1238 | } | |
1239 | ||
1e59de90 TL |
1240 | char* rocksdb_get(rocksdb_t* db, const rocksdb_readoptions_t* options, |
1241 | const char* key, size_t keylen, size_t* vallen, | |
1242 | char** errptr) { | |
7c673cae FG |
1243 | char* result = nullptr; |
1244 | std::string tmp; | |
1245 | Status s = db->rep->Get(options->rep, Slice(key, keylen), &tmp); | |
1246 | if (s.ok()) { | |
1247 | *vallen = tmp.size(); | |
1248 | result = CopyString(tmp); | |
1249 | } else { | |
1250 | *vallen = 0; | |
1251 | if (!s.IsNotFound()) { | |
1252 | SaveError(errptr, s); | |
1253 | } | |
1254 | } | |
1255 | return result; | |
1256 | } | |
1257 | ||
1e59de90 TL |
1258 | char* rocksdb_get_cf(rocksdb_t* db, const rocksdb_readoptions_t* options, |
1259 | rocksdb_column_family_handle_t* column_family, | |
1260 | const char* key, size_t keylen, size_t* vallen, | |
1261 | char** errptr) { | |
7c673cae FG |
1262 | char* result = nullptr; |
1263 | std::string tmp; | |
1e59de90 TL |
1264 | Status s = |
1265 | db->rep->Get(options->rep, column_family->rep, Slice(key, keylen), &tmp); | |
7c673cae FG |
1266 | if (s.ok()) { |
1267 | *vallen = tmp.size(); | |
1268 | result = CopyString(tmp); | |
1269 | } else { | |
1270 | *vallen = 0; | |
1271 | if (!s.IsNotFound()) { | |
1272 | SaveError(errptr, s); | |
1273 | } | |
1274 | } | |
1275 | return result; | |
1276 | } | |
1277 | ||
1e59de90 TL |
1278 | char* rocksdb_get_with_ts(rocksdb_t* db, const rocksdb_readoptions_t* options, |
1279 | const char* key, size_t keylen, size_t* vallen, | |
1280 | char** ts, size_t* tslen, char** errptr) { | |
1281 | char* result = nullptr; | |
1282 | std::string tmp_val; | |
1283 | std::string tmp_ts; | |
1284 | Status s = db->rep->Get(options->rep, Slice(key, keylen), &tmp_val, &tmp_ts); | |
1285 | if (s.ok()) { | |
1286 | *vallen = tmp_val.size(); | |
1287 | result = CopyString(tmp_val); | |
1288 | *tslen = tmp_ts.size(); | |
1289 | *ts = CopyString(tmp_ts); | |
1290 | } else { | |
1291 | *vallen = 0; | |
1292 | *tslen = 0; | |
1293 | if (!s.IsNotFound()) { | |
1294 | SaveError(errptr, s); | |
1295 | } | |
1296 | } | |
1297 | return result; | |
1298 | } | |
1299 | ||
1300 | char* rocksdb_get_cf_with_ts(rocksdb_t* db, | |
1301 | const rocksdb_readoptions_t* options, | |
1302 | rocksdb_column_family_handle_t* column_family, | |
1303 | const char* key, size_t keylen, size_t* vallen, | |
1304 | char** ts, size_t* tslen, char** errptr) { | |
1305 | char* result = nullptr; | |
1306 | std::string tmp; | |
1307 | std::string tmp_ts; | |
1308 | Status s = db->rep->Get(options->rep, column_family->rep, Slice(key, keylen), | |
1309 | &tmp, &tmp_ts); | |
1310 | if (s.ok()) { | |
1311 | *vallen = tmp.size(); | |
1312 | result = CopyString(tmp); | |
1313 | *tslen = tmp_ts.size(); | |
1314 | *ts = CopyString(tmp_ts); | |
1315 | } else { | |
1316 | *vallen = 0; | |
1317 | *tslen = 0; | |
1318 | if (!s.IsNotFound()) { | |
1319 | SaveError(errptr, s); | |
1320 | } | |
1321 | } | |
1322 | return result; | |
1323 | } | |
1324 | ||
1325 | void rocksdb_multi_get(rocksdb_t* db, const rocksdb_readoptions_t* options, | |
1326 | size_t num_keys, const char* const* keys_list, | |
1327 | const size_t* keys_list_sizes, char** values_list, | |
1328 | size_t* values_list_sizes, char** errs) { | |
7c673cae FG |
1329 | std::vector<Slice> keys(num_keys); |
1330 | for (size_t i = 0; i < num_keys; i++) { | |
1331 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1332 | } | |
1333 | std::vector<std::string> values(num_keys); | |
1334 | std::vector<Status> statuses = db->rep->MultiGet(options->rep, keys, &values); | |
1335 | for (size_t i = 0; i < num_keys; i++) { | |
1336 | if (statuses[i].ok()) { | |
1337 | values_list[i] = CopyString(values[i]); | |
1338 | values_list_sizes[i] = values[i].size(); | |
1339 | errs[i] = nullptr; | |
1340 | } else { | |
1341 | values_list[i] = nullptr; | |
1342 | values_list_sizes[i] = 0; | |
1343 | if (!statuses[i].IsNotFound()) { | |
1344 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
1345 | } else { | |
1346 | errs[i] = nullptr; | |
1347 | } | |
1348 | } | |
1349 | } | |
1350 | } | |
1351 | ||
1e59de90 TL |
1352 | void rocksdb_multi_get_with_ts(rocksdb_t* db, |
1353 | const rocksdb_readoptions_t* options, | |
1354 | size_t num_keys, const char* const* keys_list, | |
1355 | const size_t* keys_list_sizes, | |
1356 | char** values_list, size_t* values_list_sizes, | |
1357 | char** timestamp_list, | |
1358 | size_t* timestamp_list_sizes, char** errs) { | |
7c673cae | 1359 | std::vector<Slice> keys(num_keys); |
7c673cae FG |
1360 | for (size_t i = 0; i < num_keys; i++) { |
1361 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
7c673cae FG |
1362 | } |
1363 | std::vector<std::string> values(num_keys); | |
1e59de90 TL |
1364 | std::vector<std::string> timestamps(num_keys); |
1365 | std::vector<Status> statuses = | |
1366 | db->rep->MultiGet(options->rep, keys, &values, ×tamps); | |
7c673cae FG |
1367 | for (size_t i = 0; i < num_keys; i++) { |
1368 | if (statuses[i].ok()) { | |
1369 | values_list[i] = CopyString(values[i]); | |
1370 | values_list_sizes[i] = values[i].size(); | |
1e59de90 TL |
1371 | timestamp_list[i] = CopyString(timestamps[i]); |
1372 | timestamp_list_sizes[i] = timestamps[i].size(); | |
7c673cae FG |
1373 | errs[i] = nullptr; |
1374 | } else { | |
1375 | values_list[i] = nullptr; | |
1376 | values_list_sizes[i] = 0; | |
1e59de90 TL |
1377 | timestamp_list[i] = nullptr; |
1378 | timestamp_list_sizes[i] = 0; | |
7c673cae FG |
1379 | if (!statuses[i].IsNotFound()) { |
1380 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
1381 | } else { | |
1382 | errs[i] = nullptr; | |
1383 | } | |
1384 | } | |
1385 | } | |
1386 | } | |
1387 | ||
1e59de90 TL |
1388 | void rocksdb_multi_get_cf( |
1389 | rocksdb_t* db, const rocksdb_readoptions_t* options, | |
1390 | const rocksdb_column_family_handle_t* const* column_families, | |
1391 | size_t num_keys, const char* const* keys_list, | |
1392 | const size_t* keys_list_sizes, char** values_list, | |
1393 | size_t* values_list_sizes, char** errs) { | |
1394 | std::vector<Slice> keys(num_keys); | |
1395 | std::vector<ColumnFamilyHandle*> cfs(num_keys); | |
1396 | for (size_t i = 0; i < num_keys; i++) { | |
1397 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1398 | cfs[i] = column_families[i]->rep; | |
20effc67 | 1399 | } |
1e59de90 TL |
1400 | std::vector<std::string> values(num_keys); |
1401 | std::vector<Status> statuses = | |
1402 | db->rep->MultiGet(options->rep, cfs, keys, &values); | |
1403 | for (size_t i = 0; i < num_keys; i++) { | |
1404 | if (statuses[i].ok()) { | |
1405 | values_list[i] = CopyString(values[i]); | |
1406 | values_list_sizes[i] = values[i].size(); | |
1407 | errs[i] = nullptr; | |
1408 | } else { | |
1409 | values_list[i] = nullptr; | |
1410 | values_list_sizes[i] = 0; | |
1411 | if (!statuses[i].IsNotFound()) { | |
1412 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
1413 | } else { | |
1414 | errs[i] = nullptr; | |
1415 | } | |
20effc67 TL |
1416 | } |
1417 | } | |
20effc67 TL |
1418 | } |
1419 | ||
1e59de90 | 1420 | void rocksdb_multi_get_cf_with_ts( |
20effc67 | 1421 | rocksdb_t* db, const rocksdb_readoptions_t* options, |
1e59de90 TL |
1422 | const rocksdb_column_family_handle_t* const* column_families, |
1423 | size_t num_keys, const char* const* keys_list, | |
1424 | const size_t* keys_list_sizes, char** values_list, | |
1425 | size_t* values_list_sizes, char** timestamps_list, | |
1426 | size_t* timestamps_list_sizes, char** errs) { | |
1427 | std::vector<Slice> keys(num_keys); | |
1428 | std::vector<ColumnFamilyHandle*> cfs(num_keys); | |
1429 | for (size_t i = 0; i < num_keys; i++) { | |
1430 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1431 | cfs[i] = column_families[i]->rep; | |
1432 | } | |
1433 | std::vector<std::string> values(num_keys); | |
1434 | std::vector<std::string> timestamps(num_keys); | |
1435 | std::vector<Status> statuses = | |
1436 | db->rep->MultiGet(options->rep, cfs, keys, &values, ×tamps); | |
1437 | for (size_t i = 0; i < num_keys; i++) { | |
1438 | if (statuses[i].ok()) { | |
1439 | values_list[i] = CopyString(values[i]); | |
1440 | values_list_sizes[i] = values[i].size(); | |
1441 | timestamps_list[i] = CopyString(timestamps[i]); | |
1442 | timestamps_list_sizes[i] = timestamps[i].size(); | |
1443 | errs[i] = nullptr; | |
1444 | } else { | |
1445 | values_list[i] = nullptr; | |
1446 | values_list_sizes[i] = 0; | |
1447 | timestamps_list[i] = nullptr; | |
1448 | timestamps_list_sizes[i] = 0; | |
1449 | if (!statuses[i].IsNotFound()) { | |
1450 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
1451 | } else { | |
1452 | errs[i] = nullptr; | |
1453 | } | |
1454 | } | |
1455 | } | |
1456 | } | |
1457 | ||
1458 | void rocksdb_batched_multi_get_cf(rocksdb_t* db, | |
1459 | const rocksdb_readoptions_t* options, | |
1460 | rocksdb_column_family_handle_t* column_family, | |
1461 | size_t num_keys, const char* const* keys_list, | |
1462 | const size_t* keys_list_sizes, | |
1463 | rocksdb_pinnableslice_t** values, char** errs, | |
1464 | const bool sorted_input) { | |
1465 | Slice* key_slices = new Slice[num_keys]; | |
1466 | PinnableSlice* value_slices = new PinnableSlice[num_keys]; | |
1467 | Status* statuses = new Status[num_keys]; | |
1468 | for (size_t i = 0; i < num_keys; ++i) { | |
1469 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1470 | } | |
1471 | ||
1472 | db->rep->MultiGet(options->rep, column_family->rep, num_keys, key_slices, | |
1473 | value_slices, statuses, sorted_input); | |
1474 | ||
1475 | for (size_t i = 0; i < num_keys; ++i) { | |
1476 | if (statuses[i].ok()) { | |
1477 | values[i] = new (rocksdb_pinnableslice_t); | |
1478 | values[i]->rep = std::move(value_slices[i]); | |
1479 | errs[i] = nullptr; | |
1480 | } else { | |
1481 | values[i] = nullptr; | |
1482 | if (!statuses[i].IsNotFound()) { | |
1483 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
1484 | } else { | |
1485 | errs[i] = nullptr; | |
1486 | } | |
1487 | } | |
1488 | } | |
1489 | ||
1490 | delete[] key_slices; | |
1491 | delete[] value_slices; | |
1492 | delete[] statuses; | |
1493 | } | |
1494 | ||
1495 | unsigned char rocksdb_key_may_exist(rocksdb_t* db, | |
1496 | const rocksdb_readoptions_t* options, | |
1497 | const char* key, size_t key_len, | |
1498 | char** value, size_t* val_len, | |
1499 | const char* timestamp, size_t timestamp_len, | |
1500 | unsigned char* value_found) { | |
1501 | std::string tmp; | |
1502 | std::string time; | |
1503 | if (timestamp) { | |
1504 | time.assign(timestamp, timestamp_len); | |
1505 | } | |
1506 | bool found = false; | |
1507 | const bool result = db->rep->KeyMayExist(options->rep, Slice(key, key_len), | |
1508 | &tmp, timestamp ? &time : nullptr, | |
1509 | value_found ? &found : nullptr); | |
1510 | if (value_found) { | |
1511 | *value_found = found; | |
1512 | if (found) { | |
1513 | *val_len = tmp.size(); | |
1514 | *value = CopyString(tmp); | |
1515 | } | |
1516 | } | |
1517 | return result; | |
1518 | } | |
1519 | ||
1520 | unsigned char rocksdb_key_may_exist_cf( | |
1521 | rocksdb_t* db, const rocksdb_readoptions_t* options, | |
1522 | rocksdb_column_family_handle_t* column_family, const char* key, | |
1523 | size_t key_len, char** value, size_t* val_len, const char* timestamp, | |
1524 | size_t timestamp_len, unsigned char* value_found) { | |
1525 | std::string tmp; | |
1526 | std::string time; | |
1527 | if (timestamp) { | |
1528 | time.assign(timestamp, timestamp_len); | |
1529 | } | |
1530 | bool found = false; | |
1531 | const bool result = db->rep->KeyMayExist( | |
1532 | options->rep, column_family->rep, Slice(key, key_len), &tmp, | |
1533 | timestamp ? &time : nullptr, value_found ? &found : nullptr); | |
1534 | if (value_found) { | |
20effc67 TL |
1535 | *value_found = found; |
1536 | if (found) { | |
1537 | *val_len = tmp.size(); | |
1538 | *value = CopyString(tmp); | |
1539 | } | |
1540 | } | |
1541 | return result; | |
1542 | } | |
1543 | ||
7c673cae | 1544 | rocksdb_iterator_t* rocksdb_create_iterator( |
1e59de90 | 1545 | rocksdb_t* db, const rocksdb_readoptions_t* options) { |
7c673cae FG |
1546 | rocksdb_iterator_t* result = new rocksdb_iterator_t; |
1547 | result->rep = db->rep->NewIterator(options->rep); | |
1548 | return result; | |
1549 | } | |
1550 | ||
11fdf7f2 | 1551 | rocksdb_wal_iterator_t* rocksdb_get_updates_since( |
1e59de90 TL |
1552 | rocksdb_t* db, uint64_t seq_number, |
1553 | const rocksdb_wal_readoptions_t* options, char** errptr) { | |
11fdf7f2 TL |
1554 | std::unique_ptr<TransactionLogIterator> iter; |
1555 | TransactionLogIterator::ReadOptions ro; | |
1e59de90 TL |
1556 | if (options != nullptr) { |
1557 | ro = options->rep; | |
11fdf7f2 TL |
1558 | } |
1559 | if (SaveError(errptr, db->rep->GetUpdatesSince(seq_number, &iter, ro))) { | |
1560 | return nullptr; | |
1561 | } | |
1562 | rocksdb_wal_iterator_t* result = new rocksdb_wal_iterator_t; | |
1563 | result->rep = iter.release(); | |
1564 | return result; | |
1565 | } | |
1566 | ||
1e59de90 | 1567 | void rocksdb_wal_iter_next(rocksdb_wal_iterator_t* iter) { iter->rep->Next(); } |
11fdf7f2 TL |
1568 | |
1569 | unsigned char rocksdb_wal_iter_valid(const rocksdb_wal_iterator_t* iter) { | |
1e59de90 | 1570 | return iter->rep->Valid(); |
11fdf7f2 TL |
1571 | } |
1572 | ||
1e59de90 TL |
1573 | void rocksdb_wal_iter_status(const rocksdb_wal_iterator_t* iter, |
1574 | char** errptr) { | |
1575 | SaveError(errptr, iter->rep->status()); | |
11fdf7f2 TL |
1576 | } |
1577 | ||
1e59de90 | 1578 | void rocksdb_wal_iter_destroy(const rocksdb_wal_iterator_t* iter) { |
11fdf7f2 TL |
1579 | delete iter->rep; |
1580 | delete iter; | |
1581 | } | |
1582 | ||
1e59de90 TL |
1583 | rocksdb_writebatch_t* rocksdb_wal_iter_get_batch( |
1584 | const rocksdb_wal_iterator_t* iter, uint64_t* seq) { | |
11fdf7f2 TL |
1585 | rocksdb_writebatch_t* result = rocksdb_writebatch_create(); |
1586 | BatchResult wal_batch = iter->rep->GetBatch(); | |
f67539c2 | 1587 | result->rep = std::move(*wal_batch.writeBatchPtr); |
11fdf7f2 TL |
1588 | if (seq != nullptr) { |
1589 | *seq = wal_batch.sequence; | |
1590 | } | |
1591 | return result; | |
1592 | } | |
1593 | ||
1e59de90 TL |
1594 | uint64_t rocksdb_get_latest_sequence_number(rocksdb_t* db) { |
1595 | return db->rep->GetLatestSequenceNumber(); | |
11fdf7f2 TL |
1596 | } |
1597 | ||
7c673cae | 1598 | rocksdb_iterator_t* rocksdb_create_iterator_cf( |
1e59de90 | 1599 | rocksdb_t* db, const rocksdb_readoptions_t* options, |
7c673cae FG |
1600 | rocksdb_column_family_handle_t* column_family) { |
1601 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
1602 | result->rep = db->rep->NewIterator(options->rep, column_family->rep); | |
1603 | return result; | |
1604 | } | |
1605 | ||
1e59de90 TL |
1606 | void rocksdb_create_iterators(rocksdb_t* db, rocksdb_readoptions_t* opts, |
1607 | rocksdb_column_family_handle_t** column_families, | |
1608 | rocksdb_iterator_t** iterators, size_t size, | |
1609 | char** errptr) { | |
7c673cae FG |
1610 | std::vector<ColumnFamilyHandle*> column_families_vec; |
1611 | for (size_t i = 0; i < size; i++) { | |
1612 | column_families_vec.push_back(column_families[i]->rep); | |
1613 | } | |
1614 | ||
1615 | std::vector<Iterator*> res; | |
1616 | Status status = db->rep->NewIterators(opts->rep, column_families_vec, &res); | |
1617 | assert(res.size() == size); | |
1618 | if (SaveError(errptr, status)) { | |
1619 | return; | |
1620 | } | |
1621 | ||
1622 | for (size_t i = 0; i < size; i++) { | |
1623 | iterators[i] = new rocksdb_iterator_t; | |
1624 | iterators[i]->rep = res[i]; | |
1625 | } | |
1626 | } | |
1627 | ||
1e59de90 | 1628 | const rocksdb_snapshot_t* rocksdb_create_snapshot(rocksdb_t* db) { |
7c673cae FG |
1629 | rocksdb_snapshot_t* result = new rocksdb_snapshot_t; |
1630 | result->rep = db->rep->GetSnapshot(); | |
1631 | return result; | |
1632 | } | |
1633 | ||
1e59de90 TL |
1634 | void rocksdb_release_snapshot(rocksdb_t* db, |
1635 | const rocksdb_snapshot_t* snapshot) { | |
7c673cae FG |
1636 | db->rep->ReleaseSnapshot(snapshot->rep); |
1637 | delete snapshot; | |
1638 | } | |
1639 | ||
1e59de90 | 1640 | char* rocksdb_property_value(rocksdb_t* db, const char* propname) { |
7c673cae FG |
1641 | std::string tmp; |
1642 | if (db->rep->GetProperty(Slice(propname), &tmp)) { | |
1643 | // We use strdup() since we expect human readable output. | |
1644 | return strdup(tmp.c_str()); | |
1645 | } else { | |
1646 | return nullptr; | |
1647 | } | |
1648 | } | |
1649 | ||
1e59de90 TL |
1650 | int rocksdb_property_int(rocksdb_t* db, const char* propname, |
1651 | uint64_t* out_val) { | |
7c673cae FG |
1652 | if (db->rep->GetIntProperty(Slice(propname), out_val)) { |
1653 | return 0; | |
1654 | } else { | |
1655 | return -1; | |
1656 | } | |
1657 | } | |
1658 | ||
1e59de90 TL |
1659 | int rocksdb_property_int_cf(rocksdb_t* db, |
1660 | rocksdb_column_family_handle_t* column_family, | |
1661 | const char* propname, uint64_t* out_val) { | |
f67539c2 TL |
1662 | if (db->rep->GetIntProperty(column_family->rep, Slice(propname), out_val)) { |
1663 | return 0; | |
1664 | } else { | |
1665 | return -1; | |
1666 | } | |
1667 | } | |
1668 | ||
1e59de90 TL |
1669 | char* rocksdb_property_value_cf(rocksdb_t* db, |
1670 | rocksdb_column_family_handle_t* column_family, | |
1671 | const char* propname) { | |
7c673cae FG |
1672 | std::string tmp; |
1673 | if (db->rep->GetProperty(column_family->rep, Slice(propname), &tmp)) { | |
1674 | // We use strdup() since we expect human readable output. | |
1675 | return strdup(tmp.c_str()); | |
1676 | } else { | |
1677 | return nullptr; | |
1678 | } | |
1679 | } | |
1680 | ||
1e59de90 TL |
1681 | void rocksdb_approximate_sizes(rocksdb_t* db, int num_ranges, |
1682 | const char* const* range_start_key, | |
1683 | const size_t* range_start_key_len, | |
1684 | const char* const* range_limit_key, | |
1685 | const size_t* range_limit_key_len, | |
1686 | uint64_t* sizes, char** errptr) { | |
7c673cae FG |
1687 | Range* ranges = new Range[num_ranges]; |
1688 | for (int i = 0; i < num_ranges; i++) { | |
1689 | ranges[i].start = Slice(range_start_key[i], range_start_key_len[i]); | |
1690 | ranges[i].limit = Slice(range_limit_key[i], range_limit_key_len[i]); | |
1691 | } | |
1e59de90 TL |
1692 | Status s = db->rep->GetApproximateSizes(ranges, num_ranges, sizes); |
1693 | if (!s.ok()) { | |
1694 | SaveError(errptr, s); | |
1695 | } | |
7c673cae FG |
1696 | delete[] ranges; |
1697 | } | |
1698 | ||
1699 | void rocksdb_approximate_sizes_cf( | |
1e59de90 TL |
1700 | rocksdb_t* db, rocksdb_column_family_handle_t* column_family, |
1701 | int num_ranges, const char* const* range_start_key, | |
1702 | const size_t* range_start_key_len, const char* const* range_limit_key, | |
1703 | const size_t* range_limit_key_len, uint64_t* sizes, char** errptr) { | |
7c673cae FG |
1704 | Range* ranges = new Range[num_ranges]; |
1705 | for (int i = 0; i < num_ranges; i++) { | |
1706 | ranges[i].start = Slice(range_start_key[i], range_start_key_len[i]); | |
1707 | ranges[i].limit = Slice(range_limit_key[i], range_limit_key_len[i]); | |
1708 | } | |
1e59de90 TL |
1709 | Status s = db->rep->GetApproximateSizes(column_family->rep, ranges, |
1710 | num_ranges, sizes); | |
1711 | if (!s.ok()) { | |
1712 | SaveError(errptr, s); | |
1713 | } | |
7c673cae FG |
1714 | delete[] ranges; |
1715 | } | |
1716 | ||
1e59de90 | 1717 | void rocksdb_delete_file(rocksdb_t* db, const char* name) { |
7c673cae FG |
1718 | db->rep->DeleteFile(name); |
1719 | } | |
1720 | ||
1e59de90 | 1721 | const rocksdb_livefiles_t* rocksdb_livefiles(rocksdb_t* db) { |
7c673cae FG |
1722 | rocksdb_livefiles_t* result = new rocksdb_livefiles_t; |
1723 | db->rep->GetLiveFilesMetaData(&result->rep); | |
1724 | return result; | |
1725 | } | |
1726 | ||
1e59de90 TL |
1727 | void rocksdb_compact_range(rocksdb_t* db, const char* start_key, |
1728 | size_t start_key_len, const char* limit_key, | |
1729 | size_t limit_key_len) { | |
7c673cae FG |
1730 | Slice a, b; |
1731 | db->rep->CompactRange( | |
1732 | CompactRangeOptions(), | |
1733 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1734 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1735 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1736 | } | |
1737 | ||
1e59de90 TL |
1738 | void rocksdb_compact_range_cf(rocksdb_t* db, |
1739 | rocksdb_column_family_handle_t* column_family, | |
1740 | const char* start_key, size_t start_key_len, | |
1741 | const char* limit_key, size_t limit_key_len) { | |
7c673cae FG |
1742 | Slice a, b; |
1743 | db->rep->CompactRange( | |
1744 | CompactRangeOptions(), column_family->rep, | |
1745 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1746 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1747 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1748 | } | |
1749 | ||
1e59de90 TL |
1750 | void rocksdb_suggest_compact_range(rocksdb_t* db, const char* start_key, |
1751 | size_t start_key_len, const char* limit_key, | |
1752 | size_t limit_key_len, char** errptr) { | |
1753 | Slice a, b; | |
1754 | Status s = ROCKSDB_NAMESPACE::experimental::SuggestCompactRange( | |
1755 | db->rep, | |
1756 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1757 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1758 | SaveError(errptr, s); | |
1759 | } | |
1760 | ||
1761 | void rocksdb_suggest_compact_range_cf( | |
1762 | rocksdb_t* db, rocksdb_column_family_handle_t* column_family, | |
1763 | const char* start_key, size_t start_key_len, const char* limit_key, | |
1764 | size_t limit_key_len, char** errptr) { | |
1765 | Slice a, b; | |
1766 | Status s = db->rep->SuggestCompactRange( | |
1767 | column_family->rep, | |
1768 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1769 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1770 | SaveError(errptr, s); | |
1771 | } | |
1772 | ||
7c673cae FG |
1773 | void rocksdb_compact_range_opt(rocksdb_t* db, rocksdb_compactoptions_t* opt, |
1774 | const char* start_key, size_t start_key_len, | |
1775 | const char* limit_key, size_t limit_key_len) { | |
1776 | Slice a, b; | |
1777 | db->rep->CompactRange( | |
1778 | opt->rep, | |
1779 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1780 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1781 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1782 | } | |
1783 | ||
1784 | void rocksdb_compact_range_cf_opt(rocksdb_t* db, | |
1785 | rocksdb_column_family_handle_t* column_family, | |
1786 | rocksdb_compactoptions_t* opt, | |
1787 | const char* start_key, size_t start_key_len, | |
1788 | const char* limit_key, size_t limit_key_len) { | |
1789 | Slice a, b; | |
1790 | db->rep->CompactRange( | |
1791 | opt->rep, column_family->rep, | |
1792 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1793 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1794 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1795 | } | |
1796 | ||
1e59de90 TL |
1797 | void rocksdb_flush(rocksdb_t* db, const rocksdb_flushoptions_t* options, |
1798 | char** errptr) { | |
7c673cae FG |
1799 | SaveError(errptr, db->rep->Flush(options->rep)); |
1800 | } | |
1801 | ||
1e59de90 TL |
1802 | void rocksdb_flush_cf(rocksdb_t* db, const rocksdb_flushoptions_t* options, |
1803 | rocksdb_column_family_handle_t* column_family, | |
1804 | char** errptr) { | |
f67539c2 TL |
1805 | SaveError(errptr, db->rep->Flush(options->rep, column_family->rep)); |
1806 | } | |
1807 | ||
1e59de90 TL |
1808 | void rocksdb_flush_wal(rocksdb_t* db, unsigned char sync, char** errptr) { |
1809 | SaveError(errptr, db->rep->FlushWAL(sync)); | |
1810 | } | |
1811 | ||
1812 | void rocksdb_disable_file_deletions(rocksdb_t* db, char** errptr) { | |
7c673cae FG |
1813 | SaveError(errptr, db->rep->DisableFileDeletions()); |
1814 | } | |
1815 | ||
1e59de90 TL |
1816 | void rocksdb_enable_file_deletions(rocksdb_t* db, unsigned char force, |
1817 | char** errptr) { | |
7c673cae FG |
1818 | SaveError(errptr, db->rep->EnableFileDeletions(force)); |
1819 | } | |
1820 | ||
1e59de90 TL |
1821 | void rocksdb_destroy_db(const rocksdb_options_t* options, const char* name, |
1822 | char** errptr) { | |
7c673cae FG |
1823 | SaveError(errptr, DestroyDB(name, options->rep)); |
1824 | } | |
1825 | ||
1e59de90 TL |
1826 | void rocksdb_repair_db(const rocksdb_options_t* options, const char* name, |
1827 | char** errptr) { | |
7c673cae FG |
1828 | SaveError(errptr, RepairDB(name, options->rep)); |
1829 | } | |
1830 | ||
1831 | void rocksdb_iter_destroy(rocksdb_iterator_t* iter) { | |
1832 | delete iter->rep; | |
1833 | delete iter; | |
1834 | } | |
1835 | ||
1836 | unsigned char rocksdb_iter_valid(const rocksdb_iterator_t* iter) { | |
1837 | return iter->rep->Valid(); | |
1838 | } | |
1839 | ||
1840 | void rocksdb_iter_seek_to_first(rocksdb_iterator_t* iter) { | |
1841 | iter->rep->SeekToFirst(); | |
1842 | } | |
1843 | ||
1844 | void rocksdb_iter_seek_to_last(rocksdb_iterator_t* iter) { | |
1845 | iter->rep->SeekToLast(); | |
1846 | } | |
1847 | ||
1848 | void rocksdb_iter_seek(rocksdb_iterator_t* iter, const char* k, size_t klen) { | |
1849 | iter->rep->Seek(Slice(k, klen)); | |
1850 | } | |
1851 | ||
1852 | void rocksdb_iter_seek_for_prev(rocksdb_iterator_t* iter, const char* k, | |
1853 | size_t klen) { | |
1854 | iter->rep->SeekForPrev(Slice(k, klen)); | |
1855 | } | |
1856 | ||
1e59de90 | 1857 | void rocksdb_iter_next(rocksdb_iterator_t* iter) { iter->rep->Next(); } |
7c673cae | 1858 | |
1e59de90 | 1859 | void rocksdb_iter_prev(rocksdb_iterator_t* iter) { iter->rep->Prev(); } |
7c673cae FG |
1860 | |
1861 | const char* rocksdb_iter_key(const rocksdb_iterator_t* iter, size_t* klen) { | |
1862 | Slice s = iter->rep->key(); | |
1863 | *klen = s.size(); | |
1864 | return s.data(); | |
1865 | } | |
1866 | ||
1867 | const char* rocksdb_iter_value(const rocksdb_iterator_t* iter, size_t* vlen) { | |
1868 | Slice s = iter->rep->value(); | |
1869 | *vlen = s.size(); | |
1870 | return s.data(); | |
1871 | } | |
1872 | ||
1e59de90 TL |
1873 | const char* rocksdb_iter_timestamp(const rocksdb_iterator_t* iter, |
1874 | size_t* tslen) { | |
1875 | Slice s = iter->rep->timestamp(); | |
1876 | *tslen = s.size(); | |
1877 | return s.data(); | |
1878 | } | |
1879 | ||
7c673cae FG |
1880 | void rocksdb_iter_get_error(const rocksdb_iterator_t* iter, char** errptr) { |
1881 | SaveError(errptr, iter->rep->status()); | |
1882 | } | |
1883 | ||
1884 | rocksdb_writebatch_t* rocksdb_writebatch_create() { | |
1885 | return new rocksdb_writebatch_t; | |
1886 | } | |
1887 | ||
1888 | rocksdb_writebatch_t* rocksdb_writebatch_create_from(const char* rep, | |
1889 | size_t size) { | |
1890 | rocksdb_writebatch_t* b = new rocksdb_writebatch_t; | |
1891 | b->rep = WriteBatch(std::string(rep, size)); | |
1892 | return b; | |
1893 | } | |
1894 | ||
1e59de90 | 1895 | void rocksdb_writebatch_destroy(rocksdb_writebatch_t* b) { delete b; } |
7c673cae | 1896 | |
1e59de90 | 1897 | void rocksdb_writebatch_clear(rocksdb_writebatch_t* b) { b->rep.Clear(); } |
7c673cae | 1898 | |
1e59de90 | 1899 | int rocksdb_writebatch_count(rocksdb_writebatch_t* b) { return b->rep.Count(); } |
7c673cae | 1900 | |
1e59de90 TL |
1901 | void rocksdb_writebatch_put(rocksdb_writebatch_t* b, const char* key, |
1902 | size_t klen, const char* val, size_t vlen) { | |
7c673cae FG |
1903 | b->rep.Put(Slice(key, klen), Slice(val, vlen)); |
1904 | } | |
1905 | ||
1e59de90 TL |
1906 | void rocksdb_writebatch_put_cf(rocksdb_writebatch_t* b, |
1907 | rocksdb_column_family_handle_t* column_family, | |
1908 | const char* key, size_t klen, const char* val, | |
1909 | size_t vlen) { | |
7c673cae FG |
1910 | b->rep.Put(column_family->rep, Slice(key, klen), Slice(val, vlen)); |
1911 | } | |
1912 | ||
1e59de90 TL |
1913 | void rocksdb_writebatch_put_cf_with_ts( |
1914 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
1915 | const char* key, size_t klen, const char* ts, size_t tslen, const char* val, | |
1916 | size_t vlen) { | |
1917 | b->rep.Put(column_family->rep, Slice(key, klen), Slice(ts, tslen), | |
1918 | Slice(val, vlen)); | |
1919 | } | |
1920 | ||
1921 | void rocksdb_writebatch_putv(rocksdb_writebatch_t* b, int num_keys, | |
1922 | const char* const* keys_list, | |
1923 | const size_t* keys_list_sizes, int num_values, | |
1924 | const char* const* values_list, | |
1925 | const size_t* values_list_sizes) { | |
7c673cae FG |
1926 | std::vector<Slice> key_slices(num_keys); |
1927 | for (int i = 0; i < num_keys; i++) { | |
1928 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1929 | } | |
1930 | std::vector<Slice> value_slices(num_values); | |
1931 | for (int i = 0; i < num_values; i++) { | |
1932 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1933 | } | |
1934 | b->rep.Put(SliceParts(key_slices.data(), num_keys), | |
1935 | SliceParts(value_slices.data(), num_values)); | |
1936 | } | |
1937 | ||
1e59de90 TL |
1938 | void rocksdb_writebatch_putv_cf(rocksdb_writebatch_t* b, |
1939 | rocksdb_column_family_handle_t* column_family, | |
1940 | int num_keys, const char* const* keys_list, | |
1941 | const size_t* keys_list_sizes, int num_values, | |
1942 | const char* const* values_list, | |
1943 | const size_t* values_list_sizes) { | |
7c673cae FG |
1944 | std::vector<Slice> key_slices(num_keys); |
1945 | for (int i = 0; i < num_keys; i++) { | |
1946 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1947 | } | |
1948 | std::vector<Slice> value_slices(num_values); | |
1949 | for (int i = 0; i < num_values; i++) { | |
1950 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1951 | } | |
1952 | b->rep.Put(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
1953 | SliceParts(value_slices.data(), num_values)); | |
1954 | } | |
1955 | ||
1e59de90 TL |
1956 | void rocksdb_writebatch_merge(rocksdb_writebatch_t* b, const char* key, |
1957 | size_t klen, const char* val, size_t vlen) { | |
7c673cae FG |
1958 | b->rep.Merge(Slice(key, klen), Slice(val, vlen)); |
1959 | } | |
1960 | ||
1e59de90 TL |
1961 | void rocksdb_writebatch_merge_cf(rocksdb_writebatch_t* b, |
1962 | rocksdb_column_family_handle_t* column_family, | |
1963 | const char* key, size_t klen, const char* val, | |
1964 | size_t vlen) { | |
7c673cae FG |
1965 | b->rep.Merge(column_family->rep, Slice(key, klen), Slice(val, vlen)); |
1966 | } | |
1967 | ||
1e59de90 TL |
1968 | void rocksdb_writebatch_mergev(rocksdb_writebatch_t* b, int num_keys, |
1969 | const char* const* keys_list, | |
1970 | const size_t* keys_list_sizes, int num_values, | |
1971 | const char* const* values_list, | |
1972 | const size_t* values_list_sizes) { | |
7c673cae FG |
1973 | std::vector<Slice> key_slices(num_keys); |
1974 | for (int i = 0; i < num_keys; i++) { | |
1975 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1976 | } | |
1977 | std::vector<Slice> value_slices(num_values); | |
1978 | for (int i = 0; i < num_values; i++) { | |
1979 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1980 | } | |
1981 | b->rep.Merge(SliceParts(key_slices.data(), num_keys), | |
1982 | SliceParts(value_slices.data(), num_values)); | |
1983 | } | |
1984 | ||
1e59de90 TL |
1985 | void rocksdb_writebatch_mergev_cf(rocksdb_writebatch_t* b, |
1986 | rocksdb_column_family_handle_t* column_family, | |
1987 | int num_keys, const char* const* keys_list, | |
1988 | const size_t* keys_list_sizes, int num_values, | |
1989 | const char* const* values_list, | |
1990 | const size_t* values_list_sizes) { | |
7c673cae FG |
1991 | std::vector<Slice> key_slices(num_keys); |
1992 | for (int i = 0; i < num_keys; i++) { | |
1993 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1994 | } | |
1995 | std::vector<Slice> value_slices(num_values); | |
1996 | for (int i = 0; i < num_values; i++) { | |
1997 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1998 | } | |
1999 | b->rep.Merge(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
2000 | SliceParts(value_slices.data(), num_values)); | |
2001 | } | |
2002 | ||
1e59de90 TL |
2003 | void rocksdb_writebatch_delete(rocksdb_writebatch_t* b, const char* key, |
2004 | size_t klen) { | |
7c673cae FG |
2005 | b->rep.Delete(Slice(key, klen)); |
2006 | } | |
2007 | ||
20effc67 TL |
2008 | void rocksdb_writebatch_singledelete(rocksdb_writebatch_t* b, const char* key, |
2009 | size_t klen) { | |
2010 | b->rep.SingleDelete(Slice(key, klen)); | |
2011 | } | |
2012 | ||
1e59de90 TL |
2013 | void rocksdb_writebatch_delete_cf(rocksdb_writebatch_t* b, |
2014 | rocksdb_column_family_handle_t* column_family, | |
2015 | const char* key, size_t klen) { | |
7c673cae FG |
2016 | b->rep.Delete(column_family->rep, Slice(key, klen)); |
2017 | } | |
2018 | ||
1e59de90 TL |
2019 | void rocksdb_writebatch_delete_cf_with_ts( |
2020 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
2021 | const char* key, size_t klen, const char* ts, size_t tslen) { | |
2022 | b->rep.Delete(column_family->rep, Slice(key, klen), Slice(ts, tslen)); | |
2023 | } | |
2024 | ||
20effc67 TL |
2025 | void rocksdb_writebatch_singledelete_cf( |
2026 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
2027 | const char* key, size_t klen) { | |
2028 | b->rep.SingleDelete(column_family->rep, Slice(key, klen)); | |
2029 | } | |
2030 | ||
1e59de90 TL |
2031 | void rocksdb_writebatch_singledelete_cf_with_ts( |
2032 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
2033 | const char* key, size_t klen, const char* ts, size_t tslen) { | |
2034 | b->rep.SingleDelete(column_family->rep, Slice(key, klen), Slice(ts, tslen)); | |
2035 | } | |
2036 | ||
2037 | void rocksdb_writebatch_deletev(rocksdb_writebatch_t* b, int num_keys, | |
2038 | const char* const* keys_list, | |
2039 | const size_t* keys_list_sizes) { | |
7c673cae FG |
2040 | std::vector<Slice> key_slices(num_keys); |
2041 | for (int i = 0; i < num_keys; i++) { | |
2042 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2043 | } | |
2044 | b->rep.Delete(SliceParts(key_slices.data(), num_keys)); | |
2045 | } | |
2046 | ||
2047 | void rocksdb_writebatch_deletev_cf( | |
1e59de90 TL |
2048 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, |
2049 | int num_keys, const char* const* keys_list, const size_t* keys_list_sizes) { | |
7c673cae FG |
2050 | std::vector<Slice> key_slices(num_keys); |
2051 | for (int i = 0; i < num_keys; i++) { | |
2052 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2053 | } | |
2054 | b->rep.Delete(column_family->rep, SliceParts(key_slices.data(), num_keys)); | |
2055 | } | |
2056 | ||
2057 | void rocksdb_writebatch_delete_range(rocksdb_writebatch_t* b, | |
2058 | const char* start_key, | |
2059 | size_t start_key_len, const char* end_key, | |
2060 | size_t end_key_len) { | |
2061 | b->rep.DeleteRange(Slice(start_key, start_key_len), | |
2062 | Slice(end_key, end_key_len)); | |
2063 | } | |
2064 | ||
2065 | void rocksdb_writebatch_delete_range_cf( | |
2066 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
2067 | const char* start_key, size_t start_key_len, const char* end_key, | |
2068 | size_t end_key_len) { | |
2069 | b->rep.DeleteRange(column_family->rep, Slice(start_key, start_key_len), | |
2070 | Slice(end_key, end_key_len)); | |
2071 | } | |
2072 | ||
2073 | void rocksdb_writebatch_delete_rangev(rocksdb_writebatch_t* b, int num_keys, | |
2074 | const char* const* start_keys_list, | |
2075 | const size_t* start_keys_list_sizes, | |
2076 | const char* const* end_keys_list, | |
2077 | const size_t* end_keys_list_sizes) { | |
2078 | std::vector<Slice> start_key_slices(num_keys); | |
2079 | std::vector<Slice> end_key_slices(num_keys); | |
2080 | for (int i = 0; i < num_keys; i++) { | |
2081 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
2082 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
2083 | } | |
2084 | b->rep.DeleteRange(SliceParts(start_key_slices.data(), num_keys), | |
2085 | SliceParts(end_key_slices.data(), num_keys)); | |
2086 | } | |
2087 | ||
2088 | void rocksdb_writebatch_delete_rangev_cf( | |
2089 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
2090 | int num_keys, const char* const* start_keys_list, | |
2091 | const size_t* start_keys_list_sizes, const char* const* end_keys_list, | |
2092 | const size_t* end_keys_list_sizes) { | |
2093 | std::vector<Slice> start_key_slices(num_keys); | |
2094 | std::vector<Slice> end_key_slices(num_keys); | |
2095 | for (int i = 0; i < num_keys; i++) { | |
2096 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
2097 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
2098 | } | |
2099 | b->rep.DeleteRange(column_family->rep, | |
2100 | SliceParts(start_key_slices.data(), num_keys), | |
2101 | SliceParts(end_key_slices.data(), num_keys)); | |
2102 | } | |
2103 | ||
1e59de90 TL |
2104 | void rocksdb_writebatch_put_log_data(rocksdb_writebatch_t* b, const char* blob, |
2105 | size_t len) { | |
7c673cae FG |
2106 | b->rep.PutLogData(Slice(blob, len)); |
2107 | } | |
2108 | ||
11fdf7f2 TL |
2109 | class H : public WriteBatch::Handler { |
2110 | public: | |
2111 | void* state_; | |
2112 | void (*put_)(void*, const char* k, size_t klen, const char* v, size_t vlen); | |
2113 | void (*deleted_)(void*, const char* k, size_t klen); | |
494da23a | 2114 | void Put(const Slice& key, const Slice& value) override { |
11fdf7f2 TL |
2115 | (*put_)(state_, key.data(), key.size(), value.data(), value.size()); |
2116 | } | |
494da23a | 2117 | void Delete(const Slice& key) override { |
11fdf7f2 TL |
2118 | (*deleted_)(state_, key.data(), key.size()); |
2119 | } | |
2120 | }; | |
2121 | ||
1e59de90 TL |
2122 | void rocksdb_writebatch_iterate(rocksdb_writebatch_t* b, void* state, |
2123 | void (*put)(void*, const char* k, size_t klen, | |
2124 | const char* v, size_t vlen), | |
2125 | void (*deleted)(void*, const char* k, | |
2126 | size_t klen)) { | |
7c673cae FG |
2127 | H handler; |
2128 | handler.state_ = state; | |
2129 | handler.put_ = put; | |
2130 | handler.deleted_ = deleted; | |
2131 | b->rep.Iterate(&handler); | |
2132 | } | |
2133 | ||
2134 | const char* rocksdb_writebatch_data(rocksdb_writebatch_t* b, size_t* size) { | |
2135 | *size = b->rep.GetDataSize(); | |
2136 | return b->rep.Data().c_str(); | |
2137 | } | |
2138 | ||
2139 | void rocksdb_writebatch_set_save_point(rocksdb_writebatch_t* b) { | |
2140 | b->rep.SetSavePoint(); | |
2141 | } | |
2142 | ||
2143 | void rocksdb_writebatch_rollback_to_save_point(rocksdb_writebatch_t* b, | |
2144 | char** errptr) { | |
2145 | SaveError(errptr, b->rep.RollbackToSavePoint()); | |
2146 | } | |
2147 | ||
11fdf7f2 TL |
2148 | void rocksdb_writebatch_pop_save_point(rocksdb_writebatch_t* b, char** errptr) { |
2149 | SaveError(errptr, b->rep.PopSavePoint()); | |
2150 | } | |
2151 | ||
1e59de90 TL |
2152 | rocksdb_writebatch_wi_t* rocksdb_writebatch_wi_create( |
2153 | size_t reserved_bytes, unsigned char overwrite_key) { | |
7c673cae | 2154 | rocksdb_writebatch_wi_t* b = new rocksdb_writebatch_wi_t; |
1e59de90 TL |
2155 | b->rep = new WriteBatchWithIndex(BytewiseComparator(), reserved_bytes, |
2156 | overwrite_key); | |
7c673cae FG |
2157 | return b; |
2158 | } | |
2159 | ||
2160 | void rocksdb_writebatch_wi_destroy(rocksdb_writebatch_wi_t* b) { | |
2161 | if (b->rep) { | |
2162 | delete b->rep; | |
2163 | } | |
2164 | delete b; | |
2165 | } | |
2166 | ||
2167 | void rocksdb_writebatch_wi_clear(rocksdb_writebatch_wi_t* b) { | |
2168 | b->rep->Clear(); | |
2169 | } | |
2170 | ||
2171 | int rocksdb_writebatch_wi_count(rocksdb_writebatch_wi_t* b) { | |
2172 | return b->rep->GetWriteBatch()->Count(); | |
2173 | } | |
2174 | ||
1e59de90 TL |
2175 | void rocksdb_writebatch_wi_put(rocksdb_writebatch_wi_t* b, const char* key, |
2176 | size_t klen, const char* val, size_t vlen) { | |
7c673cae FG |
2177 | b->rep->Put(Slice(key, klen), Slice(val, vlen)); |
2178 | } | |
2179 | ||
1e59de90 TL |
2180 | void rocksdb_writebatch_wi_put_cf(rocksdb_writebatch_wi_t* b, |
2181 | rocksdb_column_family_handle_t* column_family, | |
2182 | const char* key, size_t klen, const char* val, | |
2183 | size_t vlen) { | |
7c673cae FG |
2184 | b->rep->Put(column_family->rep, Slice(key, klen), Slice(val, vlen)); |
2185 | } | |
2186 | ||
1e59de90 TL |
2187 | void rocksdb_writebatch_wi_putv(rocksdb_writebatch_wi_t* b, int num_keys, |
2188 | const char* const* keys_list, | |
2189 | const size_t* keys_list_sizes, int num_values, | |
2190 | const char* const* values_list, | |
2191 | const size_t* values_list_sizes) { | |
7c673cae FG |
2192 | std::vector<Slice> key_slices(num_keys); |
2193 | for (int i = 0; i < num_keys; i++) { | |
2194 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2195 | } | |
2196 | std::vector<Slice> value_slices(num_values); | |
2197 | for (int i = 0; i < num_values; i++) { | |
2198 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
2199 | } | |
2200 | b->rep->Put(SliceParts(key_slices.data(), num_keys), | |
1e59de90 | 2201 | SliceParts(value_slices.data(), num_values)); |
7c673cae FG |
2202 | } |
2203 | ||
2204 | void rocksdb_writebatch_wi_putv_cf( | |
1e59de90 TL |
2205 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, |
2206 | int num_keys, const char* const* keys_list, const size_t* keys_list_sizes, | |
7c673cae FG |
2207 | int num_values, const char* const* values_list, |
2208 | const size_t* values_list_sizes) { | |
2209 | std::vector<Slice> key_slices(num_keys); | |
2210 | for (int i = 0; i < num_keys; i++) { | |
2211 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2212 | } | |
2213 | std::vector<Slice> value_slices(num_values); | |
2214 | for (int i = 0; i < num_values; i++) { | |
2215 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
2216 | } | |
2217 | b->rep->Put(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
1e59de90 | 2218 | SliceParts(value_slices.data(), num_values)); |
7c673cae FG |
2219 | } |
2220 | ||
1e59de90 TL |
2221 | void rocksdb_writebatch_wi_merge(rocksdb_writebatch_wi_t* b, const char* key, |
2222 | size_t klen, const char* val, size_t vlen) { | |
7c673cae FG |
2223 | b->rep->Merge(Slice(key, klen), Slice(val, vlen)); |
2224 | } | |
2225 | ||
2226 | void rocksdb_writebatch_wi_merge_cf( | |
1e59de90 TL |
2227 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, |
2228 | const char* key, size_t klen, const char* val, size_t vlen) { | |
7c673cae FG |
2229 | b->rep->Merge(column_family->rep, Slice(key, klen), Slice(val, vlen)); |
2230 | } | |
2231 | ||
1e59de90 TL |
2232 | void rocksdb_writebatch_wi_mergev(rocksdb_writebatch_wi_t* b, int num_keys, |
2233 | const char* const* keys_list, | |
2234 | const size_t* keys_list_sizes, int num_values, | |
2235 | const char* const* values_list, | |
2236 | const size_t* values_list_sizes) { | |
7c673cae FG |
2237 | std::vector<Slice> key_slices(num_keys); |
2238 | for (int i = 0; i < num_keys; i++) { | |
2239 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2240 | } | |
2241 | std::vector<Slice> value_slices(num_values); | |
2242 | for (int i = 0; i < num_values; i++) { | |
2243 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
2244 | } | |
2245 | b->rep->Merge(SliceParts(key_slices.data(), num_keys), | |
1e59de90 | 2246 | SliceParts(value_slices.data(), num_values)); |
7c673cae FG |
2247 | } |
2248 | ||
2249 | void rocksdb_writebatch_wi_mergev_cf( | |
1e59de90 TL |
2250 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, |
2251 | int num_keys, const char* const* keys_list, const size_t* keys_list_sizes, | |
7c673cae FG |
2252 | int num_values, const char* const* values_list, |
2253 | const size_t* values_list_sizes) { | |
2254 | std::vector<Slice> key_slices(num_keys); | |
2255 | for (int i = 0; i < num_keys; i++) { | |
2256 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2257 | } | |
2258 | std::vector<Slice> value_slices(num_values); | |
2259 | for (int i = 0; i < num_values; i++) { | |
2260 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
2261 | } | |
2262 | b->rep->Merge(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
1e59de90 | 2263 | SliceParts(value_slices.data(), num_values)); |
7c673cae FG |
2264 | } |
2265 | ||
1e59de90 TL |
2266 | void rocksdb_writebatch_wi_delete(rocksdb_writebatch_wi_t* b, const char* key, |
2267 | size_t klen) { | |
7c673cae FG |
2268 | b->rep->Delete(Slice(key, klen)); |
2269 | } | |
2270 | ||
20effc67 TL |
2271 | void rocksdb_writebatch_wi_singledelete(rocksdb_writebatch_wi_t* b, |
2272 | const char* key, size_t klen) { | |
2273 | b->rep->SingleDelete(Slice(key, klen)); | |
2274 | } | |
2275 | ||
7c673cae | 2276 | void rocksdb_writebatch_wi_delete_cf( |
1e59de90 | 2277 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, |
7c673cae FG |
2278 | const char* key, size_t klen) { |
2279 | b->rep->Delete(column_family->rep, Slice(key, klen)); | |
2280 | } | |
2281 | ||
20effc67 TL |
2282 | void rocksdb_writebatch_wi_singledelete_cf( |
2283 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, | |
2284 | const char* key, size_t klen) { | |
2285 | b->rep->SingleDelete(column_family->rep, Slice(key, klen)); | |
2286 | } | |
2287 | ||
1e59de90 TL |
2288 | void rocksdb_writebatch_wi_deletev(rocksdb_writebatch_wi_t* b, int num_keys, |
2289 | const char* const* keys_list, | |
2290 | const size_t* keys_list_sizes) { | |
7c673cae FG |
2291 | std::vector<Slice> key_slices(num_keys); |
2292 | for (int i = 0; i < num_keys; i++) { | |
2293 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2294 | } | |
2295 | b->rep->Delete(SliceParts(key_slices.data(), num_keys)); | |
2296 | } | |
2297 | ||
2298 | void rocksdb_writebatch_wi_deletev_cf( | |
1e59de90 TL |
2299 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, |
2300 | int num_keys, const char* const* keys_list, const size_t* keys_list_sizes) { | |
7c673cae FG |
2301 | std::vector<Slice> key_slices(num_keys); |
2302 | for (int i = 0; i < num_keys; i++) { | |
2303 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
2304 | } | |
2305 | b->rep->Delete(column_family->rep, SliceParts(key_slices.data(), num_keys)); | |
2306 | } | |
2307 | ||
2308 | void rocksdb_writebatch_wi_delete_range(rocksdb_writebatch_wi_t* b, | |
1e59de90 TL |
2309 | const char* start_key, |
2310 | size_t start_key_len, | |
2311 | const char* end_key, | |
2312 | size_t end_key_len) { | |
7c673cae | 2313 | b->rep->DeleteRange(Slice(start_key, start_key_len), |
1e59de90 | 2314 | Slice(end_key, end_key_len)); |
7c673cae FG |
2315 | } |
2316 | ||
2317 | void rocksdb_writebatch_wi_delete_range_cf( | |
2318 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, | |
2319 | const char* start_key, size_t start_key_len, const char* end_key, | |
2320 | size_t end_key_len) { | |
2321 | b->rep->DeleteRange(column_family->rep, Slice(start_key, start_key_len), | |
1e59de90 | 2322 | Slice(end_key, end_key_len)); |
7c673cae FG |
2323 | } |
2324 | ||
1e59de90 TL |
2325 | void rocksdb_writebatch_wi_delete_rangev(rocksdb_writebatch_wi_t* b, |
2326 | int num_keys, | |
2327 | const char* const* start_keys_list, | |
2328 | const size_t* start_keys_list_sizes, | |
2329 | const char* const* end_keys_list, | |
2330 | const size_t* end_keys_list_sizes) { | |
7c673cae FG |
2331 | std::vector<Slice> start_key_slices(num_keys); |
2332 | std::vector<Slice> end_key_slices(num_keys); | |
2333 | for (int i = 0; i < num_keys; i++) { | |
2334 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
2335 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
2336 | } | |
2337 | b->rep->DeleteRange(SliceParts(start_key_slices.data(), num_keys), | |
1e59de90 | 2338 | SliceParts(end_key_slices.data(), num_keys)); |
7c673cae FG |
2339 | } |
2340 | ||
2341 | void rocksdb_writebatch_wi_delete_rangev_cf( | |
2342 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, | |
2343 | int num_keys, const char* const* start_keys_list, | |
2344 | const size_t* start_keys_list_sizes, const char* const* end_keys_list, | |
2345 | const size_t* end_keys_list_sizes) { | |
2346 | std::vector<Slice> start_key_slices(num_keys); | |
2347 | std::vector<Slice> end_key_slices(num_keys); | |
2348 | for (int i = 0; i < num_keys; i++) { | |
2349 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
2350 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
2351 | } | |
2352 | b->rep->DeleteRange(column_family->rep, | |
1e59de90 TL |
2353 | SliceParts(start_key_slices.data(), num_keys), |
2354 | SliceParts(end_key_slices.data(), num_keys)); | |
7c673cae FG |
2355 | } |
2356 | ||
1e59de90 TL |
2357 | void rocksdb_writebatch_wi_put_log_data(rocksdb_writebatch_wi_t* b, |
2358 | const char* blob, size_t len) { | |
7c673cae FG |
2359 | b->rep->PutLogData(Slice(blob, len)); |
2360 | } | |
2361 | ||
2362 | void rocksdb_writebatch_wi_iterate( | |
1e59de90 | 2363 | rocksdb_writebatch_wi_t* b, void* state, |
7c673cae FG |
2364 | void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), |
2365 | void (*deleted)(void*, const char* k, size_t klen)) { | |
7c673cae FG |
2366 | H handler; |
2367 | handler.state_ = state; | |
2368 | handler.put_ = put; | |
2369 | handler.deleted_ = deleted; | |
2370 | b->rep->GetWriteBatch()->Iterate(&handler); | |
2371 | } | |
2372 | ||
1e59de90 TL |
2373 | const char* rocksdb_writebatch_wi_data(rocksdb_writebatch_wi_t* b, |
2374 | size_t* size) { | |
7c673cae FG |
2375 | WriteBatch* wb = b->rep->GetWriteBatch(); |
2376 | *size = wb->GetDataSize(); | |
2377 | return wb->Data().c_str(); | |
2378 | } | |
2379 | ||
2380 | void rocksdb_writebatch_wi_set_save_point(rocksdb_writebatch_wi_t* b) { | |
2381 | b->rep->SetSavePoint(); | |
2382 | } | |
2383 | ||
2384 | void rocksdb_writebatch_wi_rollback_to_save_point(rocksdb_writebatch_wi_t* b, | |
1e59de90 | 2385 | char** errptr) { |
7c673cae FG |
2386 | SaveError(errptr, b->rep->RollbackToSavePoint()); |
2387 | } | |
2388 | ||
2389 | rocksdb_iterator_t* rocksdb_writebatch_wi_create_iterator_with_base( | |
1e59de90 | 2390 | rocksdb_writebatch_wi_t* wbwi, rocksdb_iterator_t* base_iterator) { |
7c673cae FG |
2391 | rocksdb_iterator_t* result = new rocksdb_iterator_t; |
2392 | result->rep = wbwi->rep->NewIteratorWithBase(base_iterator->rep); | |
2393 | delete base_iterator; | |
2394 | return result; | |
2395 | } | |
2396 | ||
2397 | rocksdb_iterator_t* rocksdb_writebatch_wi_create_iterator_with_base_cf( | |
494da23a | 2398 | rocksdb_writebatch_wi_t* wbwi, rocksdb_iterator_t* base_iterator, |
7c673cae FG |
2399 | rocksdb_column_family_handle_t* column_family) { |
2400 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
494da23a TL |
2401 | result->rep = |
2402 | wbwi->rep->NewIteratorWithBase(column_family->rep, base_iterator->rep); | |
7c673cae FG |
2403 | delete base_iterator; |
2404 | return result; | |
2405 | } | |
2406 | ||
1e59de90 TL |
2407 | char* rocksdb_writebatch_wi_get_from_batch(rocksdb_writebatch_wi_t* wbwi, |
2408 | const rocksdb_options_t* options, | |
2409 | const char* key, size_t keylen, | |
2410 | size_t* vallen, char** errptr) { | |
7c673cae FG |
2411 | char* result = nullptr; |
2412 | std::string tmp; | |
2413 | Status s = wbwi->rep->GetFromBatch(options->rep, Slice(key, keylen), &tmp); | |
2414 | if (s.ok()) { | |
2415 | *vallen = tmp.size(); | |
2416 | result = CopyString(tmp); | |
2417 | } else { | |
2418 | *vallen = 0; | |
2419 | if (!s.IsNotFound()) { | |
2420 | SaveError(errptr, s); | |
2421 | } | |
2422 | } | |
2423 | return result; | |
2424 | } | |
2425 | ||
2426 | char* rocksdb_writebatch_wi_get_from_batch_cf( | |
1e59de90 TL |
2427 | rocksdb_writebatch_wi_t* wbwi, const rocksdb_options_t* options, |
2428 | rocksdb_column_family_handle_t* column_family, const char* key, | |
2429 | size_t keylen, size_t* vallen, char** errptr) { | |
7c673cae FG |
2430 | char* result = nullptr; |
2431 | std::string tmp; | |
2432 | Status s = wbwi->rep->GetFromBatch(column_family->rep, options->rep, | |
1e59de90 | 2433 | Slice(key, keylen), &tmp); |
7c673cae FG |
2434 | if (s.ok()) { |
2435 | *vallen = tmp.size(); | |
2436 | result = CopyString(tmp); | |
2437 | } else { | |
2438 | *vallen = 0; | |
2439 | if (!s.IsNotFound()) { | |
2440 | SaveError(errptr, s); | |
2441 | } | |
2442 | } | |
2443 | return result; | |
2444 | } | |
2445 | ||
2446 | char* rocksdb_writebatch_wi_get_from_batch_and_db( | |
1e59de90 TL |
2447 | rocksdb_writebatch_wi_t* wbwi, rocksdb_t* db, |
2448 | const rocksdb_readoptions_t* options, const char* key, size_t keylen, | |
2449 | size_t* vallen, char** errptr) { | |
7c673cae FG |
2450 | char* result = nullptr; |
2451 | std::string tmp; | |
1e59de90 TL |
2452 | Status s = wbwi->rep->GetFromBatchAndDB(db->rep, options->rep, |
2453 | Slice(key, keylen), &tmp); | |
7c673cae FG |
2454 | if (s.ok()) { |
2455 | *vallen = tmp.size(); | |
2456 | result = CopyString(tmp); | |
2457 | } else { | |
2458 | *vallen = 0; | |
2459 | if (!s.IsNotFound()) { | |
2460 | SaveError(errptr, s); | |
2461 | } | |
2462 | } | |
2463 | return result; | |
2464 | } | |
2465 | ||
2466 | char* rocksdb_writebatch_wi_get_from_batch_and_db_cf( | |
1e59de90 | 2467 | rocksdb_writebatch_wi_t* wbwi, rocksdb_t* db, |
7c673cae | 2468 | const rocksdb_readoptions_t* options, |
1e59de90 TL |
2469 | rocksdb_column_family_handle_t* column_family, const char* key, |
2470 | size_t keylen, size_t* vallen, char** errptr) { | |
7c673cae FG |
2471 | char* result = nullptr; |
2472 | std::string tmp; | |
1e59de90 TL |
2473 | Status s = wbwi->rep->GetFromBatchAndDB( |
2474 | db->rep, options->rep, column_family->rep, Slice(key, keylen), &tmp); | |
7c673cae FG |
2475 | if (s.ok()) { |
2476 | *vallen = tmp.size(); | |
2477 | result = CopyString(tmp); | |
2478 | } else { | |
2479 | *vallen = 0; | |
2480 | if (!s.IsNotFound()) { | |
2481 | SaveError(errptr, s); | |
2482 | } | |
2483 | } | |
2484 | return result; | |
2485 | } | |
2486 | ||
1e59de90 TL |
2487 | void rocksdb_write_writebatch_wi(rocksdb_t* db, |
2488 | const rocksdb_writeoptions_t* options, | |
2489 | rocksdb_writebatch_wi_t* wbwi, char** errptr) { | |
7c673cae FG |
2490 | WriteBatch* wb = wbwi->rep->GetWriteBatch(); |
2491 | SaveError(errptr, db->rep->Write(options->rep, wb)); | |
2492 | } | |
2493 | ||
1e59de90 TL |
2494 | void rocksdb_load_latest_options( |
2495 | const char* db_path, rocksdb_env_t* env, bool ignore_unknown_options, | |
2496 | rocksdb_cache_t* cache, rocksdb_options_t** db_options, | |
2497 | size_t* num_column_families, char*** list_column_family_names, | |
2498 | rocksdb_options_t*** list_column_family_options, char** errptr) { | |
2499 | DBOptions db_opt; | |
2500 | std::vector<ColumnFamilyDescriptor> cf_descs; | |
2501 | Status s = LoadLatestOptions(std::string(db_path), env->rep, &db_opt, | |
2502 | &cf_descs, ignore_unknown_options, &cache->rep); | |
2503 | if (s.ok()) { | |
2504 | char** cf_names = (char**)malloc(cf_descs.size() * sizeof(char*)); | |
2505 | rocksdb_options_t** cf_options = (rocksdb_options_t**)malloc( | |
2506 | cf_descs.size() * sizeof(rocksdb_options_t*)); | |
2507 | for (size_t i = 0; i < cf_descs.size(); ++i) { | |
2508 | cf_names[i] = strdup(cf_descs[i].name.c_str()); | |
2509 | cf_options[i] = new rocksdb_options_t{ | |
2510 | Options(DBOptions(), std::move(cf_descs[i].options))}; | |
2511 | } | |
2512 | *num_column_families = cf_descs.size(); | |
2513 | *db_options = new rocksdb_options_t{ | |
2514 | Options(std::move(db_opt), ColumnFamilyOptions())}; | |
2515 | *list_column_family_names = cf_names; | |
2516 | *list_column_family_options = cf_options; | |
2517 | } else { | |
2518 | *num_column_families = 0; | |
2519 | *db_options = nullptr; | |
2520 | *list_column_family_names = nullptr; | |
2521 | *list_column_family_options = nullptr; | |
2522 | SaveError(errptr, s); | |
2523 | } | |
2524 | } | |
2525 | ||
2526 | void rocksdb_load_latest_options_destroy( | |
2527 | rocksdb_options_t* db_options, char** list_column_family_names, | |
2528 | rocksdb_options_t** list_column_family_options, size_t len) { | |
2529 | rocksdb_options_destroy(db_options); | |
2530 | if (list_column_family_names) { | |
2531 | for (size_t i = 0; i < len; ++i) { | |
2532 | free(list_column_family_names[i]); | |
2533 | } | |
2534 | free(list_column_family_names); | |
2535 | } | |
2536 | if (list_column_family_options) { | |
2537 | for (size_t i = 0; i < len; ++i) { | |
2538 | rocksdb_options_destroy(list_column_family_options[i]); | |
2539 | } | |
2540 | free(list_column_family_options); | |
2541 | } | |
2542 | } | |
2543 | ||
2544 | rocksdb_block_based_table_options_t* rocksdb_block_based_options_create() { | |
7c673cae FG |
2545 | return new rocksdb_block_based_table_options_t; |
2546 | } | |
2547 | ||
2548 | void rocksdb_block_based_options_destroy( | |
2549 | rocksdb_block_based_table_options_t* options) { | |
2550 | delete options; | |
2551 | } | |
2552 | ||
1e59de90 TL |
2553 | void rocksdb_block_based_options_set_checksum( |
2554 | rocksdb_block_based_table_options_t* opt, char v) { | |
2555 | opt->rep.checksum = static_cast<ROCKSDB_NAMESPACE::ChecksumType>(v); | |
2556 | } | |
2557 | ||
7c673cae FG |
2558 | void rocksdb_block_based_options_set_block_size( |
2559 | rocksdb_block_based_table_options_t* options, size_t block_size) { | |
2560 | options->rep.block_size = block_size; | |
2561 | } | |
2562 | ||
2563 | void rocksdb_block_based_options_set_block_size_deviation( | |
2564 | rocksdb_block_based_table_options_t* options, int block_size_deviation) { | |
2565 | options->rep.block_size_deviation = block_size_deviation; | |
2566 | } | |
2567 | ||
2568 | void rocksdb_block_based_options_set_block_restart_interval( | |
2569 | rocksdb_block_based_table_options_t* options, int block_restart_interval) { | |
2570 | options->rep.block_restart_interval = block_restart_interval; | |
2571 | } | |
2572 | ||
11fdf7f2 | 2573 | void rocksdb_block_based_options_set_index_block_restart_interval( |
1e59de90 TL |
2574 | rocksdb_block_based_table_options_t* options, |
2575 | int index_block_restart_interval) { | |
11fdf7f2 TL |
2576 | options->rep.index_block_restart_interval = index_block_restart_interval; |
2577 | } | |
2578 | ||
2579 | void rocksdb_block_based_options_set_metadata_block_size( | |
1e59de90 TL |
2580 | rocksdb_block_based_table_options_t* options, |
2581 | uint64_t metadata_block_size) { | |
11fdf7f2 TL |
2582 | options->rep.metadata_block_size = metadata_block_size; |
2583 | } | |
2584 | ||
2585 | void rocksdb_block_based_options_set_partition_filters( | |
1e59de90 TL |
2586 | rocksdb_block_based_table_options_t* options, |
2587 | unsigned char partition_filters) { | |
11fdf7f2 TL |
2588 | options->rep.partition_filters = partition_filters; |
2589 | } | |
2590 | ||
2591 | void rocksdb_block_based_options_set_use_delta_encoding( | |
1e59de90 TL |
2592 | rocksdb_block_based_table_options_t* options, |
2593 | unsigned char use_delta_encoding) { | |
11fdf7f2 TL |
2594 | options->rep.use_delta_encoding = use_delta_encoding; |
2595 | } | |
2596 | ||
7c673cae FG |
2597 | void rocksdb_block_based_options_set_filter_policy( |
2598 | rocksdb_block_based_table_options_t* options, | |
2599 | rocksdb_filterpolicy_t* filter_policy) { | |
2600 | options->rep.filter_policy.reset(filter_policy); | |
2601 | } | |
2602 | ||
2603 | void rocksdb_block_based_options_set_no_block_cache( | |
2604 | rocksdb_block_based_table_options_t* options, | |
2605 | unsigned char no_block_cache) { | |
2606 | options->rep.no_block_cache = no_block_cache; | |
2607 | } | |
2608 | ||
2609 | void rocksdb_block_based_options_set_block_cache( | |
2610 | rocksdb_block_based_table_options_t* options, | |
2611 | rocksdb_cache_t* block_cache) { | |
2612 | if (block_cache) { | |
2613 | options->rep.block_cache = block_cache->rep; | |
2614 | } | |
2615 | } | |
2616 | ||
2617 | void rocksdb_block_based_options_set_block_cache_compressed( | |
2618 | rocksdb_block_based_table_options_t* options, | |
2619 | rocksdb_cache_t* block_cache_compressed) { | |
2620 | if (block_cache_compressed) { | |
2621 | options->rep.block_cache_compressed = block_cache_compressed->rep; | |
2622 | } | |
2623 | } | |
2624 | ||
2625 | void rocksdb_block_based_options_set_whole_key_filtering( | |
2626 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
2627 | options->rep.whole_key_filtering = v; | |
2628 | } | |
2629 | ||
2630 | void rocksdb_block_based_options_set_format_version( | |
2631 | rocksdb_block_based_table_options_t* options, int v) { | |
2632 | options->rep.format_version = v; | |
2633 | } | |
2634 | ||
2635 | void rocksdb_block_based_options_set_index_type( | |
2636 | rocksdb_block_based_table_options_t* options, int v) { | |
2637 | options->rep.index_type = static_cast<BlockBasedTableOptions::IndexType>(v); | |
2638 | } | |
2639 | ||
f67539c2 TL |
2640 | void rocksdb_block_based_options_set_data_block_index_type( |
2641 | rocksdb_block_based_table_options_t* options, int v) { | |
2642 | options->rep.data_block_index_type = | |
1e59de90 | 2643 | static_cast<BlockBasedTableOptions::DataBlockIndexType>(v); |
f67539c2 TL |
2644 | } |
2645 | ||
2646 | void rocksdb_block_based_options_set_data_block_hash_ratio( | |
2647 | rocksdb_block_based_table_options_t* options, double v) { | |
2648 | options->rep.data_block_hash_table_util_ratio = v; | |
2649 | } | |
2650 | ||
7c673cae FG |
2651 | void rocksdb_block_based_options_set_cache_index_and_filter_blocks( |
2652 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
2653 | options->rep.cache_index_and_filter_blocks = v; | |
2654 | } | |
2655 | ||
11fdf7f2 TL |
2656 | void rocksdb_block_based_options_set_cache_index_and_filter_blocks_with_high_priority( |
2657 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
2658 | options->rep.cache_index_and_filter_blocks_with_high_priority = v; | |
2659 | } | |
2660 | ||
7c673cae FG |
2661 | void rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache( |
2662 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
2663 | options->rep.pin_l0_filter_and_index_blocks_in_cache = v; | |
2664 | } | |
2665 | ||
11fdf7f2 TL |
2666 | void rocksdb_block_based_options_set_pin_top_level_index_and_filter( |
2667 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
2668 | options->rep.pin_top_level_index_and_filter = v; | |
2669 | } | |
2670 | ||
7c673cae | 2671 | void rocksdb_options_set_block_based_table_factory( |
1e59de90 | 2672 | rocksdb_options_t* opt, |
7c673cae FG |
2673 | rocksdb_block_based_table_options_t* table_options) { |
2674 | if (table_options) { | |
2675 | opt->rep.table_factory.reset( | |
f67539c2 | 2676 | ROCKSDB_NAMESPACE::NewBlockBasedTableFactory(table_options->rep)); |
7c673cae FG |
2677 | } |
2678 | } | |
2679 | ||
1e59de90 | 2680 | rocksdb_cuckoo_table_options_t* rocksdb_cuckoo_options_create() { |
7c673cae FG |
2681 | return new rocksdb_cuckoo_table_options_t; |
2682 | } | |
2683 | ||
1e59de90 | 2684 | void rocksdb_cuckoo_options_destroy(rocksdb_cuckoo_table_options_t* options) { |
7c673cae FG |
2685 | delete options; |
2686 | } | |
2687 | ||
2688 | void rocksdb_cuckoo_options_set_hash_ratio( | |
2689 | rocksdb_cuckoo_table_options_t* options, double v) { | |
2690 | options->rep.hash_table_ratio = v; | |
2691 | } | |
2692 | ||
2693 | void rocksdb_cuckoo_options_set_max_search_depth( | |
2694 | rocksdb_cuckoo_table_options_t* options, uint32_t v) { | |
2695 | options->rep.max_search_depth = v; | |
2696 | } | |
2697 | ||
2698 | void rocksdb_cuckoo_options_set_cuckoo_block_size( | |
2699 | rocksdb_cuckoo_table_options_t* options, uint32_t v) { | |
2700 | options->rep.cuckoo_block_size = v; | |
2701 | } | |
2702 | ||
2703 | void rocksdb_cuckoo_options_set_identity_as_first_hash( | |
2704 | rocksdb_cuckoo_table_options_t* options, unsigned char v) { | |
2705 | options->rep.identity_as_first_hash = v; | |
2706 | } | |
2707 | ||
2708 | void rocksdb_cuckoo_options_set_use_module_hash( | |
2709 | rocksdb_cuckoo_table_options_t* options, unsigned char v) { | |
2710 | options->rep.use_module_hash = v; | |
2711 | } | |
2712 | ||
2713 | void rocksdb_options_set_cuckoo_table_factory( | |
1e59de90 | 2714 | rocksdb_options_t* opt, rocksdb_cuckoo_table_options_t* table_options) { |
7c673cae FG |
2715 | if (table_options) { |
2716 | opt->rep.table_factory.reset( | |
f67539c2 | 2717 | ROCKSDB_NAMESPACE::NewCuckooTableFactory(table_options->rep)); |
7c673cae FG |
2718 | } |
2719 | } | |
2720 | ||
1e59de90 TL |
2721 | void rocksdb_set_options(rocksdb_t* db, int count, const char* const keys[], |
2722 | const char* const values[], char** errptr) { | |
2723 | std::unordered_map<std::string, std::string> options_map; | |
2724 | for (int i = 0; i < count; i++) options_map[keys[i]] = values[i]; | |
2725 | SaveError(errptr, db->rep->SetOptions(options_map)); | |
7c673cae FG |
2726 | } |
2727 | ||
1e59de90 TL |
2728 | void rocksdb_set_options_cf(rocksdb_t* db, |
2729 | rocksdb_column_family_handle_t* handle, int count, | |
2730 | const char* const keys[], | |
2731 | const char* const values[], char** errptr) { | |
2732 | std::unordered_map<std::string, std::string> options_map; | |
2733 | for (int i = 0; i < count; i++) options_map[keys[i]] = values[i]; | |
2734 | SaveError(errptr, db->rep->SetOptions(handle->rep, options_map)); | |
7c673cae FG |
2735 | } |
2736 | ||
1e59de90 TL |
2737 | rocksdb_options_t* rocksdb_options_create() { return new rocksdb_options_t; } |
2738 | ||
2739 | void rocksdb_options_destroy(rocksdb_options_t* options) { delete options; } | |
2740 | ||
20effc67 TL |
2741 | rocksdb_options_t* rocksdb_options_create_copy(rocksdb_options_t* options) { |
2742 | return new rocksdb_options_t(*options); | |
2743 | } | |
2744 | ||
1e59de90 TL |
2745 | void rocksdb_options_increase_parallelism(rocksdb_options_t* opt, |
2746 | int total_threads) { | |
7c673cae FG |
2747 | opt->rep.IncreaseParallelism(total_threads); |
2748 | } | |
2749 | ||
1e59de90 TL |
2750 | void rocksdb_options_optimize_for_point_lookup(rocksdb_options_t* opt, |
2751 | uint64_t block_cache_size_mb) { | |
7c673cae FG |
2752 | opt->rep.OptimizeForPointLookup(block_cache_size_mb); |
2753 | } | |
2754 | ||
2755 | void rocksdb_options_optimize_level_style_compaction( | |
2756 | rocksdb_options_t* opt, uint64_t memtable_memory_budget) { | |
2757 | opt->rep.OptimizeLevelStyleCompaction(memtable_memory_budget); | |
2758 | } | |
2759 | ||
2760 | void rocksdb_options_optimize_universal_style_compaction( | |
2761 | rocksdb_options_t* opt, uint64_t memtable_memory_budget) { | |
2762 | opt->rep.OptimizeUniversalStyleCompaction(memtable_memory_budget); | |
2763 | } | |
2764 | ||
1e59de90 TL |
2765 | void rocksdb_options_set_allow_ingest_behind(rocksdb_options_t* opt, |
2766 | unsigned char v) { | |
11fdf7f2 TL |
2767 | opt->rep.allow_ingest_behind = v; |
2768 | } | |
2769 | ||
20effc67 TL |
2770 | unsigned char rocksdb_options_get_allow_ingest_behind(rocksdb_options_t* opt) { |
2771 | return opt->rep.allow_ingest_behind; | |
2772 | } | |
2773 | ||
1e59de90 TL |
2774 | void rocksdb_options_set_compaction_filter(rocksdb_options_t* opt, |
2775 | rocksdb_compactionfilter_t* filter) { | |
7c673cae FG |
2776 | opt->rep.compaction_filter = filter; |
2777 | } | |
2778 | ||
2779 | void rocksdb_options_set_compaction_filter_factory( | |
2780 | rocksdb_options_t* opt, rocksdb_compactionfilterfactory_t* factory) { | |
2781 | opt->rep.compaction_filter_factory = | |
2782 | std::shared_ptr<CompactionFilterFactory>(factory); | |
2783 | } | |
2784 | ||
1e59de90 TL |
2785 | void rocksdb_options_compaction_readahead_size(rocksdb_options_t* opt, |
2786 | size_t s) { | |
7c673cae FG |
2787 | opt->rep.compaction_readahead_size = s; |
2788 | } | |
2789 | ||
20effc67 TL |
2790 | size_t rocksdb_options_get_compaction_readahead_size(rocksdb_options_t* opt) { |
2791 | return opt->rep.compaction_readahead_size; | |
2792 | } | |
2793 | ||
1e59de90 TL |
2794 | void rocksdb_options_set_comparator(rocksdb_options_t* opt, |
2795 | rocksdb_comparator_t* cmp) { | |
7c673cae FG |
2796 | opt->rep.comparator = cmp; |
2797 | } | |
2798 | ||
2799 | void rocksdb_options_set_merge_operator( | |
1e59de90 | 2800 | rocksdb_options_t* opt, rocksdb_mergeoperator_t* merge_operator) { |
7c673cae FG |
2801 | opt->rep.merge_operator = std::shared_ptr<MergeOperator>(merge_operator); |
2802 | } | |
2803 | ||
1e59de90 TL |
2804 | void rocksdb_options_set_create_if_missing(rocksdb_options_t* opt, |
2805 | unsigned char v) { | |
7c673cae FG |
2806 | opt->rep.create_if_missing = v; |
2807 | } | |
2808 | ||
20effc67 TL |
2809 | unsigned char rocksdb_options_get_create_if_missing(rocksdb_options_t* opt) { |
2810 | return opt->rep.create_if_missing; | |
2811 | } | |
2812 | ||
1e59de90 TL |
2813 | void rocksdb_options_set_create_missing_column_families(rocksdb_options_t* opt, |
2814 | unsigned char v) { | |
7c673cae FG |
2815 | opt->rep.create_missing_column_families = v; |
2816 | } | |
2817 | ||
20effc67 TL |
2818 | unsigned char rocksdb_options_get_create_missing_column_families( |
2819 | rocksdb_options_t* opt) { | |
2820 | return opt->rep.create_missing_column_families; | |
2821 | } | |
2822 | ||
1e59de90 TL |
2823 | void rocksdb_options_set_error_if_exists(rocksdb_options_t* opt, |
2824 | unsigned char v) { | |
7c673cae FG |
2825 | opt->rep.error_if_exists = v; |
2826 | } | |
2827 | ||
20effc67 TL |
2828 | unsigned char rocksdb_options_get_error_if_exists(rocksdb_options_t* opt) { |
2829 | return opt->rep.error_if_exists; | |
2830 | } | |
2831 | ||
1e59de90 TL |
2832 | void rocksdb_options_set_paranoid_checks(rocksdb_options_t* opt, |
2833 | unsigned char v) { | |
7c673cae FG |
2834 | opt->rep.paranoid_checks = v; |
2835 | } | |
2836 | ||
20effc67 TL |
2837 | unsigned char rocksdb_options_get_paranoid_checks(rocksdb_options_t* opt) { |
2838 | return opt->rep.paranoid_checks; | |
2839 | } | |
2840 | ||
11fdf7f2 TL |
2841 | void rocksdb_options_set_db_paths(rocksdb_options_t* opt, |
2842 | const rocksdb_dbpath_t** dbpath_values, | |
2843 | size_t num_paths) { | |
2844 | std::vector<DbPath> db_paths(num_paths); | |
2845 | for (size_t i = 0; i < num_paths; ++i) { | |
2846 | db_paths[i] = dbpath_values[i]->rep; | |
2847 | } | |
2848 | opt->rep.db_paths = db_paths; | |
2849 | } | |
2850 | ||
7c673cae FG |
2851 | void rocksdb_options_set_env(rocksdb_options_t* opt, rocksdb_env_t* env) { |
2852 | opt->rep.env = (env ? env->rep : nullptr); | |
2853 | } | |
2854 | ||
2855 | void rocksdb_options_set_info_log(rocksdb_options_t* opt, rocksdb_logger_t* l) { | |
2856 | if (l) { | |
2857 | opt->rep.info_log = l->rep; | |
2858 | } | |
2859 | } | |
2860 | ||
1e59de90 | 2861 | void rocksdb_options_set_info_log_level(rocksdb_options_t* opt, int v) { |
7c673cae FG |
2862 | opt->rep.info_log_level = static_cast<InfoLogLevel>(v); |
2863 | } | |
2864 | ||
20effc67 TL |
2865 | int rocksdb_options_get_info_log_level(rocksdb_options_t* opt) { |
2866 | return static_cast<int>(opt->rep.info_log_level); | |
2867 | } | |
2868 | ||
7c673cae FG |
2869 | void rocksdb_options_set_db_write_buffer_size(rocksdb_options_t* opt, |
2870 | size_t s) { | |
2871 | opt->rep.db_write_buffer_size = s; | |
2872 | } | |
2873 | ||
20effc67 TL |
2874 | size_t rocksdb_options_get_db_write_buffer_size(rocksdb_options_t* opt) { |
2875 | return opt->rep.db_write_buffer_size; | |
2876 | } | |
2877 | ||
7c673cae FG |
2878 | void rocksdb_options_set_write_buffer_size(rocksdb_options_t* opt, size_t s) { |
2879 | opt->rep.write_buffer_size = s; | |
2880 | } | |
2881 | ||
20effc67 TL |
2882 | size_t rocksdb_options_get_write_buffer_size(rocksdb_options_t* opt) { |
2883 | return opt->rep.write_buffer_size; | |
2884 | } | |
2885 | ||
7c673cae FG |
2886 | void rocksdb_options_set_max_open_files(rocksdb_options_t* opt, int n) { |
2887 | opt->rep.max_open_files = n; | |
2888 | } | |
2889 | ||
20effc67 TL |
2890 | int rocksdb_options_get_max_open_files(rocksdb_options_t* opt) { |
2891 | return opt->rep.max_open_files; | |
2892 | } | |
2893 | ||
1e59de90 TL |
2894 | void rocksdb_options_set_max_file_opening_threads(rocksdb_options_t* opt, |
2895 | int n) { | |
11fdf7f2 TL |
2896 | opt->rep.max_file_opening_threads = n; |
2897 | } | |
2898 | ||
20effc67 TL |
2899 | int rocksdb_options_get_max_file_opening_threads(rocksdb_options_t* opt) { |
2900 | return opt->rep.max_file_opening_threads; | |
2901 | } | |
2902 | ||
1e59de90 TL |
2903 | void rocksdb_options_set_max_total_wal_size(rocksdb_options_t* opt, |
2904 | uint64_t n) { | |
7c673cae FG |
2905 | opt->rep.max_total_wal_size = n; |
2906 | } | |
2907 | ||
20effc67 TL |
2908 | uint64_t rocksdb_options_get_max_total_wal_size(rocksdb_options_t* opt) { |
2909 | return opt->rep.max_total_wal_size; | |
2910 | } | |
2911 | ||
1e59de90 TL |
2912 | void rocksdb_options_set_target_file_size_base(rocksdb_options_t* opt, |
2913 | uint64_t n) { | |
7c673cae FG |
2914 | opt->rep.target_file_size_base = n; |
2915 | } | |
2916 | ||
20effc67 TL |
2917 | uint64_t rocksdb_options_get_target_file_size_base(rocksdb_options_t* opt) { |
2918 | return opt->rep.target_file_size_base; | |
2919 | } | |
2920 | ||
1e59de90 TL |
2921 | void rocksdb_options_set_target_file_size_multiplier(rocksdb_options_t* opt, |
2922 | int n) { | |
7c673cae FG |
2923 | opt->rep.target_file_size_multiplier = n; |
2924 | } | |
2925 | ||
20effc67 TL |
2926 | int rocksdb_options_get_target_file_size_multiplier(rocksdb_options_t* opt) { |
2927 | return opt->rep.target_file_size_multiplier; | |
2928 | } | |
2929 | ||
1e59de90 TL |
2930 | void rocksdb_options_set_max_bytes_for_level_base(rocksdb_options_t* opt, |
2931 | uint64_t n) { | |
7c673cae FG |
2932 | opt->rep.max_bytes_for_level_base = n; |
2933 | } | |
2934 | ||
20effc67 TL |
2935 | uint64_t rocksdb_options_get_max_bytes_for_level_base(rocksdb_options_t* opt) { |
2936 | return opt->rep.max_bytes_for_level_base; | |
2937 | } | |
2938 | ||
7c673cae FG |
2939 | void rocksdb_options_set_level_compaction_dynamic_level_bytes( |
2940 | rocksdb_options_t* opt, unsigned char v) { | |
2941 | opt->rep.level_compaction_dynamic_level_bytes = v; | |
2942 | } | |
2943 | ||
20effc67 TL |
2944 | unsigned char rocksdb_options_get_level_compaction_dynamic_level_bytes( |
2945 | rocksdb_options_t* opt) { | |
2946 | return opt->rep.level_compaction_dynamic_level_bytes; | |
2947 | } | |
2948 | ||
7c673cae FG |
2949 | void rocksdb_options_set_max_bytes_for_level_multiplier(rocksdb_options_t* opt, |
2950 | double n) { | |
2951 | opt->rep.max_bytes_for_level_multiplier = n; | |
2952 | } | |
2953 | ||
20effc67 TL |
2954 | double rocksdb_options_get_max_bytes_for_level_multiplier( |
2955 | rocksdb_options_t* opt) { | |
2956 | return opt->rep.max_bytes_for_level_multiplier; | |
2957 | } | |
2958 | ||
7c673cae FG |
2959 | void rocksdb_options_set_max_compaction_bytes(rocksdb_options_t* opt, |
2960 | uint64_t n) { | |
2961 | opt->rep.max_compaction_bytes = n; | |
2962 | } | |
2963 | ||
20effc67 TL |
2964 | uint64_t rocksdb_options_get_max_compaction_bytes(rocksdb_options_t* opt) { |
2965 | return opt->rep.max_compaction_bytes; | |
2966 | } | |
2967 | ||
7c673cae FG |
2968 | void rocksdb_options_set_max_bytes_for_level_multiplier_additional( |
2969 | rocksdb_options_t* opt, int* level_values, size_t num_levels) { | |
2970 | opt->rep.max_bytes_for_level_multiplier_additional.resize(num_levels); | |
2971 | for (size_t i = 0; i < num_levels; ++i) { | |
2972 | opt->rep.max_bytes_for_level_multiplier_additional[i] = level_values[i]; | |
2973 | } | |
2974 | } | |
2975 | ||
2976 | void rocksdb_options_enable_statistics(rocksdb_options_t* opt) { | |
f67539c2 | 2977 | opt->rep.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics(); |
7c673cae FG |
2978 | } |
2979 | ||
11fdf7f2 TL |
2980 | void rocksdb_options_set_skip_stats_update_on_db_open(rocksdb_options_t* opt, |
2981 | unsigned char val) { | |
2982 | opt->rep.skip_stats_update_on_db_open = val; | |
2983 | } | |
2984 | ||
20effc67 TL |
2985 | unsigned char rocksdb_options_get_skip_stats_update_on_db_open( |
2986 | rocksdb_options_t* opt) { | |
2987 | return opt->rep.skip_stats_update_on_db_open; | |
2988 | } | |
2989 | ||
f67539c2 TL |
2990 | void rocksdb_options_set_skip_checking_sst_file_sizes_on_db_open( |
2991 | rocksdb_options_t* opt, unsigned char val) { | |
2992 | opt->rep.skip_checking_sst_file_sizes_on_db_open = val; | |
2993 | } | |
2994 | ||
20effc67 TL |
2995 | unsigned char rocksdb_options_get_skip_checking_sst_file_sizes_on_db_open( |
2996 | rocksdb_options_t* opt) { | |
2997 | return opt->rep.skip_checking_sst_file_sizes_on_db_open; | |
2998 | } | |
2999 | ||
1e59de90 TL |
3000 | /* Blob Options Settings */ |
3001 | void rocksdb_options_set_enable_blob_files(rocksdb_options_t* opt, | |
3002 | unsigned char val) { | |
3003 | opt->rep.enable_blob_files = val; | |
3004 | } | |
3005 | extern ROCKSDB_LIBRARY_API unsigned char rocksdb_options_get_enable_blob_files( | |
3006 | rocksdb_options_t* opt) { | |
3007 | return opt->rep.enable_blob_files; | |
7c673cae FG |
3008 | } |
3009 | ||
1e59de90 TL |
3010 | void rocksdb_options_set_min_blob_size(rocksdb_options_t* opt, uint64_t val) { |
3011 | opt->rep.min_blob_size = val; | |
20effc67 TL |
3012 | } |
3013 | ||
1e59de90 TL |
3014 | uint64_t rocksdb_options_get_min_blob_size(rocksdb_options_t* opt) { |
3015 | return opt->rep.min_blob_size; | |
7c673cae FG |
3016 | } |
3017 | ||
1e59de90 TL |
3018 | void rocksdb_options_set_blob_file_size(rocksdb_options_t* opt, uint64_t val) { |
3019 | opt->rep.blob_file_size = val; | |
3020 | } | |
3021 | ||
3022 | uint64_t rocksdb_options_get_blob_file_size(rocksdb_options_t* opt) { | |
3023 | return opt->rep.blob_file_size; | |
3024 | } | |
3025 | ||
3026 | void rocksdb_options_set_blob_compression_type(rocksdb_options_t* opt, | |
3027 | int val) { | |
3028 | opt->rep.blob_compression_type = static_cast<CompressionType>(val); | |
3029 | } | |
3030 | ||
3031 | int rocksdb_options_get_blob_compression_type(rocksdb_options_t* opt) { | |
3032 | return opt->rep.blob_compression_type; | |
3033 | } | |
3034 | ||
3035 | void rocksdb_options_set_enable_blob_gc(rocksdb_options_t* opt, | |
3036 | unsigned char val) { | |
3037 | opt->rep.enable_blob_garbage_collection = val; | |
3038 | } | |
3039 | ||
3040 | unsigned char rocksdb_options_get_enable_blob_gc(rocksdb_options_t* opt) { | |
3041 | return opt->rep.enable_blob_garbage_collection; | |
3042 | } | |
3043 | ||
3044 | void rocksdb_options_set_blob_gc_age_cutoff(rocksdb_options_t* opt, | |
3045 | double val) { | |
3046 | opt->rep.blob_garbage_collection_age_cutoff = val; | |
3047 | } | |
3048 | ||
3049 | double rocksdb_options_get_blob_gc_age_cutoff(rocksdb_options_t* opt) { | |
3050 | return opt->rep.blob_garbage_collection_age_cutoff; | |
3051 | } | |
3052 | ||
3053 | void rocksdb_options_set_blob_gc_force_threshold(rocksdb_options_t* opt, | |
3054 | double val) { | |
3055 | opt->rep.blob_garbage_collection_force_threshold = val; | |
3056 | } | |
3057 | ||
3058 | double rocksdb_options_get_blob_gc_force_threshold(rocksdb_options_t* opt) { | |
3059 | return opt->rep.blob_garbage_collection_force_threshold; | |
3060 | } | |
3061 | ||
3062 | void rocksdb_options_set_blob_compaction_readahead_size(rocksdb_options_t* opt, | |
3063 | uint64_t val) { | |
3064 | opt->rep.blob_compaction_readahead_size = val; | |
3065 | } | |
3066 | ||
3067 | uint64_t rocksdb_options_get_blob_compaction_readahead_size( | |
3068 | rocksdb_options_t* opt) { | |
3069 | return opt->rep.blob_compaction_readahead_size; | |
3070 | } | |
3071 | ||
3072 | void rocksdb_options_set_blob_file_starting_level(rocksdb_options_t* opt, | |
3073 | int val) { | |
3074 | opt->rep.blob_file_starting_level = val; | |
3075 | } | |
3076 | ||
3077 | int rocksdb_options_get_blob_file_starting_level(rocksdb_options_t* opt) { | |
3078 | return opt->rep.blob_file_starting_level; | |
3079 | } | |
3080 | ||
3081 | void rocksdb_options_set_blob_cache(rocksdb_options_t* opt, | |
3082 | rocksdb_cache_t* blob_cache) { | |
3083 | opt->rep.blob_cache = blob_cache->rep; | |
3084 | } | |
3085 | ||
3086 | void rocksdb_options_set_prepopulate_blob_cache(rocksdb_options_t* opt, int t) { | |
3087 | opt->rep.prepopulate_blob_cache = static_cast<PrepopulateBlobCache>(t); | |
20effc67 TL |
3088 | } |
3089 | ||
1e59de90 TL |
3090 | int rocksdb_options_get_prepopulate_blob_cache(rocksdb_options_t* opt) { |
3091 | return static_cast<int>(opt->rep.prepopulate_blob_cache); | |
3092 | } | |
3093 | ||
3094 | void rocksdb_options_set_num_levels(rocksdb_options_t* opt, int n) { | |
3095 | opt->rep.num_levels = n; | |
3096 | } | |
3097 | ||
3098 | int rocksdb_options_get_num_levels(rocksdb_options_t* opt) { | |
3099 | return opt->rep.num_levels; | |
3100 | } | |
3101 | ||
3102 | void rocksdb_options_set_level0_file_num_compaction_trigger( | |
7c673cae | 3103 | rocksdb_options_t* opt, int n) { |
1e59de90 TL |
3104 | opt->rep.level0_file_num_compaction_trigger = n; |
3105 | } | |
3106 | ||
3107 | int rocksdb_options_get_level0_file_num_compaction_trigger( | |
3108 | rocksdb_options_t* opt) { | |
3109 | return opt->rep.level0_file_num_compaction_trigger; | |
3110 | } | |
3111 | ||
3112 | void rocksdb_options_set_level0_slowdown_writes_trigger(rocksdb_options_t* opt, | |
3113 | int n) { | |
7c673cae FG |
3114 | opt->rep.level0_slowdown_writes_trigger = n; |
3115 | } | |
3116 | ||
20effc67 TL |
3117 | int rocksdb_options_get_level0_slowdown_writes_trigger(rocksdb_options_t* opt) { |
3118 | return opt->rep.level0_slowdown_writes_trigger; | |
3119 | } | |
3120 | ||
1e59de90 TL |
3121 | void rocksdb_options_set_level0_stop_writes_trigger(rocksdb_options_t* opt, |
3122 | int n) { | |
7c673cae FG |
3123 | opt->rep.level0_stop_writes_trigger = n; |
3124 | } | |
3125 | ||
20effc67 TL |
3126 | int rocksdb_options_get_level0_stop_writes_trigger(rocksdb_options_t* opt) { |
3127 | return opt->rep.level0_stop_writes_trigger; | |
3128 | } | |
3129 | ||
1e59de90 | 3130 | void rocksdb_options_set_wal_recovery_mode(rocksdb_options_t* opt, int mode) { |
7c673cae FG |
3131 | opt->rep.wal_recovery_mode = static_cast<WALRecoveryMode>(mode); |
3132 | } | |
3133 | ||
20effc67 TL |
3134 | int rocksdb_options_get_wal_recovery_mode(rocksdb_options_t* opt) { |
3135 | return static_cast<int>(opt->rep.wal_recovery_mode); | |
3136 | } | |
3137 | ||
7c673cae FG |
3138 | void rocksdb_options_set_compression(rocksdb_options_t* opt, int t) { |
3139 | opt->rep.compression = static_cast<CompressionType>(t); | |
3140 | } | |
3141 | ||
20effc67 TL |
3142 | int rocksdb_options_get_compression(rocksdb_options_t* opt) { |
3143 | return opt->rep.compression; | |
3144 | } | |
3145 | ||
3146 | void rocksdb_options_set_bottommost_compression(rocksdb_options_t* opt, int t) { | |
3147 | opt->rep.bottommost_compression = static_cast<CompressionType>(t); | |
3148 | } | |
3149 | ||
3150 | int rocksdb_options_get_bottommost_compression(rocksdb_options_t* opt) { | |
3151 | return opt->rep.bottommost_compression; | |
3152 | } | |
3153 | ||
7c673cae | 3154 | void rocksdb_options_set_compression_per_level(rocksdb_options_t* opt, |
1e59de90 | 3155 | const int* level_values, |
7c673cae FG |
3156 | size_t num_levels) { |
3157 | opt->rep.compression_per_level.resize(num_levels); | |
3158 | for (size_t i = 0; i < num_levels; ++i) { | |
3159 | opt->rep.compression_per_level[i] = | |
1e59de90 | 3160 | static_cast<CompressionType>(level_values[i]); |
7c673cae FG |
3161 | } |
3162 | } | |
3163 | ||
11fdf7f2 TL |
3164 | void rocksdb_options_set_bottommost_compression_options(rocksdb_options_t* opt, |
3165 | int w_bits, int level, | |
3166 | int strategy, | |
3167 | int max_dict_bytes, | |
20effc67 | 3168 | unsigned char enabled) { |
11fdf7f2 TL |
3169 | opt->rep.bottommost_compression_opts.window_bits = w_bits; |
3170 | opt->rep.bottommost_compression_opts.level = level; | |
3171 | opt->rep.bottommost_compression_opts.strategy = strategy; | |
3172 | opt->rep.bottommost_compression_opts.max_dict_bytes = max_dict_bytes; | |
3173 | opt->rep.bottommost_compression_opts.enabled = enabled; | |
3174 | } | |
3175 | ||
20effc67 TL |
3176 | void rocksdb_options_set_bottommost_compression_options_zstd_max_train_bytes( |
3177 | rocksdb_options_t* opt, int zstd_max_train_bytes, unsigned char enabled) { | |
3178 | opt->rep.bottommost_compression_opts.zstd_max_train_bytes = | |
3179 | zstd_max_train_bytes; | |
3180 | opt->rep.bottommost_compression_opts.enabled = enabled; | |
3181 | } | |
3182 | ||
1e59de90 TL |
3183 | void rocksdb_options_set_bottommost_compression_options_use_zstd_dict_trainer( |
3184 | rocksdb_options_t* opt, unsigned char use_zstd_dict_trainer, | |
3185 | unsigned char enabled) { | |
3186 | opt->rep.bottommost_compression_opts.use_zstd_dict_trainer = | |
3187 | use_zstd_dict_trainer; | |
3188 | opt->rep.bottommost_compression_opts.enabled = enabled; | |
3189 | } | |
3190 | ||
3191 | unsigned char | |
3192 | rocksdb_options_get_bottommost_compression_options_use_zstd_dict_trainer( | |
3193 | rocksdb_options_t* opt) { | |
3194 | return opt->rep.bottommost_compression_opts.use_zstd_dict_trainer; | |
3195 | } | |
3196 | ||
3197 | void rocksdb_options_set_bottommost_compression_options_max_dict_buffer_bytes( | |
3198 | rocksdb_options_t* opt, uint64_t max_dict_buffer_bytes, | |
3199 | unsigned char enabled) { | |
3200 | opt->rep.bottommost_compression_opts.max_dict_buffer_bytes = | |
3201 | max_dict_buffer_bytes; | |
3202 | opt->rep.bottommost_compression_opts.enabled = enabled; | |
3203 | } | |
3204 | ||
7c673cae FG |
3205 | void rocksdb_options_set_compression_options(rocksdb_options_t* opt, int w_bits, |
3206 | int level, int strategy, | |
3207 | int max_dict_bytes) { | |
3208 | opt->rep.compression_opts.window_bits = w_bits; | |
3209 | opt->rep.compression_opts.level = level; | |
3210 | opt->rep.compression_opts.strategy = strategy; | |
3211 | opt->rep.compression_opts.max_dict_bytes = max_dict_bytes; | |
3212 | } | |
3213 | ||
20effc67 TL |
3214 | void rocksdb_options_set_compression_options_zstd_max_train_bytes( |
3215 | rocksdb_options_t* opt, int zstd_max_train_bytes) { | |
3216 | opt->rep.compression_opts.zstd_max_train_bytes = zstd_max_train_bytes; | |
3217 | } | |
3218 | ||
1e59de90 TL |
3219 | int rocksdb_options_get_compression_options_zstd_max_train_bytes( |
3220 | rocksdb_options_t* opt) { | |
3221 | return opt->rep.compression_opts.zstd_max_train_bytes; | |
3222 | } | |
3223 | ||
3224 | void rocksdb_options_set_compression_options_use_zstd_dict_trainer( | |
3225 | rocksdb_options_t* opt, unsigned char use_zstd_dict_trainer) { | |
3226 | opt->rep.compression_opts.use_zstd_dict_trainer = use_zstd_dict_trainer; | |
3227 | } | |
3228 | ||
3229 | unsigned char rocksdb_options_get_compression_options_use_zstd_dict_trainer( | |
3230 | rocksdb_options_t* opt) { | |
3231 | return opt->rep.compression_opts.use_zstd_dict_trainer; | |
3232 | } | |
3233 | ||
3234 | void rocksdb_options_set_compression_options_parallel_threads( | |
3235 | rocksdb_options_t* opt, int value) { | |
3236 | opt->rep.compression_opts.parallel_threads = value; | |
3237 | } | |
3238 | ||
3239 | int rocksdb_options_get_compression_options_parallel_threads( | |
3240 | rocksdb_options_t* opt) { | |
3241 | return opt->rep.compression_opts.parallel_threads; | |
3242 | } | |
3243 | ||
3244 | void rocksdb_options_set_compression_options_max_dict_buffer_bytes( | |
3245 | rocksdb_options_t* opt, uint64_t max_dict_buffer_bytes) { | |
3246 | opt->rep.compression_opts.max_dict_buffer_bytes = max_dict_buffer_bytes; | |
3247 | } | |
3248 | ||
3249 | uint64_t rocksdb_options_get_compression_options_max_dict_buffer_bytes( | |
3250 | rocksdb_options_t* opt) { | |
3251 | return opt->rep.compression_opts.max_dict_buffer_bytes; | |
3252 | } | |
3253 | ||
7c673cae FG |
3254 | void rocksdb_options_set_prefix_extractor( |
3255 | rocksdb_options_t* opt, rocksdb_slicetransform_t* prefix_extractor) { | |
3256 | opt->rep.prefix_extractor.reset(prefix_extractor); | |
3257 | } | |
3258 | ||
1e59de90 | 3259 | void rocksdb_options_set_use_fsync(rocksdb_options_t* opt, int use_fsync) { |
7c673cae FG |
3260 | opt->rep.use_fsync = use_fsync; |
3261 | } | |
3262 | ||
20effc67 TL |
3263 | int rocksdb_options_get_use_fsync(rocksdb_options_t* opt) { |
3264 | return opt->rep.use_fsync; | |
3265 | } | |
3266 | ||
1e59de90 TL |
3267 | void rocksdb_options_set_db_log_dir(rocksdb_options_t* opt, |
3268 | const char* db_log_dir) { | |
7c673cae FG |
3269 | opt->rep.db_log_dir = db_log_dir; |
3270 | } | |
3271 | ||
1e59de90 | 3272 | void rocksdb_options_set_wal_dir(rocksdb_options_t* opt, const char* v) { |
7c673cae FG |
3273 | opt->rep.wal_dir = v; |
3274 | } | |
3275 | ||
3276 | void rocksdb_options_set_WAL_ttl_seconds(rocksdb_options_t* opt, uint64_t ttl) { | |
3277 | opt->rep.WAL_ttl_seconds = ttl; | |
3278 | } | |
3279 | ||
20effc67 TL |
3280 | uint64_t rocksdb_options_get_WAL_ttl_seconds(rocksdb_options_t* opt) { |
3281 | return opt->rep.WAL_ttl_seconds; | |
3282 | } | |
3283 | ||
1e59de90 TL |
3284 | void rocksdb_options_set_WAL_size_limit_MB(rocksdb_options_t* opt, |
3285 | uint64_t limit) { | |
7c673cae FG |
3286 | opt->rep.WAL_size_limit_MB = limit; |
3287 | } | |
3288 | ||
20effc67 TL |
3289 | uint64_t rocksdb_options_get_WAL_size_limit_MB(rocksdb_options_t* opt) { |
3290 | return opt->rep.WAL_size_limit_MB; | |
3291 | } | |
3292 | ||
1e59de90 TL |
3293 | void rocksdb_options_set_manifest_preallocation_size(rocksdb_options_t* opt, |
3294 | size_t v) { | |
7c673cae FG |
3295 | opt->rep.manifest_preallocation_size = v; |
3296 | } | |
3297 | ||
20effc67 TL |
3298 | size_t rocksdb_options_get_manifest_preallocation_size(rocksdb_options_t* opt) { |
3299 | return opt->rep.manifest_preallocation_size; | |
3300 | } | |
3301 | ||
7c673cae FG |
3302 | void rocksdb_options_set_use_direct_reads(rocksdb_options_t* opt, |
3303 | unsigned char v) { | |
3304 | opt->rep.use_direct_reads = v; | |
3305 | } | |
3306 | ||
20effc67 TL |
3307 | unsigned char rocksdb_options_get_use_direct_reads(rocksdb_options_t* opt) { |
3308 | return opt->rep.use_direct_reads; | |
3309 | } | |
3310 | ||
7c673cae FG |
3311 | void rocksdb_options_set_use_direct_io_for_flush_and_compaction( |
3312 | rocksdb_options_t* opt, unsigned char v) { | |
3313 | opt->rep.use_direct_io_for_flush_and_compaction = v; | |
3314 | } | |
3315 | ||
20effc67 TL |
3316 | unsigned char rocksdb_options_get_use_direct_io_for_flush_and_compaction( |
3317 | rocksdb_options_t* opt) { | |
3318 | return opt->rep.use_direct_io_for_flush_and_compaction; | |
3319 | } | |
3320 | ||
1e59de90 TL |
3321 | void rocksdb_options_set_allow_mmap_reads(rocksdb_options_t* opt, |
3322 | unsigned char v) { | |
7c673cae FG |
3323 | opt->rep.allow_mmap_reads = v; |
3324 | } | |
3325 | ||
20effc67 TL |
3326 | unsigned char rocksdb_options_get_allow_mmap_reads(rocksdb_options_t* opt) { |
3327 | return opt->rep.allow_mmap_reads; | |
3328 | } | |
3329 | ||
1e59de90 TL |
3330 | void rocksdb_options_set_allow_mmap_writes(rocksdb_options_t* opt, |
3331 | unsigned char v) { | |
7c673cae FG |
3332 | opt->rep.allow_mmap_writes = v; |
3333 | } | |
3334 | ||
20effc67 TL |
3335 | unsigned char rocksdb_options_get_allow_mmap_writes(rocksdb_options_t* opt) { |
3336 | return opt->rep.allow_mmap_writes; | |
3337 | } | |
3338 | ||
1e59de90 TL |
3339 | void rocksdb_options_set_is_fd_close_on_exec(rocksdb_options_t* opt, |
3340 | unsigned char v) { | |
7c673cae FG |
3341 | opt->rep.is_fd_close_on_exec = v; |
3342 | } | |
3343 | ||
20effc67 TL |
3344 | unsigned char rocksdb_options_get_is_fd_close_on_exec(rocksdb_options_t* opt) { |
3345 | return opt->rep.is_fd_close_on_exec; | |
3346 | } | |
3347 | ||
1e59de90 TL |
3348 | void rocksdb_options_set_stats_dump_period_sec(rocksdb_options_t* opt, |
3349 | unsigned int v) { | |
7c673cae FG |
3350 | opt->rep.stats_dump_period_sec = v; |
3351 | } | |
3352 | ||
20effc67 TL |
3353 | unsigned int rocksdb_options_get_stats_dump_period_sec(rocksdb_options_t* opt) { |
3354 | return opt->rep.stats_dump_period_sec; | |
3355 | } | |
3356 | ||
3357 | void rocksdb_options_set_stats_persist_period_sec(rocksdb_options_t* opt, | |
3358 | unsigned int v) { | |
3359 | opt->rep.stats_persist_period_sec = v; | |
3360 | } | |
3361 | ||
3362 | unsigned int rocksdb_options_get_stats_persist_period_sec( | |
3363 | rocksdb_options_t* opt) { | |
3364 | return opt->rep.stats_persist_period_sec; | |
3365 | } | |
3366 | ||
1e59de90 TL |
3367 | void rocksdb_options_set_advise_random_on_open(rocksdb_options_t* opt, |
3368 | unsigned char v) { | |
7c673cae FG |
3369 | opt->rep.advise_random_on_open = v; |
3370 | } | |
3371 | ||
20effc67 TL |
3372 | unsigned char rocksdb_options_get_advise_random_on_open( |
3373 | rocksdb_options_t* opt) { | |
3374 | return opt->rep.advise_random_on_open; | |
3375 | } | |
3376 | ||
1e59de90 TL |
3377 | void rocksdb_options_set_access_hint_on_compaction_start(rocksdb_options_t* opt, |
3378 | int v) { | |
3379 | switch (v) { | |
7c673cae | 3380 | case 0: |
f67539c2 TL |
3381 | opt->rep.access_hint_on_compaction_start = |
3382 | ROCKSDB_NAMESPACE::Options::NONE; | |
7c673cae FG |
3383 | break; |
3384 | case 1: | |
f67539c2 TL |
3385 | opt->rep.access_hint_on_compaction_start = |
3386 | ROCKSDB_NAMESPACE::Options::NORMAL; | |
7c673cae FG |
3387 | break; |
3388 | case 2: | |
f67539c2 TL |
3389 | opt->rep.access_hint_on_compaction_start = |
3390 | ROCKSDB_NAMESPACE::Options::SEQUENTIAL; | |
7c673cae FG |
3391 | break; |
3392 | case 3: | |
f67539c2 TL |
3393 | opt->rep.access_hint_on_compaction_start = |
3394 | ROCKSDB_NAMESPACE::Options::WILLNEED; | |
7c673cae | 3395 | break; |
1e59de90 TL |
3396 | default: |
3397 | assert(0); | |
7c673cae FG |
3398 | } |
3399 | } | |
3400 | ||
20effc67 TL |
3401 | int rocksdb_options_get_access_hint_on_compaction_start( |
3402 | rocksdb_options_t* opt) { | |
3403 | return opt->rep.access_hint_on_compaction_start; | |
3404 | } | |
3405 | ||
1e59de90 TL |
3406 | void rocksdb_options_set_use_adaptive_mutex(rocksdb_options_t* opt, |
3407 | unsigned char v) { | |
7c673cae FG |
3408 | opt->rep.use_adaptive_mutex = v; |
3409 | } | |
3410 | ||
20effc67 TL |
3411 | unsigned char rocksdb_options_get_use_adaptive_mutex(rocksdb_options_t* opt) { |
3412 | return opt->rep.use_adaptive_mutex; | |
3413 | } | |
3414 | ||
1e59de90 TL |
3415 | void rocksdb_options_set_wal_bytes_per_sync(rocksdb_options_t* opt, |
3416 | uint64_t v) { | |
11fdf7f2 TL |
3417 | opt->rep.wal_bytes_per_sync = v; |
3418 | } | |
3419 | ||
20effc67 TL |
3420 | uint64_t rocksdb_options_get_wal_bytes_per_sync(rocksdb_options_t* opt) { |
3421 | return opt->rep.wal_bytes_per_sync; | |
3422 | } | |
3423 | ||
1e59de90 | 3424 | void rocksdb_options_set_bytes_per_sync(rocksdb_options_t* opt, uint64_t v) { |
7c673cae FG |
3425 | opt->rep.bytes_per_sync = v; |
3426 | } | |
3427 | ||
20effc67 TL |
3428 | uint64_t rocksdb_options_get_bytes_per_sync(rocksdb_options_t* opt) { |
3429 | return opt->rep.bytes_per_sync; | |
3430 | } | |
3431 | ||
11fdf7f2 TL |
3432 | void rocksdb_options_set_writable_file_max_buffer_size(rocksdb_options_t* opt, |
3433 | uint64_t v) { | |
3434 | opt->rep.writable_file_max_buffer_size = static_cast<size_t>(v); | |
3435 | } | |
3436 | ||
20effc67 TL |
3437 | uint64_t rocksdb_options_get_writable_file_max_buffer_size( |
3438 | rocksdb_options_t* opt) { | |
3439 | return opt->rep.writable_file_max_buffer_size; | |
3440 | } | |
3441 | ||
7c673cae FG |
3442 | void rocksdb_options_set_allow_concurrent_memtable_write(rocksdb_options_t* opt, |
3443 | unsigned char v) { | |
3444 | opt->rep.allow_concurrent_memtable_write = v; | |
3445 | } | |
3446 | ||
20effc67 TL |
3447 | unsigned char rocksdb_options_get_allow_concurrent_memtable_write( |
3448 | rocksdb_options_t* opt) { | |
3449 | return opt->rep.allow_concurrent_memtable_write; | |
3450 | } | |
3451 | ||
7c673cae FG |
3452 | void rocksdb_options_set_enable_write_thread_adaptive_yield( |
3453 | rocksdb_options_t* opt, unsigned char v) { | |
3454 | opt->rep.enable_write_thread_adaptive_yield = v; | |
3455 | } | |
3456 | ||
20effc67 TL |
3457 | unsigned char rocksdb_options_get_enable_write_thread_adaptive_yield( |
3458 | rocksdb_options_t* opt) { | |
3459 | return opt->rep.enable_write_thread_adaptive_yield; | |
3460 | } | |
3461 | ||
7c673cae FG |
3462 | void rocksdb_options_set_max_sequential_skip_in_iterations( |
3463 | rocksdb_options_t* opt, uint64_t v) { | |
3464 | opt->rep.max_sequential_skip_in_iterations = v; | |
3465 | } | |
3466 | ||
20effc67 TL |
3467 | uint64_t rocksdb_options_get_max_sequential_skip_in_iterations( |
3468 | rocksdb_options_t* opt) { | |
3469 | return opt->rep.max_sequential_skip_in_iterations; | |
3470 | } | |
3471 | ||
1e59de90 TL |
3472 | void rocksdb_options_set_max_write_buffer_number(rocksdb_options_t* opt, |
3473 | int n) { | |
7c673cae FG |
3474 | opt->rep.max_write_buffer_number = n; |
3475 | } | |
3476 | ||
20effc67 TL |
3477 | int rocksdb_options_get_max_write_buffer_number(rocksdb_options_t* opt) { |
3478 | return opt->rep.max_write_buffer_number; | |
3479 | } | |
3480 | ||
1e59de90 TL |
3481 | void rocksdb_options_set_min_write_buffer_number_to_merge( |
3482 | rocksdb_options_t* opt, int n) { | |
7c673cae FG |
3483 | opt->rep.min_write_buffer_number_to_merge = n; |
3484 | } | |
3485 | ||
20effc67 TL |
3486 | int rocksdb_options_get_min_write_buffer_number_to_merge( |
3487 | rocksdb_options_t* opt) { | |
3488 | return opt->rep.min_write_buffer_number_to_merge; | |
3489 | } | |
3490 | ||
7c673cae FG |
3491 | void rocksdb_options_set_max_write_buffer_number_to_maintain( |
3492 | rocksdb_options_t* opt, int n) { | |
3493 | opt->rep.max_write_buffer_number_to_maintain = n; | |
3494 | } | |
3495 | ||
20effc67 TL |
3496 | int rocksdb_options_get_max_write_buffer_number_to_maintain( |
3497 | rocksdb_options_t* opt) { | |
3498 | return opt->rep.max_write_buffer_number_to_maintain; | |
3499 | } | |
3500 | ||
f67539c2 TL |
3501 | void rocksdb_options_set_max_write_buffer_size_to_maintain( |
3502 | rocksdb_options_t* opt, int64_t n) { | |
3503 | opt->rep.max_write_buffer_size_to_maintain = n; | |
3504 | } | |
3505 | ||
20effc67 TL |
3506 | int64_t rocksdb_options_get_max_write_buffer_size_to_maintain( |
3507 | rocksdb_options_t* opt) { | |
3508 | return opt->rep.max_write_buffer_size_to_maintain; | |
3509 | } | |
3510 | ||
11fdf7f2 TL |
3511 | void rocksdb_options_set_enable_pipelined_write(rocksdb_options_t* opt, |
3512 | unsigned char v) { | |
3513 | opt->rep.enable_pipelined_write = v; | |
3514 | } | |
3515 | ||
20effc67 TL |
3516 | unsigned char rocksdb_options_get_enable_pipelined_write( |
3517 | rocksdb_options_t* opt) { | |
3518 | return opt->rep.enable_pipelined_write; | |
3519 | } | |
3520 | ||
f67539c2 TL |
3521 | void rocksdb_options_set_unordered_write(rocksdb_options_t* opt, |
3522 | unsigned char v) { | |
3523 | opt->rep.unordered_write = v; | |
3524 | } | |
3525 | ||
20effc67 TL |
3526 | unsigned char rocksdb_options_get_unordered_write(rocksdb_options_t* opt) { |
3527 | return opt->rep.unordered_write; | |
3528 | } | |
3529 | ||
11fdf7f2 TL |
3530 | void rocksdb_options_set_max_subcompactions(rocksdb_options_t* opt, |
3531 | uint32_t n) { | |
3532 | opt->rep.max_subcompactions = n; | |
3533 | } | |
3534 | ||
20effc67 TL |
3535 | uint32_t rocksdb_options_get_max_subcompactions(rocksdb_options_t* opt) { |
3536 | return opt->rep.max_subcompactions; | |
3537 | } | |
3538 | ||
11fdf7f2 TL |
3539 | void rocksdb_options_set_max_background_jobs(rocksdb_options_t* opt, int n) { |
3540 | opt->rep.max_background_jobs = n; | |
3541 | } | |
3542 | ||
20effc67 TL |
3543 | int rocksdb_options_get_max_background_jobs(rocksdb_options_t* opt) { |
3544 | return opt->rep.max_background_jobs; | |
3545 | } | |
3546 | ||
1e59de90 TL |
3547 | void rocksdb_options_set_max_background_compactions(rocksdb_options_t* opt, |
3548 | int n) { | |
7c673cae FG |
3549 | opt->rep.max_background_compactions = n; |
3550 | } | |
3551 | ||
20effc67 TL |
3552 | int rocksdb_options_get_max_background_compactions(rocksdb_options_t* opt) { |
3553 | return opt->rep.max_background_compactions; | |
3554 | } | |
3555 | ||
7c673cae FG |
3556 | void rocksdb_options_set_max_background_flushes(rocksdb_options_t* opt, int n) { |
3557 | opt->rep.max_background_flushes = n; | |
3558 | } | |
3559 | ||
20effc67 TL |
3560 | int rocksdb_options_get_max_background_flushes(rocksdb_options_t* opt) { |
3561 | return opt->rep.max_background_flushes; | |
3562 | } | |
3563 | ||
1e59de90 TL |
3564 | void rocksdb_options_set_experimental_mempurge_threshold(rocksdb_options_t* opt, |
3565 | double v) { | |
3566 | opt->rep.experimental_mempurge_threshold = v; | |
3567 | } | |
3568 | ||
3569 | double rocksdb_options_get_experimental_mempurge_threshold( | |
3570 | rocksdb_options_t* opt) { | |
3571 | return opt->rep.experimental_mempurge_threshold; | |
3572 | } | |
3573 | ||
7c673cae FG |
3574 | void rocksdb_options_set_max_log_file_size(rocksdb_options_t* opt, size_t v) { |
3575 | opt->rep.max_log_file_size = v; | |
3576 | } | |
3577 | ||
20effc67 TL |
3578 | size_t rocksdb_options_get_max_log_file_size(rocksdb_options_t* opt) { |
3579 | return opt->rep.max_log_file_size; | |
3580 | } | |
3581 | ||
1e59de90 TL |
3582 | void rocksdb_options_set_log_file_time_to_roll(rocksdb_options_t* opt, |
3583 | size_t v) { | |
7c673cae FG |
3584 | opt->rep.log_file_time_to_roll = v; |
3585 | } | |
3586 | ||
20effc67 TL |
3587 | size_t rocksdb_options_get_log_file_time_to_roll(rocksdb_options_t* opt) { |
3588 | return opt->rep.log_file_time_to_roll; | |
3589 | } | |
3590 | ||
7c673cae FG |
3591 | void rocksdb_options_set_keep_log_file_num(rocksdb_options_t* opt, size_t v) { |
3592 | opt->rep.keep_log_file_num = v; | |
3593 | } | |
3594 | ||
20effc67 TL |
3595 | size_t rocksdb_options_get_keep_log_file_num(rocksdb_options_t* opt) { |
3596 | return opt->rep.keep_log_file_num; | |
3597 | } | |
3598 | ||
7c673cae FG |
3599 | void rocksdb_options_set_recycle_log_file_num(rocksdb_options_t* opt, |
3600 | size_t v) { | |
3601 | opt->rep.recycle_log_file_num = v; | |
3602 | } | |
3603 | ||
20effc67 TL |
3604 | size_t rocksdb_options_get_recycle_log_file_num(rocksdb_options_t* opt) { |
3605 | return opt->rep.recycle_log_file_num; | |
3606 | } | |
3607 | ||
1e59de90 TL |
3608 | void rocksdb_options_set_soft_pending_compaction_bytes_limit( |
3609 | rocksdb_options_t* opt, size_t v) { | |
7c673cae FG |
3610 | opt->rep.soft_pending_compaction_bytes_limit = v; |
3611 | } | |
3612 | ||
20effc67 TL |
3613 | size_t rocksdb_options_get_soft_pending_compaction_bytes_limit( |
3614 | rocksdb_options_t* opt) { | |
3615 | return opt->rep.soft_pending_compaction_bytes_limit; | |
3616 | } | |
3617 | ||
1e59de90 TL |
3618 | void rocksdb_options_set_hard_pending_compaction_bytes_limit( |
3619 | rocksdb_options_t* opt, size_t v) { | |
7c673cae FG |
3620 | opt->rep.hard_pending_compaction_bytes_limit = v; |
3621 | } | |
3622 | ||
20effc67 TL |
3623 | size_t rocksdb_options_get_hard_pending_compaction_bytes_limit( |
3624 | rocksdb_options_t* opt) { | |
3625 | return opt->rep.hard_pending_compaction_bytes_limit; | |
3626 | } | |
3627 | ||
1e59de90 TL |
3628 | void rocksdb_options_set_max_manifest_file_size(rocksdb_options_t* opt, |
3629 | size_t v) { | |
7c673cae FG |
3630 | opt->rep.max_manifest_file_size = v; |
3631 | } | |
3632 | ||
20effc67 TL |
3633 | size_t rocksdb_options_get_max_manifest_file_size(rocksdb_options_t* opt) { |
3634 | return opt->rep.max_manifest_file_size; | |
3635 | } | |
3636 | ||
1e59de90 TL |
3637 | void rocksdb_options_set_table_cache_numshardbits(rocksdb_options_t* opt, |
3638 | int v) { | |
7c673cae FG |
3639 | opt->rep.table_cache_numshardbits = v; |
3640 | } | |
3641 | ||
20effc67 TL |
3642 | int rocksdb_options_get_table_cache_numshardbits(rocksdb_options_t* opt) { |
3643 | return opt->rep.table_cache_numshardbits; | |
3644 | } | |
3645 | ||
1e59de90 | 3646 | void rocksdb_options_set_arena_block_size(rocksdb_options_t* opt, size_t v) { |
7c673cae FG |
3647 | opt->rep.arena_block_size = v; |
3648 | } | |
3649 | ||
20effc67 TL |
3650 | size_t rocksdb_options_get_arena_block_size(rocksdb_options_t* opt) { |
3651 | return opt->rep.arena_block_size; | |
3652 | } | |
3653 | ||
1e59de90 TL |
3654 | void rocksdb_options_set_disable_auto_compactions(rocksdb_options_t* opt, |
3655 | int disable) { | |
7c673cae FG |
3656 | opt->rep.disable_auto_compactions = disable; |
3657 | } | |
3658 | ||
20effc67 TL |
3659 | unsigned char rocksdb_options_get_disable_auto_compactions( |
3660 | rocksdb_options_t* opt) { | |
3661 | return opt->rep.disable_auto_compactions; | |
3662 | } | |
3663 | ||
1e59de90 TL |
3664 | void rocksdb_options_set_optimize_filters_for_hits(rocksdb_options_t* opt, |
3665 | int v) { | |
7c673cae FG |
3666 | opt->rep.optimize_filters_for_hits = v; |
3667 | } | |
3668 | ||
20effc67 TL |
3669 | unsigned char rocksdb_options_get_optimize_filters_for_hits( |
3670 | rocksdb_options_t* opt) { | |
3671 | return opt->rep.optimize_filters_for_hits; | |
3672 | } | |
3673 | ||
7c673cae FG |
3674 | void rocksdb_options_set_delete_obsolete_files_period_micros( |
3675 | rocksdb_options_t* opt, uint64_t v) { | |
3676 | opt->rep.delete_obsolete_files_period_micros = v; | |
3677 | } | |
3678 | ||
20effc67 TL |
3679 | uint64_t rocksdb_options_get_delete_obsolete_files_period_micros( |
3680 | rocksdb_options_t* opt) { | |
3681 | return opt->rep.delete_obsolete_files_period_micros; | |
3682 | } | |
3683 | ||
7c673cae FG |
3684 | void rocksdb_options_prepare_for_bulk_load(rocksdb_options_t* opt) { |
3685 | opt->rep.PrepareForBulkLoad(); | |
3686 | } | |
3687 | ||
1e59de90 | 3688 | void rocksdb_options_set_memtable_vector_rep(rocksdb_options_t* opt) { |
f67539c2 | 3689 | opt->rep.memtable_factory.reset(new ROCKSDB_NAMESPACE::VectorRepFactory); |
7c673cae FG |
3690 | } |
3691 | ||
3692 | void rocksdb_options_set_memtable_prefix_bloom_size_ratio( | |
3693 | rocksdb_options_t* opt, double v) { | |
3694 | opt->rep.memtable_prefix_bloom_size_ratio = v; | |
3695 | } | |
3696 | ||
20effc67 TL |
3697 | double rocksdb_options_get_memtable_prefix_bloom_size_ratio( |
3698 | rocksdb_options_t* opt) { | |
3699 | return opt->rep.memtable_prefix_bloom_size_ratio; | |
3700 | } | |
3701 | ||
7c673cae FG |
3702 | void rocksdb_options_set_memtable_huge_page_size(rocksdb_options_t* opt, |
3703 | size_t v) { | |
3704 | opt->rep.memtable_huge_page_size = v; | |
3705 | } | |
3706 | ||
20effc67 TL |
3707 | size_t rocksdb_options_get_memtable_huge_page_size(rocksdb_options_t* opt) { |
3708 | return opt->rep.memtable_huge_page_size; | |
3709 | } | |
3710 | ||
1e59de90 TL |
3711 | void rocksdb_options_set_hash_skip_list_rep(rocksdb_options_t* opt, |
3712 | size_t bucket_count, | |
3713 | int32_t skiplist_height, | |
3714 | int32_t skiplist_branching_factor) { | |
f67539c2 TL |
3715 | ROCKSDB_NAMESPACE::MemTableRepFactory* factory = |
3716 | ROCKSDB_NAMESPACE::NewHashSkipListRepFactory( | |
3717 | bucket_count, skiplist_height, skiplist_branching_factor); | |
7c673cae FG |
3718 | opt->rep.memtable_factory.reset(factory); |
3719 | } | |
3720 | ||
1e59de90 TL |
3721 | void rocksdb_options_set_hash_link_list_rep(rocksdb_options_t* opt, |
3722 | size_t bucket_count) { | |
f67539c2 TL |
3723 | opt->rep.memtable_factory.reset( |
3724 | ROCKSDB_NAMESPACE::NewHashLinkListRepFactory(bucket_count)); | |
7c673cae FG |
3725 | } |
3726 | ||
1e59de90 TL |
3727 | void rocksdb_options_set_plain_table_factory(rocksdb_options_t* opt, |
3728 | uint32_t user_key_len, | |
3729 | int bloom_bits_per_key, | |
3730 | double hash_table_ratio, | |
3731 | size_t index_sparseness) { | |
f67539c2 | 3732 | ROCKSDB_NAMESPACE::PlainTableOptions options; |
7c673cae FG |
3733 | options.user_key_len = user_key_len; |
3734 | options.bloom_bits_per_key = bloom_bits_per_key; | |
3735 | options.hash_table_ratio = hash_table_ratio; | |
3736 | options.index_sparseness = index_sparseness; | |
3737 | ||
f67539c2 TL |
3738 | ROCKSDB_NAMESPACE::TableFactory* factory = |
3739 | ROCKSDB_NAMESPACE::NewPlainTableFactory(options); | |
7c673cae FG |
3740 | opt->rep.table_factory.reset(factory); |
3741 | } | |
3742 | ||
1e59de90 TL |
3743 | void rocksdb_options_set_max_successive_merges(rocksdb_options_t* opt, |
3744 | size_t v) { | |
7c673cae FG |
3745 | opt->rep.max_successive_merges = v; |
3746 | } | |
3747 | ||
20effc67 TL |
3748 | size_t rocksdb_options_get_max_successive_merges(rocksdb_options_t* opt) { |
3749 | return opt->rep.max_successive_merges; | |
3750 | } | |
3751 | ||
1e59de90 | 3752 | void rocksdb_options_set_bloom_locality(rocksdb_options_t* opt, uint32_t v) { |
7c673cae FG |
3753 | opt->rep.bloom_locality = v; |
3754 | } | |
3755 | ||
20effc67 TL |
3756 | uint32_t rocksdb_options_get_bloom_locality(rocksdb_options_t* opt) { |
3757 | return opt->rep.bloom_locality; | |
3758 | } | |
3759 | ||
1e59de90 TL |
3760 | void rocksdb_options_set_inplace_update_support(rocksdb_options_t* opt, |
3761 | unsigned char v) { | |
7c673cae FG |
3762 | opt->rep.inplace_update_support = v; |
3763 | } | |
3764 | ||
20effc67 TL |
3765 | unsigned char rocksdb_options_get_inplace_update_support( |
3766 | rocksdb_options_t* opt) { | |
3767 | return opt->rep.inplace_update_support; | |
3768 | } | |
3769 | ||
1e59de90 TL |
3770 | void rocksdb_options_set_inplace_update_num_locks(rocksdb_options_t* opt, |
3771 | size_t v) { | |
7c673cae FG |
3772 | opt->rep.inplace_update_num_locks = v; |
3773 | } | |
3774 | ||
20effc67 TL |
3775 | size_t rocksdb_options_get_inplace_update_num_locks(rocksdb_options_t* opt) { |
3776 | return opt->rep.inplace_update_num_locks; | |
3777 | } | |
3778 | ||
1e59de90 | 3779 | void rocksdb_options_set_report_bg_io_stats(rocksdb_options_t* opt, int v) { |
7c673cae FG |
3780 | opt->rep.report_bg_io_stats = v; |
3781 | } | |
3782 | ||
20effc67 TL |
3783 | unsigned char rocksdb_options_get_report_bg_io_stats(rocksdb_options_t* opt) { |
3784 | return opt->rep.report_bg_io_stats; | |
3785 | } | |
3786 | ||
1e59de90 | 3787 | void rocksdb_options_set_compaction_style(rocksdb_options_t* opt, int style) { |
f67539c2 TL |
3788 | opt->rep.compaction_style = |
3789 | static_cast<ROCKSDB_NAMESPACE::CompactionStyle>(style); | |
7c673cae FG |
3790 | } |
3791 | ||
20effc67 TL |
3792 | int rocksdb_options_get_compaction_style(rocksdb_options_t* opt) { |
3793 | return opt->rep.compaction_style; | |
3794 | } | |
3795 | ||
1e59de90 TL |
3796 | void rocksdb_options_set_universal_compaction_options( |
3797 | rocksdb_options_t* opt, rocksdb_universal_compaction_options_t* uco) { | |
7c673cae FG |
3798 | opt->rep.compaction_options_universal = *(uco->rep); |
3799 | } | |
3800 | ||
3801 | void rocksdb_options_set_fifo_compaction_options( | |
1e59de90 | 3802 | rocksdb_options_t* opt, rocksdb_fifo_compaction_options_t* fifo) { |
7c673cae FG |
3803 | opt->rep.compaction_options_fifo = fifo->rep; |
3804 | } | |
3805 | ||
1e59de90 | 3806 | char* rocksdb_options_statistics_get_string(rocksdb_options_t* opt) { |
f67539c2 | 3807 | ROCKSDB_NAMESPACE::Statistics* statistics = opt->rep.statistics.get(); |
7c673cae FG |
3808 | if (statistics) { |
3809 | return strdup(statistics->ToString().c_str()); | |
3810 | } | |
3811 | return nullptr; | |
3812 | } | |
3813 | ||
1e59de90 TL |
3814 | void rocksdb_options_set_ratelimiter(rocksdb_options_t* opt, |
3815 | rocksdb_ratelimiter_t* limiter) { | |
11fdf7f2 TL |
3816 | if (limiter) { |
3817 | opt->rep.rate_limiter = limiter->rep; | |
3818 | } | |
7c673cae FG |
3819 | } |
3820 | ||
f67539c2 TL |
3821 | void rocksdb_options_set_atomic_flush(rocksdb_options_t* opt, |
3822 | unsigned char atomic_flush) { | |
3823 | opt->rep.atomic_flush = atomic_flush; | |
3824 | } | |
3825 | ||
20effc67 TL |
3826 | unsigned char rocksdb_options_get_atomic_flush(rocksdb_options_t* opt) { |
3827 | return opt->rep.atomic_flush; | |
3828 | } | |
3829 | ||
1e59de90 TL |
3830 | void rocksdb_options_set_manual_wal_flush(rocksdb_options_t* opt, |
3831 | unsigned char manual_wal_flush) { | |
3832 | opt->rep.manual_wal_flush = manual_wal_flush; | |
3833 | } | |
3834 | ||
3835 | unsigned char rocksdb_options_get_manual_wal_flush(rocksdb_options_t* opt) { | |
3836 | return opt->rep.manual_wal_flush; | |
3837 | } | |
3838 | ||
3839 | void rocksdb_options_set_wal_compression(rocksdb_options_t* opt, int val) { | |
3840 | opt->rep.wal_compression = static_cast<CompressionType>(val); | |
3841 | } | |
3842 | ||
3843 | int rocksdb_options_get_wal_compression(rocksdb_options_t* opt) { | |
3844 | return opt->rep.wal_compression; | |
3845 | } | |
3846 | ||
3847 | rocksdb_ratelimiter_t* rocksdb_ratelimiter_create(int64_t rate_bytes_per_sec, | |
3848 | int64_t refill_period_us, | |
3849 | int32_t fairness) { | |
7c673cae | 3850 | rocksdb_ratelimiter_t* rate_limiter = new rocksdb_ratelimiter_t; |
11fdf7f2 | 3851 | rate_limiter->rep.reset( |
1e59de90 | 3852 | NewGenericRateLimiter(rate_bytes_per_sec, refill_period_us, fairness)); |
7c673cae FG |
3853 | return rate_limiter; |
3854 | } | |
3855 | ||
1e59de90 | 3856 | void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t* limiter) { |
7c673cae FG |
3857 | delete limiter; |
3858 | } | |
3859 | ||
1e59de90 TL |
3860 | void rocksdb_options_set_row_cache(rocksdb_options_t* opt, |
3861 | rocksdb_cache_t* cache) { | |
3862 | if (cache) { | |
f67539c2 TL |
3863 | opt->rep.row_cache = cache->rep; |
3864 | } | |
3865 | } | |
3866 | ||
1e59de90 TL |
3867 | void rocksdb_options_add_compact_on_deletion_collector_factory( |
3868 | rocksdb_options_t* opt, size_t window_size, size_t num_dels_trigger) { | |
3869 | std::shared_ptr<ROCKSDB_NAMESPACE::TablePropertiesCollectorFactory> | |
3870 | compact_on_del = | |
3871 | NewCompactOnDeletionCollectorFactory(window_size, num_dels_trigger); | |
3872 | opt->rep.table_properties_collector_factories.emplace_back(compact_on_del); | |
3873 | } | |
3874 | ||
11fdf7f2 TL |
3875 | void rocksdb_set_perf_level(int v) { |
3876 | PerfLevel level = static_cast<PerfLevel>(v); | |
3877 | SetPerfLevel(level); | |
3878 | } | |
3879 | ||
3880 | rocksdb_perfcontext_t* rocksdb_perfcontext_create() { | |
3881 | rocksdb_perfcontext_t* context = new rocksdb_perfcontext_t; | |
f67539c2 | 3882 | context->rep = ROCKSDB_NAMESPACE::get_perf_context(); |
11fdf7f2 TL |
3883 | return context; |
3884 | } | |
3885 | ||
3886 | void rocksdb_perfcontext_reset(rocksdb_perfcontext_t* context) { | |
3887 | context->rep->Reset(); | |
3888 | } | |
3889 | ||
3890 | char* rocksdb_perfcontext_report(rocksdb_perfcontext_t* context, | |
1e59de90 | 3891 | unsigned char exclude_zero_counters) { |
11fdf7f2 TL |
3892 | return strdup(context->rep->ToString(exclude_zero_counters).c_str()); |
3893 | } | |
3894 | ||
3895 | uint64_t rocksdb_perfcontext_metric(rocksdb_perfcontext_t* context, | |
1e59de90 | 3896 | int metric) { |
11fdf7f2 TL |
3897 | PerfContext* rep = context->rep; |
3898 | switch (metric) { | |
3899 | case rocksdb_user_key_comparison_count: | |
3900 | return rep->user_key_comparison_count; | |
3901 | case rocksdb_block_cache_hit_count: | |
3902 | return rep->block_cache_hit_count; | |
3903 | case rocksdb_block_read_count: | |
3904 | return rep->block_read_count; | |
3905 | case rocksdb_block_read_byte: | |
3906 | return rep->block_read_byte; | |
3907 | case rocksdb_block_read_time: | |
3908 | return rep->block_read_time; | |
3909 | case rocksdb_block_checksum_time: | |
3910 | return rep->block_checksum_time; | |
3911 | case rocksdb_block_decompress_time: | |
3912 | return rep->block_decompress_time; | |
3913 | case rocksdb_get_read_bytes: | |
3914 | return rep->get_read_bytes; | |
3915 | case rocksdb_multiget_read_bytes: | |
3916 | return rep->multiget_read_bytes; | |
3917 | case rocksdb_iter_read_bytes: | |
3918 | return rep->iter_read_bytes; | |
3919 | case rocksdb_internal_key_skipped_count: | |
3920 | return rep->internal_key_skipped_count; | |
3921 | case rocksdb_internal_delete_skipped_count: | |
3922 | return rep->internal_delete_skipped_count; | |
3923 | case rocksdb_internal_recent_skipped_count: | |
3924 | return rep->internal_recent_skipped_count; | |
3925 | case rocksdb_internal_merge_count: | |
3926 | return rep->internal_merge_count; | |
3927 | case rocksdb_get_snapshot_time: | |
3928 | return rep->get_snapshot_time; | |
3929 | case rocksdb_get_from_memtable_time: | |
3930 | return rep->get_from_memtable_time; | |
3931 | case rocksdb_get_from_memtable_count: | |
3932 | return rep->get_from_memtable_count; | |
3933 | case rocksdb_get_post_process_time: | |
3934 | return rep->get_post_process_time; | |
3935 | case rocksdb_get_from_output_files_time: | |
3936 | return rep->get_from_output_files_time; | |
3937 | case rocksdb_seek_on_memtable_time: | |
3938 | return rep->seek_on_memtable_time; | |
3939 | case rocksdb_seek_on_memtable_count: | |
3940 | return rep->seek_on_memtable_count; | |
3941 | case rocksdb_next_on_memtable_count: | |
3942 | return rep->next_on_memtable_count; | |
3943 | case rocksdb_prev_on_memtable_count: | |
3944 | return rep->prev_on_memtable_count; | |
3945 | case rocksdb_seek_child_seek_time: | |
3946 | return rep->seek_child_seek_time; | |
3947 | case rocksdb_seek_child_seek_count: | |
3948 | return rep->seek_child_seek_count; | |
3949 | case rocksdb_seek_min_heap_time: | |
3950 | return rep->seek_min_heap_time; | |
3951 | case rocksdb_seek_max_heap_time: | |
3952 | return rep->seek_max_heap_time; | |
3953 | case rocksdb_seek_internal_seek_time: | |
3954 | return rep->seek_internal_seek_time; | |
3955 | case rocksdb_find_next_user_entry_time: | |
3956 | return rep->find_next_user_entry_time; | |
3957 | case rocksdb_write_wal_time: | |
3958 | return rep->write_wal_time; | |
3959 | case rocksdb_write_memtable_time: | |
3960 | return rep->write_memtable_time; | |
3961 | case rocksdb_write_delay_time: | |
3962 | return rep->write_delay_time; | |
3963 | case rocksdb_write_pre_and_post_process_time: | |
3964 | return rep->write_pre_and_post_process_time; | |
3965 | case rocksdb_db_mutex_lock_nanos: | |
3966 | return rep->db_mutex_lock_nanos; | |
3967 | case rocksdb_db_condition_wait_nanos: | |
3968 | return rep->db_condition_wait_nanos; | |
3969 | case rocksdb_merge_operator_time_nanos: | |
3970 | return rep->merge_operator_time_nanos; | |
3971 | case rocksdb_read_index_block_nanos: | |
3972 | return rep->read_index_block_nanos; | |
3973 | case rocksdb_read_filter_block_nanos: | |
3974 | return rep->read_filter_block_nanos; | |
3975 | case rocksdb_new_table_block_iter_nanos: | |
3976 | return rep->new_table_block_iter_nanos; | |
3977 | case rocksdb_new_table_iterator_nanos: | |
3978 | return rep->new_table_iterator_nanos; | |
3979 | case rocksdb_block_seek_nanos: | |
3980 | return rep->block_seek_nanos; | |
3981 | case rocksdb_find_table_nanos: | |
3982 | return rep->find_table_nanos; | |
3983 | case rocksdb_bloom_memtable_hit_count: | |
3984 | return rep->bloom_memtable_hit_count; | |
3985 | case rocksdb_bloom_memtable_miss_count: | |
3986 | return rep->bloom_memtable_miss_count; | |
3987 | case rocksdb_bloom_sst_hit_count: | |
3988 | return rep->bloom_sst_hit_count; | |
3989 | case rocksdb_bloom_sst_miss_count: | |
3990 | return rep->bloom_sst_miss_count; | |
3991 | case rocksdb_key_lock_wait_time: | |
3992 | return rep->key_lock_wait_time; | |
3993 | case rocksdb_key_lock_wait_count: | |
3994 | return rep->key_lock_wait_count; | |
3995 | case rocksdb_env_new_sequential_file_nanos: | |
3996 | return rep->env_new_sequential_file_nanos; | |
3997 | case rocksdb_env_new_random_access_file_nanos: | |
3998 | return rep->env_new_random_access_file_nanos; | |
3999 | case rocksdb_env_new_writable_file_nanos: | |
4000 | return rep->env_new_writable_file_nanos; | |
4001 | case rocksdb_env_reuse_writable_file_nanos: | |
4002 | return rep->env_reuse_writable_file_nanos; | |
4003 | case rocksdb_env_new_random_rw_file_nanos: | |
4004 | return rep->env_new_random_rw_file_nanos; | |
4005 | case rocksdb_env_new_directory_nanos: | |
4006 | return rep->env_new_directory_nanos; | |
4007 | case rocksdb_env_file_exists_nanos: | |
4008 | return rep->env_file_exists_nanos; | |
4009 | case rocksdb_env_get_children_nanos: | |
4010 | return rep->env_get_children_nanos; | |
4011 | case rocksdb_env_get_children_file_attributes_nanos: | |
4012 | return rep->env_get_children_file_attributes_nanos; | |
4013 | case rocksdb_env_delete_file_nanos: | |
4014 | return rep->env_delete_file_nanos; | |
4015 | case rocksdb_env_create_dir_nanos: | |
4016 | return rep->env_create_dir_nanos; | |
4017 | case rocksdb_env_create_dir_if_missing_nanos: | |
4018 | return rep->env_create_dir_if_missing_nanos; | |
4019 | case rocksdb_env_delete_dir_nanos: | |
4020 | return rep->env_delete_dir_nanos; | |
4021 | case rocksdb_env_get_file_size_nanos: | |
4022 | return rep->env_get_file_size_nanos; | |
4023 | case rocksdb_env_get_file_modification_time_nanos: | |
4024 | return rep->env_get_file_modification_time_nanos; | |
4025 | case rocksdb_env_rename_file_nanos: | |
4026 | return rep->env_rename_file_nanos; | |
4027 | case rocksdb_env_link_file_nanos: | |
4028 | return rep->env_link_file_nanos; | |
4029 | case rocksdb_env_lock_file_nanos: | |
4030 | return rep->env_lock_file_nanos; | |
4031 | case rocksdb_env_unlock_file_nanos: | |
4032 | return rep->env_unlock_file_nanos; | |
4033 | case rocksdb_env_new_logger_nanos: | |
4034 | return rep->env_new_logger_nanos; | |
1e59de90 TL |
4035 | case rocksdb_number_async_seek: |
4036 | return rep->number_async_seek; | |
4037 | case rocksdb_blob_cache_hit_count: | |
4038 | return rep->blob_cache_hit_count; | |
4039 | case rocksdb_blob_read_count: | |
4040 | return rep->blob_read_count; | |
4041 | case rocksdb_blob_read_byte: | |
4042 | return rep->blob_read_byte; | |
4043 | case rocksdb_blob_read_time: | |
4044 | return rep->blob_read_time; | |
4045 | case rocksdb_blob_checksum_time: | |
4046 | return rep->blob_checksum_time; | |
4047 | case rocksdb_blob_decompress_time: | |
4048 | return rep->blob_decompress_time; | |
4049 | case rocksdb_internal_range_del_reseek_count: | |
4050 | return rep->internal_range_del_reseek_count; | |
11fdf7f2 TL |
4051 | default: |
4052 | break; | |
4053 | } | |
4054 | return 0; | |
4055 | } | |
4056 | ||
4057 | void rocksdb_perfcontext_destroy(rocksdb_perfcontext_t* context) { | |
4058 | delete context; | |
4059 | } | |
4060 | ||
7c673cae FG |
4061 | /* |
4062 | TODO: | |
4063 | DB::OpenForReadOnly | |
4064 | DB::KeyMayExist | |
4065 | DB::GetOptions | |
4066 | DB::GetSortedWalFiles | |
4067 | DB::GetLatestSequenceNumber | |
4068 | DB::GetUpdatesSince | |
4069 | DB::GetDbIdentity | |
4070 | DB::RunManualCompaction | |
4071 | custom cache | |
4072 | table_properties_collectors | |
4073 | */ | |
4074 | ||
4075 | rocksdb_compactionfilter_t* rocksdb_compactionfilter_create( | |
1e59de90 TL |
4076 | void* state, void (*destructor)(void*), |
4077 | unsigned char (*filter)(void*, int level, const char* key, | |
4078 | size_t key_length, const char* existing_value, | |
4079 | size_t value_length, char** new_value, | |
4080 | size_t* new_value_length, | |
4081 | unsigned char* value_changed), | |
7c673cae FG |
4082 | const char* (*name)(void*)) { |
4083 | rocksdb_compactionfilter_t* result = new rocksdb_compactionfilter_t; | |
4084 | result->state_ = state; | |
4085 | result->destructor_ = destructor; | |
4086 | result->filter_ = filter; | |
494da23a | 4087 | result->ignore_snapshots_ = true; |
7c673cae FG |
4088 | result->name_ = name; |
4089 | return result; | |
4090 | } | |
4091 | ||
4092 | void rocksdb_compactionfilter_set_ignore_snapshots( | |
1e59de90 | 4093 | rocksdb_compactionfilter_t* filter, unsigned char whether_ignore) { |
7c673cae FG |
4094 | filter->ignore_snapshots_ = whether_ignore; |
4095 | } | |
4096 | ||
4097 | void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t* filter) { | |
4098 | delete filter; | |
4099 | } | |
4100 | ||
4101 | unsigned char rocksdb_compactionfiltercontext_is_full_compaction( | |
4102 | rocksdb_compactionfiltercontext_t* context) { | |
4103 | return context->rep.is_full_compaction; | |
4104 | } | |
4105 | ||
4106 | unsigned char rocksdb_compactionfiltercontext_is_manual_compaction( | |
4107 | rocksdb_compactionfiltercontext_t* context) { | |
4108 | return context->rep.is_manual_compaction; | |
4109 | } | |
4110 | ||
4111 | rocksdb_compactionfilterfactory_t* rocksdb_compactionfilterfactory_create( | |
4112 | void* state, void (*destructor)(void*), | |
4113 | rocksdb_compactionfilter_t* (*create_compaction_filter)( | |
4114 | void*, rocksdb_compactionfiltercontext_t* context), | |
4115 | const char* (*name)(void*)) { | |
4116 | rocksdb_compactionfilterfactory_t* result = | |
4117 | new rocksdb_compactionfilterfactory_t; | |
4118 | result->state_ = state; | |
4119 | result->destructor_ = destructor; | |
4120 | result->create_compaction_filter_ = create_compaction_filter; | |
4121 | result->name_ = name; | |
4122 | return result; | |
4123 | } | |
4124 | ||
4125 | void rocksdb_compactionfilterfactory_destroy( | |
4126 | rocksdb_compactionfilterfactory_t* factory) { | |
4127 | delete factory; | |
4128 | } | |
4129 | ||
4130 | rocksdb_comparator_t* rocksdb_comparator_create( | |
1e59de90 TL |
4131 | void* state, void (*destructor)(void*), |
4132 | int (*compare)(void*, const char* a, size_t alen, const char* b, | |
4133 | size_t blen), | |
7c673cae FG |
4134 | const char* (*name)(void*)) { |
4135 | rocksdb_comparator_t* result = new rocksdb_comparator_t; | |
4136 | result->state_ = state; | |
4137 | result->destructor_ = destructor; | |
4138 | result->compare_ = compare; | |
4139 | result->name_ = name; | |
1e59de90 TL |
4140 | result->compare_ts_ = nullptr; |
4141 | result->compare_without_ts_ = nullptr; | |
7c673cae FG |
4142 | return result; |
4143 | } | |
4144 | ||
1e59de90 TL |
4145 | void rocksdb_comparator_destroy(rocksdb_comparator_t* cmp) { delete cmp; } |
4146 | ||
4147 | rocksdb_comparator_t* rocksdb_comparator_with_ts_create( | |
4148 | void* state, void (*destructor)(void*), | |
4149 | int (*compare)(void*, const char* a, size_t alen, const char* b, | |
4150 | size_t blen), | |
4151 | int (*compare_ts)(void*, const char* a_ts, size_t a_tslen, const char* b_ts, | |
4152 | size_t b_tslen), | |
4153 | int (*compare_without_ts)(void*, const char* a, size_t alen, | |
4154 | unsigned char a_has_ts, const char* b, | |
4155 | size_t blen, unsigned char b_has_ts), | |
4156 | const char* (*name)(void*), size_t timestamp_size) { | |
4157 | rocksdb_comparator_t* result = new rocksdb_comparator_t(timestamp_size); | |
7c673cae FG |
4158 | result->state_ = state; |
4159 | result->destructor_ = destructor; | |
1e59de90 TL |
4160 | result->compare_ = compare; |
4161 | result->compare_ts_ = compare_ts; | |
4162 | result->compare_without_ts_ = compare_without_ts; | |
7c673cae FG |
4163 | result->name_ = name; |
4164 | return result; | |
4165 | } | |
4166 | ||
4167 | void rocksdb_filterpolicy_destroy(rocksdb_filterpolicy_t* filter) { | |
4168 | delete filter; | |
4169 | } | |
4170 | ||
1e59de90 TL |
4171 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_bloom_format( |
4172 | double bits_per_key, bool original_format) { | |
7c673cae FG |
4173 | // Make a rocksdb_filterpolicy_t, but override all of its methods so |
4174 | // they delegate to a NewBloomFilterPolicy() instead of user | |
4175 | // supplied C functions. | |
4176 | struct Wrapper : public rocksdb_filterpolicy_t { | |
4177 | const FilterPolicy* rep_; | |
494da23a | 4178 | ~Wrapper() override { delete rep_; } |
7c673cae | 4179 | const char* Name() const override { return rep_->Name(); } |
1e59de90 TL |
4180 | const char* CompatibilityName() const override { |
4181 | return rep_->CompatibilityName(); | |
7c673cae | 4182 | } |
f67539c2 TL |
4183 | // No need to override GetFilterBitsBuilder if this one is overridden |
4184 | ROCKSDB_NAMESPACE::FilterBitsBuilder* GetBuilderWithContext( | |
4185 | const ROCKSDB_NAMESPACE::FilterBuildingContext& context) | |
4186 | const override { | |
4187 | return rep_->GetBuilderWithContext(context); | |
4188 | } | |
4189 | ROCKSDB_NAMESPACE::FilterBitsReader* GetFilterBitsReader( | |
4190 | const Slice& contents) const override { | |
4191 | return rep_->GetFilterBitsReader(contents); | |
4192 | } | |
4193 | static void DoNothing(void*) {} | |
7c673cae FG |
4194 | }; |
4195 | Wrapper* wrapper = new Wrapper; | |
4196 | wrapper->rep_ = NewBloomFilterPolicy(bits_per_key, original_format); | |
4197 | wrapper->state_ = nullptr; | |
7c673cae FG |
4198 | wrapper->destructor_ = &Wrapper::DoNothing; |
4199 | return wrapper; | |
4200 | } | |
4201 | ||
1e59de90 TL |
4202 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_bloom_full( |
4203 | double bits_per_key) { | |
7c673cae FG |
4204 | return rocksdb_filterpolicy_create_bloom_format(bits_per_key, false); |
4205 | } | |
4206 | ||
1e59de90 | 4207 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_bloom(double bits_per_key) { |
7c673cae FG |
4208 | return rocksdb_filterpolicy_create_bloom_format(bits_per_key, true); |
4209 | } | |
4210 | ||
1e59de90 TL |
4211 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_ribbon_format( |
4212 | double bloom_equivalent_bits_per_key, int bloom_before_level) { | |
4213 | // Make a rocksdb_filterpolicy_t, but override all of its methods so | |
4214 | // they delegate to a NewRibbonFilterPolicy() instead of user | |
4215 | // supplied C functions. | |
4216 | struct Wrapper : public rocksdb_filterpolicy_t { | |
4217 | const FilterPolicy* rep_; | |
4218 | ~Wrapper() override { delete rep_; } | |
4219 | const char* Name() const override { return rep_->Name(); } | |
4220 | const char* CompatibilityName() const override { | |
4221 | return rep_->CompatibilityName(); | |
4222 | } | |
4223 | ROCKSDB_NAMESPACE::FilterBitsBuilder* GetBuilderWithContext( | |
4224 | const ROCKSDB_NAMESPACE::FilterBuildingContext& context) | |
4225 | const override { | |
4226 | return rep_->GetBuilderWithContext(context); | |
4227 | } | |
4228 | ROCKSDB_NAMESPACE::FilterBitsReader* GetFilterBitsReader( | |
4229 | const Slice& contents) const override { | |
4230 | return rep_->GetFilterBitsReader(contents); | |
4231 | } | |
4232 | static void DoNothing(void*) {} | |
4233 | }; | |
4234 | Wrapper* wrapper = new Wrapper; | |
4235 | wrapper->rep_ = | |
4236 | NewRibbonFilterPolicy(bloom_equivalent_bits_per_key, bloom_before_level); | |
4237 | wrapper->state_ = nullptr; | |
4238 | wrapper->destructor_ = &Wrapper::DoNothing; | |
4239 | return wrapper; | |
4240 | } | |
4241 | ||
4242 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_ribbon( | |
4243 | double bloom_equivalent_bits_per_key) { | |
4244 | return rocksdb_filterpolicy_create_ribbon_format( | |
4245 | bloom_equivalent_bits_per_key, /*bloom_before_level = disabled*/ -1); | |
4246 | } | |
4247 | ||
4248 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_ribbon_hybrid( | |
4249 | double bloom_equivalent_bits_per_key, int bloom_before_level) { | |
4250 | return rocksdb_filterpolicy_create_ribbon_format( | |
4251 | bloom_equivalent_bits_per_key, bloom_before_level); | |
4252 | } | |
4253 | ||
7c673cae FG |
4254 | rocksdb_mergeoperator_t* rocksdb_mergeoperator_create( |
4255 | void* state, void (*destructor)(void*), | |
4256 | char* (*full_merge)(void*, const char* key, size_t key_length, | |
4257 | const char* existing_value, | |
4258 | size_t existing_value_length, | |
4259 | const char* const* operands_list, | |
4260 | const size_t* operands_list_length, int num_operands, | |
4261 | unsigned char* success, size_t* new_value_length), | |
4262 | char* (*partial_merge)(void*, const char* key, size_t key_length, | |
4263 | const char* const* operands_list, | |
4264 | const size_t* operands_list_length, int num_operands, | |
4265 | unsigned char* success, size_t* new_value_length), | |
4266 | void (*delete_value)(void*, const char* value, size_t value_length), | |
4267 | const char* (*name)(void*)) { | |
4268 | rocksdb_mergeoperator_t* result = new rocksdb_mergeoperator_t; | |
4269 | result->state_ = state; | |
4270 | result->destructor_ = destructor; | |
4271 | result->full_merge_ = full_merge; | |
4272 | result->partial_merge_ = partial_merge; | |
4273 | result->delete_value_ = delete_value; | |
4274 | result->name_ = name; | |
4275 | return result; | |
4276 | } | |
4277 | ||
4278 | void rocksdb_mergeoperator_destroy(rocksdb_mergeoperator_t* merge_operator) { | |
4279 | delete merge_operator; | |
4280 | } | |
4281 | ||
4282 | rocksdb_readoptions_t* rocksdb_readoptions_create() { | |
4283 | return new rocksdb_readoptions_t; | |
4284 | } | |
4285 | ||
1e59de90 | 4286 | void rocksdb_readoptions_destroy(rocksdb_readoptions_t* opt) { delete opt; } |
7c673cae | 4287 | |
1e59de90 TL |
4288 | void rocksdb_readoptions_set_verify_checksums(rocksdb_readoptions_t* opt, |
4289 | unsigned char v) { | |
7c673cae FG |
4290 | opt->rep.verify_checksums = v; |
4291 | } | |
4292 | ||
20effc67 TL |
4293 | unsigned char rocksdb_readoptions_get_verify_checksums( |
4294 | rocksdb_readoptions_t* opt) { | |
4295 | return opt->rep.verify_checksums; | |
4296 | } | |
4297 | ||
1e59de90 TL |
4298 | void rocksdb_readoptions_set_fill_cache(rocksdb_readoptions_t* opt, |
4299 | unsigned char v) { | |
7c673cae FG |
4300 | opt->rep.fill_cache = v; |
4301 | } | |
4302 | ||
20effc67 TL |
4303 | unsigned char rocksdb_readoptions_get_fill_cache(rocksdb_readoptions_t* opt) { |
4304 | return opt->rep.fill_cache; | |
4305 | } | |
4306 | ||
1e59de90 TL |
4307 | void rocksdb_readoptions_set_snapshot(rocksdb_readoptions_t* opt, |
4308 | const rocksdb_snapshot_t* snap) { | |
7c673cae FG |
4309 | opt->rep.snapshot = (snap ? snap->rep : nullptr); |
4310 | } | |
4311 | ||
1e59de90 TL |
4312 | void rocksdb_readoptions_set_iterate_upper_bound(rocksdb_readoptions_t* opt, |
4313 | const char* key, | |
4314 | size_t keylen) { | |
7c673cae FG |
4315 | if (key == nullptr) { |
4316 | opt->upper_bound = Slice(); | |
4317 | opt->rep.iterate_upper_bound = nullptr; | |
4318 | ||
4319 | } else { | |
4320 | opt->upper_bound = Slice(key, keylen); | |
4321 | opt->rep.iterate_upper_bound = &opt->upper_bound; | |
4322 | } | |
4323 | } | |
4324 | ||
1e59de90 TL |
4325 | void rocksdb_readoptions_set_iterate_lower_bound(rocksdb_readoptions_t* opt, |
4326 | const char* key, | |
4327 | size_t keylen) { | |
11fdf7f2 TL |
4328 | if (key == nullptr) { |
4329 | opt->lower_bound = Slice(); | |
4330 | opt->rep.iterate_lower_bound = nullptr; | |
4331 | } else { | |
4332 | opt->lower_bound = Slice(key, keylen); | |
4333 | opt->rep.iterate_lower_bound = &opt->lower_bound; | |
4334 | } | |
4335 | } | |
4336 | ||
1e59de90 | 4337 | void rocksdb_readoptions_set_read_tier(rocksdb_readoptions_t* opt, int v) { |
f67539c2 | 4338 | opt->rep.read_tier = static_cast<ROCKSDB_NAMESPACE::ReadTier>(v); |
7c673cae FG |
4339 | } |
4340 | ||
20effc67 TL |
4341 | int rocksdb_readoptions_get_read_tier(rocksdb_readoptions_t* opt) { |
4342 | return static_cast<int>(opt->rep.read_tier); | |
4343 | } | |
4344 | ||
1e59de90 TL |
4345 | void rocksdb_readoptions_set_tailing(rocksdb_readoptions_t* opt, |
4346 | unsigned char v) { | |
7c673cae FG |
4347 | opt->rep.tailing = v; |
4348 | } | |
4349 | ||
20effc67 TL |
4350 | unsigned char rocksdb_readoptions_get_tailing(rocksdb_readoptions_t* opt) { |
4351 | return opt->rep.tailing; | |
4352 | } | |
4353 | ||
1e59de90 TL |
4354 | void rocksdb_readoptions_set_managed(rocksdb_readoptions_t* opt, |
4355 | unsigned char v) { | |
11fdf7f2 TL |
4356 | opt->rep.managed = v; |
4357 | } | |
4358 | ||
1e59de90 TL |
4359 | void rocksdb_readoptions_set_readahead_size(rocksdb_readoptions_t* opt, |
4360 | size_t v) { | |
7c673cae FG |
4361 | opt->rep.readahead_size = v; |
4362 | } | |
4363 | ||
20effc67 TL |
4364 | size_t rocksdb_readoptions_get_readahead_size(rocksdb_readoptions_t* opt) { |
4365 | return opt->rep.readahead_size; | |
4366 | } | |
4367 | ||
1e59de90 TL |
4368 | void rocksdb_readoptions_set_prefix_same_as_start(rocksdb_readoptions_t* opt, |
4369 | unsigned char v) { | |
11fdf7f2 TL |
4370 | opt->rep.prefix_same_as_start = v; |
4371 | } | |
4372 | ||
20effc67 TL |
4373 | unsigned char rocksdb_readoptions_get_prefix_same_as_start( |
4374 | rocksdb_readoptions_t* opt) { | |
4375 | return opt->rep.prefix_same_as_start; | |
4376 | } | |
4377 | ||
7c673cae FG |
4378 | void rocksdb_readoptions_set_pin_data(rocksdb_readoptions_t* opt, |
4379 | unsigned char v) { | |
4380 | opt->rep.pin_data = v; | |
4381 | } | |
4382 | ||
20effc67 TL |
4383 | unsigned char rocksdb_readoptions_get_pin_data(rocksdb_readoptions_t* opt) { |
4384 | return opt->rep.pin_data; | |
4385 | } | |
4386 | ||
7c673cae FG |
4387 | void rocksdb_readoptions_set_total_order_seek(rocksdb_readoptions_t* opt, |
4388 | unsigned char v) { | |
4389 | opt->rep.total_order_seek = v; | |
4390 | } | |
4391 | ||
20effc67 TL |
4392 | unsigned char rocksdb_readoptions_get_total_order_seek( |
4393 | rocksdb_readoptions_t* opt) { | |
4394 | return opt->rep.total_order_seek; | |
4395 | } | |
4396 | ||
11fdf7f2 | 4397 | void rocksdb_readoptions_set_max_skippable_internal_keys( |
1e59de90 | 4398 | rocksdb_readoptions_t* opt, uint64_t v) { |
11fdf7f2 TL |
4399 | opt->rep.max_skippable_internal_keys = v; |
4400 | } | |
4401 | ||
20effc67 TL |
4402 | uint64_t rocksdb_readoptions_get_max_skippable_internal_keys( |
4403 | rocksdb_readoptions_t* opt) { | |
4404 | return opt->rep.max_skippable_internal_keys; | |
4405 | } | |
4406 | ||
11fdf7f2 TL |
4407 | void rocksdb_readoptions_set_background_purge_on_iterator_cleanup( |
4408 | rocksdb_readoptions_t* opt, unsigned char v) { | |
4409 | opt->rep.background_purge_on_iterator_cleanup = v; | |
4410 | } | |
4411 | ||
20effc67 TL |
4412 | unsigned char rocksdb_readoptions_get_background_purge_on_iterator_cleanup( |
4413 | rocksdb_readoptions_t* opt) { | |
4414 | return opt->rep.background_purge_on_iterator_cleanup; | |
4415 | } | |
4416 | ||
1e59de90 TL |
4417 | void rocksdb_readoptions_set_ignore_range_deletions(rocksdb_readoptions_t* opt, |
4418 | unsigned char v) { | |
11fdf7f2 TL |
4419 | opt->rep.ignore_range_deletions = v; |
4420 | } | |
4421 | ||
20effc67 TL |
4422 | unsigned char rocksdb_readoptions_get_ignore_range_deletions( |
4423 | rocksdb_readoptions_t* opt) { | |
4424 | return opt->rep.ignore_range_deletions; | |
4425 | } | |
4426 | ||
1e59de90 TL |
4427 | void rocksdb_readoptions_set_deadline(rocksdb_readoptions_t* opt, |
4428 | uint64_t microseconds) { | |
4429 | opt->rep.deadline = std::chrono::microseconds(microseconds); | |
4430 | } | |
4431 | ||
4432 | uint64_t rocksdb_readoptions_get_deadline(rocksdb_readoptions_t* opt) { | |
4433 | return opt->rep.deadline.count(); | |
4434 | } | |
4435 | ||
4436 | void rocksdb_readoptions_set_io_timeout(rocksdb_readoptions_t* opt, | |
4437 | uint64_t microseconds) { | |
4438 | opt->rep.io_timeout = std::chrono::microseconds(microseconds); | |
4439 | } | |
4440 | ||
4441 | extern ROCKSDB_LIBRARY_API uint64_t | |
4442 | rocksdb_readoptions_get_io_timeout(rocksdb_readoptions_t* opt) { | |
4443 | return opt->rep.io_timeout.count(); | |
4444 | } | |
4445 | ||
4446 | void rocksdb_readoptions_set_timestamp(rocksdb_readoptions_t* opt, | |
4447 | const char* ts, size_t tslen) { | |
4448 | if (ts == nullptr) { | |
4449 | opt->timestamp = Slice(); | |
4450 | opt->rep.timestamp = nullptr; | |
4451 | } else { | |
4452 | opt->timestamp = Slice(ts, tslen); | |
4453 | opt->rep.timestamp = &opt->timestamp; | |
4454 | } | |
4455 | } | |
4456 | ||
4457 | void rocksdb_readoptions_set_iter_start_ts(rocksdb_readoptions_t* opt, | |
4458 | const char* ts, size_t tslen) { | |
4459 | if (ts == nullptr) { | |
4460 | opt->iter_start_ts = Slice(); | |
4461 | opt->rep.iter_start_ts = nullptr; | |
4462 | } else { | |
4463 | opt->iter_start_ts = Slice(ts, tslen); | |
4464 | opt->rep.iter_start_ts = &opt->iter_start_ts; | |
4465 | } | |
4466 | } | |
4467 | ||
7c673cae FG |
4468 | rocksdb_writeoptions_t* rocksdb_writeoptions_create() { |
4469 | return new rocksdb_writeoptions_t; | |
4470 | } | |
4471 | ||
1e59de90 | 4472 | void rocksdb_writeoptions_destroy(rocksdb_writeoptions_t* opt) { delete opt; } |
7c673cae | 4473 | |
1e59de90 TL |
4474 | void rocksdb_writeoptions_set_sync(rocksdb_writeoptions_t* opt, |
4475 | unsigned char v) { | |
7c673cae FG |
4476 | opt->rep.sync = v; |
4477 | } | |
4478 | ||
20effc67 TL |
4479 | unsigned char rocksdb_writeoptions_get_sync(rocksdb_writeoptions_t* opt) { |
4480 | return opt->rep.sync; | |
4481 | } | |
4482 | ||
1e59de90 TL |
4483 | void rocksdb_writeoptions_disable_WAL(rocksdb_writeoptions_t* opt, |
4484 | int disable) { | |
7c673cae FG |
4485 | opt->rep.disableWAL = disable; |
4486 | } | |
4487 | ||
20effc67 TL |
4488 | unsigned char rocksdb_writeoptions_get_disable_WAL( |
4489 | rocksdb_writeoptions_t* opt) { | |
4490 | return opt->rep.disableWAL; | |
4491 | } | |
4492 | ||
11fdf7f2 | 4493 | void rocksdb_writeoptions_set_ignore_missing_column_families( |
1e59de90 | 4494 | rocksdb_writeoptions_t* opt, unsigned char v) { |
11fdf7f2 TL |
4495 | opt->rep.ignore_missing_column_families = v; |
4496 | } | |
4497 | ||
20effc67 TL |
4498 | unsigned char rocksdb_writeoptions_get_ignore_missing_column_families( |
4499 | rocksdb_writeoptions_t* opt) { | |
4500 | return opt->rep.ignore_missing_column_families; | |
4501 | } | |
4502 | ||
1e59de90 TL |
4503 | void rocksdb_writeoptions_set_no_slowdown(rocksdb_writeoptions_t* opt, |
4504 | unsigned char v) { | |
11fdf7f2 TL |
4505 | opt->rep.no_slowdown = v; |
4506 | } | |
4507 | ||
20effc67 TL |
4508 | unsigned char rocksdb_writeoptions_get_no_slowdown( |
4509 | rocksdb_writeoptions_t* opt) { | |
4510 | return opt->rep.no_slowdown; | |
4511 | } | |
4512 | ||
1e59de90 TL |
4513 | void rocksdb_writeoptions_set_low_pri(rocksdb_writeoptions_t* opt, |
4514 | unsigned char v) { | |
11fdf7f2 TL |
4515 | opt->rep.low_pri = v; |
4516 | } | |
4517 | ||
20effc67 TL |
4518 | unsigned char rocksdb_writeoptions_get_low_pri(rocksdb_writeoptions_t* opt) { |
4519 | return opt->rep.low_pri; | |
4520 | } | |
4521 | ||
f67539c2 TL |
4522 | void rocksdb_writeoptions_set_memtable_insert_hint_per_batch( |
4523 | rocksdb_writeoptions_t* opt, unsigned char v) { | |
4524 | opt->rep.memtable_insert_hint_per_batch = v; | |
4525 | } | |
4526 | ||
20effc67 TL |
4527 | unsigned char rocksdb_writeoptions_get_memtable_insert_hint_per_batch( |
4528 | rocksdb_writeoptions_t* opt) { | |
4529 | return opt->rep.memtable_insert_hint_per_batch; | |
4530 | } | |
4531 | ||
7c673cae FG |
4532 | rocksdb_compactoptions_t* rocksdb_compactoptions_create() { |
4533 | return new rocksdb_compactoptions_t; | |
4534 | } | |
4535 | ||
4536 | void rocksdb_compactoptions_destroy(rocksdb_compactoptions_t* opt) { | |
4537 | delete opt; | |
4538 | } | |
4539 | ||
11fdf7f2 TL |
4540 | void rocksdb_compactoptions_set_bottommost_level_compaction( |
4541 | rocksdb_compactoptions_t* opt, unsigned char v) { | |
1e59de90 TL |
4542 | opt->rep.bottommost_level_compaction = |
4543 | static_cast<BottommostLevelCompaction>(v); | |
11fdf7f2 TL |
4544 | } |
4545 | ||
20effc67 TL |
4546 | unsigned char rocksdb_compactoptions_get_bottommost_level_compaction( |
4547 | rocksdb_compactoptions_t* opt) { | |
4548 | return static_cast<unsigned char>(opt->rep.bottommost_level_compaction); | |
4549 | } | |
4550 | ||
7c673cae FG |
4551 | void rocksdb_compactoptions_set_exclusive_manual_compaction( |
4552 | rocksdb_compactoptions_t* opt, unsigned char v) { | |
4553 | opt->rep.exclusive_manual_compaction = v; | |
4554 | } | |
4555 | ||
20effc67 TL |
4556 | unsigned char rocksdb_compactoptions_get_exclusive_manual_compaction( |
4557 | rocksdb_compactoptions_t* opt) { | |
4558 | return opt->rep.exclusive_manual_compaction; | |
4559 | } | |
4560 | ||
7c673cae FG |
4561 | void rocksdb_compactoptions_set_change_level(rocksdb_compactoptions_t* opt, |
4562 | unsigned char v) { | |
4563 | opt->rep.change_level = v; | |
4564 | } | |
4565 | ||
20effc67 TL |
4566 | unsigned char rocksdb_compactoptions_get_change_level( |
4567 | rocksdb_compactoptions_t* opt) { | |
4568 | return opt->rep.change_level; | |
4569 | } | |
4570 | ||
7c673cae FG |
4571 | void rocksdb_compactoptions_set_target_level(rocksdb_compactoptions_t* opt, |
4572 | int n) { | |
4573 | opt->rep.target_level = n; | |
4574 | } | |
4575 | ||
20effc67 TL |
4576 | int rocksdb_compactoptions_get_target_level(rocksdb_compactoptions_t* opt) { |
4577 | return opt->rep.target_level; | |
4578 | } | |
4579 | ||
1e59de90 TL |
4580 | void rocksdb_compactoptions_set_full_history_ts_low( |
4581 | rocksdb_compactoptions_t* opt, char* ts, size_t tslen) { | |
4582 | if (ts == nullptr) { | |
4583 | opt->full_history_ts_low = Slice(); | |
4584 | opt->rep.full_history_ts_low = nullptr; | |
4585 | } else { | |
4586 | opt->full_history_ts_low = Slice(ts, tslen); | |
4587 | opt->rep.full_history_ts_low = &opt->full_history_ts_low; | |
4588 | } | |
4589 | } | |
4590 | ||
7c673cae FG |
4591 | rocksdb_flushoptions_t* rocksdb_flushoptions_create() { |
4592 | return new rocksdb_flushoptions_t; | |
4593 | } | |
4594 | ||
1e59de90 | 4595 | void rocksdb_flushoptions_destroy(rocksdb_flushoptions_t* opt) { delete opt; } |
7c673cae | 4596 | |
1e59de90 TL |
4597 | void rocksdb_flushoptions_set_wait(rocksdb_flushoptions_t* opt, |
4598 | unsigned char v) { | |
7c673cae FG |
4599 | opt->rep.wait = v; |
4600 | } | |
4601 | ||
20effc67 TL |
4602 | unsigned char rocksdb_flushoptions_get_wait(rocksdb_flushoptions_t* opt) { |
4603 | return opt->rep.wait; | |
4604 | } | |
4605 | ||
1e59de90 TL |
4606 | rocksdb_memory_allocator_t* rocksdb_jemalloc_nodump_allocator_create( |
4607 | char** errptr) { | |
4608 | rocksdb_memory_allocator_t* allocator = new rocksdb_memory_allocator_t; | |
4609 | ROCKSDB_NAMESPACE::JemallocAllocatorOptions options; | |
4610 | SaveError(errptr, ROCKSDB_NAMESPACE::NewJemallocNodumpAllocator( | |
4611 | options, &allocator->rep)); | |
4612 | return allocator; | |
4613 | } | |
4614 | ||
4615 | void rocksdb_memory_allocator_destroy(rocksdb_memory_allocator_t* allocator) { | |
4616 | delete allocator; | |
4617 | } | |
4618 | ||
4619 | rocksdb_lru_cache_options_t* rocksdb_lru_cache_options_create() { | |
4620 | return new rocksdb_lru_cache_options_t; | |
4621 | } | |
4622 | ||
4623 | void rocksdb_lru_cache_options_destroy(rocksdb_lru_cache_options_t* opt) { | |
4624 | delete opt; | |
4625 | } | |
4626 | ||
4627 | void rocksdb_lru_cache_options_set_capacity(rocksdb_lru_cache_options_t* opt, | |
4628 | size_t capacity) { | |
4629 | opt->rep.capacity = capacity; | |
4630 | } | |
4631 | ||
4632 | void rocksdb_lru_cache_options_set_num_shard_bits( | |
4633 | rocksdb_lru_cache_options_t* opt, int num_shard_bits) { | |
4634 | opt->rep.num_shard_bits = num_shard_bits; | |
4635 | } | |
4636 | ||
4637 | void rocksdb_lru_cache_options_set_memory_allocator( | |
4638 | rocksdb_lru_cache_options_t* opt, rocksdb_memory_allocator_t* allocator) { | |
4639 | opt->rep.memory_allocator = allocator->rep; | |
4640 | } | |
4641 | ||
7c673cae FG |
4642 | rocksdb_cache_t* rocksdb_cache_create_lru(size_t capacity) { |
4643 | rocksdb_cache_t* c = new rocksdb_cache_t; | |
4644 | c->rep = NewLRUCache(capacity); | |
4645 | return c; | |
4646 | } | |
4647 | ||
1e59de90 TL |
4648 | rocksdb_cache_t* rocksdb_cache_create_lru_with_strict_capacity_limit( |
4649 | size_t capacity) { | |
4650 | rocksdb_cache_t* c = new rocksdb_cache_t; | |
4651 | c->rep = NewLRUCache(capacity); | |
4652 | c->rep->SetStrictCapacityLimit(true); | |
4653 | return c; | |
4654 | } | |
4655 | ||
4656 | rocksdb_cache_t* rocksdb_cache_create_lru_opts( | |
4657 | rocksdb_lru_cache_options_t* opt) { | |
4658 | rocksdb_cache_t* c = new rocksdb_cache_t; | |
4659 | c->rep = NewLRUCache(opt->rep); | |
4660 | return c; | |
4661 | } | |
4662 | ||
4663 | void rocksdb_cache_destroy(rocksdb_cache_t* cache) { delete cache; } | |
4664 | ||
4665 | void rocksdb_cache_disown_data(rocksdb_cache_t* cache) { | |
4666 | cache->rep->DisownData(); | |
7c673cae FG |
4667 | } |
4668 | ||
4669 | void rocksdb_cache_set_capacity(rocksdb_cache_t* cache, size_t capacity) { | |
4670 | cache->rep->SetCapacity(capacity); | |
4671 | } | |
4672 | ||
20effc67 TL |
4673 | size_t rocksdb_cache_get_capacity(rocksdb_cache_t* cache) { |
4674 | return cache->rep->GetCapacity(); | |
4675 | } | |
4676 | ||
7c673cae FG |
4677 | size_t rocksdb_cache_get_usage(rocksdb_cache_t* cache) { |
4678 | return cache->rep->GetUsage(); | |
4679 | } | |
4680 | ||
4681 | size_t rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache) { | |
4682 | return cache->rep->GetPinnedUsage(); | |
4683 | } | |
4684 | ||
1e59de90 TL |
4685 | rocksdb_dbpath_t* rocksdb_dbpath_create(const char* path, |
4686 | uint64_t target_size) { | |
11fdf7f2 TL |
4687 | rocksdb_dbpath_t* result = new rocksdb_dbpath_t; |
4688 | result->rep.path = std::string(path); | |
4689 | result->rep.target_size = target_size; | |
4690 | return result; | |
4691 | } | |
4692 | ||
1e59de90 | 4693 | void rocksdb_dbpath_destroy(rocksdb_dbpath_t* dbpath) { delete dbpath; } |
11fdf7f2 | 4694 | |
7c673cae FG |
4695 | rocksdb_env_t* rocksdb_create_default_env() { |
4696 | rocksdb_env_t* result = new rocksdb_env_t; | |
4697 | result->rep = Env::Default(); | |
4698 | result->is_default = true; | |
4699 | return result; | |
4700 | } | |
4701 | ||
4702 | rocksdb_env_t* rocksdb_create_mem_env() { | |
4703 | rocksdb_env_t* result = new rocksdb_env_t; | |
f67539c2 | 4704 | result->rep = ROCKSDB_NAMESPACE::NewMemEnv(Env::Default()); |
7c673cae FG |
4705 | result->is_default = false; |
4706 | return result; | |
4707 | } | |
4708 | ||
4709 | void rocksdb_env_set_background_threads(rocksdb_env_t* env, int n) { | |
4710 | env->rep->SetBackgroundThreads(n); | |
4711 | } | |
4712 | ||
20effc67 TL |
4713 | int rocksdb_env_get_background_threads(rocksdb_env_t* env) { |
4714 | return env->rep->GetBackgroundThreads(); | |
4715 | } | |
4716 | ||
4717 | void rocksdb_env_set_bottom_priority_background_threads(rocksdb_env_t* env, | |
4718 | int n) { | |
4719 | env->rep->SetBackgroundThreads(n, Env::BOTTOM); | |
4720 | } | |
4721 | ||
4722 | int rocksdb_env_get_bottom_priority_background_threads(rocksdb_env_t* env) { | |
4723 | return env->rep->GetBackgroundThreads(Env::BOTTOM); | |
4724 | } | |
4725 | ||
1e59de90 TL |
4726 | void rocksdb_env_set_high_priority_background_threads(rocksdb_env_t* env, |
4727 | int n) { | |
7c673cae FG |
4728 | env->rep->SetBackgroundThreads(n, Env::HIGH); |
4729 | } | |
4730 | ||
20effc67 TL |
4731 | int rocksdb_env_get_high_priority_background_threads(rocksdb_env_t* env) { |
4732 | return env->rep->GetBackgroundThreads(Env::HIGH); | |
4733 | } | |
4734 | ||
4735 | void rocksdb_env_set_low_priority_background_threads(rocksdb_env_t* env, | |
4736 | int n) { | |
4737 | env->rep->SetBackgroundThreads(n, Env::LOW); | |
4738 | } | |
4739 | ||
4740 | int rocksdb_env_get_low_priority_background_threads(rocksdb_env_t* env) { | |
4741 | return env->rep->GetBackgroundThreads(Env::LOW); | |
4742 | } | |
4743 | ||
7c673cae FG |
4744 | void rocksdb_env_join_all_threads(rocksdb_env_t* env) { |
4745 | env->rep->WaitForJoin(); | |
4746 | } | |
4747 | ||
f67539c2 TL |
4748 | void rocksdb_env_lower_thread_pool_io_priority(rocksdb_env_t* env) { |
4749 | env->rep->LowerThreadPoolIOPriority(); | |
4750 | } | |
4751 | ||
1e59de90 TL |
4752 | void rocksdb_env_lower_high_priority_thread_pool_io_priority( |
4753 | rocksdb_env_t* env) { | |
f67539c2 TL |
4754 | env->rep->LowerThreadPoolIOPriority(Env::HIGH); |
4755 | } | |
4756 | ||
4757 | void rocksdb_env_lower_thread_pool_cpu_priority(rocksdb_env_t* env) { | |
4758 | env->rep->LowerThreadPoolCPUPriority(); | |
4759 | } | |
4760 | ||
1e59de90 TL |
4761 | void rocksdb_env_lower_high_priority_thread_pool_cpu_priority( |
4762 | rocksdb_env_t* env) { | |
f67539c2 TL |
4763 | env->rep->LowerThreadPoolCPUPriority(Env::HIGH); |
4764 | } | |
4765 | ||
7c673cae FG |
4766 | void rocksdb_env_destroy(rocksdb_env_t* env) { |
4767 | if (!env->is_default) delete env->rep; | |
4768 | delete env; | |
4769 | } | |
4770 | ||
4771 | rocksdb_envoptions_t* rocksdb_envoptions_create() { | |
4772 | rocksdb_envoptions_t* opt = new rocksdb_envoptions_t; | |
4773 | return opt; | |
4774 | } | |
4775 | ||
4776 | void rocksdb_envoptions_destroy(rocksdb_envoptions_t* opt) { delete opt; } | |
4777 | ||
4778 | rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create( | |
4779 | const rocksdb_envoptions_t* env, const rocksdb_options_t* io_options) { | |
4780 | rocksdb_sstfilewriter_t* writer = new rocksdb_sstfilewriter_t; | |
4781 | writer->rep = new SstFileWriter(env->rep, io_options->rep); | |
4782 | return writer; | |
4783 | } | |
4784 | ||
1e59de90 TL |
4785 | void rocksdb_create_dir_if_missing(rocksdb_env_t* env, const char* path, |
4786 | char** errptr) { | |
4787 | SaveError(errptr, env->rep->CreateDirIfMissing(std::string(path))); | |
4788 | } | |
4789 | ||
7c673cae FG |
4790 | rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create_with_comparator( |
4791 | const rocksdb_envoptions_t* env, const rocksdb_options_t* io_options, | |
11fdf7f2 | 4792 | const rocksdb_comparator_t* /*comparator*/) { |
7c673cae FG |
4793 | rocksdb_sstfilewriter_t* writer = new rocksdb_sstfilewriter_t; |
4794 | writer->rep = new SstFileWriter(env->rep, io_options->rep); | |
4795 | return writer; | |
4796 | } | |
4797 | ||
4798 | void rocksdb_sstfilewriter_open(rocksdb_sstfilewriter_t* writer, | |
4799 | const char* name, char** errptr) { | |
4800 | SaveError(errptr, writer->rep->Open(std::string(name))); | |
4801 | } | |
4802 | ||
4803 | void rocksdb_sstfilewriter_add(rocksdb_sstfilewriter_t* writer, const char* key, | |
4804 | size_t keylen, const char* val, size_t vallen, | |
4805 | char** errptr) { | |
11fdf7f2 TL |
4806 | SaveError(errptr, writer->rep->Put(Slice(key, keylen), Slice(val, vallen))); |
4807 | } | |
4808 | ||
4809 | void rocksdb_sstfilewriter_put(rocksdb_sstfilewriter_t* writer, const char* key, | |
4810 | size_t keylen, const char* val, size_t vallen, | |
4811 | char** errptr) { | |
4812 | SaveError(errptr, writer->rep->Put(Slice(key, keylen), Slice(val, vallen))); | |
4813 | } | |
4814 | ||
1e59de90 TL |
4815 | void rocksdb_sstfilewriter_put_with_ts(rocksdb_sstfilewriter_t* writer, |
4816 | const char* key, size_t keylen, | |
4817 | const char* ts, size_t tslen, | |
4818 | const char* val, size_t vallen, | |
4819 | char** errptr) { | |
4820 | SaveError(errptr, writer->rep->Put(Slice(key, keylen), Slice(ts, tslen), | |
4821 | Slice(val, vallen))); | |
4822 | } | |
4823 | ||
11fdf7f2 TL |
4824 | void rocksdb_sstfilewriter_merge(rocksdb_sstfilewriter_t* writer, |
4825 | const char* key, size_t keylen, | |
4826 | const char* val, size_t vallen, | |
4827 | char** errptr) { | |
4828 | SaveError(errptr, writer->rep->Merge(Slice(key, keylen), Slice(val, vallen))); | |
4829 | } | |
4830 | ||
4831 | void rocksdb_sstfilewriter_delete(rocksdb_sstfilewriter_t* writer, | |
4832 | const char* key, size_t keylen, | |
4833 | char** errptr) { | |
4834 | SaveError(errptr, writer->rep->Delete(Slice(key, keylen))); | |
7c673cae FG |
4835 | } |
4836 | ||
1e59de90 TL |
4837 | void rocksdb_sstfilewriter_delete_with_ts(rocksdb_sstfilewriter_t* writer, |
4838 | const char* key, size_t keylen, | |
4839 | const char* ts, size_t tslen, | |
4840 | char** errptr) { | |
4841 | SaveError(errptr, writer->rep->Delete(Slice(key, keylen), Slice(ts, tslen))); | |
4842 | } | |
4843 | ||
4844 | void rocksdb_sstfilewriter_delete_range(rocksdb_sstfilewriter_t* writer, | |
4845 | const char* begin_key, | |
4846 | size_t begin_keylen, | |
4847 | const char* end_key, size_t end_keylen, | |
4848 | char** errptr) { | |
4849 | SaveError(errptr, writer->rep->DeleteRange(Slice(begin_key, begin_keylen), | |
4850 | Slice(end_key, end_keylen))); | |
4851 | } | |
4852 | ||
7c673cae FG |
4853 | void rocksdb_sstfilewriter_finish(rocksdb_sstfilewriter_t* writer, |
4854 | char** errptr) { | |
11fdf7f2 TL |
4855 | SaveError(errptr, writer->rep->Finish(nullptr)); |
4856 | } | |
4857 | ||
4858 | void rocksdb_sstfilewriter_file_size(rocksdb_sstfilewriter_t* writer, | |
1e59de90 | 4859 | uint64_t* file_size) { |
11fdf7f2 | 4860 | *file_size = writer->rep->FileSize(); |
7c673cae FG |
4861 | } |
4862 | ||
4863 | void rocksdb_sstfilewriter_destroy(rocksdb_sstfilewriter_t* writer) { | |
4864 | delete writer->rep; | |
4865 | delete writer; | |
4866 | } | |
4867 | ||
4868 | rocksdb_ingestexternalfileoptions_t* | |
4869 | rocksdb_ingestexternalfileoptions_create() { | |
4870 | rocksdb_ingestexternalfileoptions_t* opt = | |
4871 | new rocksdb_ingestexternalfileoptions_t; | |
4872 | return opt; | |
4873 | } | |
4874 | ||
4875 | void rocksdb_ingestexternalfileoptions_set_move_files( | |
4876 | rocksdb_ingestexternalfileoptions_t* opt, unsigned char move_files) { | |
4877 | opt->rep.move_files = move_files; | |
4878 | } | |
4879 | ||
4880 | void rocksdb_ingestexternalfileoptions_set_snapshot_consistency( | |
4881 | rocksdb_ingestexternalfileoptions_t* opt, | |
4882 | unsigned char snapshot_consistency) { | |
4883 | opt->rep.snapshot_consistency = snapshot_consistency; | |
4884 | } | |
4885 | ||
4886 | void rocksdb_ingestexternalfileoptions_set_allow_global_seqno( | |
4887 | rocksdb_ingestexternalfileoptions_t* opt, | |
4888 | unsigned char allow_global_seqno) { | |
4889 | opt->rep.allow_global_seqno = allow_global_seqno; | |
4890 | } | |
4891 | ||
4892 | void rocksdb_ingestexternalfileoptions_set_allow_blocking_flush( | |
4893 | rocksdb_ingestexternalfileoptions_t* opt, | |
4894 | unsigned char allow_blocking_flush) { | |
4895 | opt->rep.allow_blocking_flush = allow_blocking_flush; | |
4896 | } | |
4897 | ||
11fdf7f2 | 4898 | void rocksdb_ingestexternalfileoptions_set_ingest_behind( |
1e59de90 | 4899 | rocksdb_ingestexternalfileoptions_t* opt, unsigned char ingest_behind) { |
11fdf7f2 TL |
4900 | opt->rep.ingest_behind = ingest_behind; |
4901 | } | |
4902 | ||
7c673cae FG |
4903 | void rocksdb_ingestexternalfileoptions_destroy( |
4904 | rocksdb_ingestexternalfileoptions_t* opt) { | |
4905 | delete opt; | |
4906 | } | |
4907 | ||
4908 | void rocksdb_ingest_external_file( | |
4909 | rocksdb_t* db, const char* const* file_list, const size_t list_len, | |
4910 | const rocksdb_ingestexternalfileoptions_t* opt, char** errptr) { | |
4911 | std::vector<std::string> files(list_len); | |
4912 | for (size_t i = 0; i < list_len; ++i) { | |
4913 | files[i] = std::string(file_list[i]); | |
4914 | } | |
4915 | SaveError(errptr, db->rep->IngestExternalFile(files, opt->rep)); | |
4916 | } | |
4917 | ||
4918 | void rocksdb_ingest_external_file_cf( | |
4919 | rocksdb_t* db, rocksdb_column_family_handle_t* handle, | |
4920 | const char* const* file_list, const size_t list_len, | |
4921 | const rocksdb_ingestexternalfileoptions_t* opt, char** errptr) { | |
4922 | std::vector<std::string> files(list_len); | |
4923 | for (size_t i = 0; i < list_len; ++i) { | |
4924 | files[i] = std::string(file_list[i]); | |
4925 | } | |
4926 | SaveError(errptr, db->rep->IngestExternalFile(handle->rep, files, opt->rep)); | |
4927 | } | |
4928 | ||
f67539c2 TL |
4929 | void rocksdb_try_catch_up_with_primary(rocksdb_t* db, char** errptr) { |
4930 | SaveError(errptr, db->rep->TryCatchUpWithPrimary()); | |
4931 | } | |
4932 | ||
7c673cae | 4933 | rocksdb_slicetransform_t* rocksdb_slicetransform_create( |
1e59de90 TL |
4934 | void* state, void (*destructor)(void*), |
4935 | char* (*transform)(void*, const char* key, size_t length, | |
4936 | size_t* dst_length), | |
4937 | unsigned char (*in_domain)(void*, const char* key, size_t length), | |
4938 | unsigned char (*in_range)(void*, const char* key, size_t length), | |
7c673cae FG |
4939 | const char* (*name)(void*)) { |
4940 | rocksdb_slicetransform_t* result = new rocksdb_slicetransform_t; | |
4941 | result->state_ = state; | |
4942 | result->destructor_ = destructor; | |
4943 | result->transform_ = transform; | |
4944 | result->in_domain_ = in_domain; | |
4945 | result->in_range_ = in_range; | |
4946 | result->name_ = name; | |
4947 | return result; | |
4948 | } | |
4949 | ||
1e59de90 | 4950 | void rocksdb_slicetransform_destroy(rocksdb_slicetransform_t* st) { delete st; } |
7c673cae | 4951 | |
1e59de90 | 4952 | struct SliceTransformWrapper : public rocksdb_slicetransform_t { |
11fdf7f2 | 4953 | const SliceTransform* rep_; |
1e59de90 | 4954 | ~SliceTransformWrapper() override { delete rep_; } |
11fdf7f2 | 4955 | const char* Name() const override { return rep_->Name(); } |
1e59de90 | 4956 | std::string GetId() const override { return rep_->GetId(); } |
11fdf7f2 TL |
4957 | Slice Transform(const Slice& src) const override { |
4958 | return rep_->Transform(src); | |
4959 | } | |
1e59de90 | 4960 | bool InDomain(const Slice& src) const override { return rep_->InDomain(src); } |
11fdf7f2 | 4961 | bool InRange(const Slice& src) const override { return rep_->InRange(src); } |
1e59de90 | 4962 | static void DoNothing(void*) {} |
11fdf7f2 TL |
4963 | }; |
4964 | ||
1e59de90 TL |
4965 | rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix( |
4966 | size_t prefixLen) { | |
4967 | SliceTransformWrapper* wrapper = new SliceTransformWrapper; | |
f67539c2 | 4968 | wrapper->rep_ = ROCKSDB_NAMESPACE::NewFixedPrefixTransform(prefixLen); |
7c673cae | 4969 | wrapper->state_ = nullptr; |
1e59de90 | 4970 | wrapper->destructor_ = &SliceTransformWrapper::DoNothing; |
7c673cae FG |
4971 | return wrapper; |
4972 | } | |
4973 | ||
4974 | rocksdb_slicetransform_t* rocksdb_slicetransform_create_noop() { | |
1e59de90 | 4975 | SliceTransformWrapper* wrapper = new SliceTransformWrapper; |
f67539c2 | 4976 | wrapper->rep_ = ROCKSDB_NAMESPACE::NewNoopTransform(); |
7c673cae | 4977 | wrapper->state_ = nullptr; |
1e59de90 | 4978 | wrapper->destructor_ = &SliceTransformWrapper::DoNothing; |
7c673cae FG |
4979 | return wrapper; |
4980 | } | |
4981 | ||
1e59de90 TL |
4982 | rocksdb_universal_compaction_options_t* |
4983 | rocksdb_universal_compaction_options_create() { | |
4984 | rocksdb_universal_compaction_options_t* result = | |
4985 | new rocksdb_universal_compaction_options_t; | |
f67539c2 | 4986 | result->rep = new ROCKSDB_NAMESPACE::CompactionOptionsUniversal; |
7c673cae FG |
4987 | return result; |
4988 | } | |
4989 | ||
4990 | void rocksdb_universal_compaction_options_set_size_ratio( | |
1e59de90 | 4991 | rocksdb_universal_compaction_options_t* uco, int ratio) { |
7c673cae FG |
4992 | uco->rep->size_ratio = ratio; |
4993 | } | |
4994 | ||
20effc67 TL |
4995 | int rocksdb_universal_compaction_options_get_size_ratio( |
4996 | rocksdb_universal_compaction_options_t* uco) { | |
4997 | return uco->rep->size_ratio; | |
4998 | } | |
4999 | ||
7c673cae | 5000 | void rocksdb_universal_compaction_options_set_min_merge_width( |
1e59de90 | 5001 | rocksdb_universal_compaction_options_t* uco, int w) { |
7c673cae FG |
5002 | uco->rep->min_merge_width = w; |
5003 | } | |
5004 | ||
20effc67 TL |
5005 | int rocksdb_universal_compaction_options_get_min_merge_width( |
5006 | rocksdb_universal_compaction_options_t* uco) { | |
5007 | return uco->rep->min_merge_width; | |
5008 | } | |
5009 | ||
7c673cae | 5010 | void rocksdb_universal_compaction_options_set_max_merge_width( |
1e59de90 | 5011 | rocksdb_universal_compaction_options_t* uco, int w) { |
7c673cae FG |
5012 | uco->rep->max_merge_width = w; |
5013 | } | |
5014 | ||
20effc67 TL |
5015 | int rocksdb_universal_compaction_options_get_max_merge_width( |
5016 | rocksdb_universal_compaction_options_t* uco) { | |
5017 | return uco->rep->max_merge_width; | |
5018 | } | |
5019 | ||
7c673cae | 5020 | void rocksdb_universal_compaction_options_set_max_size_amplification_percent( |
1e59de90 | 5021 | rocksdb_universal_compaction_options_t* uco, int p) { |
7c673cae FG |
5022 | uco->rep->max_size_amplification_percent = p; |
5023 | } | |
5024 | ||
20effc67 TL |
5025 | int rocksdb_universal_compaction_options_get_max_size_amplification_percent( |
5026 | rocksdb_universal_compaction_options_t* uco) { | |
5027 | return uco->rep->max_size_amplification_percent; | |
5028 | } | |
5029 | ||
7c673cae | 5030 | void rocksdb_universal_compaction_options_set_compression_size_percent( |
1e59de90 | 5031 | rocksdb_universal_compaction_options_t* uco, int p) { |
7c673cae FG |
5032 | uco->rep->compression_size_percent = p; |
5033 | } | |
5034 | ||
20effc67 TL |
5035 | int rocksdb_universal_compaction_options_get_compression_size_percent( |
5036 | rocksdb_universal_compaction_options_t* uco) { | |
5037 | return uco->rep->compression_size_percent; | |
5038 | } | |
5039 | ||
7c673cae | 5040 | void rocksdb_universal_compaction_options_set_stop_style( |
1e59de90 | 5041 | rocksdb_universal_compaction_options_t* uco, int style) { |
f67539c2 TL |
5042 | uco->rep->stop_style = |
5043 | static_cast<ROCKSDB_NAMESPACE::CompactionStopStyle>(style); | |
7c673cae FG |
5044 | } |
5045 | ||
20effc67 TL |
5046 | int rocksdb_universal_compaction_options_get_stop_style( |
5047 | rocksdb_universal_compaction_options_t* uco) { | |
5048 | return static_cast<int>(uco->rep->stop_style); | |
5049 | } | |
5050 | ||
7c673cae | 5051 | void rocksdb_universal_compaction_options_destroy( |
1e59de90 | 5052 | rocksdb_universal_compaction_options_t* uco) { |
7c673cae FG |
5053 | delete uco->rep; |
5054 | delete uco; | |
5055 | } | |
5056 | ||
5057 | rocksdb_fifo_compaction_options_t* rocksdb_fifo_compaction_options_create() { | |
1e59de90 TL |
5058 | rocksdb_fifo_compaction_options_t* result = |
5059 | new rocksdb_fifo_compaction_options_t; | |
5060 | result->rep = CompactionOptionsFIFO(); | |
7c673cae FG |
5061 | return result; |
5062 | } | |
5063 | ||
5064 | void rocksdb_fifo_compaction_options_set_max_table_files_size( | |
5065 | rocksdb_fifo_compaction_options_t* fifo_opts, uint64_t size) { | |
5066 | fifo_opts->rep.max_table_files_size = size; | |
5067 | } | |
5068 | ||
20effc67 TL |
5069 | uint64_t rocksdb_fifo_compaction_options_get_max_table_files_size( |
5070 | rocksdb_fifo_compaction_options_t* fifo_opts) { | |
5071 | return fifo_opts->rep.max_table_files_size; | |
5072 | } | |
5073 | ||
7c673cae FG |
5074 | void rocksdb_fifo_compaction_options_destroy( |
5075 | rocksdb_fifo_compaction_options_t* fifo_opts) { | |
5076 | delete fifo_opts; | |
5077 | } | |
5078 | ||
1e59de90 TL |
5079 | void rocksdb_options_set_min_level_to_compress(rocksdb_options_t* opt, |
5080 | int level) { | |
7c673cae FG |
5081 | if (level >= 0) { |
5082 | assert(level <= opt->rep.num_levels); | |
5083 | opt->rep.compression_per_level.resize(opt->rep.num_levels); | |
5084 | for (int i = 0; i < level; i++) { | |
f67539c2 | 5085 | opt->rep.compression_per_level[i] = ROCKSDB_NAMESPACE::kNoCompression; |
7c673cae FG |
5086 | } |
5087 | for (int i = level; i < opt->rep.num_levels; i++) { | |
5088 | opt->rep.compression_per_level[i] = opt->rep.compression; | |
5089 | } | |
5090 | } | |
5091 | } | |
5092 | ||
1e59de90 | 5093 | int rocksdb_livefiles_count(const rocksdb_livefiles_t* lf) { |
7c673cae FG |
5094 | return static_cast<int>(lf->rep.size()); |
5095 | } | |
5096 | ||
1e59de90 TL |
5097 | const char* rocksdb_livefiles_column_family_name(const rocksdb_livefiles_t* lf, |
5098 | int index) { | |
5099 | return lf->rep[index].column_family_name.c_str(); | |
5100 | } | |
5101 | ||
5102 | const char* rocksdb_livefiles_name(const rocksdb_livefiles_t* lf, int index) { | |
7c673cae FG |
5103 | return lf->rep[index].name.c_str(); |
5104 | } | |
5105 | ||
1e59de90 | 5106 | int rocksdb_livefiles_level(const rocksdb_livefiles_t* lf, int index) { |
7c673cae FG |
5107 | return lf->rep[index].level; |
5108 | } | |
5109 | ||
1e59de90 | 5110 | size_t rocksdb_livefiles_size(const rocksdb_livefiles_t* lf, int index) { |
7c673cae FG |
5111 | return lf->rep[index].size; |
5112 | } | |
5113 | ||
1e59de90 TL |
5114 | const char* rocksdb_livefiles_smallestkey(const rocksdb_livefiles_t* lf, |
5115 | int index, size_t* size) { | |
7c673cae FG |
5116 | *size = lf->rep[index].smallestkey.size(); |
5117 | return lf->rep[index].smallestkey.data(); | |
5118 | } | |
5119 | ||
1e59de90 TL |
5120 | const char* rocksdb_livefiles_largestkey(const rocksdb_livefiles_t* lf, |
5121 | int index, size_t* size) { | |
7c673cae FG |
5122 | *size = lf->rep[index].largestkey.size(); |
5123 | return lf->rep[index].largestkey.data(); | |
5124 | } | |
5125 | ||
1e59de90 | 5126 | uint64_t rocksdb_livefiles_entries(const rocksdb_livefiles_t* lf, int index) { |
494da23a TL |
5127 | return lf->rep[index].num_entries; |
5128 | } | |
5129 | ||
1e59de90 | 5130 | uint64_t rocksdb_livefiles_deletions(const rocksdb_livefiles_t* lf, int index) { |
494da23a TL |
5131 | return lf->rep[index].num_deletions; |
5132 | } | |
5133 | ||
1e59de90 | 5134 | extern void rocksdb_livefiles_destroy(const rocksdb_livefiles_t* lf) { |
7c673cae FG |
5135 | delete lf; |
5136 | } | |
5137 | ||
5138 | void rocksdb_get_options_from_string(const rocksdb_options_t* base_options, | |
5139 | const char* opts_str, | |
5140 | rocksdb_options_t* new_options, | |
5141 | char** errptr) { | |
5142 | SaveError(errptr, | |
5143 | GetOptionsFromString(base_options->rep, std::string(opts_str), | |
5144 | &new_options->rep)); | |
5145 | } | |
5146 | ||
5147 | void rocksdb_delete_file_in_range(rocksdb_t* db, const char* start_key, | |
5148 | size_t start_key_len, const char* limit_key, | |
5149 | size_t limit_key_len, char** errptr) { | |
5150 | Slice a, b; | |
5151 | SaveError( | |
5152 | errptr, | |
5153 | DeleteFilesInRange( | |
5154 | db->rep, db->rep->DefaultColumnFamily(), | |
5155 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
5156 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr))); | |
5157 | } | |
5158 | ||
5159 | void rocksdb_delete_file_in_range_cf( | |
5160 | rocksdb_t* db, rocksdb_column_family_handle_t* column_family, | |
5161 | const char* start_key, size_t start_key_len, const char* limit_key, | |
5162 | size_t limit_key_len, char** errptr) { | |
5163 | Slice a, b; | |
5164 | SaveError( | |
5165 | errptr, | |
5166 | DeleteFilesInRange( | |
5167 | db->rep, column_family->rep, | |
5168 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
5169 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr))); | |
5170 | } | |
5171 | ||
1e59de90 TL |
5172 | /* MetaData */ |
5173 | ||
5174 | rocksdb_column_family_metadata_t* rocksdb_get_column_family_metadata( | |
5175 | rocksdb_t* db) { | |
5176 | rocksdb_column_family_metadata_t* meta = new rocksdb_column_family_metadata_t; | |
5177 | db->rep->GetColumnFamilyMetaData(&meta->rep); | |
5178 | return meta; | |
5179 | } | |
5180 | ||
5181 | rocksdb_column_family_metadata_t* rocksdb_get_column_family_metadata_cf( | |
5182 | rocksdb_t* db, rocksdb_column_family_handle_t* column_family) { | |
5183 | rocksdb_column_family_metadata_t* meta = new rocksdb_column_family_metadata_t; | |
5184 | db->rep->GetColumnFamilyMetaData(column_family->rep, &meta->rep); | |
5185 | return meta; | |
5186 | } | |
5187 | ||
5188 | void rocksdb_column_family_metadata_destroy( | |
5189 | rocksdb_column_family_metadata_t* cf_meta) { | |
5190 | delete cf_meta; | |
5191 | } | |
5192 | ||
5193 | uint64_t rocksdb_column_family_metadata_get_size( | |
5194 | rocksdb_column_family_metadata_t* cf_meta) { | |
5195 | return cf_meta->rep.size; | |
5196 | } | |
5197 | ||
5198 | size_t rocksdb_column_family_metadata_get_file_count( | |
5199 | rocksdb_column_family_metadata_t* cf_meta) { | |
5200 | return cf_meta->rep.file_count; | |
5201 | } | |
5202 | ||
5203 | char* rocksdb_column_family_metadata_get_name( | |
5204 | rocksdb_column_family_metadata_t* cf_meta) { | |
5205 | return strdup(cf_meta->rep.name.c_str()); | |
5206 | } | |
5207 | ||
5208 | size_t rocksdb_column_family_metadata_get_level_count( | |
5209 | rocksdb_column_family_metadata_t* cf_meta) { | |
5210 | return cf_meta->rep.levels.size(); | |
5211 | } | |
5212 | ||
5213 | rocksdb_level_metadata_t* rocksdb_column_family_metadata_get_level_metadata( | |
5214 | rocksdb_column_family_metadata_t* cf_meta, size_t i) { | |
5215 | if (i >= cf_meta->rep.levels.size()) { | |
5216 | return NULL; | |
5217 | } | |
5218 | rocksdb_level_metadata_t* level_meta = | |
5219 | (rocksdb_level_metadata_t*)malloc(sizeof(rocksdb_level_metadata_t)); | |
5220 | level_meta->rep = &cf_meta->rep.levels[i]; | |
5221 | ||
5222 | return level_meta; | |
5223 | } | |
5224 | ||
5225 | void rocksdb_level_metadata_destroy(rocksdb_level_metadata_t* level_meta) { | |
5226 | // Only free the base pointer as its parent rocksdb_column_family_metadata_t | |
5227 | // has the ownership of its rep. | |
5228 | free(level_meta); | |
5229 | } | |
5230 | ||
5231 | int rocksdb_level_metadata_get_level(rocksdb_level_metadata_t* level_meta) { | |
5232 | return level_meta->rep->level; | |
5233 | } | |
5234 | ||
5235 | uint64_t rocksdb_level_metadata_get_size(rocksdb_level_metadata_t* level_meta) { | |
5236 | return level_meta->rep->size; | |
5237 | } | |
5238 | ||
5239 | size_t rocksdb_level_metadata_get_file_count( | |
5240 | rocksdb_level_metadata_t* level_meta) { | |
5241 | return level_meta->rep->files.size(); | |
5242 | } | |
5243 | ||
5244 | rocksdb_sst_file_metadata_t* rocksdb_level_metadata_get_sst_file_metadata( | |
5245 | rocksdb_level_metadata_t* level_meta, size_t i) { | |
5246 | if (i >= level_meta->rep->files.size()) { | |
5247 | return nullptr; | |
5248 | } | |
5249 | rocksdb_sst_file_metadata_t* file_meta = | |
5250 | (rocksdb_sst_file_metadata_t*)malloc(sizeof(rocksdb_sst_file_metadata_t)); | |
5251 | file_meta->rep = &level_meta->rep->files[i]; | |
5252 | return file_meta; | |
5253 | } | |
5254 | ||
5255 | void rocksdb_sst_file_metadata_destroy(rocksdb_sst_file_metadata_t* file_meta) { | |
5256 | // Only free the base pointer as its parent rocksdb_level_metadata_t | |
5257 | // has the ownership of its rep. | |
5258 | free(file_meta); | |
5259 | } | |
5260 | ||
5261 | char* rocksdb_sst_file_metadata_get_relative_filename( | |
5262 | rocksdb_sst_file_metadata_t* file_meta) { | |
5263 | return strdup(file_meta->rep->relative_filename.c_str()); | |
5264 | } | |
5265 | ||
5266 | uint64_t rocksdb_sst_file_metadata_get_size( | |
5267 | rocksdb_sst_file_metadata_t* file_meta) { | |
5268 | return file_meta->rep->size; | |
5269 | } | |
5270 | ||
5271 | char* rocksdb_sst_file_metadata_get_smallestkey( | |
5272 | rocksdb_sst_file_metadata_t* file_meta, size_t* key_len) { | |
5273 | *key_len = file_meta->rep->smallestkey.size(); | |
5274 | return CopyString(file_meta->rep->smallestkey); | |
5275 | } | |
5276 | ||
5277 | char* rocksdb_sst_file_metadata_get_largestkey( | |
5278 | rocksdb_sst_file_metadata_t* file_meta, size_t* key_len) { | |
5279 | *key_len = file_meta->rep->largestkey.size(); | |
5280 | return CopyString(file_meta->rep->largestkey); | |
5281 | } | |
5282 | ||
5283 | /* Transactions */ | |
5284 | ||
11fdf7f2 TL |
5285 | rocksdb_transactiondb_options_t* rocksdb_transactiondb_options_create() { |
5286 | return new rocksdb_transactiondb_options_t; | |
5287 | } | |
5288 | ||
1e59de90 TL |
5289 | void rocksdb_transactiondb_options_destroy( |
5290 | rocksdb_transactiondb_options_t* opt) { | |
11fdf7f2 TL |
5291 | delete opt; |
5292 | } | |
5293 | ||
5294 | void rocksdb_transactiondb_options_set_max_num_locks( | |
5295 | rocksdb_transactiondb_options_t* opt, int64_t max_num_locks) { | |
5296 | opt->rep.max_num_locks = max_num_locks; | |
5297 | } | |
5298 | ||
5299 | void rocksdb_transactiondb_options_set_num_stripes( | |
5300 | rocksdb_transactiondb_options_t* opt, size_t num_stripes) { | |
5301 | opt->rep.num_stripes = num_stripes; | |
5302 | } | |
5303 | ||
5304 | void rocksdb_transactiondb_options_set_transaction_lock_timeout( | |
5305 | rocksdb_transactiondb_options_t* opt, int64_t txn_lock_timeout) { | |
5306 | opt->rep.transaction_lock_timeout = txn_lock_timeout; | |
5307 | } | |
5308 | ||
5309 | void rocksdb_transactiondb_options_set_default_lock_timeout( | |
5310 | rocksdb_transactiondb_options_t* opt, int64_t default_lock_timeout) { | |
5311 | opt->rep.default_lock_timeout = default_lock_timeout; | |
5312 | } | |
5313 | ||
5314 | rocksdb_transaction_options_t* rocksdb_transaction_options_create() { | |
5315 | return new rocksdb_transaction_options_t; | |
5316 | } | |
5317 | ||
5318 | void rocksdb_transaction_options_destroy(rocksdb_transaction_options_t* opt) { | |
5319 | delete opt; | |
5320 | } | |
5321 | ||
5322 | void rocksdb_transaction_options_set_set_snapshot( | |
5323 | rocksdb_transaction_options_t* opt, unsigned char v) { | |
5324 | opt->rep.set_snapshot = v; | |
5325 | } | |
5326 | ||
5327 | void rocksdb_transaction_options_set_deadlock_detect( | |
5328 | rocksdb_transaction_options_t* opt, unsigned char v) { | |
5329 | opt->rep.deadlock_detect = v; | |
5330 | } | |
5331 | ||
5332 | void rocksdb_transaction_options_set_lock_timeout( | |
5333 | rocksdb_transaction_options_t* opt, int64_t lock_timeout) { | |
5334 | opt->rep.lock_timeout = lock_timeout; | |
5335 | } | |
5336 | ||
5337 | void rocksdb_transaction_options_set_expiration( | |
5338 | rocksdb_transaction_options_t* opt, int64_t expiration) { | |
5339 | opt->rep.expiration = expiration; | |
5340 | } | |
5341 | ||
5342 | void rocksdb_transaction_options_set_deadlock_detect_depth( | |
5343 | rocksdb_transaction_options_t* opt, int64_t depth) { | |
5344 | opt->rep.deadlock_detect_depth = depth; | |
5345 | } | |
5346 | ||
5347 | void rocksdb_transaction_options_set_max_write_batch_size( | |
5348 | rocksdb_transaction_options_t* opt, size_t size) { | |
5349 | opt->rep.max_write_batch_size = size; | |
5350 | } | |
5351 | ||
1e59de90 TL |
5352 | void rocksdb_transaction_options_set_skip_prepare( |
5353 | rocksdb_transaction_options_t* opt, unsigned char v) { | |
5354 | opt->rep.skip_prepare = v; | |
5355 | } | |
5356 | ||
11fdf7f2 TL |
5357 | rocksdb_optimistictransaction_options_t* |
5358 | rocksdb_optimistictransaction_options_create() { | |
5359 | return new rocksdb_optimistictransaction_options_t; | |
5360 | } | |
5361 | ||
5362 | void rocksdb_optimistictransaction_options_destroy( | |
5363 | rocksdb_optimistictransaction_options_t* opt) { | |
5364 | delete opt; | |
5365 | } | |
5366 | ||
5367 | void rocksdb_optimistictransaction_options_set_set_snapshot( | |
5368 | rocksdb_optimistictransaction_options_t* opt, unsigned char v) { | |
5369 | opt->rep.set_snapshot = v; | |
5370 | } | |
5371 | ||
1e59de90 TL |
5372 | char* rocksdb_optimistictransactiondb_property_value( |
5373 | rocksdb_optimistictransactiondb_t* db, const char* propname) { | |
5374 | std::string tmp; | |
5375 | if (db->rep->GetProperty(Slice(propname), &tmp)) { | |
5376 | // We use strdup() since we expect human readable output. | |
5377 | return strdup(tmp.c_str()); | |
5378 | } else { | |
5379 | return nullptr; | |
5380 | } | |
5381 | } | |
5382 | ||
5383 | int rocksdb_optimistictransactiondb_property_int( | |
5384 | rocksdb_optimistictransactiondb_t* db, const char* propname, | |
5385 | uint64_t* out_val) { | |
5386 | if (db->rep->GetIntProperty(Slice(propname), out_val)) { | |
5387 | return 0; | |
5388 | } else { | |
5389 | return -1; | |
5390 | } | |
5391 | } | |
5392 | ||
11fdf7f2 TL |
5393 | rocksdb_column_family_handle_t* rocksdb_transactiondb_create_column_family( |
5394 | rocksdb_transactiondb_t* txn_db, | |
5395 | const rocksdb_options_t* column_family_options, | |
5396 | const char* column_family_name, char** errptr) { | |
5397 | rocksdb_column_family_handle_t* handle = new rocksdb_column_family_handle_t; | |
5398 | SaveError(errptr, txn_db->rep->CreateColumnFamily( | |
5399 | ColumnFamilyOptions(column_family_options->rep), | |
5400 | std::string(column_family_name), &(handle->rep))); | |
5401 | return handle; | |
5402 | } | |
5403 | ||
5404 | rocksdb_transactiondb_t* rocksdb_transactiondb_open( | |
5405 | const rocksdb_options_t* options, | |
5406 | const rocksdb_transactiondb_options_t* txn_db_options, const char* name, | |
5407 | char** errptr) { | |
5408 | TransactionDB* txn_db; | |
5409 | if (SaveError(errptr, TransactionDB::Open(options->rep, txn_db_options->rep, | |
5410 | std::string(name), &txn_db))) { | |
5411 | return nullptr; | |
5412 | } | |
5413 | rocksdb_transactiondb_t* result = new rocksdb_transactiondb_t; | |
5414 | result->rep = txn_db; | |
5415 | return result; | |
5416 | } | |
5417 | ||
494da23a TL |
5418 | rocksdb_transactiondb_t* rocksdb_transactiondb_open_column_families( |
5419 | const rocksdb_options_t* options, | |
5420 | const rocksdb_transactiondb_options_t* txn_db_options, const char* name, | |
f67539c2 TL |
5421 | int num_column_families, const char* const* column_family_names, |
5422 | const rocksdb_options_t* const* column_family_options, | |
494da23a TL |
5423 | rocksdb_column_family_handle_t** column_family_handles, char** errptr) { |
5424 | std::vector<ColumnFamilyDescriptor> column_families; | |
5425 | for (int i = 0; i < num_column_families; i++) { | |
5426 | column_families.push_back(ColumnFamilyDescriptor( | |
5427 | std::string(column_family_names[i]), | |
5428 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
5429 | } | |
5430 | ||
5431 | TransactionDB* txn_db; | |
5432 | std::vector<ColumnFamilyHandle*> handles; | |
5433 | if (SaveError(errptr, TransactionDB::Open(options->rep, txn_db_options->rep, | |
5434 | std::string(name), column_families, | |
5435 | &handles, &txn_db))) { | |
5436 | return nullptr; | |
5437 | } | |
5438 | ||
5439 | for (size_t i = 0; i < handles.size(); i++) { | |
5440 | rocksdb_column_family_handle_t* c_handle = | |
5441 | new rocksdb_column_family_handle_t; | |
5442 | c_handle->rep = handles[i]; | |
5443 | column_family_handles[i] = c_handle; | |
5444 | } | |
5445 | rocksdb_transactiondb_t* result = new rocksdb_transactiondb_t; | |
5446 | result->rep = txn_db; | |
5447 | return result; | |
5448 | } | |
5449 | ||
11fdf7f2 TL |
5450 | const rocksdb_snapshot_t* rocksdb_transactiondb_create_snapshot( |
5451 | rocksdb_transactiondb_t* txn_db) { | |
5452 | rocksdb_snapshot_t* result = new rocksdb_snapshot_t; | |
5453 | result->rep = txn_db->rep->GetSnapshot(); | |
5454 | return result; | |
5455 | } | |
5456 | ||
5457 | void rocksdb_transactiondb_release_snapshot( | |
5458 | rocksdb_transactiondb_t* txn_db, const rocksdb_snapshot_t* snapshot) { | |
5459 | txn_db->rep->ReleaseSnapshot(snapshot->rep); | |
5460 | delete snapshot; | |
5461 | } | |
5462 | ||
1e59de90 TL |
5463 | char* rocksdb_transactiondb_property_value(rocksdb_transactiondb_t* db, |
5464 | const char* propname) { | |
5465 | std::string tmp; | |
5466 | if (db->rep->GetProperty(Slice(propname), &tmp)) { | |
5467 | // We use strdup() since we expect human readable output. | |
5468 | return strdup(tmp.c_str()); | |
5469 | } else { | |
5470 | return nullptr; | |
5471 | } | |
5472 | } | |
5473 | ||
5474 | int rocksdb_transactiondb_property_int(rocksdb_transactiondb_t* db, | |
5475 | const char* propname, | |
5476 | uint64_t* out_val) { | |
5477 | if (db->rep->GetIntProperty(Slice(propname), out_val)) { | |
5478 | return 0; | |
5479 | } else { | |
5480 | return -1; | |
5481 | } | |
5482 | } | |
5483 | ||
11fdf7f2 TL |
5484 | rocksdb_transaction_t* rocksdb_transaction_begin( |
5485 | rocksdb_transactiondb_t* txn_db, | |
5486 | const rocksdb_writeoptions_t* write_options, | |
5487 | const rocksdb_transaction_options_t* txn_options, | |
5488 | rocksdb_transaction_t* old_txn) { | |
5489 | if (old_txn == nullptr) { | |
5490 | rocksdb_transaction_t* result = new rocksdb_transaction_t; | |
5491 | result->rep = txn_db->rep->BeginTransaction(write_options->rep, | |
5492 | txn_options->rep, nullptr); | |
5493 | return result; | |
5494 | } | |
5495 | old_txn->rep = txn_db->rep->BeginTransaction(write_options->rep, | |
1e59de90 | 5496 | txn_options->rep, old_txn->rep); |
11fdf7f2 TL |
5497 | return old_txn; |
5498 | } | |
5499 | ||
1e59de90 TL |
5500 | rocksdb_transaction_t** rocksdb_transactiondb_get_prepared_transactions( |
5501 | rocksdb_transactiondb_t* txn_db, size_t* cnt) { | |
5502 | std::vector<Transaction*> txns; | |
5503 | txn_db->rep->GetAllPreparedTransactions(&txns); | |
5504 | *cnt = txns.size(); | |
5505 | if (txns.empty()) { | |
5506 | return nullptr; | |
5507 | } else { | |
5508 | rocksdb_transaction_t** buf = (rocksdb_transaction_t**)malloc( | |
5509 | txns.size() * sizeof(rocksdb_transaction_t*)); | |
5510 | for (size_t i = 0; i < txns.size(); i++) { | |
5511 | buf[i] = new rocksdb_transaction_t; | |
5512 | buf[i]->rep = txns[i]; | |
5513 | } | |
5514 | return buf; | |
5515 | } | |
5516 | } | |
5517 | ||
5518 | void rocksdb_transaction_set_name(rocksdb_transaction_t* txn, const char* name, | |
5519 | size_t name_len, char** errptr) { | |
5520 | std::string str = std::string(name, name_len); | |
5521 | SaveError(errptr, txn->rep->SetName(str)); | |
5522 | } | |
5523 | ||
5524 | char* rocksdb_transaction_get_name(rocksdb_transaction_t* txn, | |
5525 | size_t* name_len) { | |
5526 | auto name = txn->rep->GetName(); | |
5527 | *name_len = name.size(); | |
5528 | return CopyString(name); | |
5529 | } | |
5530 | ||
5531 | void rocksdb_transaction_prepare(rocksdb_transaction_t* txn, char** errptr) { | |
5532 | SaveError(errptr, txn->rep->Prepare()); | |
5533 | } | |
5534 | ||
5535 | rocksdb_writebatch_wi_t* rocksdb_transaction_get_writebatch_wi( | |
5536 | rocksdb_transaction_t* txn) { | |
5537 | rocksdb_writebatch_wi_t* wi = | |
5538 | (rocksdb_writebatch_wi_t*)malloc(sizeof(rocksdb_writebatch_wi_t)); | |
5539 | wi->rep = txn->rep->GetWriteBatch(); | |
5540 | ||
5541 | return wi; | |
5542 | } | |
5543 | ||
5544 | void rocksdb_transaction_rebuild_from_writebatch( | |
5545 | rocksdb_transaction_t* txn, rocksdb_writebatch_t* writebatch, | |
5546 | char** errptr) { | |
5547 | SaveError(errptr, txn->rep->RebuildFromWriteBatch(&writebatch->rep)); | |
5548 | } | |
5549 | ||
5550 | void rocksdb_transaction_rebuild_from_writebatch_wi(rocksdb_transaction_t* txn, | |
5551 | rocksdb_writebatch_wi_t* wi, | |
5552 | char** errptr) { | |
5553 | SaveError(errptr, txn->rep->RebuildFromWriteBatch(wi->rep->GetWriteBatch())); | |
5554 | } | |
5555 | ||
11fdf7f2 TL |
5556 | void rocksdb_transaction_commit(rocksdb_transaction_t* txn, char** errptr) { |
5557 | SaveError(errptr, txn->rep->Commit()); | |
5558 | } | |
5559 | ||
5560 | void rocksdb_transaction_rollback(rocksdb_transaction_t* txn, char** errptr) { | |
5561 | SaveError(errptr, txn->rep->Rollback()); | |
5562 | } | |
5563 | ||
5564 | void rocksdb_transaction_set_savepoint(rocksdb_transaction_t* txn) { | |
5565 | txn->rep->SetSavePoint(); | |
5566 | } | |
5567 | ||
1e59de90 TL |
5568 | void rocksdb_transaction_rollback_to_savepoint(rocksdb_transaction_t* txn, |
5569 | char** errptr) { | |
11fdf7f2 TL |
5570 | SaveError(errptr, txn->rep->RollbackToSavePoint()); |
5571 | } | |
5572 | ||
5573 | void rocksdb_transaction_destroy(rocksdb_transaction_t* txn) { | |
5574 | delete txn->rep; | |
5575 | delete txn; | |
5576 | } | |
5577 | ||
5578 | const rocksdb_snapshot_t* rocksdb_transaction_get_snapshot( | |
5579 | rocksdb_transaction_t* txn) { | |
1e59de90 TL |
5580 | // This will be freed later on using free, so use malloc here to avoid a |
5581 | // mismatch | |
5582 | rocksdb_snapshot_t* result = | |
5583 | (rocksdb_snapshot_t*)malloc(sizeof(rocksdb_snapshot_t)); | |
11fdf7f2 TL |
5584 | result->rep = txn->rep->GetSnapshot(); |
5585 | return result; | |
5586 | } | |
5587 | ||
5588 | // Read a key inside a transaction | |
5589 | char* rocksdb_transaction_get(rocksdb_transaction_t* txn, | |
5590 | const rocksdb_readoptions_t* options, | |
5591 | const char* key, size_t klen, size_t* vlen, | |
5592 | char** errptr) { | |
5593 | char* result = nullptr; | |
5594 | std::string tmp; | |
5595 | Status s = txn->rep->Get(options->rep, Slice(key, klen), &tmp); | |
5596 | if (s.ok()) { | |
5597 | *vlen = tmp.size(); | |
5598 | result = CopyString(tmp); | |
5599 | } else { | |
5600 | *vlen = 0; | |
5601 | if (!s.IsNotFound()) { | |
5602 | SaveError(errptr, s); | |
5603 | } | |
5604 | } | |
5605 | return result; | |
5606 | } | |
5607 | ||
1e59de90 TL |
5608 | rocksdb_pinnableslice_t* rocksdb_transaction_get_pinned( |
5609 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
5610 | const char* key, size_t klen, char** errptr) { | |
5611 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
5612 | Status s = txn->rep->Get(options->rep, Slice(key, klen), &v->rep); | |
5613 | if (!s.ok()) { | |
5614 | delete (v); | |
5615 | if (!s.IsNotFound()) { | |
5616 | SaveError(errptr, s); | |
5617 | } | |
5618 | return nullptr; | |
5619 | } | |
5620 | return v; | |
5621 | } | |
5622 | ||
11fdf7f2 TL |
5623 | char* rocksdb_transaction_get_cf(rocksdb_transaction_t* txn, |
5624 | const rocksdb_readoptions_t* options, | |
5625 | rocksdb_column_family_handle_t* column_family, | |
5626 | const char* key, size_t klen, size_t* vlen, | |
5627 | char** errptr) { | |
5628 | char* result = nullptr; | |
5629 | std::string tmp; | |
5630 | Status s = | |
5631 | txn->rep->Get(options->rep, column_family->rep, Slice(key, klen), &tmp); | |
5632 | if (s.ok()) { | |
5633 | *vlen = tmp.size(); | |
5634 | result = CopyString(tmp); | |
5635 | } else { | |
5636 | *vlen = 0; | |
5637 | if (!s.IsNotFound()) { | |
5638 | SaveError(errptr, s); | |
5639 | } | |
5640 | } | |
5641 | return result; | |
5642 | } | |
5643 | ||
1e59de90 TL |
5644 | rocksdb_pinnableslice_t* rocksdb_transaction_get_pinned_cf( |
5645 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
5646 | rocksdb_column_family_handle_t* column_family, const char* key, size_t klen, | |
5647 | char** errptr) { | |
5648 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
5649 | Status s = txn->rep->Get(options->rep, column_family->rep, Slice(key, klen), | |
5650 | &v->rep); | |
5651 | if (!s.ok()) { | |
5652 | delete (v); | |
5653 | if (!s.IsNotFound()) { | |
5654 | SaveError(errptr, s); | |
5655 | } | |
5656 | return nullptr; | |
5657 | } | |
5658 | return v; | |
5659 | } | |
5660 | ||
11fdf7f2 TL |
5661 | // Read a key inside a transaction |
5662 | char* rocksdb_transaction_get_for_update(rocksdb_transaction_t* txn, | |
5663 | const rocksdb_readoptions_t* options, | |
5664 | const char* key, size_t klen, | |
5665 | size_t* vlen, unsigned char exclusive, | |
5666 | char** errptr) { | |
5667 | char* result = nullptr; | |
5668 | std::string tmp; | |
5669 | Status s = | |
5670 | txn->rep->GetForUpdate(options->rep, Slice(key, klen), &tmp, exclusive); | |
5671 | if (s.ok()) { | |
5672 | *vlen = tmp.size(); | |
5673 | result = CopyString(tmp); | |
5674 | } else { | |
5675 | *vlen = 0; | |
5676 | if (!s.IsNotFound()) { | |
5677 | SaveError(errptr, s); | |
5678 | } | |
5679 | } | |
5680 | return result; | |
5681 | } | |
5682 | ||
1e59de90 TL |
5683 | rocksdb_pinnableslice_t* rocksdb_transaction_get_pinned_for_update( |
5684 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
5685 | const char* key, size_t klen, unsigned char exclusive, char** errptr) { | |
5686 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
5687 | Status s = txn->rep->GetForUpdate(options->rep, Slice(key, klen), | |
5688 | v->rep.GetSelf(), exclusive); | |
5689 | v->rep.PinSelf(); | |
5690 | if (!s.ok()) { | |
5691 | delete (v); | |
5692 | if (!s.IsNotFound()) { | |
5693 | SaveError(errptr, s); | |
5694 | } | |
5695 | return nullptr; | |
5696 | } | |
5697 | return v; | |
5698 | } | |
5699 | ||
494da23a TL |
5700 | char* rocksdb_transaction_get_for_update_cf( |
5701 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
5702 | rocksdb_column_family_handle_t* column_family, const char* key, size_t klen, | |
5703 | size_t* vlen, unsigned char exclusive, char** errptr) { | |
5704 | char* result = nullptr; | |
5705 | std::string tmp; | |
5706 | Status s = txn->rep->GetForUpdate(options->rep, column_family->rep, | |
5707 | Slice(key, klen), &tmp, exclusive); | |
5708 | if (s.ok()) { | |
5709 | *vlen = tmp.size(); | |
5710 | result = CopyString(tmp); | |
5711 | } else { | |
5712 | *vlen = 0; | |
5713 | if (!s.IsNotFound()) { | |
5714 | SaveError(errptr, s); | |
5715 | } | |
5716 | } | |
5717 | return result; | |
5718 | } | |
5719 | ||
1e59de90 TL |
5720 | rocksdb_pinnableslice_t* rocksdb_transaction_get_pinned_for_update_cf( |
5721 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
5722 | rocksdb_column_family_handle_t* column_family, const char* key, size_t klen, | |
5723 | unsigned char exclusive, char** errptr) { | |
5724 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
5725 | Status s = txn->rep->GetForUpdate(options->rep, column_family->rep, | |
5726 | Slice(key, klen), &v->rep, exclusive); | |
5727 | if (!s.ok()) { | |
5728 | delete (v); | |
5729 | if (!s.IsNotFound()) { | |
5730 | SaveError(errptr, s); | |
5731 | } | |
5732 | return nullptr; | |
5733 | } | |
5734 | return v; | |
5735 | } | |
5736 | ||
5737 | void rocksdb_transaction_multi_get(rocksdb_transaction_t* txn, | |
5738 | const rocksdb_readoptions_t* options, | |
5739 | size_t num_keys, | |
5740 | const char* const* keys_list, | |
5741 | const size_t* keys_list_sizes, | |
5742 | char** values_list, | |
5743 | size_t* values_list_sizes, char** errs) { | |
5744 | std::vector<Slice> keys(num_keys); | |
5745 | for (size_t i = 0; i < num_keys; i++) { | |
5746 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
5747 | } | |
5748 | std::vector<std::string> values(num_keys); | |
5749 | std::vector<Status> statuses = | |
5750 | txn->rep->MultiGet(options->rep, keys, &values); | |
5751 | for (size_t i = 0; i < num_keys; i++) { | |
5752 | if (statuses[i].ok()) { | |
5753 | values_list[i] = CopyString(values[i]); | |
5754 | values_list_sizes[i] = values[i].size(); | |
5755 | errs[i] = nullptr; | |
5756 | } else { | |
5757 | values_list[i] = nullptr; | |
5758 | values_list_sizes[i] = 0; | |
5759 | if (!statuses[i].IsNotFound()) { | |
5760 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
5761 | } else { | |
5762 | errs[i] = nullptr; | |
5763 | } | |
5764 | } | |
5765 | } | |
5766 | } | |
5767 | ||
5768 | void rocksdb_transaction_multi_get_cf( | |
5769 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
5770 | const rocksdb_column_family_handle_t* const* column_families, | |
5771 | size_t num_keys, const char* const* keys_list, | |
5772 | const size_t* keys_list_sizes, char** values_list, | |
5773 | size_t* values_list_sizes, char** errs) { | |
5774 | std::vector<Slice> keys(num_keys); | |
5775 | std::vector<ColumnFamilyHandle*> cfs(num_keys); | |
5776 | for (size_t i = 0; i < num_keys; i++) { | |
5777 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
5778 | cfs[i] = column_families[i]->rep; | |
5779 | } | |
5780 | std::vector<std::string> values(num_keys); | |
5781 | std::vector<Status> statuses = | |
5782 | txn->rep->MultiGet(options->rep, cfs, keys, &values); | |
5783 | for (size_t i = 0; i < num_keys; i++) { | |
5784 | if (statuses[i].ok()) { | |
5785 | values_list[i] = CopyString(values[i]); | |
5786 | values_list_sizes[i] = values[i].size(); | |
5787 | errs[i] = nullptr; | |
5788 | } else { | |
5789 | values_list[i] = nullptr; | |
5790 | values_list_sizes[i] = 0; | |
5791 | if (!statuses[i].IsNotFound()) { | |
5792 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
5793 | } else { | |
5794 | errs[i] = nullptr; | |
5795 | } | |
5796 | } | |
5797 | } | |
5798 | } | |
5799 | ||
11fdf7f2 | 5800 | // Read a key outside a transaction |
1e59de90 TL |
5801 | char* rocksdb_transactiondb_get(rocksdb_transactiondb_t* txn_db, |
5802 | const rocksdb_readoptions_t* options, | |
5803 | const char* key, size_t klen, size_t* vlen, | |
5804 | char** errptr) { | |
11fdf7f2 TL |
5805 | char* result = nullptr; |
5806 | std::string tmp; | |
5807 | Status s = txn_db->rep->Get(options->rep, Slice(key, klen), &tmp); | |
5808 | if (s.ok()) { | |
5809 | *vlen = tmp.size(); | |
5810 | result = CopyString(tmp); | |
5811 | } else { | |
5812 | *vlen = 0; | |
5813 | if (!s.IsNotFound()) { | |
5814 | SaveError(errptr, s); | |
5815 | } | |
5816 | } | |
5817 | return result; | |
5818 | } | |
5819 | ||
1e59de90 TL |
5820 | rocksdb_pinnableslice_t* rocksdb_transactiondb_get_pinned( |
5821 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options, | |
5822 | const char* key, size_t klen, char** errptr) { | |
5823 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
5824 | Status s = txn_db->rep->Get(options->rep, txn_db->rep->DefaultColumnFamily(), | |
5825 | Slice(key, klen), &v->rep); | |
5826 | if (!s.ok()) { | |
5827 | delete (v); | |
5828 | if (!s.IsNotFound()) { | |
5829 | SaveError(errptr, s); | |
5830 | } | |
5831 | return nullptr; | |
5832 | } | |
5833 | return v; | |
5834 | } | |
5835 | ||
11fdf7f2 TL |
5836 | char* rocksdb_transactiondb_get_cf( |
5837 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options, | |
5838 | rocksdb_column_family_handle_t* column_family, const char* key, | |
5839 | size_t keylen, size_t* vallen, char** errptr) { | |
5840 | char* result = nullptr; | |
5841 | std::string tmp; | |
5842 | Status s = txn_db->rep->Get(options->rep, column_family->rep, | |
5843 | Slice(key, keylen), &tmp); | |
5844 | if (s.ok()) { | |
5845 | *vallen = tmp.size(); | |
5846 | result = CopyString(tmp); | |
5847 | } else { | |
5848 | *vallen = 0; | |
5849 | if (!s.IsNotFound()) { | |
5850 | SaveError(errptr, s); | |
5851 | } | |
5852 | } | |
5853 | return result; | |
5854 | } | |
5855 | ||
1e59de90 TL |
5856 | rocksdb_pinnableslice_t* rocksdb_transactiondb_get_pinned_cf( |
5857 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options, | |
5858 | rocksdb_column_family_handle_t* column_family, const char* key, | |
5859 | size_t keylen, char** errptr) { | |
5860 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
5861 | Status s = txn_db->rep->Get(options->rep, column_family->rep, | |
5862 | Slice(key, keylen), &v->rep); | |
5863 | if (!s.ok()) { | |
5864 | delete (v); | |
5865 | if (!s.IsNotFound()) { | |
5866 | SaveError(errptr, s); | |
5867 | } | |
5868 | return nullptr; | |
5869 | } | |
5870 | return v; | |
5871 | } | |
5872 | ||
5873 | void rocksdb_transactiondb_multi_get(rocksdb_transactiondb_t* txn_db, | |
5874 | const rocksdb_readoptions_t* options, | |
5875 | size_t num_keys, | |
5876 | const char* const* keys_list, | |
5877 | const size_t* keys_list_sizes, | |
5878 | char** values_list, | |
5879 | size_t* values_list_sizes, char** errs) { | |
5880 | std::vector<Slice> keys(num_keys); | |
5881 | for (size_t i = 0; i < num_keys; i++) { | |
5882 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
5883 | } | |
5884 | std::vector<std::string> values(num_keys); | |
5885 | std::vector<Status> statuses = | |
5886 | txn_db->rep->MultiGet(options->rep, keys, &values); | |
5887 | for (size_t i = 0; i < num_keys; i++) { | |
5888 | if (statuses[i].ok()) { | |
5889 | values_list[i] = CopyString(values[i]); | |
5890 | values_list_sizes[i] = values[i].size(); | |
5891 | errs[i] = nullptr; | |
5892 | } else { | |
5893 | values_list[i] = nullptr; | |
5894 | values_list_sizes[i] = 0; | |
5895 | if (!statuses[i].IsNotFound()) { | |
5896 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
5897 | } else { | |
5898 | errs[i] = nullptr; | |
5899 | } | |
5900 | } | |
5901 | } | |
5902 | } | |
5903 | ||
5904 | void rocksdb_transactiondb_multi_get_cf( | |
5905 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options, | |
5906 | const rocksdb_column_family_handle_t* const* column_families, | |
5907 | size_t num_keys, const char* const* keys_list, | |
5908 | const size_t* keys_list_sizes, char** values_list, | |
5909 | size_t* values_list_sizes, char** errs) { | |
5910 | std::vector<Slice> keys(num_keys); | |
5911 | std::vector<ColumnFamilyHandle*> cfs(num_keys); | |
5912 | for (size_t i = 0; i < num_keys; i++) { | |
5913 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
5914 | cfs[i] = column_families[i]->rep; | |
5915 | } | |
5916 | std::vector<std::string> values(num_keys); | |
5917 | std::vector<Status> statuses = | |
5918 | txn_db->rep->MultiGet(options->rep, cfs, keys, &values); | |
5919 | for (size_t i = 0; i < num_keys; i++) { | |
5920 | if (statuses[i].ok()) { | |
5921 | values_list[i] = CopyString(values[i]); | |
5922 | values_list_sizes[i] = values[i].size(); | |
5923 | errs[i] = nullptr; | |
5924 | } else { | |
5925 | values_list[i] = nullptr; | |
5926 | values_list_sizes[i] = 0; | |
5927 | if (!statuses[i].IsNotFound()) { | |
5928 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
5929 | } else { | |
5930 | errs[i] = nullptr; | |
5931 | } | |
5932 | } | |
5933 | } | |
5934 | } | |
5935 | ||
11fdf7f2 TL |
5936 | // Put a key inside a transaction |
5937 | void rocksdb_transaction_put(rocksdb_transaction_t* txn, const char* key, | |
5938 | size_t klen, const char* val, size_t vlen, | |
5939 | char** errptr) { | |
5940 | SaveError(errptr, txn->rep->Put(Slice(key, klen), Slice(val, vlen))); | |
5941 | } | |
5942 | ||
5943 | void rocksdb_transaction_put_cf(rocksdb_transaction_t* txn, | |
5944 | rocksdb_column_family_handle_t* column_family, | |
5945 | const char* key, size_t klen, const char* val, | |
5946 | size_t vlen, char** errptr) { | |
5947 | SaveError(errptr, txn->rep->Put(column_family->rep, Slice(key, klen), | |
5948 | Slice(val, vlen))); | |
5949 | } | |
5950 | ||
1e59de90 TL |
5951 | void rocksdb_transaction_set_commit_timestamp(rocksdb_transaction_t* txn, |
5952 | uint64_t commit_timestamp) { | |
5953 | txn->rep->SetCommitTimestamp(commit_timestamp); | |
5954 | } | |
5955 | ||
5956 | void rocksdb_transaction_set_read_timestamp_for_validation( | |
5957 | rocksdb_transaction_t* txn, uint64_t read_timestamp) { | |
5958 | txn->rep->SetReadTimestampForValidation(read_timestamp); | |
5959 | } | |
5960 | ||
11fdf7f2 TL |
5961 | // Put a key outside a transaction |
5962 | void rocksdb_transactiondb_put(rocksdb_transactiondb_t* txn_db, | |
5963 | const rocksdb_writeoptions_t* options, | |
5964 | const char* key, size_t klen, const char* val, | |
5965 | size_t vlen, char** errptr) { | |
5966 | SaveError(errptr, | |
5967 | txn_db->rep->Put(options->rep, Slice(key, klen), Slice(val, vlen))); | |
5968 | } | |
5969 | ||
5970 | void rocksdb_transactiondb_put_cf(rocksdb_transactiondb_t* txn_db, | |
5971 | const rocksdb_writeoptions_t* options, | |
5972 | rocksdb_column_family_handle_t* column_family, | |
5973 | const char* key, size_t keylen, | |
5974 | const char* val, size_t vallen, | |
5975 | char** errptr) { | |
5976 | SaveError(errptr, txn_db->rep->Put(options->rep, column_family->rep, | |
5977 | Slice(key, keylen), Slice(val, vallen))); | |
5978 | } | |
5979 | ||
5980 | // Write batch into transaction db | |
1e59de90 TL |
5981 | void rocksdb_transactiondb_write(rocksdb_transactiondb_t* db, |
5982 | const rocksdb_writeoptions_t* options, | |
5983 | rocksdb_writebatch_t* batch, char** errptr) { | |
11fdf7f2 TL |
5984 | SaveError(errptr, db->rep->Write(options->rep, &batch->rep)); |
5985 | } | |
5986 | ||
5987 | // Merge a key inside a transaction | |
5988 | void rocksdb_transaction_merge(rocksdb_transaction_t* txn, const char* key, | |
5989 | size_t klen, const char* val, size_t vlen, | |
5990 | char** errptr) { | |
5991 | SaveError(errptr, txn->rep->Merge(Slice(key, klen), Slice(val, vlen))); | |
5992 | } | |
5993 | ||
494da23a TL |
5994 | void rocksdb_transaction_merge_cf(rocksdb_transaction_t* txn, |
5995 | rocksdb_column_family_handle_t* column_family, | |
5996 | const char* key, size_t klen, const char* val, | |
5997 | size_t vlen, char** errptr) { | |
5998 | SaveError(errptr, txn->rep->Merge(column_family->rep, Slice(key, klen), | |
5999 | Slice(val, vlen))); | |
6000 | } | |
6001 | ||
11fdf7f2 TL |
6002 | // Merge a key outside a transaction |
6003 | void rocksdb_transactiondb_merge(rocksdb_transactiondb_t* txn_db, | |
6004 | const rocksdb_writeoptions_t* options, | |
6005 | const char* key, size_t klen, const char* val, | |
6006 | size_t vlen, char** errptr) { | |
6007 | SaveError(errptr, txn_db->rep->Merge(options->rep, Slice(key, klen), | |
6008 | Slice(val, vlen))); | |
6009 | } | |
6010 | ||
494da23a TL |
6011 | void rocksdb_transactiondb_merge_cf( |
6012 | rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options, | |
6013 | rocksdb_column_family_handle_t* column_family, const char* key, size_t klen, | |
6014 | const char* val, size_t vlen, char** errptr) { | |
6015 | SaveError(errptr, txn_db->rep->Merge(options->rep, column_family->rep, | |
6016 | Slice(key, klen), Slice(val, vlen))); | |
6017 | } | |
6018 | ||
11fdf7f2 TL |
6019 | // Delete a key inside a transaction |
6020 | void rocksdb_transaction_delete(rocksdb_transaction_t* txn, const char* key, | |
6021 | size_t klen, char** errptr) { | |
6022 | SaveError(errptr, txn->rep->Delete(Slice(key, klen))); | |
6023 | } | |
6024 | ||
6025 | void rocksdb_transaction_delete_cf( | |
6026 | rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family, | |
6027 | const char* key, size_t klen, char** errptr) { | |
6028 | SaveError(errptr, txn->rep->Delete(column_family->rep, Slice(key, klen))); | |
6029 | } | |
6030 | ||
6031 | // Delete a key outside a transaction | |
6032 | void rocksdb_transactiondb_delete(rocksdb_transactiondb_t* txn_db, | |
6033 | const rocksdb_writeoptions_t* options, | |
6034 | const char* key, size_t klen, char** errptr) { | |
6035 | SaveError(errptr, txn_db->rep->Delete(options->rep, Slice(key, klen))); | |
6036 | } | |
6037 | ||
6038 | void rocksdb_transactiondb_delete_cf( | |
6039 | rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options, | |
6040 | rocksdb_column_family_handle_t* column_family, const char* key, | |
6041 | size_t keylen, char** errptr) { | |
6042 | SaveError(errptr, txn_db->rep->Delete(options->rep, column_family->rep, | |
6043 | Slice(key, keylen))); | |
6044 | } | |
6045 | ||
6046 | // Create an iterator inside a transaction | |
6047 | rocksdb_iterator_t* rocksdb_transaction_create_iterator( | |
6048 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options) { | |
6049 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
6050 | result->rep = txn->rep->GetIterator(options->rep); | |
6051 | return result; | |
6052 | } | |
6053 | ||
6054 | // Create an iterator inside a transaction with column family | |
6055 | rocksdb_iterator_t* rocksdb_transaction_create_iterator_cf( | |
6056 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
6057 | rocksdb_column_family_handle_t* column_family) { | |
6058 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
6059 | result->rep = txn->rep->GetIterator(options->rep, column_family->rep); | |
6060 | return result; | |
6061 | } | |
6062 | ||
6063 | // Create an iterator outside a transaction | |
6064 | rocksdb_iterator_t* rocksdb_transactiondb_create_iterator( | |
6065 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options) { | |
6066 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
6067 | result->rep = txn_db->rep->NewIterator(options->rep); | |
6068 | return result; | |
6069 | } | |
6070 | ||
494da23a TL |
6071 | rocksdb_iterator_t* rocksdb_transactiondb_create_iterator_cf( |
6072 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options, | |
6073 | rocksdb_column_family_handle_t* column_family) { | |
6074 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
6075 | result->rep = txn_db->rep->NewIterator(options->rep, column_family->rep); | |
6076 | return result; | |
6077 | } | |
6078 | ||
11fdf7f2 TL |
6079 | void rocksdb_transactiondb_close(rocksdb_transactiondb_t* txn_db) { |
6080 | delete txn_db->rep; | |
6081 | delete txn_db; | |
6082 | } | |
6083 | ||
1e59de90 TL |
6084 | void rocksdb_transactiondb_flush_wal(rocksdb_transactiondb_t* txn_db, |
6085 | unsigned char sync, char** errptr) { | |
6086 | SaveError(errptr, txn_db->rep->FlushWAL(sync)); | |
6087 | } | |
6088 | ||
6089 | void rocksdb_transactiondb_flush(rocksdb_transactiondb_t* txn_db, | |
6090 | const rocksdb_flushoptions_t* options, | |
6091 | char** errptr) { | |
6092 | SaveError(errptr, txn_db->rep->Flush(options->rep)); | |
6093 | } | |
6094 | ||
6095 | void rocksdb_transactiondb_flush_cf( | |
6096 | rocksdb_transactiondb_t* txn_db, const rocksdb_flushoptions_t* options, | |
6097 | rocksdb_column_family_handle_t* column_family, char** errptr) { | |
6098 | SaveError(errptr, txn_db->rep->Flush(options->rep, column_family->rep)); | |
6099 | } | |
6100 | ||
11fdf7f2 TL |
6101 | rocksdb_checkpoint_t* rocksdb_transactiondb_checkpoint_object_create( |
6102 | rocksdb_transactiondb_t* txn_db, char** errptr) { | |
6103 | Checkpoint* checkpoint; | |
6104 | if (SaveError(errptr, Checkpoint::Create(txn_db->rep, &checkpoint))) { | |
6105 | return nullptr; | |
6106 | } | |
6107 | rocksdb_checkpoint_t* result = new rocksdb_checkpoint_t; | |
6108 | result->rep = checkpoint; | |
6109 | return result; | |
6110 | } | |
6111 | ||
6112 | rocksdb_optimistictransactiondb_t* rocksdb_optimistictransactiondb_open( | |
6113 | const rocksdb_options_t* options, const char* name, char** errptr) { | |
6114 | OptimisticTransactionDB* otxn_db; | |
6115 | if (SaveError(errptr, OptimisticTransactionDB::Open( | |
6116 | options->rep, std::string(name), &otxn_db))) { | |
6117 | return nullptr; | |
6118 | } | |
6119 | rocksdb_optimistictransactiondb_t* result = | |
6120 | new rocksdb_optimistictransactiondb_t; | |
6121 | result->rep = otxn_db; | |
6122 | return result; | |
6123 | } | |
6124 | ||
6125 | rocksdb_optimistictransactiondb_t* | |
6126 | rocksdb_optimistictransactiondb_open_column_families( | |
6127 | const rocksdb_options_t* db_options, const char* name, | |
f67539c2 TL |
6128 | int num_column_families, const char* const* column_family_names, |
6129 | const rocksdb_options_t* const* column_family_options, | |
11fdf7f2 TL |
6130 | rocksdb_column_family_handle_t** column_family_handles, char** errptr) { |
6131 | std::vector<ColumnFamilyDescriptor> column_families; | |
6132 | for (int i = 0; i < num_column_families; i++) { | |
6133 | column_families.push_back(ColumnFamilyDescriptor( | |
6134 | std::string(column_family_names[i]), | |
6135 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
6136 | } | |
6137 | ||
6138 | OptimisticTransactionDB* otxn_db; | |
6139 | std::vector<ColumnFamilyHandle*> handles; | |
6140 | if (SaveError(errptr, OptimisticTransactionDB::Open( | |
6141 | DBOptions(db_options->rep), std::string(name), | |
6142 | column_families, &handles, &otxn_db))) { | |
6143 | return nullptr; | |
6144 | } | |
6145 | ||
6146 | for (size_t i = 0; i < handles.size(); i++) { | |
6147 | rocksdb_column_family_handle_t* c_handle = | |
6148 | new rocksdb_column_family_handle_t; | |
6149 | c_handle->rep = handles[i]; | |
6150 | column_family_handles[i] = c_handle; | |
6151 | } | |
6152 | rocksdb_optimistictransactiondb_t* result = | |
6153 | new rocksdb_optimistictransactiondb_t; | |
6154 | result->rep = otxn_db; | |
6155 | return result; | |
6156 | } | |
6157 | ||
6158 | rocksdb_t* rocksdb_optimistictransactiondb_get_base_db( | |
6159 | rocksdb_optimistictransactiondb_t* otxn_db) { | |
6160 | DB* base_db = otxn_db->rep->GetBaseDB(); | |
6161 | ||
6162 | if (base_db != nullptr) { | |
6163 | rocksdb_t* result = new rocksdb_t; | |
6164 | result->rep = base_db; | |
6165 | return result; | |
6166 | } | |
6167 | ||
6168 | return nullptr; | |
6169 | } | |
6170 | ||
6171 | void rocksdb_optimistictransactiondb_close_base_db(rocksdb_t* base_db) { | |
6172 | delete base_db; | |
6173 | } | |
6174 | ||
6175 | rocksdb_transaction_t* rocksdb_optimistictransaction_begin( | |
6176 | rocksdb_optimistictransactiondb_t* otxn_db, | |
6177 | const rocksdb_writeoptions_t* write_options, | |
6178 | const rocksdb_optimistictransaction_options_t* otxn_options, | |
6179 | rocksdb_transaction_t* old_txn) { | |
6180 | if (old_txn == nullptr) { | |
6181 | rocksdb_transaction_t* result = new rocksdb_transaction_t; | |
6182 | result->rep = otxn_db->rep->BeginTransaction(write_options->rep, | |
6183 | otxn_options->rep, nullptr); | |
6184 | return result; | |
6185 | } | |
6186 | old_txn->rep = otxn_db->rep->BeginTransaction( | |
6187 | write_options->rep, otxn_options->rep, old_txn->rep); | |
6188 | return old_txn; | |
6189 | } | |
6190 | ||
1e59de90 TL |
6191 | // Write batch into OptimisticTransactionDB |
6192 | void rocksdb_optimistictransactiondb_write( | |
6193 | rocksdb_optimistictransactiondb_t* otxn_db, | |
6194 | const rocksdb_writeoptions_t* options, rocksdb_writebatch_t* batch, | |
6195 | char** errptr) { | |
6196 | SaveError(errptr, otxn_db->rep->Write(options->rep, &batch->rep)); | |
6197 | } | |
6198 | ||
11fdf7f2 TL |
6199 | void rocksdb_optimistictransactiondb_close( |
6200 | rocksdb_optimistictransactiondb_t* otxn_db) { | |
6201 | delete otxn_db->rep; | |
6202 | delete otxn_db; | |
6203 | } | |
6204 | ||
1e59de90 TL |
6205 | rocksdb_checkpoint_t* rocksdb_optimistictransactiondb_checkpoint_object_create( |
6206 | rocksdb_optimistictransactiondb_t* otxn_db, char** errptr) { | |
6207 | Checkpoint* checkpoint; | |
6208 | if (SaveError(errptr, Checkpoint::Create(otxn_db->rep, &checkpoint))) { | |
6209 | return nullptr; | |
6210 | } | |
6211 | rocksdb_checkpoint_t* result = new rocksdb_checkpoint_t; | |
6212 | result->rep = checkpoint; | |
6213 | return result; | |
6214 | } | |
6215 | ||
7c673cae FG |
6216 | void rocksdb_free(void* ptr) { free(ptr); } |
6217 | ||
11fdf7f2 TL |
6218 | rocksdb_pinnableslice_t* rocksdb_get_pinned( |
6219 | rocksdb_t* db, const rocksdb_readoptions_t* options, const char* key, | |
6220 | size_t keylen, char** errptr) { | |
6221 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
6222 | Status s = db->rep->Get(options->rep, db->rep->DefaultColumnFamily(), | |
6223 | Slice(key, keylen), &v->rep); | |
6224 | if (!s.ok()) { | |
6225 | delete (v); | |
6226 | if (!s.IsNotFound()) { | |
6227 | SaveError(errptr, s); | |
6228 | } | |
6229 | return nullptr; | |
6230 | } | |
6231 | return v; | |
6232 | } | |
6233 | ||
6234 | rocksdb_pinnableslice_t* rocksdb_get_pinned_cf( | |
6235 | rocksdb_t* db, const rocksdb_readoptions_t* options, | |
6236 | rocksdb_column_family_handle_t* column_family, const char* key, | |
6237 | size_t keylen, char** errptr) { | |
6238 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
6239 | Status s = db->rep->Get(options->rep, column_family->rep, Slice(key, keylen), | |
6240 | &v->rep); | |
6241 | if (!s.ok()) { | |
6242 | delete v; | |
6243 | if (!s.IsNotFound()) { | |
6244 | SaveError(errptr, s); | |
6245 | } | |
6246 | return nullptr; | |
6247 | } | |
6248 | return v; | |
6249 | } | |
6250 | ||
6251 | void rocksdb_pinnableslice_destroy(rocksdb_pinnableslice_t* v) { delete v; } | |
6252 | ||
6253 | const char* rocksdb_pinnableslice_value(const rocksdb_pinnableslice_t* v, | |
6254 | size_t* vlen) { | |
6255 | if (!v) { | |
6256 | *vlen = 0; | |
6257 | return nullptr; | |
6258 | } | |
6259 | ||
6260 | *vlen = v->rep.size(); | |
6261 | return v->rep.data(); | |
6262 | } | |
6263 | ||
f67539c2 TL |
6264 | // container to keep databases and caches in order to use |
6265 | // ROCKSDB_NAMESPACE::MemoryUtil | |
11fdf7f2 TL |
6266 | struct rocksdb_memory_consumers_t { |
6267 | std::vector<rocksdb_t*> dbs; | |
6268 | std::unordered_set<rocksdb_cache_t*> caches; | |
6269 | }; | |
6270 | ||
6271 | // initializes new container of memory consumers | |
6272 | rocksdb_memory_consumers_t* rocksdb_memory_consumers_create() { | |
6273 | return new rocksdb_memory_consumers_t; | |
6274 | } | |
6275 | ||
6276 | // adds datatabase to the container of memory consumers | |
6277 | void rocksdb_memory_consumers_add_db(rocksdb_memory_consumers_t* consumers, | |
6278 | rocksdb_t* db) { | |
6279 | consumers->dbs.push_back(db); | |
6280 | } | |
6281 | ||
6282 | // adds cache to the container of memory consumers | |
6283 | void rocksdb_memory_consumers_add_cache(rocksdb_memory_consumers_t* consumers, | |
6284 | rocksdb_cache_t* cache) { | |
6285 | consumers->caches.insert(cache); | |
6286 | } | |
6287 | ||
6288 | // deletes container with memory consumers | |
6289 | void rocksdb_memory_consumers_destroy(rocksdb_memory_consumers_t* consumers) { | |
6290 | delete consumers; | |
6291 | } | |
6292 | ||
f67539c2 | 6293 | // contains memory usage statistics provided by ROCKSDB_NAMESPACE::MemoryUtil |
11fdf7f2 TL |
6294 | struct rocksdb_memory_usage_t { |
6295 | uint64_t mem_table_total; | |
6296 | uint64_t mem_table_unflushed; | |
6297 | uint64_t mem_table_readers_total; | |
6298 | uint64_t cache_total; | |
6299 | }; | |
6300 | ||
6301 | // estimates amount of memory occupied by consumers (dbs and caches) | |
6302 | rocksdb_memory_usage_t* rocksdb_approximate_memory_usage_create( | |
6303 | rocksdb_memory_consumers_t* consumers, char** errptr) { | |
11fdf7f2 TL |
6304 | vector<DB*> dbs; |
6305 | for (auto db : consumers->dbs) { | |
6306 | dbs.push_back(db->rep); | |
6307 | } | |
6308 | ||
6309 | unordered_set<const Cache*> cache_set; | |
6310 | for (auto cache : consumers->caches) { | |
6311 | cache_set.insert(const_cast<const Cache*>(cache->rep.get())); | |
6312 | } | |
6313 | ||
f67539c2 | 6314 | std::map<ROCKSDB_NAMESPACE::MemoryUtil::UsageType, uint64_t> usage_by_type; |
11fdf7f2 TL |
6315 | |
6316 | auto status = MemoryUtil::GetApproximateMemoryUsageByType(dbs, cache_set, | |
6317 | &usage_by_type); | |
6318 | if (SaveError(errptr, status)) { | |
6319 | return nullptr; | |
6320 | } | |
6321 | ||
6322 | auto result = new rocksdb_memory_usage_t; | |
6323 | result->mem_table_total = usage_by_type[MemoryUtil::kMemTableTotal]; | |
6324 | result->mem_table_unflushed = usage_by_type[MemoryUtil::kMemTableUnFlushed]; | |
1e59de90 TL |
6325 | result->mem_table_readers_total = |
6326 | usage_by_type[MemoryUtil::kTableReadersTotal]; | |
11fdf7f2 TL |
6327 | result->cache_total = usage_by_type[MemoryUtil::kCacheTotal]; |
6328 | return result; | |
6329 | } | |
6330 | ||
6331 | uint64_t rocksdb_approximate_memory_usage_get_mem_table_total( | |
6332 | rocksdb_memory_usage_t* memory_usage) { | |
6333 | return memory_usage->mem_table_total; | |
6334 | } | |
6335 | ||
6336 | uint64_t rocksdb_approximate_memory_usage_get_mem_table_unflushed( | |
6337 | rocksdb_memory_usage_t* memory_usage) { | |
6338 | return memory_usage->mem_table_unflushed; | |
6339 | } | |
6340 | ||
6341 | uint64_t rocksdb_approximate_memory_usage_get_mem_table_readers_total( | |
6342 | rocksdb_memory_usage_t* memory_usage) { | |
6343 | return memory_usage->mem_table_readers_total; | |
6344 | } | |
6345 | ||
6346 | uint64_t rocksdb_approximate_memory_usage_get_cache_total( | |
6347 | rocksdb_memory_usage_t* memory_usage) { | |
6348 | return memory_usage->cache_total; | |
6349 | } | |
6350 | ||
20effc67 TL |
6351 | void rocksdb_options_set_dump_malloc_stats(rocksdb_options_t* opt, |
6352 | unsigned char val) { | |
6353 | opt->rep.dump_malloc_stats = val; | |
6354 | } | |
6355 | ||
6356 | void rocksdb_options_set_memtable_whole_key_filtering(rocksdb_options_t* opt, | |
6357 | unsigned char val) { | |
6358 | opt->rep.memtable_whole_key_filtering = val; | |
6359 | } | |
6360 | ||
1e59de90 TL |
6361 | void rocksdb_options_set_avoid_unnecessary_blocking_io(rocksdb_options_t* opt, |
6362 | unsigned char val) { | |
6363 | opt->rep.avoid_unnecessary_blocking_io = val; | |
6364 | } | |
6365 | ||
6366 | unsigned char rocksdb_options_get_avoid_unnecessary_blocking_io( | |
6367 | rocksdb_options_t* opt) { | |
6368 | return opt->rep.avoid_unnecessary_blocking_io; | |
6369 | } | |
6370 | ||
11fdf7f2 TL |
6371 | // deletes container with memory usage estimates |
6372 | void rocksdb_approximate_memory_usage_destroy(rocksdb_memory_usage_t* usage) { | |
6373 | delete usage; | |
6374 | } | |
6375 | ||
20effc67 TL |
6376 | void rocksdb_cancel_all_background_work(rocksdb_t* db, unsigned char wait) { |
6377 | CancelAllBackgroundWork(db->rep, wait); | |
6378 | } | |
6379 | ||
1e59de90 TL |
6380 | void rocksdb_disable_manual_compaction(rocksdb_t* db) { |
6381 | db->rep->DisableManualCompaction(); | |
6382 | } | |
6383 | ||
6384 | void rocksdb_enable_manual_compaction(rocksdb_t* db) { | |
6385 | db->rep->EnableManualCompaction(); | |
6386 | } | |
6387 | ||
7c673cae FG |
6388 | } // end extern "C" |
6389 | ||
6390 | #endif // !ROCKSDB_LITE |