]>
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 | ||
14 | #include <stdlib.h> | |
15 | #include "port/port.h" | |
16 | #include "rocksdb/cache.h" | |
17 | #include "rocksdb/compaction_filter.h" | |
18 | #include "rocksdb/comparator.h" | |
19 | #include "rocksdb/convenience.h" | |
20 | #include "rocksdb/db.h" | |
21 | #include "rocksdb/env.h" | |
22 | #include "rocksdb/filter_policy.h" | |
23 | #include "rocksdb/iterator.h" | |
11fdf7f2 | 24 | #include "rocksdb/memtablerep.h" |
7c673cae FG |
25 | #include "rocksdb/merge_operator.h" |
26 | #include "rocksdb/options.h" | |
11fdf7f2 | 27 | #include "rocksdb/rate_limiter.h" |
7c673cae | 28 | #include "rocksdb/slice_transform.h" |
11fdf7f2 TL |
29 | #include "rocksdb/statistics.h" |
30 | #include "rocksdb/status.h" | |
7c673cae | 31 | #include "rocksdb/table.h" |
11fdf7f2 | 32 | #include "rocksdb/universal_compaction.h" |
7c673cae | 33 | #include "rocksdb/utilities/backupable_db.h" |
11fdf7f2 TL |
34 | #include "rocksdb/utilities/checkpoint.h" |
35 | #include "rocksdb/utilities/db_ttl.h" | |
36 | #include "rocksdb/utilities/memory_util.h" | |
37 | #include "rocksdb/utilities/optimistic_transaction_db.h" | |
38 | #include "rocksdb/utilities/transaction.h" | |
39 | #include "rocksdb/utilities/transaction_db.h" | |
7c673cae | 40 | #include "rocksdb/utilities/write_batch_with_index.h" |
11fdf7f2 TL |
41 | #include "rocksdb/write_batch.h" |
42 | #include "rocksdb/perf_context.h" | |
7c673cae FG |
43 | #include "utilities/merge_operators.h" |
44 | ||
11fdf7f2 TL |
45 | #include <vector> |
46 | #include <unordered_set> | |
47 | #include <map> | |
48 | ||
7c673cae FG |
49 | using rocksdb::BytewiseComparator; |
50 | using rocksdb::Cache; | |
51 | using rocksdb::ColumnFamilyDescriptor; | |
52 | using rocksdb::ColumnFamilyHandle; | |
53 | using rocksdb::ColumnFamilyOptions; | |
54 | using rocksdb::CompactionFilter; | |
55 | using rocksdb::CompactionFilterFactory; | |
56 | using rocksdb::CompactionFilterContext; | |
57 | using rocksdb::CompactionOptionsFIFO; | |
58 | using rocksdb::Comparator; | |
59 | using rocksdb::CompressionType; | |
60 | using rocksdb::WALRecoveryMode; | |
61 | using rocksdb::DB; | |
62 | using rocksdb::DBOptions; | |
11fdf7f2 | 63 | using rocksdb::DbPath; |
7c673cae FG |
64 | using rocksdb::Env; |
65 | using rocksdb::EnvOptions; | |
66 | using rocksdb::InfoLogLevel; | |
67 | using rocksdb::FileLock; | |
68 | using rocksdb::FilterPolicy; | |
69 | using rocksdb::FlushOptions; | |
70 | using rocksdb::IngestExternalFileOptions; | |
71 | using rocksdb::Iterator; | |
72 | using rocksdb::Logger; | |
73 | using rocksdb::MergeOperator; | |
74 | using rocksdb::MergeOperators; | |
75 | using rocksdb::NewBloomFilterPolicy; | |
76 | using rocksdb::NewLRUCache; | |
77 | using rocksdb::Options; | |
78 | using rocksdb::BlockBasedTableOptions; | |
79 | using rocksdb::CuckooTableOptions; | |
80 | using rocksdb::RandomAccessFile; | |
81 | using rocksdb::Range; | |
82 | using rocksdb::ReadOptions; | |
83 | using rocksdb::SequentialFile; | |
84 | using rocksdb::Slice; | |
85 | using rocksdb::SliceParts; | |
86 | using rocksdb::SliceTransform; | |
87 | using rocksdb::Snapshot; | |
88 | using rocksdb::SstFileWriter; | |
89 | using rocksdb::Status; | |
90 | using rocksdb::WritableFile; | |
91 | using rocksdb::WriteBatch; | |
92 | using rocksdb::WriteBatchWithIndex; | |
93 | using rocksdb::WriteOptions; | |
94 | using rocksdb::LiveFileMetaData; | |
95 | using rocksdb::BackupEngine; | |
96 | using rocksdb::BackupableDBOptions; | |
97 | using rocksdb::BackupInfo; | |
11fdf7f2 | 98 | using rocksdb::BackupID; |
7c673cae FG |
99 | using rocksdb::RestoreOptions; |
100 | using rocksdb::CompactRangeOptions; | |
11fdf7f2 | 101 | using rocksdb::BottommostLevelCompaction; |
7c673cae FG |
102 | using rocksdb::RateLimiter; |
103 | using rocksdb::NewGenericRateLimiter; | |
11fdf7f2 TL |
104 | using rocksdb::PinnableSlice; |
105 | using rocksdb::TransactionDBOptions; | |
106 | using rocksdb::TransactionDB; | |
107 | using rocksdb::TransactionOptions; | |
108 | using rocksdb::OptimisticTransactionDB; | |
109 | using rocksdb::OptimisticTransactionOptions; | |
110 | using rocksdb::Transaction; | |
111 | using rocksdb::Checkpoint; | |
112 | using rocksdb::TransactionLogIterator; | |
113 | using rocksdb::BatchResult; | |
114 | using rocksdb::PerfLevel; | |
115 | using rocksdb::PerfContext; | |
116 | using rocksdb::MemoryUtil; | |
7c673cae FG |
117 | |
118 | using std::shared_ptr; | |
11fdf7f2 TL |
119 | using std::vector; |
120 | using std::unordered_set; | |
121 | using std::map; | |
7c673cae FG |
122 | |
123 | extern "C" { | |
124 | ||
125 | struct rocksdb_t { DB* rep; }; | |
126 | struct rocksdb_backup_engine_t { BackupEngine* rep; }; | |
127 | struct rocksdb_backup_engine_info_t { std::vector<BackupInfo> rep; }; | |
128 | struct rocksdb_restore_options_t { RestoreOptions rep; }; | |
129 | struct rocksdb_iterator_t { Iterator* rep; }; | |
130 | struct rocksdb_writebatch_t { WriteBatch rep; }; | |
131 | struct rocksdb_writebatch_wi_t { WriteBatchWithIndex* rep; }; | |
132 | struct rocksdb_snapshot_t { const Snapshot* rep; }; | |
133 | struct rocksdb_flushoptions_t { FlushOptions rep; }; | |
134 | struct rocksdb_fifo_compaction_options_t { CompactionOptionsFIFO rep; }; | |
135 | struct rocksdb_readoptions_t { | |
136 | ReadOptions rep; | |
11fdf7f2 TL |
137 | // stack variables to set pointers to in ReadOptions |
138 | Slice upper_bound; | |
139 | Slice lower_bound; | |
7c673cae FG |
140 | }; |
141 | struct rocksdb_writeoptions_t { WriteOptions rep; }; | |
142 | struct rocksdb_options_t { Options rep; }; | |
143 | struct rocksdb_compactoptions_t { | |
144 | CompactRangeOptions rep; | |
145 | }; | |
146 | struct rocksdb_block_based_table_options_t { BlockBasedTableOptions rep; }; | |
147 | struct rocksdb_cuckoo_table_options_t { CuckooTableOptions rep; }; | |
148 | struct rocksdb_seqfile_t { SequentialFile* rep; }; | |
149 | struct rocksdb_randomfile_t { RandomAccessFile* rep; }; | |
150 | struct rocksdb_writablefile_t { WritableFile* rep; }; | |
11fdf7f2 TL |
151 | struct rocksdb_wal_iterator_t { TransactionLogIterator* rep; }; |
152 | struct rocksdb_wal_readoptions_t { TransactionLogIterator::ReadOptions rep; }; | |
7c673cae | 153 | struct rocksdb_filelock_t { FileLock* rep; }; |
494da23a TL |
154 | struct rocksdb_logger_t { |
155 | std::shared_ptr<Logger> rep; | |
156 | }; | |
157 | struct rocksdb_cache_t { | |
158 | std::shared_ptr<Cache> rep; | |
159 | }; | |
7c673cae FG |
160 | struct rocksdb_livefiles_t { std::vector<LiveFileMetaData> rep; }; |
161 | struct rocksdb_column_family_handle_t { ColumnFamilyHandle* rep; }; | |
162 | struct rocksdb_envoptions_t { EnvOptions rep; }; | |
163 | struct rocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; }; | |
164 | struct rocksdb_sstfilewriter_t { SstFileWriter* rep; }; | |
494da23a TL |
165 | struct rocksdb_ratelimiter_t { |
166 | std::shared_ptr<RateLimiter> rep; | |
167 | }; | |
11fdf7f2 TL |
168 | struct rocksdb_perfcontext_t { PerfContext* rep; }; |
169 | struct rocksdb_pinnableslice_t { | |
170 | PinnableSlice rep; | |
171 | }; | |
172 | struct rocksdb_transactiondb_options_t { | |
173 | TransactionDBOptions rep; | |
174 | }; | |
175 | struct rocksdb_transactiondb_t { | |
176 | TransactionDB* rep; | |
177 | }; | |
178 | struct rocksdb_transaction_options_t { | |
179 | TransactionOptions rep; | |
180 | }; | |
181 | struct rocksdb_transaction_t { | |
182 | Transaction* rep; | |
183 | }; | |
184 | struct rocksdb_checkpoint_t { | |
185 | Checkpoint* rep; | |
186 | }; | |
187 | struct rocksdb_optimistictransactiondb_t { | |
188 | OptimisticTransactionDB* rep; | |
189 | }; | |
190 | struct rocksdb_optimistictransaction_options_t { | |
191 | OptimisticTransactionOptions rep; | |
192 | }; | |
7c673cae FG |
193 | |
194 | struct rocksdb_compactionfiltercontext_t { | |
195 | CompactionFilter::Context rep; | |
196 | }; | |
197 | ||
198 | struct rocksdb_compactionfilter_t : public CompactionFilter { | |
199 | void* state_; | |
200 | void (*destructor_)(void*); | |
201 | unsigned char (*filter_)( | |
202 | void*, | |
203 | int level, | |
204 | const char* key, size_t key_length, | |
205 | const char* existing_value, size_t value_length, | |
206 | char** new_value, size_t *new_value_length, | |
207 | unsigned char* value_changed); | |
208 | const char* (*name_)(void*); | |
209 | unsigned char ignore_snapshots_; | |
210 | ||
494da23a | 211 | ~rocksdb_compactionfilter_t() override { (*destructor_)(state_); } |
7c673cae | 212 | |
494da23a TL |
213 | bool Filter(int level, const Slice& key, const Slice& existing_value, |
214 | std::string* new_value, bool* value_changed) const override { | |
7c673cae FG |
215 | char* c_new_value = nullptr; |
216 | size_t new_value_length = 0; | |
217 | unsigned char c_value_changed = 0; | |
218 | unsigned char result = (*filter_)( | |
219 | state_, | |
220 | level, | |
221 | key.data(), key.size(), | |
222 | existing_value.data(), existing_value.size(), | |
223 | &c_new_value, &new_value_length, &c_value_changed); | |
224 | if (c_value_changed) { | |
225 | new_value->assign(c_new_value, new_value_length); | |
226 | *value_changed = true; | |
227 | } | |
228 | return result; | |
229 | } | |
230 | ||
494da23a | 231 | const char* Name() const override { return (*name_)(state_); } |
7c673cae | 232 | |
494da23a | 233 | bool IgnoreSnapshots() const override { return ignore_snapshots_; } |
7c673cae FG |
234 | }; |
235 | ||
236 | struct rocksdb_compactionfilterfactory_t : public CompactionFilterFactory { | |
237 | void* state_; | |
238 | void (*destructor_)(void*); | |
239 | rocksdb_compactionfilter_t* (*create_compaction_filter_)( | |
240 | void*, rocksdb_compactionfiltercontext_t* context); | |
241 | const char* (*name_)(void*); | |
242 | ||
494da23a | 243 | ~rocksdb_compactionfilterfactory_t() override { (*destructor_)(state_); } |
7c673cae | 244 | |
494da23a | 245 | std::unique_ptr<CompactionFilter> CreateCompactionFilter( |
7c673cae FG |
246 | const CompactionFilter::Context& context) override { |
247 | rocksdb_compactionfiltercontext_t ccontext; | |
248 | ccontext.rep = context; | |
249 | CompactionFilter* cf = (*create_compaction_filter_)(state_, &ccontext); | |
250 | return std::unique_ptr<CompactionFilter>(cf); | |
251 | } | |
252 | ||
494da23a | 253 | const char* Name() const override { return (*name_)(state_); } |
7c673cae FG |
254 | }; |
255 | ||
256 | struct rocksdb_comparator_t : public Comparator { | |
257 | void* state_; | |
258 | void (*destructor_)(void*); | |
259 | int (*compare_)( | |
260 | void*, | |
261 | const char* a, size_t alen, | |
262 | const char* b, size_t blen); | |
263 | const char* (*name_)(void*); | |
264 | ||
494da23a | 265 | ~rocksdb_comparator_t() override { (*destructor_)(state_); } |
7c673cae | 266 | |
494da23a | 267 | int Compare(const Slice& a, const Slice& b) const override { |
7c673cae FG |
268 | return (*compare_)(state_, a.data(), a.size(), b.data(), b.size()); |
269 | } | |
270 | ||
494da23a | 271 | const char* Name() const override { return (*name_)(state_); } |
7c673cae FG |
272 | |
273 | // No-ops since the C binding does not support key shortening methods. | |
494da23a TL |
274 | void FindShortestSeparator(std::string*, const Slice&) const override {} |
275 | void FindShortSuccessor(std::string* /*key*/) const override {} | |
7c673cae FG |
276 | }; |
277 | ||
278 | struct rocksdb_filterpolicy_t : public FilterPolicy { | |
279 | void* state_; | |
280 | void (*destructor_)(void*); | |
281 | const char* (*name_)(void*); | |
282 | char* (*create_)( | |
283 | void*, | |
284 | const char* const* key_array, const size_t* key_length_array, | |
285 | int num_keys, | |
286 | size_t* filter_length); | |
287 | unsigned char (*key_match_)( | |
288 | void*, | |
289 | const char* key, size_t length, | |
290 | const char* filter, size_t filter_length); | |
291 | void (*delete_filter_)( | |
292 | void*, | |
293 | const char* filter, size_t filter_length); | |
294 | ||
494da23a | 295 | ~rocksdb_filterpolicy_t() override { (*destructor_)(state_); } |
7c673cae | 296 | |
494da23a | 297 | const char* Name() const override { return (*name_)(state_); } |
7c673cae | 298 | |
494da23a | 299 | void CreateFilter(const Slice* keys, int n, std::string* dst) const override { |
7c673cae FG |
300 | std::vector<const char*> key_pointers(n); |
301 | std::vector<size_t> key_sizes(n); | |
302 | for (int i = 0; i < n; i++) { | |
303 | key_pointers[i] = keys[i].data(); | |
304 | key_sizes[i] = keys[i].size(); | |
305 | } | |
306 | size_t len; | |
307 | char* filter = (*create_)(state_, &key_pointers[0], &key_sizes[0], n, &len); | |
308 | dst->append(filter, len); | |
309 | ||
310 | if (delete_filter_ != nullptr) { | |
311 | (*delete_filter_)(state_, filter, len); | |
312 | } else { | |
313 | free(filter); | |
314 | } | |
315 | } | |
316 | ||
494da23a | 317 | bool KeyMayMatch(const Slice& key, const Slice& filter) const override { |
7c673cae FG |
318 | return (*key_match_)(state_, key.data(), key.size(), |
319 | filter.data(), filter.size()); | |
320 | } | |
321 | }; | |
322 | ||
323 | struct rocksdb_mergeoperator_t : public MergeOperator { | |
324 | void* state_; | |
325 | void (*destructor_)(void*); | |
326 | const char* (*name_)(void*); | |
327 | char* (*full_merge_)( | |
328 | void*, | |
329 | const char* key, size_t key_length, | |
330 | const char* existing_value, size_t existing_value_length, | |
331 | const char* const* operands_list, const size_t* operands_list_length, | |
332 | int num_operands, | |
333 | unsigned char* success, size_t* new_value_length); | |
334 | char* (*partial_merge_)(void*, const char* key, size_t key_length, | |
335 | const char* const* operands_list, | |
336 | const size_t* operands_list_length, int num_operands, | |
337 | unsigned char* success, size_t* new_value_length); | |
338 | void (*delete_value_)( | |
339 | void*, | |
340 | const char* value, size_t value_length); | |
341 | ||
494da23a | 342 | ~rocksdb_mergeoperator_t() override { (*destructor_)(state_); } |
7c673cae | 343 | |
494da23a | 344 | const char* Name() const override { return (*name_)(state_); } |
7c673cae | 345 | |
494da23a TL |
346 | bool FullMergeV2(const MergeOperationInput& merge_in, |
347 | MergeOperationOutput* merge_out) const override { | |
7c673cae FG |
348 | size_t n = merge_in.operand_list.size(); |
349 | std::vector<const char*> operand_pointers(n); | |
350 | std::vector<size_t> operand_sizes(n); | |
351 | for (size_t i = 0; i < n; i++) { | |
352 | Slice operand(merge_in.operand_list[i]); | |
353 | operand_pointers[i] = operand.data(); | |
354 | operand_sizes[i] = operand.size(); | |
355 | } | |
356 | ||
357 | const char* existing_value_data = nullptr; | |
358 | size_t existing_value_len = 0; | |
359 | if (merge_in.existing_value != nullptr) { | |
360 | existing_value_data = merge_in.existing_value->data(); | |
361 | existing_value_len = merge_in.existing_value->size(); | |
362 | } | |
363 | ||
364 | unsigned char success; | |
365 | size_t new_value_len; | |
366 | char* tmp_new_value = (*full_merge_)( | |
367 | state_, merge_in.key.data(), merge_in.key.size(), existing_value_data, | |
368 | existing_value_len, &operand_pointers[0], &operand_sizes[0], | |
369 | static_cast<int>(n), &success, &new_value_len); | |
370 | merge_out->new_value.assign(tmp_new_value, new_value_len); | |
371 | ||
372 | if (delete_value_ != nullptr) { | |
373 | (*delete_value_)(state_, tmp_new_value, new_value_len); | |
374 | } else { | |
375 | free(tmp_new_value); | |
376 | } | |
377 | ||
378 | return success; | |
379 | } | |
380 | ||
494da23a TL |
381 | bool PartialMergeMulti(const Slice& key, |
382 | const std::deque<Slice>& operand_list, | |
383 | std::string* new_value, | |
384 | Logger* /*logger*/) const override { | |
7c673cae FG |
385 | size_t operand_count = operand_list.size(); |
386 | std::vector<const char*> operand_pointers(operand_count); | |
387 | std::vector<size_t> operand_sizes(operand_count); | |
388 | for (size_t i = 0; i < operand_count; ++i) { | |
389 | Slice operand(operand_list[i]); | |
390 | operand_pointers[i] = operand.data(); | |
391 | operand_sizes[i] = operand.size(); | |
392 | } | |
393 | ||
394 | unsigned char success; | |
395 | size_t new_value_len; | |
396 | char* tmp_new_value = (*partial_merge_)( | |
397 | state_, key.data(), key.size(), &operand_pointers[0], &operand_sizes[0], | |
398 | static_cast<int>(operand_count), &success, &new_value_len); | |
399 | new_value->assign(tmp_new_value, new_value_len); | |
400 | ||
401 | if (delete_value_ != nullptr) { | |
402 | (*delete_value_)(state_, tmp_new_value, new_value_len); | |
403 | } else { | |
404 | free(tmp_new_value); | |
405 | } | |
406 | ||
407 | return success; | |
408 | } | |
409 | }; | |
410 | ||
11fdf7f2 TL |
411 | struct rocksdb_dbpath_t { |
412 | DbPath rep; | |
413 | }; | |
414 | ||
7c673cae FG |
415 | struct rocksdb_env_t { |
416 | Env* rep; | |
417 | bool is_default; | |
418 | }; | |
419 | ||
420 | struct rocksdb_slicetransform_t : public SliceTransform { | |
421 | void* state_; | |
422 | void (*destructor_)(void*); | |
423 | const char* (*name_)(void*); | |
424 | char* (*transform_)( | |
425 | void*, | |
426 | const char* key, size_t length, | |
427 | size_t* dst_length); | |
428 | unsigned char (*in_domain_)( | |
429 | void*, | |
430 | const char* key, size_t length); | |
431 | unsigned char (*in_range_)( | |
432 | void*, | |
433 | const char* key, size_t length); | |
434 | ||
494da23a | 435 | ~rocksdb_slicetransform_t() override { (*destructor_)(state_); } |
7c673cae | 436 | |
494da23a | 437 | const char* Name() const override { return (*name_)(state_); } |
7c673cae | 438 | |
494da23a | 439 | Slice Transform(const Slice& src) const override { |
7c673cae FG |
440 | size_t len; |
441 | char* dst = (*transform_)(state_, src.data(), src.size(), &len); | |
442 | return Slice(dst, len); | |
443 | } | |
444 | ||
494da23a | 445 | bool InDomain(const Slice& src) const override { |
7c673cae FG |
446 | return (*in_domain_)(state_, src.data(), src.size()); |
447 | } | |
448 | ||
494da23a | 449 | bool InRange(const Slice& src) const override { |
7c673cae FG |
450 | return (*in_range_)(state_, src.data(), src.size()); |
451 | } | |
452 | }; | |
453 | ||
454 | struct rocksdb_universal_compaction_options_t { | |
455 | rocksdb::CompactionOptionsUniversal *rep; | |
456 | }; | |
457 | ||
458 | static bool SaveError(char** errptr, const Status& s) { | |
459 | assert(errptr != nullptr); | |
460 | if (s.ok()) { | |
461 | return false; | |
462 | } else if (*errptr == nullptr) { | |
463 | *errptr = strdup(s.ToString().c_str()); | |
464 | } else { | |
465 | // TODO(sanjay): Merge with existing error? | |
466 | // This is a bug if *errptr is not created by malloc() | |
467 | free(*errptr); | |
468 | *errptr = strdup(s.ToString().c_str()); | |
469 | } | |
470 | return true; | |
471 | } | |
472 | ||
473 | static char* CopyString(const std::string& str) { | |
474 | char* result = reinterpret_cast<char*>(malloc(sizeof(char) * str.size())); | |
475 | memcpy(result, str.data(), sizeof(char) * str.size()); | |
476 | return result; | |
477 | } | |
478 | ||
479 | rocksdb_t* rocksdb_open( | |
480 | const rocksdb_options_t* options, | |
481 | const char* name, | |
482 | char** errptr) { | |
483 | DB* db; | |
484 | if (SaveError(errptr, DB::Open(options->rep, std::string(name), &db))) { | |
485 | return nullptr; | |
486 | } | |
487 | rocksdb_t* result = new rocksdb_t; | |
488 | result->rep = db; | |
489 | return result; | |
490 | } | |
491 | ||
11fdf7f2 TL |
492 | rocksdb_t* rocksdb_open_with_ttl( |
493 | const rocksdb_options_t* options, | |
494 | const char* name, | |
495 | int ttl, | |
496 | char** errptr) { | |
497 | rocksdb::DBWithTTL* db; | |
498 | if (SaveError(errptr, rocksdb::DBWithTTL::Open(options->rep, std::string(name), &db, ttl))) { | |
499 | return nullptr; | |
500 | } | |
501 | rocksdb_t* result = new rocksdb_t; | |
502 | result->rep = db; | |
503 | return result; | |
504 | } | |
505 | ||
7c673cae FG |
506 | rocksdb_t* rocksdb_open_for_read_only( |
507 | const rocksdb_options_t* options, | |
508 | const char* name, | |
509 | unsigned char error_if_log_file_exist, | |
510 | char** errptr) { | |
511 | DB* db; | |
512 | if (SaveError(errptr, DB::OpenForReadOnly(options->rep, std::string(name), &db, error_if_log_file_exist))) { | |
513 | return nullptr; | |
514 | } | |
515 | rocksdb_t* result = new rocksdb_t; | |
516 | result->rep = db; | |
517 | return result; | |
518 | } | |
519 | ||
520 | rocksdb_backup_engine_t* rocksdb_backup_engine_open( | |
521 | const rocksdb_options_t* options, const char* path, char** errptr) { | |
522 | BackupEngine* be; | |
523 | if (SaveError(errptr, BackupEngine::Open(options->rep.env, | |
524 | BackupableDBOptions(path, | |
525 | nullptr, | |
526 | true, | |
527 | options->rep.info_log.get()), | |
528 | &be))) { | |
529 | return nullptr; | |
530 | } | |
531 | rocksdb_backup_engine_t* result = new rocksdb_backup_engine_t; | |
532 | result->rep = be; | |
533 | return result; | |
534 | } | |
535 | ||
536 | void rocksdb_backup_engine_create_new_backup(rocksdb_backup_engine_t* be, | |
11fdf7f2 TL |
537 | rocksdb_t* db, |
538 | char** errptr) { | |
7c673cae FG |
539 | SaveError(errptr, be->rep->CreateNewBackup(db->rep)); |
540 | } | |
541 | ||
11fdf7f2 TL |
542 | void rocksdb_backup_engine_create_new_backup_flush(rocksdb_backup_engine_t* be, |
543 | rocksdb_t* db, | |
544 | unsigned char flush_before_backup, | |
545 | char** errptr) { | |
546 | SaveError(errptr, be->rep->CreateNewBackup(db->rep, flush_before_backup)); | |
547 | } | |
548 | ||
7c673cae FG |
549 | void rocksdb_backup_engine_purge_old_backups(rocksdb_backup_engine_t* be, |
550 | uint32_t num_backups_to_keep, | |
551 | char** errptr) { | |
552 | SaveError(errptr, be->rep->PurgeOldBackups(num_backups_to_keep)); | |
553 | } | |
554 | ||
555 | rocksdb_restore_options_t* rocksdb_restore_options_create() { | |
556 | return new rocksdb_restore_options_t; | |
557 | } | |
558 | ||
559 | void rocksdb_restore_options_destroy(rocksdb_restore_options_t* opt) { | |
560 | delete opt; | |
561 | } | |
562 | ||
563 | void rocksdb_restore_options_set_keep_log_files(rocksdb_restore_options_t* opt, | |
564 | int v) { | |
565 | opt->rep.keep_log_files = v; | |
566 | } | |
567 | ||
11fdf7f2 TL |
568 | |
569 | void rocksdb_backup_engine_verify_backup(rocksdb_backup_engine_t* be, | |
570 | uint32_t backup_id, char** errptr) { | |
571 | SaveError(errptr, be->rep->VerifyBackup(static_cast<BackupID>(backup_id))); | |
572 | } | |
573 | ||
7c673cae FG |
574 | void rocksdb_backup_engine_restore_db_from_latest_backup( |
575 | rocksdb_backup_engine_t* be, const char* db_dir, const char* wal_dir, | |
576 | const rocksdb_restore_options_t* restore_options, char** errptr) { | |
577 | SaveError(errptr, be->rep->RestoreDBFromLatestBackup(std::string(db_dir), | |
578 | std::string(wal_dir), | |
579 | restore_options->rep)); | |
580 | } | |
581 | ||
582 | const rocksdb_backup_engine_info_t* rocksdb_backup_engine_get_backup_info( | |
583 | rocksdb_backup_engine_t* be) { | |
584 | rocksdb_backup_engine_info_t* result = new rocksdb_backup_engine_info_t; | |
585 | be->rep->GetBackupInfo(&result->rep); | |
586 | return result; | |
587 | } | |
588 | ||
589 | int rocksdb_backup_engine_info_count(const rocksdb_backup_engine_info_t* info) { | |
590 | return static_cast<int>(info->rep.size()); | |
591 | } | |
592 | ||
593 | int64_t rocksdb_backup_engine_info_timestamp( | |
594 | const rocksdb_backup_engine_info_t* info, int index) { | |
595 | return info->rep[index].timestamp; | |
596 | } | |
597 | ||
598 | uint32_t rocksdb_backup_engine_info_backup_id( | |
599 | const rocksdb_backup_engine_info_t* info, int index) { | |
600 | return info->rep[index].backup_id; | |
601 | } | |
602 | ||
603 | uint64_t rocksdb_backup_engine_info_size( | |
604 | const rocksdb_backup_engine_info_t* info, int index) { | |
605 | return info->rep[index].size; | |
606 | } | |
607 | ||
608 | uint32_t rocksdb_backup_engine_info_number_files( | |
609 | const rocksdb_backup_engine_info_t* info, int index) { | |
610 | return info->rep[index].number_files; | |
611 | } | |
612 | ||
613 | void rocksdb_backup_engine_info_destroy( | |
614 | const rocksdb_backup_engine_info_t* info) { | |
615 | delete info; | |
616 | } | |
617 | ||
618 | void rocksdb_backup_engine_close(rocksdb_backup_engine_t* be) { | |
619 | delete be->rep; | |
620 | delete be; | |
621 | } | |
622 | ||
11fdf7f2 TL |
623 | rocksdb_checkpoint_t* rocksdb_checkpoint_object_create(rocksdb_t* db, |
624 | char** errptr) { | |
625 | Checkpoint* checkpoint; | |
626 | if (SaveError(errptr, Checkpoint::Create(db->rep, &checkpoint))) { | |
627 | return nullptr; | |
628 | } | |
629 | rocksdb_checkpoint_t* result = new rocksdb_checkpoint_t; | |
630 | result->rep = checkpoint; | |
631 | return result; | |
632 | } | |
633 | ||
634 | void rocksdb_checkpoint_create(rocksdb_checkpoint_t* checkpoint, | |
635 | const char* checkpoint_dir, | |
636 | uint64_t log_size_for_flush, char** errptr) { | |
637 | SaveError(errptr, checkpoint->rep->CreateCheckpoint( | |
638 | std::string(checkpoint_dir), log_size_for_flush)); | |
639 | } | |
640 | ||
641 | void rocksdb_checkpoint_object_destroy(rocksdb_checkpoint_t* checkpoint) { | |
642 | delete checkpoint->rep; | |
643 | delete checkpoint; | |
644 | } | |
645 | ||
7c673cae FG |
646 | void rocksdb_close(rocksdb_t* db) { |
647 | delete db->rep; | |
648 | delete db; | |
649 | } | |
650 | ||
651 | void rocksdb_options_set_uint64add_merge_operator(rocksdb_options_t* opt) { | |
652 | opt->rep.merge_operator = rocksdb::MergeOperators::CreateUInt64AddOperator(); | |
653 | } | |
654 | ||
655 | rocksdb_t* rocksdb_open_column_families( | |
656 | const rocksdb_options_t* db_options, | |
657 | const char* name, | |
658 | int num_column_families, | |
659 | const char** column_family_names, | |
660 | const rocksdb_options_t** column_family_options, | |
661 | rocksdb_column_family_handle_t** column_family_handles, | |
662 | char** errptr) { | |
663 | std::vector<ColumnFamilyDescriptor> column_families; | |
664 | for (int i = 0; i < num_column_families; i++) { | |
665 | column_families.push_back(ColumnFamilyDescriptor( | |
666 | std::string(column_family_names[i]), | |
667 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
668 | } | |
669 | ||
670 | DB* db; | |
671 | std::vector<ColumnFamilyHandle*> handles; | |
672 | if (SaveError(errptr, DB::Open(DBOptions(db_options->rep), | |
673 | std::string(name), column_families, &handles, &db))) { | |
674 | return nullptr; | |
675 | } | |
676 | ||
677 | for (size_t i = 0; i < handles.size(); i++) { | |
678 | rocksdb_column_family_handle_t* c_handle = new rocksdb_column_family_handle_t; | |
679 | c_handle->rep = handles[i]; | |
680 | column_family_handles[i] = c_handle; | |
681 | } | |
682 | rocksdb_t* result = new rocksdb_t; | |
683 | result->rep = db; | |
684 | return result; | |
685 | } | |
686 | ||
687 | rocksdb_t* rocksdb_open_for_read_only_column_families( | |
688 | const rocksdb_options_t* db_options, | |
689 | const char* name, | |
690 | int num_column_families, | |
691 | const char** column_family_names, | |
692 | const rocksdb_options_t** column_family_options, | |
693 | rocksdb_column_family_handle_t** column_family_handles, | |
694 | unsigned char error_if_log_file_exist, | |
695 | char** errptr) { | |
696 | std::vector<ColumnFamilyDescriptor> column_families; | |
697 | for (int i = 0; i < num_column_families; i++) { | |
698 | column_families.push_back(ColumnFamilyDescriptor( | |
699 | std::string(column_family_names[i]), | |
700 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
701 | } | |
702 | ||
703 | DB* db; | |
704 | std::vector<ColumnFamilyHandle*> handles; | |
705 | if (SaveError(errptr, DB::OpenForReadOnly(DBOptions(db_options->rep), | |
706 | std::string(name), column_families, &handles, &db, error_if_log_file_exist))) { | |
707 | return nullptr; | |
708 | } | |
709 | ||
710 | for (size_t i = 0; i < handles.size(); i++) { | |
711 | rocksdb_column_family_handle_t* c_handle = new rocksdb_column_family_handle_t; | |
712 | c_handle->rep = handles[i]; | |
713 | column_family_handles[i] = c_handle; | |
714 | } | |
715 | rocksdb_t* result = new rocksdb_t; | |
716 | result->rep = db; | |
717 | return result; | |
718 | } | |
719 | ||
720 | char** rocksdb_list_column_families( | |
721 | const rocksdb_options_t* options, | |
722 | const char* name, | |
723 | size_t* lencfs, | |
724 | char** errptr) { | |
725 | std::vector<std::string> fams; | |
726 | SaveError(errptr, | |
727 | DB::ListColumnFamilies(DBOptions(options->rep), | |
728 | std::string(name), &fams)); | |
729 | ||
730 | *lencfs = fams.size(); | |
731 | char** column_families = static_cast<char**>(malloc(sizeof(char*) * fams.size())); | |
732 | for (size_t i = 0; i < fams.size(); i++) { | |
733 | column_families[i] = strdup(fams[i].c_str()); | |
734 | } | |
735 | return column_families; | |
736 | } | |
737 | ||
738 | void rocksdb_list_column_families_destroy(char** list, size_t len) { | |
739 | for (size_t i = 0; i < len; ++i) { | |
740 | free(list[i]); | |
741 | } | |
742 | free(list); | |
743 | } | |
744 | ||
745 | rocksdb_column_family_handle_t* rocksdb_create_column_family( | |
746 | rocksdb_t* db, | |
747 | const rocksdb_options_t* column_family_options, | |
748 | const char* column_family_name, | |
749 | char** errptr) { | |
750 | rocksdb_column_family_handle_t* handle = new rocksdb_column_family_handle_t; | |
751 | SaveError(errptr, | |
752 | db->rep->CreateColumnFamily(ColumnFamilyOptions(column_family_options->rep), | |
753 | std::string(column_family_name), &(handle->rep))); | |
754 | return handle; | |
755 | } | |
756 | ||
757 | void rocksdb_drop_column_family( | |
758 | rocksdb_t* db, | |
759 | rocksdb_column_family_handle_t* handle, | |
760 | char** errptr) { | |
761 | SaveError(errptr, db->rep->DropColumnFamily(handle->rep)); | |
762 | } | |
763 | ||
764 | void rocksdb_column_family_handle_destroy(rocksdb_column_family_handle_t* handle) { | |
765 | delete handle->rep; | |
766 | delete handle; | |
767 | } | |
768 | ||
769 | void rocksdb_put( | |
770 | rocksdb_t* db, | |
771 | const rocksdb_writeoptions_t* options, | |
772 | const char* key, size_t keylen, | |
773 | const char* val, size_t vallen, | |
774 | char** errptr) { | |
775 | SaveError(errptr, | |
776 | db->rep->Put(options->rep, Slice(key, keylen), Slice(val, vallen))); | |
777 | } | |
778 | ||
779 | void rocksdb_put_cf( | |
780 | rocksdb_t* db, | |
781 | const rocksdb_writeoptions_t* options, | |
782 | rocksdb_column_family_handle_t* column_family, | |
783 | const char* key, size_t keylen, | |
784 | const char* val, size_t vallen, | |
785 | char** errptr) { | |
786 | SaveError(errptr, | |
787 | db->rep->Put(options->rep, column_family->rep, | |
788 | Slice(key, keylen), Slice(val, vallen))); | |
789 | } | |
790 | ||
791 | void rocksdb_delete( | |
792 | rocksdb_t* db, | |
793 | const rocksdb_writeoptions_t* options, | |
794 | const char* key, size_t keylen, | |
795 | char** errptr) { | |
796 | SaveError(errptr, db->rep->Delete(options->rep, Slice(key, keylen))); | |
797 | } | |
798 | ||
799 | void rocksdb_delete_cf( | |
800 | rocksdb_t* db, | |
801 | const rocksdb_writeoptions_t* options, | |
802 | rocksdb_column_family_handle_t* column_family, | |
803 | const char* key, size_t keylen, | |
804 | char** errptr) { | |
805 | SaveError(errptr, db->rep->Delete(options->rep, column_family->rep, | |
806 | Slice(key, keylen))); | |
807 | } | |
808 | ||
809 | void rocksdb_merge( | |
810 | rocksdb_t* db, | |
811 | const rocksdb_writeoptions_t* options, | |
812 | const char* key, size_t keylen, | |
813 | const char* val, size_t vallen, | |
814 | char** errptr) { | |
815 | SaveError(errptr, | |
816 | db->rep->Merge(options->rep, Slice(key, keylen), Slice(val, vallen))); | |
817 | } | |
818 | ||
819 | void rocksdb_merge_cf( | |
820 | rocksdb_t* db, | |
821 | const rocksdb_writeoptions_t* options, | |
822 | rocksdb_column_family_handle_t* column_family, | |
823 | const char* key, size_t keylen, | |
824 | const char* val, size_t vallen, | |
825 | char** errptr) { | |
826 | SaveError(errptr, | |
827 | db->rep->Merge(options->rep, column_family->rep, | |
828 | Slice(key, keylen), Slice(val, vallen))); | |
829 | } | |
830 | ||
831 | void rocksdb_write( | |
832 | rocksdb_t* db, | |
833 | const rocksdb_writeoptions_t* options, | |
834 | rocksdb_writebatch_t* batch, | |
835 | char** errptr) { | |
836 | SaveError(errptr, db->rep->Write(options->rep, &batch->rep)); | |
837 | } | |
838 | ||
839 | char* rocksdb_get( | |
840 | rocksdb_t* db, | |
841 | const rocksdb_readoptions_t* options, | |
842 | const char* key, size_t keylen, | |
843 | size_t* vallen, | |
844 | char** errptr) { | |
845 | char* result = nullptr; | |
846 | std::string tmp; | |
847 | Status s = db->rep->Get(options->rep, Slice(key, keylen), &tmp); | |
848 | if (s.ok()) { | |
849 | *vallen = tmp.size(); | |
850 | result = CopyString(tmp); | |
851 | } else { | |
852 | *vallen = 0; | |
853 | if (!s.IsNotFound()) { | |
854 | SaveError(errptr, s); | |
855 | } | |
856 | } | |
857 | return result; | |
858 | } | |
859 | ||
860 | char* rocksdb_get_cf( | |
861 | rocksdb_t* db, | |
862 | const rocksdb_readoptions_t* options, | |
863 | rocksdb_column_family_handle_t* column_family, | |
864 | const char* key, size_t keylen, | |
865 | size_t* vallen, | |
866 | char** errptr) { | |
867 | char* result = nullptr; | |
868 | std::string tmp; | |
869 | Status s = db->rep->Get(options->rep, column_family->rep, | |
870 | Slice(key, keylen), &tmp); | |
871 | if (s.ok()) { | |
872 | *vallen = tmp.size(); | |
873 | result = CopyString(tmp); | |
874 | } else { | |
875 | *vallen = 0; | |
876 | if (!s.IsNotFound()) { | |
877 | SaveError(errptr, s); | |
878 | } | |
879 | } | |
880 | return result; | |
881 | } | |
882 | ||
883 | void rocksdb_multi_get( | |
884 | rocksdb_t* db, | |
885 | const rocksdb_readoptions_t* options, | |
886 | size_t num_keys, const char* const* keys_list, | |
887 | const size_t* keys_list_sizes, | |
888 | char** values_list, size_t* values_list_sizes, | |
889 | char** errs) { | |
890 | std::vector<Slice> keys(num_keys); | |
891 | for (size_t i = 0; i < num_keys; i++) { | |
892 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
893 | } | |
894 | std::vector<std::string> values(num_keys); | |
895 | std::vector<Status> statuses = db->rep->MultiGet(options->rep, keys, &values); | |
896 | for (size_t i = 0; i < num_keys; i++) { | |
897 | if (statuses[i].ok()) { | |
898 | values_list[i] = CopyString(values[i]); | |
899 | values_list_sizes[i] = values[i].size(); | |
900 | errs[i] = nullptr; | |
901 | } else { | |
902 | values_list[i] = nullptr; | |
903 | values_list_sizes[i] = 0; | |
904 | if (!statuses[i].IsNotFound()) { | |
905 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
906 | } else { | |
907 | errs[i] = nullptr; | |
908 | } | |
909 | } | |
910 | } | |
911 | } | |
912 | ||
913 | void rocksdb_multi_get_cf( | |
914 | rocksdb_t* db, | |
915 | const rocksdb_readoptions_t* options, | |
916 | const rocksdb_column_family_handle_t* const* column_families, | |
917 | size_t num_keys, const char* const* keys_list, | |
918 | const size_t* keys_list_sizes, | |
919 | char** values_list, size_t* values_list_sizes, | |
920 | char** errs) { | |
921 | std::vector<Slice> keys(num_keys); | |
922 | std::vector<ColumnFamilyHandle*> cfs(num_keys); | |
923 | for (size_t i = 0; i < num_keys; i++) { | |
924 | keys[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
925 | cfs[i] = column_families[i]->rep; | |
926 | } | |
927 | std::vector<std::string> values(num_keys); | |
928 | std::vector<Status> statuses = db->rep->MultiGet(options->rep, cfs, keys, &values); | |
929 | for (size_t i = 0; i < num_keys; i++) { | |
930 | if (statuses[i].ok()) { | |
931 | values_list[i] = CopyString(values[i]); | |
932 | values_list_sizes[i] = values[i].size(); | |
933 | errs[i] = nullptr; | |
934 | } else { | |
935 | values_list[i] = nullptr; | |
936 | values_list_sizes[i] = 0; | |
937 | if (!statuses[i].IsNotFound()) { | |
938 | errs[i] = strdup(statuses[i].ToString().c_str()); | |
939 | } else { | |
940 | errs[i] = nullptr; | |
941 | } | |
942 | } | |
943 | } | |
944 | } | |
945 | ||
946 | rocksdb_iterator_t* rocksdb_create_iterator( | |
947 | rocksdb_t* db, | |
948 | const rocksdb_readoptions_t* options) { | |
949 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
950 | result->rep = db->rep->NewIterator(options->rep); | |
951 | return result; | |
952 | } | |
953 | ||
11fdf7f2 TL |
954 | rocksdb_wal_iterator_t* rocksdb_get_updates_since( |
955 | rocksdb_t* db, uint64_t seq_number, | |
956 | const rocksdb_wal_readoptions_t* options, | |
957 | char** errptr) { | |
958 | std::unique_ptr<TransactionLogIterator> iter; | |
959 | TransactionLogIterator::ReadOptions ro; | |
960 | if (options!=nullptr) { | |
961 | ro = options->rep; | |
962 | } | |
963 | if (SaveError(errptr, db->rep->GetUpdatesSince(seq_number, &iter, ro))) { | |
964 | return nullptr; | |
965 | } | |
966 | rocksdb_wal_iterator_t* result = new rocksdb_wal_iterator_t; | |
967 | result->rep = iter.release(); | |
968 | return result; | |
969 | } | |
970 | ||
971 | void rocksdb_wal_iter_next(rocksdb_wal_iterator_t* iter) { | |
972 | iter->rep->Next(); | |
973 | } | |
974 | ||
975 | unsigned char rocksdb_wal_iter_valid(const rocksdb_wal_iterator_t* iter) { | |
976 | return iter->rep->Valid(); | |
977 | } | |
978 | ||
979 | void rocksdb_wal_iter_status (const rocksdb_wal_iterator_t* iter, char** errptr) { | |
980 | SaveError(errptr, iter->rep->status()); | |
981 | } | |
982 | ||
983 | void rocksdb_wal_iter_destroy (const rocksdb_wal_iterator_t* iter) { | |
984 | delete iter->rep; | |
985 | delete iter; | |
986 | } | |
987 | ||
988 | rocksdb_writebatch_t* rocksdb_wal_iter_get_batch (const rocksdb_wal_iterator_t* iter, uint64_t* seq) { | |
989 | rocksdb_writebatch_t* result = rocksdb_writebatch_create(); | |
990 | BatchResult wal_batch = iter->rep->GetBatch(); | |
991 | result->rep = * wal_batch.writeBatchPtr.release(); | |
992 | if (seq != nullptr) { | |
993 | *seq = wal_batch.sequence; | |
994 | } | |
995 | return result; | |
996 | } | |
997 | ||
998 | uint64_t rocksdb_get_latest_sequence_number (rocksdb_t *db) { | |
999 | return db->rep->GetLatestSequenceNumber(); | |
1000 | } | |
1001 | ||
7c673cae FG |
1002 | rocksdb_iterator_t* rocksdb_create_iterator_cf( |
1003 | rocksdb_t* db, | |
1004 | const rocksdb_readoptions_t* options, | |
1005 | rocksdb_column_family_handle_t* column_family) { | |
1006 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
1007 | result->rep = db->rep->NewIterator(options->rep, column_family->rep); | |
1008 | return result; | |
1009 | } | |
1010 | ||
1011 | void rocksdb_create_iterators( | |
1012 | rocksdb_t *db, | |
1013 | rocksdb_readoptions_t* opts, | |
1014 | rocksdb_column_family_handle_t** column_families, | |
1015 | rocksdb_iterator_t** iterators, | |
1016 | size_t size, | |
1017 | char** errptr) { | |
1018 | std::vector<ColumnFamilyHandle*> column_families_vec; | |
1019 | for (size_t i = 0; i < size; i++) { | |
1020 | column_families_vec.push_back(column_families[i]->rep); | |
1021 | } | |
1022 | ||
1023 | std::vector<Iterator*> res; | |
1024 | Status status = db->rep->NewIterators(opts->rep, column_families_vec, &res); | |
1025 | assert(res.size() == size); | |
1026 | if (SaveError(errptr, status)) { | |
1027 | return; | |
1028 | } | |
1029 | ||
1030 | for (size_t i = 0; i < size; i++) { | |
1031 | iterators[i] = new rocksdb_iterator_t; | |
1032 | iterators[i]->rep = res[i]; | |
1033 | } | |
1034 | } | |
1035 | ||
1036 | const rocksdb_snapshot_t* rocksdb_create_snapshot( | |
1037 | rocksdb_t* db) { | |
1038 | rocksdb_snapshot_t* result = new rocksdb_snapshot_t; | |
1039 | result->rep = db->rep->GetSnapshot(); | |
1040 | return result; | |
1041 | } | |
1042 | ||
1043 | void rocksdb_release_snapshot( | |
1044 | rocksdb_t* db, | |
1045 | const rocksdb_snapshot_t* snapshot) { | |
1046 | db->rep->ReleaseSnapshot(snapshot->rep); | |
1047 | delete snapshot; | |
1048 | } | |
1049 | ||
1050 | char* rocksdb_property_value( | |
1051 | rocksdb_t* db, | |
1052 | const char* propname) { | |
1053 | std::string tmp; | |
1054 | if (db->rep->GetProperty(Slice(propname), &tmp)) { | |
1055 | // We use strdup() since we expect human readable output. | |
1056 | return strdup(tmp.c_str()); | |
1057 | } else { | |
1058 | return nullptr; | |
1059 | } | |
1060 | } | |
1061 | ||
1062 | int rocksdb_property_int( | |
1063 | rocksdb_t* db, | |
1064 | const char* propname, | |
1065 | uint64_t *out_val) { | |
1066 | if (db->rep->GetIntProperty(Slice(propname), out_val)) { | |
1067 | return 0; | |
1068 | } else { | |
1069 | return -1; | |
1070 | } | |
1071 | } | |
1072 | ||
1073 | char* rocksdb_property_value_cf( | |
1074 | rocksdb_t* db, | |
1075 | rocksdb_column_family_handle_t* column_family, | |
1076 | const char* propname) { | |
1077 | std::string tmp; | |
1078 | if (db->rep->GetProperty(column_family->rep, Slice(propname), &tmp)) { | |
1079 | // We use strdup() since we expect human readable output. | |
1080 | return strdup(tmp.c_str()); | |
1081 | } else { | |
1082 | return nullptr; | |
1083 | } | |
1084 | } | |
1085 | ||
1086 | void rocksdb_approximate_sizes( | |
1087 | rocksdb_t* db, | |
1088 | int num_ranges, | |
1089 | const char* const* range_start_key, const size_t* range_start_key_len, | |
1090 | const char* const* range_limit_key, const size_t* range_limit_key_len, | |
1091 | uint64_t* sizes) { | |
1092 | Range* ranges = new Range[num_ranges]; | |
1093 | for (int i = 0; i < num_ranges; i++) { | |
1094 | ranges[i].start = Slice(range_start_key[i], range_start_key_len[i]); | |
1095 | ranges[i].limit = Slice(range_limit_key[i], range_limit_key_len[i]); | |
1096 | } | |
1097 | db->rep->GetApproximateSizes(ranges, num_ranges, sizes); | |
1098 | delete[] ranges; | |
1099 | } | |
1100 | ||
1101 | void rocksdb_approximate_sizes_cf( | |
1102 | rocksdb_t* db, | |
1103 | rocksdb_column_family_handle_t* column_family, | |
1104 | int num_ranges, | |
1105 | const char* const* range_start_key, const size_t* range_start_key_len, | |
1106 | const char* const* range_limit_key, const size_t* range_limit_key_len, | |
1107 | uint64_t* sizes) { | |
1108 | Range* ranges = new Range[num_ranges]; | |
1109 | for (int i = 0; i < num_ranges; i++) { | |
1110 | ranges[i].start = Slice(range_start_key[i], range_start_key_len[i]); | |
1111 | ranges[i].limit = Slice(range_limit_key[i], range_limit_key_len[i]); | |
1112 | } | |
1113 | db->rep->GetApproximateSizes(column_family->rep, ranges, num_ranges, sizes); | |
1114 | delete[] ranges; | |
1115 | } | |
1116 | ||
1117 | void rocksdb_delete_file( | |
1118 | rocksdb_t* db, | |
1119 | const char* name) { | |
1120 | db->rep->DeleteFile(name); | |
1121 | } | |
1122 | ||
1123 | const rocksdb_livefiles_t* rocksdb_livefiles( | |
1124 | rocksdb_t* db) { | |
1125 | rocksdb_livefiles_t* result = new rocksdb_livefiles_t; | |
1126 | db->rep->GetLiveFilesMetaData(&result->rep); | |
1127 | return result; | |
1128 | } | |
1129 | ||
1130 | void rocksdb_compact_range( | |
1131 | rocksdb_t* db, | |
1132 | const char* start_key, size_t start_key_len, | |
1133 | const char* limit_key, size_t limit_key_len) { | |
1134 | Slice a, b; | |
1135 | db->rep->CompactRange( | |
1136 | CompactRangeOptions(), | |
1137 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1138 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1139 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1140 | } | |
1141 | ||
1142 | void rocksdb_compact_range_cf( | |
1143 | rocksdb_t* db, | |
1144 | rocksdb_column_family_handle_t* column_family, | |
1145 | const char* start_key, size_t start_key_len, | |
1146 | const char* limit_key, size_t limit_key_len) { | |
1147 | Slice a, b; | |
1148 | db->rep->CompactRange( | |
1149 | CompactRangeOptions(), column_family->rep, | |
1150 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1151 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1152 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1153 | } | |
1154 | ||
1155 | void rocksdb_compact_range_opt(rocksdb_t* db, rocksdb_compactoptions_t* opt, | |
1156 | const char* start_key, size_t start_key_len, | |
1157 | const char* limit_key, size_t limit_key_len) { | |
1158 | Slice a, b; | |
1159 | db->rep->CompactRange( | |
1160 | opt->rep, | |
1161 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1162 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1163 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1164 | } | |
1165 | ||
1166 | void rocksdb_compact_range_cf_opt(rocksdb_t* db, | |
1167 | rocksdb_column_family_handle_t* column_family, | |
1168 | rocksdb_compactoptions_t* opt, | |
1169 | const char* start_key, size_t start_key_len, | |
1170 | const char* limit_key, size_t limit_key_len) { | |
1171 | Slice a, b; | |
1172 | db->rep->CompactRange( | |
1173 | opt->rep, column_family->rep, | |
1174 | // Pass nullptr Slice if corresponding "const char*" is nullptr | |
1175 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
1176 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); | |
1177 | } | |
1178 | ||
1179 | void rocksdb_flush( | |
1180 | rocksdb_t* db, | |
1181 | const rocksdb_flushoptions_t* options, | |
1182 | char** errptr) { | |
1183 | SaveError(errptr, db->rep->Flush(options->rep)); | |
1184 | } | |
1185 | ||
1186 | void rocksdb_disable_file_deletions( | |
1187 | rocksdb_t* db, | |
1188 | char** errptr) { | |
1189 | SaveError(errptr, db->rep->DisableFileDeletions()); | |
1190 | } | |
1191 | ||
1192 | void rocksdb_enable_file_deletions( | |
1193 | rocksdb_t* db, | |
1194 | unsigned char force, | |
1195 | char** errptr) { | |
1196 | SaveError(errptr, db->rep->EnableFileDeletions(force)); | |
1197 | } | |
1198 | ||
1199 | void rocksdb_destroy_db( | |
1200 | const rocksdb_options_t* options, | |
1201 | const char* name, | |
1202 | char** errptr) { | |
1203 | SaveError(errptr, DestroyDB(name, options->rep)); | |
1204 | } | |
1205 | ||
1206 | void rocksdb_repair_db( | |
1207 | const rocksdb_options_t* options, | |
1208 | const char* name, | |
1209 | char** errptr) { | |
1210 | SaveError(errptr, RepairDB(name, options->rep)); | |
1211 | } | |
1212 | ||
1213 | void rocksdb_iter_destroy(rocksdb_iterator_t* iter) { | |
1214 | delete iter->rep; | |
1215 | delete iter; | |
1216 | } | |
1217 | ||
1218 | unsigned char rocksdb_iter_valid(const rocksdb_iterator_t* iter) { | |
1219 | return iter->rep->Valid(); | |
1220 | } | |
1221 | ||
1222 | void rocksdb_iter_seek_to_first(rocksdb_iterator_t* iter) { | |
1223 | iter->rep->SeekToFirst(); | |
1224 | } | |
1225 | ||
1226 | void rocksdb_iter_seek_to_last(rocksdb_iterator_t* iter) { | |
1227 | iter->rep->SeekToLast(); | |
1228 | } | |
1229 | ||
1230 | void rocksdb_iter_seek(rocksdb_iterator_t* iter, const char* k, size_t klen) { | |
1231 | iter->rep->Seek(Slice(k, klen)); | |
1232 | } | |
1233 | ||
1234 | void rocksdb_iter_seek_for_prev(rocksdb_iterator_t* iter, const char* k, | |
1235 | size_t klen) { | |
1236 | iter->rep->SeekForPrev(Slice(k, klen)); | |
1237 | } | |
1238 | ||
1239 | void rocksdb_iter_next(rocksdb_iterator_t* iter) { | |
1240 | iter->rep->Next(); | |
1241 | } | |
1242 | ||
1243 | void rocksdb_iter_prev(rocksdb_iterator_t* iter) { | |
1244 | iter->rep->Prev(); | |
1245 | } | |
1246 | ||
1247 | const char* rocksdb_iter_key(const rocksdb_iterator_t* iter, size_t* klen) { | |
1248 | Slice s = iter->rep->key(); | |
1249 | *klen = s.size(); | |
1250 | return s.data(); | |
1251 | } | |
1252 | ||
1253 | const char* rocksdb_iter_value(const rocksdb_iterator_t* iter, size_t* vlen) { | |
1254 | Slice s = iter->rep->value(); | |
1255 | *vlen = s.size(); | |
1256 | return s.data(); | |
1257 | } | |
1258 | ||
1259 | void rocksdb_iter_get_error(const rocksdb_iterator_t* iter, char** errptr) { | |
1260 | SaveError(errptr, iter->rep->status()); | |
1261 | } | |
1262 | ||
1263 | rocksdb_writebatch_t* rocksdb_writebatch_create() { | |
1264 | return new rocksdb_writebatch_t; | |
1265 | } | |
1266 | ||
1267 | rocksdb_writebatch_t* rocksdb_writebatch_create_from(const char* rep, | |
1268 | size_t size) { | |
1269 | rocksdb_writebatch_t* b = new rocksdb_writebatch_t; | |
1270 | b->rep = WriteBatch(std::string(rep, size)); | |
1271 | return b; | |
1272 | } | |
1273 | ||
1274 | void rocksdb_writebatch_destroy(rocksdb_writebatch_t* b) { | |
1275 | delete b; | |
1276 | } | |
1277 | ||
1278 | void rocksdb_writebatch_clear(rocksdb_writebatch_t* b) { | |
1279 | b->rep.Clear(); | |
1280 | } | |
1281 | ||
1282 | int rocksdb_writebatch_count(rocksdb_writebatch_t* b) { | |
1283 | return b->rep.Count(); | |
1284 | } | |
1285 | ||
1286 | void rocksdb_writebatch_put( | |
1287 | rocksdb_writebatch_t* b, | |
1288 | const char* key, size_t klen, | |
1289 | const char* val, size_t vlen) { | |
1290 | b->rep.Put(Slice(key, klen), Slice(val, vlen)); | |
1291 | } | |
1292 | ||
1293 | void rocksdb_writebatch_put_cf( | |
1294 | rocksdb_writebatch_t* b, | |
1295 | rocksdb_column_family_handle_t* column_family, | |
1296 | const char* key, size_t klen, | |
1297 | const char* val, size_t vlen) { | |
1298 | b->rep.Put(column_family->rep, Slice(key, klen), Slice(val, vlen)); | |
1299 | } | |
1300 | ||
1301 | void rocksdb_writebatch_putv( | |
1302 | rocksdb_writebatch_t* b, | |
1303 | int num_keys, const char* const* keys_list, | |
1304 | const size_t* keys_list_sizes, | |
1305 | int num_values, const char* const* values_list, | |
1306 | const size_t* values_list_sizes) { | |
1307 | std::vector<Slice> key_slices(num_keys); | |
1308 | for (int i = 0; i < num_keys; i++) { | |
1309 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1310 | } | |
1311 | std::vector<Slice> value_slices(num_values); | |
1312 | for (int i = 0; i < num_values; i++) { | |
1313 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1314 | } | |
1315 | b->rep.Put(SliceParts(key_slices.data(), num_keys), | |
1316 | SliceParts(value_slices.data(), num_values)); | |
1317 | } | |
1318 | ||
1319 | void rocksdb_writebatch_putv_cf( | |
1320 | rocksdb_writebatch_t* b, | |
1321 | rocksdb_column_family_handle_t* column_family, | |
1322 | int num_keys, const char* const* keys_list, | |
1323 | const size_t* keys_list_sizes, | |
1324 | int num_values, const char* const* values_list, | |
1325 | const size_t* values_list_sizes) { | |
1326 | std::vector<Slice> key_slices(num_keys); | |
1327 | for (int i = 0; i < num_keys; i++) { | |
1328 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1329 | } | |
1330 | std::vector<Slice> value_slices(num_values); | |
1331 | for (int i = 0; i < num_values; i++) { | |
1332 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1333 | } | |
1334 | b->rep.Put(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
1335 | SliceParts(value_slices.data(), num_values)); | |
1336 | } | |
1337 | ||
1338 | void rocksdb_writebatch_merge( | |
1339 | rocksdb_writebatch_t* b, | |
1340 | const char* key, size_t klen, | |
1341 | const char* val, size_t vlen) { | |
1342 | b->rep.Merge(Slice(key, klen), Slice(val, vlen)); | |
1343 | } | |
1344 | ||
1345 | void rocksdb_writebatch_merge_cf( | |
1346 | rocksdb_writebatch_t* b, | |
1347 | rocksdb_column_family_handle_t* column_family, | |
1348 | const char* key, size_t klen, | |
1349 | const char* val, size_t vlen) { | |
1350 | b->rep.Merge(column_family->rep, Slice(key, klen), Slice(val, vlen)); | |
1351 | } | |
1352 | ||
1353 | void rocksdb_writebatch_mergev( | |
1354 | rocksdb_writebatch_t* b, | |
1355 | int num_keys, const char* const* keys_list, | |
1356 | const size_t* keys_list_sizes, | |
1357 | int num_values, const char* const* values_list, | |
1358 | const size_t* values_list_sizes) { | |
1359 | std::vector<Slice> key_slices(num_keys); | |
1360 | for (int i = 0; i < num_keys; i++) { | |
1361 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1362 | } | |
1363 | std::vector<Slice> value_slices(num_values); | |
1364 | for (int i = 0; i < num_values; i++) { | |
1365 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1366 | } | |
1367 | b->rep.Merge(SliceParts(key_slices.data(), num_keys), | |
1368 | SliceParts(value_slices.data(), num_values)); | |
1369 | } | |
1370 | ||
1371 | void rocksdb_writebatch_mergev_cf( | |
1372 | rocksdb_writebatch_t* b, | |
1373 | rocksdb_column_family_handle_t* column_family, | |
1374 | int num_keys, const char* const* keys_list, | |
1375 | const size_t* keys_list_sizes, | |
1376 | int num_values, const char* const* values_list, | |
1377 | const size_t* values_list_sizes) { | |
1378 | std::vector<Slice> key_slices(num_keys); | |
1379 | for (int i = 0; i < num_keys; i++) { | |
1380 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1381 | } | |
1382 | std::vector<Slice> value_slices(num_values); | |
1383 | for (int i = 0; i < num_values; i++) { | |
1384 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1385 | } | |
1386 | b->rep.Merge(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
1387 | SliceParts(value_slices.data(), num_values)); | |
1388 | } | |
1389 | ||
1390 | void rocksdb_writebatch_delete( | |
1391 | rocksdb_writebatch_t* b, | |
1392 | const char* key, size_t klen) { | |
1393 | b->rep.Delete(Slice(key, klen)); | |
1394 | } | |
1395 | ||
1396 | void rocksdb_writebatch_delete_cf( | |
1397 | rocksdb_writebatch_t* b, | |
1398 | rocksdb_column_family_handle_t* column_family, | |
1399 | const char* key, size_t klen) { | |
1400 | b->rep.Delete(column_family->rep, Slice(key, klen)); | |
1401 | } | |
1402 | ||
1403 | void rocksdb_writebatch_deletev( | |
1404 | rocksdb_writebatch_t* b, | |
1405 | int num_keys, const char* const* keys_list, | |
1406 | const size_t* keys_list_sizes) { | |
1407 | std::vector<Slice> key_slices(num_keys); | |
1408 | for (int i = 0; i < num_keys; i++) { | |
1409 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1410 | } | |
1411 | b->rep.Delete(SliceParts(key_slices.data(), num_keys)); | |
1412 | } | |
1413 | ||
1414 | void rocksdb_writebatch_deletev_cf( | |
1415 | rocksdb_writebatch_t* b, | |
1416 | rocksdb_column_family_handle_t* column_family, | |
1417 | int num_keys, const char* const* keys_list, | |
1418 | const size_t* keys_list_sizes) { | |
1419 | std::vector<Slice> key_slices(num_keys); | |
1420 | for (int i = 0; i < num_keys; i++) { | |
1421 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1422 | } | |
1423 | b->rep.Delete(column_family->rep, SliceParts(key_slices.data(), num_keys)); | |
1424 | } | |
1425 | ||
1426 | void rocksdb_writebatch_delete_range(rocksdb_writebatch_t* b, | |
1427 | const char* start_key, | |
1428 | size_t start_key_len, const char* end_key, | |
1429 | size_t end_key_len) { | |
1430 | b->rep.DeleteRange(Slice(start_key, start_key_len), | |
1431 | Slice(end_key, end_key_len)); | |
1432 | } | |
1433 | ||
1434 | void rocksdb_writebatch_delete_range_cf( | |
1435 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
1436 | const char* start_key, size_t start_key_len, const char* end_key, | |
1437 | size_t end_key_len) { | |
1438 | b->rep.DeleteRange(column_family->rep, Slice(start_key, start_key_len), | |
1439 | Slice(end_key, end_key_len)); | |
1440 | } | |
1441 | ||
1442 | void rocksdb_writebatch_delete_rangev(rocksdb_writebatch_t* b, int num_keys, | |
1443 | const char* const* start_keys_list, | |
1444 | const size_t* start_keys_list_sizes, | |
1445 | const char* const* end_keys_list, | |
1446 | const size_t* end_keys_list_sizes) { | |
1447 | std::vector<Slice> start_key_slices(num_keys); | |
1448 | std::vector<Slice> end_key_slices(num_keys); | |
1449 | for (int i = 0; i < num_keys; i++) { | |
1450 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
1451 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
1452 | } | |
1453 | b->rep.DeleteRange(SliceParts(start_key_slices.data(), num_keys), | |
1454 | SliceParts(end_key_slices.data(), num_keys)); | |
1455 | } | |
1456 | ||
1457 | void rocksdb_writebatch_delete_rangev_cf( | |
1458 | rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, | |
1459 | int num_keys, const char* const* start_keys_list, | |
1460 | const size_t* start_keys_list_sizes, const char* const* end_keys_list, | |
1461 | const size_t* end_keys_list_sizes) { | |
1462 | std::vector<Slice> start_key_slices(num_keys); | |
1463 | std::vector<Slice> end_key_slices(num_keys); | |
1464 | for (int i = 0; i < num_keys; i++) { | |
1465 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
1466 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
1467 | } | |
1468 | b->rep.DeleteRange(column_family->rep, | |
1469 | SliceParts(start_key_slices.data(), num_keys), | |
1470 | SliceParts(end_key_slices.data(), num_keys)); | |
1471 | } | |
1472 | ||
1473 | void rocksdb_writebatch_put_log_data( | |
1474 | rocksdb_writebatch_t* b, | |
1475 | const char* blob, size_t len) { | |
1476 | b->rep.PutLogData(Slice(blob, len)); | |
1477 | } | |
1478 | ||
11fdf7f2 TL |
1479 | class H : public WriteBatch::Handler { |
1480 | public: | |
1481 | void* state_; | |
1482 | void (*put_)(void*, const char* k, size_t klen, const char* v, size_t vlen); | |
1483 | void (*deleted_)(void*, const char* k, size_t klen); | |
494da23a | 1484 | void Put(const Slice& key, const Slice& value) override { |
11fdf7f2 TL |
1485 | (*put_)(state_, key.data(), key.size(), value.data(), value.size()); |
1486 | } | |
494da23a | 1487 | void Delete(const Slice& key) override { |
11fdf7f2 TL |
1488 | (*deleted_)(state_, key.data(), key.size()); |
1489 | } | |
1490 | }; | |
1491 | ||
7c673cae FG |
1492 | void rocksdb_writebatch_iterate( |
1493 | rocksdb_writebatch_t* b, | |
1494 | void* state, | |
1495 | void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), | |
1496 | void (*deleted)(void*, const char* k, size_t klen)) { | |
7c673cae FG |
1497 | H handler; |
1498 | handler.state_ = state; | |
1499 | handler.put_ = put; | |
1500 | handler.deleted_ = deleted; | |
1501 | b->rep.Iterate(&handler); | |
1502 | } | |
1503 | ||
1504 | const char* rocksdb_writebatch_data(rocksdb_writebatch_t* b, size_t* size) { | |
1505 | *size = b->rep.GetDataSize(); | |
1506 | return b->rep.Data().c_str(); | |
1507 | } | |
1508 | ||
1509 | void rocksdb_writebatch_set_save_point(rocksdb_writebatch_t* b) { | |
1510 | b->rep.SetSavePoint(); | |
1511 | } | |
1512 | ||
1513 | void rocksdb_writebatch_rollback_to_save_point(rocksdb_writebatch_t* b, | |
1514 | char** errptr) { | |
1515 | SaveError(errptr, b->rep.RollbackToSavePoint()); | |
1516 | } | |
1517 | ||
11fdf7f2 TL |
1518 | void rocksdb_writebatch_pop_save_point(rocksdb_writebatch_t* b, char** errptr) { |
1519 | SaveError(errptr, b->rep.PopSavePoint()); | |
1520 | } | |
1521 | ||
7c673cae FG |
1522 | rocksdb_writebatch_wi_t* rocksdb_writebatch_wi_create(size_t reserved_bytes, unsigned char overwrite_key) { |
1523 | rocksdb_writebatch_wi_t* b = new rocksdb_writebatch_wi_t; | |
1524 | b->rep = new WriteBatchWithIndex(BytewiseComparator(), reserved_bytes, overwrite_key); | |
1525 | return b; | |
1526 | } | |
1527 | ||
1528 | void rocksdb_writebatch_wi_destroy(rocksdb_writebatch_wi_t* b) { | |
1529 | if (b->rep) { | |
1530 | delete b->rep; | |
1531 | } | |
1532 | delete b; | |
1533 | } | |
1534 | ||
1535 | void rocksdb_writebatch_wi_clear(rocksdb_writebatch_wi_t* b) { | |
1536 | b->rep->Clear(); | |
1537 | } | |
1538 | ||
1539 | int rocksdb_writebatch_wi_count(rocksdb_writebatch_wi_t* b) { | |
1540 | return b->rep->GetWriteBatch()->Count(); | |
1541 | } | |
1542 | ||
1543 | void rocksdb_writebatch_wi_put( | |
1544 | rocksdb_writebatch_wi_t* b, | |
1545 | const char* key, size_t klen, | |
1546 | const char* val, size_t vlen) { | |
1547 | b->rep->Put(Slice(key, klen), Slice(val, vlen)); | |
1548 | } | |
1549 | ||
1550 | void rocksdb_writebatch_wi_put_cf( | |
1551 | rocksdb_writebatch_wi_t* b, | |
1552 | rocksdb_column_family_handle_t* column_family, | |
1553 | const char* key, size_t klen, | |
1554 | const char* val, size_t vlen) { | |
1555 | b->rep->Put(column_family->rep, Slice(key, klen), Slice(val, vlen)); | |
1556 | } | |
1557 | ||
1558 | void rocksdb_writebatch_wi_putv( | |
1559 | rocksdb_writebatch_wi_t* b, | |
1560 | int num_keys, const char* const* keys_list, | |
1561 | const size_t* keys_list_sizes, | |
1562 | int num_values, const char* const* values_list, | |
1563 | const size_t* values_list_sizes) { | |
1564 | std::vector<Slice> key_slices(num_keys); | |
1565 | for (int i = 0; i < num_keys; i++) { | |
1566 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1567 | } | |
1568 | std::vector<Slice> value_slices(num_values); | |
1569 | for (int i = 0; i < num_values; i++) { | |
1570 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1571 | } | |
1572 | b->rep->Put(SliceParts(key_slices.data(), num_keys), | |
1573 | SliceParts(value_slices.data(), num_values)); | |
1574 | } | |
1575 | ||
1576 | void rocksdb_writebatch_wi_putv_cf( | |
1577 | rocksdb_writebatch_wi_t* b, | |
1578 | rocksdb_column_family_handle_t* column_family, | |
1579 | int num_keys, const char* const* keys_list, | |
1580 | const size_t* keys_list_sizes, | |
1581 | int num_values, const char* const* values_list, | |
1582 | const size_t* values_list_sizes) { | |
1583 | std::vector<Slice> key_slices(num_keys); | |
1584 | for (int i = 0; i < num_keys; i++) { | |
1585 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1586 | } | |
1587 | std::vector<Slice> value_slices(num_values); | |
1588 | for (int i = 0; i < num_values; i++) { | |
1589 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1590 | } | |
1591 | b->rep->Put(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
1592 | SliceParts(value_slices.data(), num_values)); | |
1593 | } | |
1594 | ||
1595 | void rocksdb_writebatch_wi_merge( | |
1596 | rocksdb_writebatch_wi_t* b, | |
1597 | const char* key, size_t klen, | |
1598 | const char* val, size_t vlen) { | |
1599 | b->rep->Merge(Slice(key, klen), Slice(val, vlen)); | |
1600 | } | |
1601 | ||
1602 | void rocksdb_writebatch_wi_merge_cf( | |
1603 | rocksdb_writebatch_wi_t* b, | |
1604 | rocksdb_column_family_handle_t* column_family, | |
1605 | const char* key, size_t klen, | |
1606 | const char* val, size_t vlen) { | |
1607 | b->rep->Merge(column_family->rep, Slice(key, klen), Slice(val, vlen)); | |
1608 | } | |
1609 | ||
1610 | void rocksdb_writebatch_wi_mergev( | |
1611 | rocksdb_writebatch_wi_t* b, | |
1612 | int num_keys, const char* const* keys_list, | |
1613 | const size_t* keys_list_sizes, | |
1614 | int num_values, const char* const* values_list, | |
1615 | const size_t* values_list_sizes) { | |
1616 | std::vector<Slice> key_slices(num_keys); | |
1617 | for (int i = 0; i < num_keys; i++) { | |
1618 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1619 | } | |
1620 | std::vector<Slice> value_slices(num_values); | |
1621 | for (int i = 0; i < num_values; i++) { | |
1622 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1623 | } | |
1624 | b->rep->Merge(SliceParts(key_slices.data(), num_keys), | |
1625 | SliceParts(value_slices.data(), num_values)); | |
1626 | } | |
1627 | ||
1628 | void rocksdb_writebatch_wi_mergev_cf( | |
1629 | rocksdb_writebatch_wi_t* b, | |
1630 | rocksdb_column_family_handle_t* column_family, | |
1631 | int num_keys, const char* const* keys_list, | |
1632 | const size_t* keys_list_sizes, | |
1633 | int num_values, const char* const* values_list, | |
1634 | const size_t* values_list_sizes) { | |
1635 | std::vector<Slice> key_slices(num_keys); | |
1636 | for (int i = 0; i < num_keys; i++) { | |
1637 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1638 | } | |
1639 | std::vector<Slice> value_slices(num_values); | |
1640 | for (int i = 0; i < num_values; i++) { | |
1641 | value_slices[i] = Slice(values_list[i], values_list_sizes[i]); | |
1642 | } | |
1643 | b->rep->Merge(column_family->rep, SliceParts(key_slices.data(), num_keys), | |
1644 | SliceParts(value_slices.data(), num_values)); | |
1645 | } | |
1646 | ||
1647 | void rocksdb_writebatch_wi_delete( | |
1648 | rocksdb_writebatch_wi_t* b, | |
1649 | const char* key, size_t klen) { | |
1650 | b->rep->Delete(Slice(key, klen)); | |
1651 | } | |
1652 | ||
1653 | void rocksdb_writebatch_wi_delete_cf( | |
1654 | rocksdb_writebatch_wi_t* b, | |
1655 | rocksdb_column_family_handle_t* column_family, | |
1656 | const char* key, size_t klen) { | |
1657 | b->rep->Delete(column_family->rep, Slice(key, klen)); | |
1658 | } | |
1659 | ||
1660 | void rocksdb_writebatch_wi_deletev( | |
1661 | rocksdb_writebatch_wi_t* b, | |
1662 | int num_keys, const char* const* keys_list, | |
1663 | const size_t* keys_list_sizes) { | |
1664 | std::vector<Slice> key_slices(num_keys); | |
1665 | for (int i = 0; i < num_keys; i++) { | |
1666 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1667 | } | |
1668 | b->rep->Delete(SliceParts(key_slices.data(), num_keys)); | |
1669 | } | |
1670 | ||
1671 | void rocksdb_writebatch_wi_deletev_cf( | |
1672 | rocksdb_writebatch_wi_t* b, | |
1673 | rocksdb_column_family_handle_t* column_family, | |
1674 | int num_keys, const char* const* keys_list, | |
1675 | const size_t* keys_list_sizes) { | |
1676 | std::vector<Slice> key_slices(num_keys); | |
1677 | for (int i = 0; i < num_keys; i++) { | |
1678 | key_slices[i] = Slice(keys_list[i], keys_list_sizes[i]); | |
1679 | } | |
1680 | b->rep->Delete(column_family->rep, SliceParts(key_slices.data(), num_keys)); | |
1681 | } | |
1682 | ||
1683 | void rocksdb_writebatch_wi_delete_range(rocksdb_writebatch_wi_t* b, | |
1684 | const char* start_key, | |
1685 | size_t start_key_len, const char* end_key, | |
1686 | size_t end_key_len) { | |
1687 | b->rep->DeleteRange(Slice(start_key, start_key_len), | |
1688 | Slice(end_key, end_key_len)); | |
1689 | } | |
1690 | ||
1691 | void rocksdb_writebatch_wi_delete_range_cf( | |
1692 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, | |
1693 | const char* start_key, size_t start_key_len, const char* end_key, | |
1694 | size_t end_key_len) { | |
1695 | b->rep->DeleteRange(column_family->rep, Slice(start_key, start_key_len), | |
1696 | Slice(end_key, end_key_len)); | |
1697 | } | |
1698 | ||
1699 | void rocksdb_writebatch_wi_delete_rangev(rocksdb_writebatch_wi_t* b, int num_keys, | |
1700 | const char* const* start_keys_list, | |
1701 | const size_t* start_keys_list_sizes, | |
1702 | const char* const* end_keys_list, | |
1703 | const size_t* end_keys_list_sizes) { | |
1704 | std::vector<Slice> start_key_slices(num_keys); | |
1705 | std::vector<Slice> end_key_slices(num_keys); | |
1706 | for (int i = 0; i < num_keys; i++) { | |
1707 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
1708 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
1709 | } | |
1710 | b->rep->DeleteRange(SliceParts(start_key_slices.data(), num_keys), | |
1711 | SliceParts(end_key_slices.data(), num_keys)); | |
1712 | } | |
1713 | ||
1714 | void rocksdb_writebatch_wi_delete_rangev_cf( | |
1715 | rocksdb_writebatch_wi_t* b, rocksdb_column_family_handle_t* column_family, | |
1716 | int num_keys, const char* const* start_keys_list, | |
1717 | const size_t* start_keys_list_sizes, const char* const* end_keys_list, | |
1718 | const size_t* end_keys_list_sizes) { | |
1719 | std::vector<Slice> start_key_slices(num_keys); | |
1720 | std::vector<Slice> end_key_slices(num_keys); | |
1721 | for (int i = 0; i < num_keys; i++) { | |
1722 | start_key_slices[i] = Slice(start_keys_list[i], start_keys_list_sizes[i]); | |
1723 | end_key_slices[i] = Slice(end_keys_list[i], end_keys_list_sizes[i]); | |
1724 | } | |
1725 | b->rep->DeleteRange(column_family->rep, | |
1726 | SliceParts(start_key_slices.data(), num_keys), | |
1727 | SliceParts(end_key_slices.data(), num_keys)); | |
1728 | } | |
1729 | ||
1730 | void rocksdb_writebatch_wi_put_log_data( | |
1731 | rocksdb_writebatch_wi_t* b, | |
1732 | const char* blob, size_t len) { | |
1733 | b->rep->PutLogData(Slice(blob, len)); | |
1734 | } | |
1735 | ||
1736 | void rocksdb_writebatch_wi_iterate( | |
1737 | rocksdb_writebatch_wi_t* b, | |
1738 | void* state, | |
1739 | void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), | |
1740 | void (*deleted)(void*, const char* k, size_t klen)) { | |
7c673cae FG |
1741 | H handler; |
1742 | handler.state_ = state; | |
1743 | handler.put_ = put; | |
1744 | handler.deleted_ = deleted; | |
1745 | b->rep->GetWriteBatch()->Iterate(&handler); | |
1746 | } | |
1747 | ||
1748 | const char* rocksdb_writebatch_wi_data(rocksdb_writebatch_wi_t* b, size_t* size) { | |
1749 | WriteBatch* wb = b->rep->GetWriteBatch(); | |
1750 | *size = wb->GetDataSize(); | |
1751 | return wb->Data().c_str(); | |
1752 | } | |
1753 | ||
1754 | void rocksdb_writebatch_wi_set_save_point(rocksdb_writebatch_wi_t* b) { | |
1755 | b->rep->SetSavePoint(); | |
1756 | } | |
1757 | ||
1758 | void rocksdb_writebatch_wi_rollback_to_save_point(rocksdb_writebatch_wi_t* b, | |
1759 | char** errptr) { | |
1760 | SaveError(errptr, b->rep->RollbackToSavePoint()); | |
1761 | } | |
1762 | ||
1763 | rocksdb_iterator_t* rocksdb_writebatch_wi_create_iterator_with_base( | |
1764 | rocksdb_writebatch_wi_t* wbwi, | |
1765 | rocksdb_iterator_t* base_iterator) { | |
1766 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
1767 | result->rep = wbwi->rep->NewIteratorWithBase(base_iterator->rep); | |
1768 | delete base_iterator; | |
1769 | return result; | |
1770 | } | |
1771 | ||
1772 | rocksdb_iterator_t* rocksdb_writebatch_wi_create_iterator_with_base_cf( | |
494da23a | 1773 | rocksdb_writebatch_wi_t* wbwi, rocksdb_iterator_t* base_iterator, |
7c673cae FG |
1774 | rocksdb_column_family_handle_t* column_family) { |
1775 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
494da23a TL |
1776 | result->rep = |
1777 | wbwi->rep->NewIteratorWithBase(column_family->rep, base_iterator->rep); | |
7c673cae FG |
1778 | delete base_iterator; |
1779 | return result; | |
1780 | } | |
1781 | ||
1782 | char* rocksdb_writebatch_wi_get_from_batch( | |
1783 | rocksdb_writebatch_wi_t* wbwi, | |
1784 | const rocksdb_options_t* options, | |
1785 | const char* key, size_t keylen, | |
1786 | size_t* vallen, | |
1787 | char** errptr) { | |
1788 | char* result = nullptr; | |
1789 | std::string tmp; | |
1790 | Status s = wbwi->rep->GetFromBatch(options->rep, Slice(key, keylen), &tmp); | |
1791 | if (s.ok()) { | |
1792 | *vallen = tmp.size(); | |
1793 | result = CopyString(tmp); | |
1794 | } else { | |
1795 | *vallen = 0; | |
1796 | if (!s.IsNotFound()) { | |
1797 | SaveError(errptr, s); | |
1798 | } | |
1799 | } | |
1800 | return result; | |
1801 | } | |
1802 | ||
1803 | char* rocksdb_writebatch_wi_get_from_batch_cf( | |
1804 | rocksdb_writebatch_wi_t* wbwi, | |
1805 | const rocksdb_options_t* options, | |
1806 | rocksdb_column_family_handle_t* column_family, | |
1807 | const char* key, size_t keylen, | |
1808 | size_t* vallen, | |
1809 | char** errptr) { | |
1810 | char* result = nullptr; | |
1811 | std::string tmp; | |
1812 | Status s = wbwi->rep->GetFromBatch(column_family->rep, options->rep, | |
1813 | Slice(key, keylen), &tmp); | |
1814 | if (s.ok()) { | |
1815 | *vallen = tmp.size(); | |
1816 | result = CopyString(tmp); | |
1817 | } else { | |
1818 | *vallen = 0; | |
1819 | if (!s.IsNotFound()) { | |
1820 | SaveError(errptr, s); | |
1821 | } | |
1822 | } | |
1823 | return result; | |
1824 | } | |
1825 | ||
1826 | char* rocksdb_writebatch_wi_get_from_batch_and_db( | |
1827 | rocksdb_writebatch_wi_t* wbwi, | |
1828 | rocksdb_t* db, | |
1829 | const rocksdb_readoptions_t* options, | |
1830 | const char* key, size_t keylen, | |
1831 | size_t* vallen, | |
1832 | char** errptr) { | |
1833 | char* result = nullptr; | |
1834 | std::string tmp; | |
1835 | Status s = wbwi->rep->GetFromBatchAndDB(db->rep, options->rep, Slice(key, keylen), &tmp); | |
1836 | if (s.ok()) { | |
1837 | *vallen = tmp.size(); | |
1838 | result = CopyString(tmp); | |
1839 | } else { | |
1840 | *vallen = 0; | |
1841 | if (!s.IsNotFound()) { | |
1842 | SaveError(errptr, s); | |
1843 | } | |
1844 | } | |
1845 | return result; | |
1846 | } | |
1847 | ||
1848 | char* rocksdb_writebatch_wi_get_from_batch_and_db_cf( | |
1849 | rocksdb_writebatch_wi_t* wbwi, | |
1850 | rocksdb_t* db, | |
1851 | const rocksdb_readoptions_t* options, | |
1852 | rocksdb_column_family_handle_t* column_family, | |
1853 | const char* key, size_t keylen, | |
1854 | size_t* vallen, | |
1855 | char** errptr) { | |
1856 | char* result = nullptr; | |
1857 | std::string tmp; | |
1858 | Status s = wbwi->rep->GetFromBatchAndDB(db->rep, options->rep, column_family->rep, | |
1859 | Slice(key, keylen), &tmp); | |
1860 | if (s.ok()) { | |
1861 | *vallen = tmp.size(); | |
1862 | result = CopyString(tmp); | |
1863 | } else { | |
1864 | *vallen = 0; | |
1865 | if (!s.IsNotFound()) { | |
1866 | SaveError(errptr, s); | |
1867 | } | |
1868 | } | |
1869 | return result; | |
1870 | } | |
1871 | ||
1872 | void rocksdb_write_writebatch_wi( | |
1873 | rocksdb_t* db, | |
1874 | const rocksdb_writeoptions_t* options, | |
1875 | rocksdb_writebatch_wi_t* wbwi, | |
1876 | char** errptr) { | |
1877 | WriteBatch* wb = wbwi->rep->GetWriteBatch(); | |
1878 | SaveError(errptr, db->rep->Write(options->rep, wb)); | |
1879 | } | |
1880 | ||
1881 | rocksdb_block_based_table_options_t* | |
1882 | rocksdb_block_based_options_create() { | |
1883 | return new rocksdb_block_based_table_options_t; | |
1884 | } | |
1885 | ||
1886 | void rocksdb_block_based_options_destroy( | |
1887 | rocksdb_block_based_table_options_t* options) { | |
1888 | delete options; | |
1889 | } | |
1890 | ||
1891 | void rocksdb_block_based_options_set_block_size( | |
1892 | rocksdb_block_based_table_options_t* options, size_t block_size) { | |
1893 | options->rep.block_size = block_size; | |
1894 | } | |
1895 | ||
1896 | void rocksdb_block_based_options_set_block_size_deviation( | |
1897 | rocksdb_block_based_table_options_t* options, int block_size_deviation) { | |
1898 | options->rep.block_size_deviation = block_size_deviation; | |
1899 | } | |
1900 | ||
1901 | void rocksdb_block_based_options_set_block_restart_interval( | |
1902 | rocksdb_block_based_table_options_t* options, int block_restart_interval) { | |
1903 | options->rep.block_restart_interval = block_restart_interval; | |
1904 | } | |
1905 | ||
11fdf7f2 TL |
1906 | void rocksdb_block_based_options_set_index_block_restart_interval( |
1907 | rocksdb_block_based_table_options_t* options, int index_block_restart_interval) { | |
1908 | options->rep.index_block_restart_interval = index_block_restart_interval; | |
1909 | } | |
1910 | ||
1911 | void rocksdb_block_based_options_set_metadata_block_size( | |
1912 | rocksdb_block_based_table_options_t* options, uint64_t metadata_block_size) { | |
1913 | options->rep.metadata_block_size = metadata_block_size; | |
1914 | } | |
1915 | ||
1916 | void rocksdb_block_based_options_set_partition_filters( | |
1917 | rocksdb_block_based_table_options_t* options, unsigned char partition_filters) { | |
1918 | options->rep.partition_filters = partition_filters; | |
1919 | } | |
1920 | ||
1921 | void rocksdb_block_based_options_set_use_delta_encoding( | |
1922 | rocksdb_block_based_table_options_t* options, unsigned char use_delta_encoding) { | |
1923 | options->rep.use_delta_encoding = use_delta_encoding; | |
1924 | } | |
1925 | ||
7c673cae FG |
1926 | void rocksdb_block_based_options_set_filter_policy( |
1927 | rocksdb_block_based_table_options_t* options, | |
1928 | rocksdb_filterpolicy_t* filter_policy) { | |
1929 | options->rep.filter_policy.reset(filter_policy); | |
1930 | } | |
1931 | ||
1932 | void rocksdb_block_based_options_set_no_block_cache( | |
1933 | rocksdb_block_based_table_options_t* options, | |
1934 | unsigned char no_block_cache) { | |
1935 | options->rep.no_block_cache = no_block_cache; | |
1936 | } | |
1937 | ||
1938 | void rocksdb_block_based_options_set_block_cache( | |
1939 | rocksdb_block_based_table_options_t* options, | |
1940 | rocksdb_cache_t* block_cache) { | |
1941 | if (block_cache) { | |
1942 | options->rep.block_cache = block_cache->rep; | |
1943 | } | |
1944 | } | |
1945 | ||
1946 | void rocksdb_block_based_options_set_block_cache_compressed( | |
1947 | rocksdb_block_based_table_options_t* options, | |
1948 | rocksdb_cache_t* block_cache_compressed) { | |
1949 | if (block_cache_compressed) { | |
1950 | options->rep.block_cache_compressed = block_cache_compressed->rep; | |
1951 | } | |
1952 | } | |
1953 | ||
1954 | void rocksdb_block_based_options_set_whole_key_filtering( | |
1955 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
1956 | options->rep.whole_key_filtering = v; | |
1957 | } | |
1958 | ||
1959 | void rocksdb_block_based_options_set_format_version( | |
1960 | rocksdb_block_based_table_options_t* options, int v) { | |
1961 | options->rep.format_version = v; | |
1962 | } | |
1963 | ||
1964 | void rocksdb_block_based_options_set_index_type( | |
1965 | rocksdb_block_based_table_options_t* options, int v) { | |
1966 | options->rep.index_type = static_cast<BlockBasedTableOptions::IndexType>(v); | |
1967 | } | |
1968 | ||
1969 | void rocksdb_block_based_options_set_hash_index_allow_collision( | |
1970 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
1971 | options->rep.hash_index_allow_collision = v; | |
1972 | } | |
1973 | ||
1974 | void rocksdb_block_based_options_set_cache_index_and_filter_blocks( | |
1975 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
1976 | options->rep.cache_index_and_filter_blocks = v; | |
1977 | } | |
1978 | ||
11fdf7f2 TL |
1979 | void rocksdb_block_based_options_set_cache_index_and_filter_blocks_with_high_priority( |
1980 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
1981 | options->rep.cache_index_and_filter_blocks_with_high_priority = v; | |
1982 | } | |
1983 | ||
7c673cae FG |
1984 | void rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache( |
1985 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
1986 | options->rep.pin_l0_filter_and_index_blocks_in_cache = v; | |
1987 | } | |
1988 | ||
11fdf7f2 TL |
1989 | void rocksdb_block_based_options_set_pin_top_level_index_and_filter( |
1990 | rocksdb_block_based_table_options_t* options, unsigned char v) { | |
1991 | options->rep.pin_top_level_index_and_filter = v; | |
1992 | } | |
1993 | ||
7c673cae FG |
1994 | void rocksdb_options_set_block_based_table_factory( |
1995 | rocksdb_options_t *opt, | |
1996 | rocksdb_block_based_table_options_t* table_options) { | |
1997 | if (table_options) { | |
1998 | opt->rep.table_factory.reset( | |
1999 | rocksdb::NewBlockBasedTableFactory(table_options->rep)); | |
2000 | } | |
2001 | } | |
2002 | ||
7c673cae FG |
2003 | rocksdb_cuckoo_table_options_t* |
2004 | rocksdb_cuckoo_options_create() { | |
2005 | return new rocksdb_cuckoo_table_options_t; | |
2006 | } | |
2007 | ||
2008 | void rocksdb_cuckoo_options_destroy( | |
2009 | rocksdb_cuckoo_table_options_t* options) { | |
2010 | delete options; | |
2011 | } | |
2012 | ||
2013 | void rocksdb_cuckoo_options_set_hash_ratio( | |
2014 | rocksdb_cuckoo_table_options_t* options, double v) { | |
2015 | options->rep.hash_table_ratio = v; | |
2016 | } | |
2017 | ||
2018 | void rocksdb_cuckoo_options_set_max_search_depth( | |
2019 | rocksdb_cuckoo_table_options_t* options, uint32_t v) { | |
2020 | options->rep.max_search_depth = v; | |
2021 | } | |
2022 | ||
2023 | void rocksdb_cuckoo_options_set_cuckoo_block_size( | |
2024 | rocksdb_cuckoo_table_options_t* options, uint32_t v) { | |
2025 | options->rep.cuckoo_block_size = v; | |
2026 | } | |
2027 | ||
2028 | void rocksdb_cuckoo_options_set_identity_as_first_hash( | |
2029 | rocksdb_cuckoo_table_options_t* options, unsigned char v) { | |
2030 | options->rep.identity_as_first_hash = v; | |
2031 | } | |
2032 | ||
2033 | void rocksdb_cuckoo_options_set_use_module_hash( | |
2034 | rocksdb_cuckoo_table_options_t* options, unsigned char v) { | |
2035 | options->rep.use_module_hash = v; | |
2036 | } | |
2037 | ||
2038 | void rocksdb_options_set_cuckoo_table_factory( | |
2039 | rocksdb_options_t *opt, | |
2040 | rocksdb_cuckoo_table_options_t* table_options) { | |
2041 | if (table_options) { | |
2042 | opt->rep.table_factory.reset( | |
2043 | rocksdb::NewCuckooTableFactory(table_options->rep)); | |
2044 | } | |
2045 | } | |
2046 | ||
2047 | void rocksdb_set_options( | |
2048 | rocksdb_t* db, int count, const char* const keys[], const char* const values[], char** errptr) { | |
2049 | std::unordered_map<std::string, std::string> options_map; | |
2050 | for (int i=0; i<count; i++) | |
2051 | options_map[keys[i]] = values[i]; | |
2052 | SaveError(errptr, | |
2053 | db->rep->SetOptions(options_map)); | |
2054 | } | |
2055 | ||
494da23a TL |
2056 | void rocksdb_set_options_cf( |
2057 | rocksdb_t* db, rocksdb_column_family_handle_t* handle, int count, const char* const keys[], const char* const values[], char** errptr) { | |
2058 | std::unordered_map<std::string, std::string> options_map; | |
2059 | for (int i=0; i<count; i++) | |
2060 | options_map[keys[i]] = values[i]; | |
2061 | SaveError(errptr, | |
2062 | db->rep->SetOptions(handle->rep, options_map)); | |
2063 | } | |
2064 | ||
7c673cae FG |
2065 | rocksdb_options_t* rocksdb_options_create() { |
2066 | return new rocksdb_options_t; | |
2067 | } | |
2068 | ||
2069 | void rocksdb_options_destroy(rocksdb_options_t* options) { | |
2070 | delete options; | |
2071 | } | |
2072 | ||
2073 | void rocksdb_options_increase_parallelism( | |
2074 | rocksdb_options_t* opt, int total_threads) { | |
2075 | opt->rep.IncreaseParallelism(total_threads); | |
2076 | } | |
2077 | ||
2078 | void rocksdb_options_optimize_for_point_lookup( | |
2079 | rocksdb_options_t* opt, uint64_t block_cache_size_mb) { | |
2080 | opt->rep.OptimizeForPointLookup(block_cache_size_mb); | |
2081 | } | |
2082 | ||
2083 | void rocksdb_options_optimize_level_style_compaction( | |
2084 | rocksdb_options_t* opt, uint64_t memtable_memory_budget) { | |
2085 | opt->rep.OptimizeLevelStyleCompaction(memtable_memory_budget); | |
2086 | } | |
2087 | ||
2088 | void rocksdb_options_optimize_universal_style_compaction( | |
2089 | rocksdb_options_t* opt, uint64_t memtable_memory_budget) { | |
2090 | opt->rep.OptimizeUniversalStyleCompaction(memtable_memory_budget); | |
2091 | } | |
2092 | ||
11fdf7f2 TL |
2093 | void rocksdb_options_set_allow_ingest_behind( |
2094 | rocksdb_options_t* opt, unsigned char v) { | |
2095 | opt->rep.allow_ingest_behind = v; | |
2096 | } | |
2097 | ||
7c673cae FG |
2098 | void rocksdb_options_set_compaction_filter( |
2099 | rocksdb_options_t* opt, | |
2100 | rocksdb_compactionfilter_t* filter) { | |
2101 | opt->rep.compaction_filter = filter; | |
2102 | } | |
2103 | ||
2104 | void rocksdb_options_set_compaction_filter_factory( | |
2105 | rocksdb_options_t* opt, rocksdb_compactionfilterfactory_t* factory) { | |
2106 | opt->rep.compaction_filter_factory = | |
2107 | std::shared_ptr<CompactionFilterFactory>(factory); | |
2108 | } | |
2109 | ||
2110 | void rocksdb_options_compaction_readahead_size( | |
2111 | rocksdb_options_t* opt, size_t s) { | |
2112 | opt->rep.compaction_readahead_size = s; | |
2113 | } | |
2114 | ||
2115 | void rocksdb_options_set_comparator( | |
2116 | rocksdb_options_t* opt, | |
2117 | rocksdb_comparator_t* cmp) { | |
2118 | opt->rep.comparator = cmp; | |
2119 | } | |
2120 | ||
2121 | void rocksdb_options_set_merge_operator( | |
2122 | rocksdb_options_t* opt, | |
2123 | rocksdb_mergeoperator_t* merge_operator) { | |
2124 | opt->rep.merge_operator = std::shared_ptr<MergeOperator>(merge_operator); | |
2125 | } | |
2126 | ||
2127 | ||
2128 | void rocksdb_options_set_create_if_missing( | |
2129 | rocksdb_options_t* opt, unsigned char v) { | |
2130 | opt->rep.create_if_missing = v; | |
2131 | } | |
2132 | ||
2133 | void rocksdb_options_set_create_missing_column_families( | |
2134 | rocksdb_options_t* opt, unsigned char v) { | |
2135 | opt->rep.create_missing_column_families = v; | |
2136 | } | |
2137 | ||
2138 | void rocksdb_options_set_error_if_exists( | |
2139 | rocksdb_options_t* opt, unsigned char v) { | |
2140 | opt->rep.error_if_exists = v; | |
2141 | } | |
2142 | ||
2143 | void rocksdb_options_set_paranoid_checks( | |
2144 | rocksdb_options_t* opt, unsigned char v) { | |
2145 | opt->rep.paranoid_checks = v; | |
2146 | } | |
2147 | ||
11fdf7f2 TL |
2148 | void rocksdb_options_set_db_paths(rocksdb_options_t* opt, |
2149 | const rocksdb_dbpath_t** dbpath_values, | |
2150 | size_t num_paths) { | |
2151 | std::vector<DbPath> db_paths(num_paths); | |
2152 | for (size_t i = 0; i < num_paths; ++i) { | |
2153 | db_paths[i] = dbpath_values[i]->rep; | |
2154 | } | |
2155 | opt->rep.db_paths = db_paths; | |
2156 | } | |
2157 | ||
7c673cae FG |
2158 | void rocksdb_options_set_env(rocksdb_options_t* opt, rocksdb_env_t* env) { |
2159 | opt->rep.env = (env ? env->rep : nullptr); | |
2160 | } | |
2161 | ||
2162 | void rocksdb_options_set_info_log(rocksdb_options_t* opt, rocksdb_logger_t* l) { | |
2163 | if (l) { | |
2164 | opt->rep.info_log = l->rep; | |
2165 | } | |
2166 | } | |
2167 | ||
2168 | void rocksdb_options_set_info_log_level( | |
2169 | rocksdb_options_t* opt, int v) { | |
2170 | opt->rep.info_log_level = static_cast<InfoLogLevel>(v); | |
2171 | } | |
2172 | ||
2173 | void rocksdb_options_set_db_write_buffer_size(rocksdb_options_t* opt, | |
2174 | size_t s) { | |
2175 | opt->rep.db_write_buffer_size = s; | |
2176 | } | |
2177 | ||
2178 | void rocksdb_options_set_write_buffer_size(rocksdb_options_t* opt, size_t s) { | |
2179 | opt->rep.write_buffer_size = s; | |
2180 | } | |
2181 | ||
2182 | void rocksdb_options_set_max_open_files(rocksdb_options_t* opt, int n) { | |
2183 | opt->rep.max_open_files = n; | |
2184 | } | |
2185 | ||
11fdf7f2 TL |
2186 | void rocksdb_options_set_max_file_opening_threads(rocksdb_options_t* opt, int n) { |
2187 | opt->rep.max_file_opening_threads = n; | |
2188 | } | |
2189 | ||
7c673cae FG |
2190 | void rocksdb_options_set_max_total_wal_size(rocksdb_options_t* opt, uint64_t n) { |
2191 | opt->rep.max_total_wal_size = n; | |
2192 | } | |
2193 | ||
2194 | void rocksdb_options_set_target_file_size_base( | |
2195 | rocksdb_options_t* opt, uint64_t n) { | |
2196 | opt->rep.target_file_size_base = n; | |
2197 | } | |
2198 | ||
2199 | void rocksdb_options_set_target_file_size_multiplier( | |
2200 | rocksdb_options_t* opt, int n) { | |
2201 | opt->rep.target_file_size_multiplier = n; | |
2202 | } | |
2203 | ||
2204 | void rocksdb_options_set_max_bytes_for_level_base( | |
2205 | rocksdb_options_t* opt, uint64_t n) { | |
2206 | opt->rep.max_bytes_for_level_base = n; | |
2207 | } | |
2208 | ||
2209 | void rocksdb_options_set_level_compaction_dynamic_level_bytes( | |
2210 | rocksdb_options_t* opt, unsigned char v) { | |
2211 | opt->rep.level_compaction_dynamic_level_bytes = v; | |
2212 | } | |
2213 | ||
2214 | void rocksdb_options_set_max_bytes_for_level_multiplier(rocksdb_options_t* opt, | |
2215 | double n) { | |
2216 | opt->rep.max_bytes_for_level_multiplier = n; | |
2217 | } | |
2218 | ||
2219 | void rocksdb_options_set_max_compaction_bytes(rocksdb_options_t* opt, | |
2220 | uint64_t n) { | |
2221 | opt->rep.max_compaction_bytes = n; | |
2222 | } | |
2223 | ||
2224 | void rocksdb_options_set_max_bytes_for_level_multiplier_additional( | |
2225 | rocksdb_options_t* opt, int* level_values, size_t num_levels) { | |
2226 | opt->rep.max_bytes_for_level_multiplier_additional.resize(num_levels); | |
2227 | for (size_t i = 0; i < num_levels; ++i) { | |
2228 | opt->rep.max_bytes_for_level_multiplier_additional[i] = level_values[i]; | |
2229 | } | |
2230 | } | |
2231 | ||
2232 | void rocksdb_options_enable_statistics(rocksdb_options_t* opt) { | |
2233 | opt->rep.statistics = rocksdb::CreateDBStatistics(); | |
2234 | } | |
2235 | ||
11fdf7f2 TL |
2236 | void rocksdb_options_set_skip_stats_update_on_db_open(rocksdb_options_t* opt, |
2237 | unsigned char val) { | |
2238 | opt->rep.skip_stats_update_on_db_open = val; | |
2239 | } | |
2240 | ||
7c673cae FG |
2241 | void rocksdb_options_set_num_levels(rocksdb_options_t* opt, int n) { |
2242 | opt->rep.num_levels = n; | |
2243 | } | |
2244 | ||
2245 | void rocksdb_options_set_level0_file_num_compaction_trigger( | |
2246 | rocksdb_options_t* opt, int n) { | |
2247 | opt->rep.level0_file_num_compaction_trigger = n; | |
2248 | } | |
2249 | ||
2250 | void rocksdb_options_set_level0_slowdown_writes_trigger( | |
2251 | rocksdb_options_t* opt, int n) { | |
2252 | opt->rep.level0_slowdown_writes_trigger = n; | |
2253 | } | |
2254 | ||
2255 | void rocksdb_options_set_level0_stop_writes_trigger( | |
2256 | rocksdb_options_t* opt, int n) { | |
2257 | opt->rep.level0_stop_writes_trigger = n; | |
2258 | } | |
2259 | ||
11fdf7f2 TL |
2260 | void rocksdb_options_set_max_mem_compaction_level(rocksdb_options_t* /*opt*/, |
2261 | int /*n*/) {} | |
7c673cae FG |
2262 | |
2263 | void rocksdb_options_set_wal_recovery_mode(rocksdb_options_t* opt,int mode) { | |
2264 | opt->rep.wal_recovery_mode = static_cast<WALRecoveryMode>(mode); | |
2265 | } | |
2266 | ||
2267 | void rocksdb_options_set_compression(rocksdb_options_t* opt, int t) { | |
2268 | opt->rep.compression = static_cast<CompressionType>(t); | |
2269 | } | |
2270 | ||
2271 | void rocksdb_options_set_compression_per_level(rocksdb_options_t* opt, | |
2272 | int* level_values, | |
2273 | size_t num_levels) { | |
2274 | opt->rep.compression_per_level.resize(num_levels); | |
2275 | for (size_t i = 0; i < num_levels; ++i) { | |
2276 | opt->rep.compression_per_level[i] = | |
2277 | static_cast<CompressionType>(level_values[i]); | |
2278 | } | |
2279 | } | |
2280 | ||
11fdf7f2 TL |
2281 | void rocksdb_options_set_bottommost_compression_options(rocksdb_options_t* opt, |
2282 | int w_bits, int level, | |
2283 | int strategy, | |
2284 | int max_dict_bytes, | |
2285 | bool enabled) { | |
2286 | opt->rep.bottommost_compression_opts.window_bits = w_bits; | |
2287 | opt->rep.bottommost_compression_opts.level = level; | |
2288 | opt->rep.bottommost_compression_opts.strategy = strategy; | |
2289 | opt->rep.bottommost_compression_opts.max_dict_bytes = max_dict_bytes; | |
2290 | opt->rep.bottommost_compression_opts.enabled = enabled; | |
2291 | } | |
2292 | ||
7c673cae FG |
2293 | void rocksdb_options_set_compression_options(rocksdb_options_t* opt, int w_bits, |
2294 | int level, int strategy, | |
2295 | int max_dict_bytes) { | |
2296 | opt->rep.compression_opts.window_bits = w_bits; | |
2297 | opt->rep.compression_opts.level = level; | |
2298 | opt->rep.compression_opts.strategy = strategy; | |
2299 | opt->rep.compression_opts.max_dict_bytes = max_dict_bytes; | |
2300 | } | |
2301 | ||
2302 | void rocksdb_options_set_prefix_extractor( | |
2303 | rocksdb_options_t* opt, rocksdb_slicetransform_t* prefix_extractor) { | |
2304 | opt->rep.prefix_extractor.reset(prefix_extractor); | |
2305 | } | |
2306 | ||
2307 | void rocksdb_options_set_use_fsync( | |
2308 | rocksdb_options_t* opt, int use_fsync) { | |
2309 | opt->rep.use_fsync = use_fsync; | |
2310 | } | |
2311 | ||
2312 | void rocksdb_options_set_db_log_dir( | |
2313 | rocksdb_options_t* opt, const char* db_log_dir) { | |
2314 | opt->rep.db_log_dir = db_log_dir; | |
2315 | } | |
2316 | ||
2317 | void rocksdb_options_set_wal_dir( | |
2318 | rocksdb_options_t* opt, const char* v) { | |
2319 | opt->rep.wal_dir = v; | |
2320 | } | |
2321 | ||
2322 | void rocksdb_options_set_WAL_ttl_seconds(rocksdb_options_t* opt, uint64_t ttl) { | |
2323 | opt->rep.WAL_ttl_seconds = ttl; | |
2324 | } | |
2325 | ||
2326 | void rocksdb_options_set_WAL_size_limit_MB( | |
2327 | rocksdb_options_t* opt, uint64_t limit) { | |
2328 | opt->rep.WAL_size_limit_MB = limit; | |
2329 | } | |
2330 | ||
2331 | void rocksdb_options_set_manifest_preallocation_size( | |
2332 | rocksdb_options_t* opt, size_t v) { | |
2333 | opt->rep.manifest_preallocation_size = v; | |
2334 | } | |
2335 | ||
2336 | // noop | |
11fdf7f2 TL |
2337 | void rocksdb_options_set_purge_redundant_kvs_while_flush( |
2338 | rocksdb_options_t* /*opt*/, unsigned char /*v*/) {} | |
7c673cae FG |
2339 | |
2340 | void rocksdb_options_set_use_direct_reads(rocksdb_options_t* opt, | |
2341 | unsigned char v) { | |
2342 | opt->rep.use_direct_reads = v; | |
2343 | } | |
2344 | ||
2345 | void rocksdb_options_set_use_direct_io_for_flush_and_compaction( | |
2346 | rocksdb_options_t* opt, unsigned char v) { | |
2347 | opt->rep.use_direct_io_for_flush_and_compaction = v; | |
2348 | } | |
2349 | ||
2350 | void rocksdb_options_set_allow_mmap_reads( | |
2351 | rocksdb_options_t* opt, unsigned char v) { | |
2352 | opt->rep.allow_mmap_reads = v; | |
2353 | } | |
2354 | ||
2355 | void rocksdb_options_set_allow_mmap_writes( | |
2356 | rocksdb_options_t* opt, unsigned char v) { | |
2357 | opt->rep.allow_mmap_writes = v; | |
2358 | } | |
2359 | ||
2360 | void rocksdb_options_set_is_fd_close_on_exec( | |
2361 | rocksdb_options_t* opt, unsigned char v) { | |
2362 | opt->rep.is_fd_close_on_exec = v; | |
2363 | } | |
2364 | ||
2365 | void rocksdb_options_set_skip_log_error_on_recovery( | |
2366 | rocksdb_options_t* opt, unsigned char v) { | |
2367 | opt->rep.skip_log_error_on_recovery = v; | |
2368 | } | |
2369 | ||
2370 | void rocksdb_options_set_stats_dump_period_sec( | |
2371 | rocksdb_options_t* opt, unsigned int v) { | |
2372 | opt->rep.stats_dump_period_sec = v; | |
2373 | } | |
2374 | ||
2375 | void rocksdb_options_set_advise_random_on_open( | |
2376 | rocksdb_options_t* opt, unsigned char v) { | |
2377 | opt->rep.advise_random_on_open = v; | |
2378 | } | |
2379 | ||
2380 | void rocksdb_options_set_access_hint_on_compaction_start( | |
2381 | rocksdb_options_t* opt, int v) { | |
2382 | switch(v) { | |
2383 | case 0: | |
2384 | opt->rep.access_hint_on_compaction_start = rocksdb::Options::NONE; | |
2385 | break; | |
2386 | case 1: | |
2387 | opt->rep.access_hint_on_compaction_start = rocksdb::Options::NORMAL; | |
2388 | break; | |
2389 | case 2: | |
2390 | opt->rep.access_hint_on_compaction_start = rocksdb::Options::SEQUENTIAL; | |
2391 | break; | |
2392 | case 3: | |
2393 | opt->rep.access_hint_on_compaction_start = rocksdb::Options::WILLNEED; | |
2394 | break; | |
2395 | } | |
2396 | } | |
2397 | ||
2398 | void rocksdb_options_set_use_adaptive_mutex( | |
2399 | rocksdb_options_t* opt, unsigned char v) { | |
2400 | opt->rep.use_adaptive_mutex = v; | |
2401 | } | |
2402 | ||
11fdf7f2 TL |
2403 | void rocksdb_options_set_wal_bytes_per_sync( |
2404 | rocksdb_options_t* opt, uint64_t v) { | |
2405 | opt->rep.wal_bytes_per_sync = v; | |
2406 | } | |
2407 | ||
7c673cae FG |
2408 | void rocksdb_options_set_bytes_per_sync( |
2409 | rocksdb_options_t* opt, uint64_t v) { | |
2410 | opt->rep.bytes_per_sync = v; | |
2411 | } | |
2412 | ||
11fdf7f2 TL |
2413 | void rocksdb_options_set_writable_file_max_buffer_size(rocksdb_options_t* opt, |
2414 | uint64_t v) { | |
2415 | opt->rep.writable_file_max_buffer_size = static_cast<size_t>(v); | |
2416 | } | |
2417 | ||
7c673cae FG |
2418 | void rocksdb_options_set_allow_concurrent_memtable_write(rocksdb_options_t* opt, |
2419 | unsigned char v) { | |
2420 | opt->rep.allow_concurrent_memtable_write = v; | |
2421 | } | |
2422 | ||
2423 | void rocksdb_options_set_enable_write_thread_adaptive_yield( | |
2424 | rocksdb_options_t* opt, unsigned char v) { | |
2425 | opt->rep.enable_write_thread_adaptive_yield = v; | |
2426 | } | |
2427 | ||
2428 | void rocksdb_options_set_max_sequential_skip_in_iterations( | |
2429 | rocksdb_options_t* opt, uint64_t v) { | |
2430 | opt->rep.max_sequential_skip_in_iterations = v; | |
2431 | } | |
2432 | ||
2433 | void rocksdb_options_set_max_write_buffer_number(rocksdb_options_t* opt, int n) { | |
2434 | opt->rep.max_write_buffer_number = n; | |
2435 | } | |
2436 | ||
2437 | void rocksdb_options_set_min_write_buffer_number_to_merge(rocksdb_options_t* opt, int n) { | |
2438 | opt->rep.min_write_buffer_number_to_merge = n; | |
2439 | } | |
2440 | ||
2441 | void rocksdb_options_set_max_write_buffer_number_to_maintain( | |
2442 | rocksdb_options_t* opt, int n) { | |
2443 | opt->rep.max_write_buffer_number_to_maintain = n; | |
2444 | } | |
2445 | ||
11fdf7f2 TL |
2446 | void rocksdb_options_set_enable_pipelined_write(rocksdb_options_t* opt, |
2447 | unsigned char v) { | |
2448 | opt->rep.enable_pipelined_write = v; | |
2449 | } | |
2450 | ||
2451 | void rocksdb_options_set_max_subcompactions(rocksdb_options_t* opt, | |
2452 | uint32_t n) { | |
2453 | opt->rep.max_subcompactions = n; | |
2454 | } | |
2455 | ||
2456 | void rocksdb_options_set_max_background_jobs(rocksdb_options_t* opt, int n) { | |
2457 | opt->rep.max_background_jobs = n; | |
2458 | } | |
2459 | ||
7c673cae FG |
2460 | void rocksdb_options_set_max_background_compactions(rocksdb_options_t* opt, int n) { |
2461 | opt->rep.max_background_compactions = n; | |
2462 | } | |
2463 | ||
2464 | void rocksdb_options_set_base_background_compactions(rocksdb_options_t* opt, | |
2465 | int n) { | |
2466 | opt->rep.base_background_compactions = n; | |
2467 | } | |
2468 | ||
2469 | void rocksdb_options_set_max_background_flushes(rocksdb_options_t* opt, int n) { | |
2470 | opt->rep.max_background_flushes = n; | |
2471 | } | |
2472 | ||
2473 | void rocksdb_options_set_max_log_file_size(rocksdb_options_t* opt, size_t v) { | |
2474 | opt->rep.max_log_file_size = v; | |
2475 | } | |
2476 | ||
2477 | void rocksdb_options_set_log_file_time_to_roll(rocksdb_options_t* opt, size_t v) { | |
2478 | opt->rep.log_file_time_to_roll = v; | |
2479 | } | |
2480 | ||
2481 | void rocksdb_options_set_keep_log_file_num(rocksdb_options_t* opt, size_t v) { | |
2482 | opt->rep.keep_log_file_num = v; | |
2483 | } | |
2484 | ||
2485 | void rocksdb_options_set_recycle_log_file_num(rocksdb_options_t* opt, | |
2486 | size_t v) { | |
2487 | opt->rep.recycle_log_file_num = v; | |
2488 | } | |
2489 | ||
2490 | void rocksdb_options_set_soft_rate_limit(rocksdb_options_t* opt, double v) { | |
2491 | opt->rep.soft_rate_limit = v; | |
2492 | } | |
2493 | ||
2494 | void rocksdb_options_set_hard_rate_limit(rocksdb_options_t* opt, double v) { | |
2495 | opt->rep.hard_rate_limit = v; | |
2496 | } | |
2497 | ||
2498 | void rocksdb_options_set_soft_pending_compaction_bytes_limit(rocksdb_options_t* opt, size_t v) { | |
2499 | opt->rep.soft_pending_compaction_bytes_limit = v; | |
2500 | } | |
2501 | ||
2502 | void rocksdb_options_set_hard_pending_compaction_bytes_limit(rocksdb_options_t* opt, size_t v) { | |
2503 | opt->rep.hard_pending_compaction_bytes_limit = v; | |
2504 | } | |
2505 | ||
2506 | void rocksdb_options_set_rate_limit_delay_max_milliseconds( | |
2507 | rocksdb_options_t* opt, unsigned int v) { | |
2508 | opt->rep.rate_limit_delay_max_milliseconds = v; | |
2509 | } | |
2510 | ||
2511 | void rocksdb_options_set_max_manifest_file_size( | |
2512 | rocksdb_options_t* opt, size_t v) { | |
2513 | opt->rep.max_manifest_file_size = v; | |
2514 | } | |
2515 | ||
2516 | void rocksdb_options_set_table_cache_numshardbits( | |
2517 | rocksdb_options_t* opt, int v) { | |
2518 | opt->rep.table_cache_numshardbits = v; | |
2519 | } | |
2520 | ||
2521 | void rocksdb_options_set_table_cache_remove_scan_count_limit( | |
11fdf7f2 | 2522 | rocksdb_options_t* /*opt*/, int /*v*/) { |
7c673cae FG |
2523 | // this option is deprecated |
2524 | } | |
2525 | ||
2526 | void rocksdb_options_set_arena_block_size( | |
2527 | rocksdb_options_t* opt, size_t v) { | |
2528 | opt->rep.arena_block_size = v; | |
2529 | } | |
2530 | ||
2531 | void rocksdb_options_set_disable_auto_compactions(rocksdb_options_t* opt, int disable) { | |
2532 | opt->rep.disable_auto_compactions = disable; | |
2533 | } | |
2534 | ||
2535 | void rocksdb_options_set_optimize_filters_for_hits(rocksdb_options_t* opt, int v) { | |
2536 | opt->rep.optimize_filters_for_hits = v; | |
2537 | } | |
2538 | ||
2539 | void rocksdb_options_set_delete_obsolete_files_period_micros( | |
2540 | rocksdb_options_t* opt, uint64_t v) { | |
2541 | opt->rep.delete_obsolete_files_period_micros = v; | |
2542 | } | |
2543 | ||
2544 | void rocksdb_options_prepare_for_bulk_load(rocksdb_options_t* opt) { | |
2545 | opt->rep.PrepareForBulkLoad(); | |
2546 | } | |
2547 | ||
2548 | void rocksdb_options_set_memtable_vector_rep(rocksdb_options_t *opt) { | |
2549 | opt->rep.memtable_factory.reset(new rocksdb::VectorRepFactory); | |
2550 | } | |
2551 | ||
2552 | void rocksdb_options_set_memtable_prefix_bloom_size_ratio( | |
2553 | rocksdb_options_t* opt, double v) { | |
2554 | opt->rep.memtable_prefix_bloom_size_ratio = v; | |
2555 | } | |
2556 | ||
2557 | void rocksdb_options_set_memtable_huge_page_size(rocksdb_options_t* opt, | |
2558 | size_t v) { | |
2559 | opt->rep.memtable_huge_page_size = v; | |
2560 | } | |
2561 | ||
2562 | void rocksdb_options_set_hash_skip_list_rep( | |
2563 | rocksdb_options_t *opt, size_t bucket_count, | |
2564 | int32_t skiplist_height, int32_t skiplist_branching_factor) { | |
2565 | rocksdb::MemTableRepFactory* factory = rocksdb::NewHashSkipListRepFactory( | |
2566 | bucket_count, skiplist_height, skiplist_branching_factor); | |
2567 | opt->rep.memtable_factory.reset(factory); | |
2568 | } | |
2569 | ||
2570 | void rocksdb_options_set_hash_link_list_rep( | |
2571 | rocksdb_options_t *opt, size_t bucket_count) { | |
2572 | opt->rep.memtable_factory.reset(rocksdb::NewHashLinkListRepFactory(bucket_count)); | |
2573 | } | |
2574 | ||
2575 | void rocksdb_options_set_plain_table_factory( | |
2576 | rocksdb_options_t *opt, uint32_t user_key_len, int bloom_bits_per_key, | |
2577 | double hash_table_ratio, size_t index_sparseness) { | |
2578 | rocksdb::PlainTableOptions options; | |
2579 | options.user_key_len = user_key_len; | |
2580 | options.bloom_bits_per_key = bloom_bits_per_key; | |
2581 | options.hash_table_ratio = hash_table_ratio; | |
2582 | options.index_sparseness = index_sparseness; | |
2583 | ||
2584 | rocksdb::TableFactory* factory = rocksdb::NewPlainTableFactory(options); | |
2585 | opt->rep.table_factory.reset(factory); | |
2586 | } | |
2587 | ||
2588 | void rocksdb_options_set_max_successive_merges( | |
2589 | rocksdb_options_t* opt, size_t v) { | |
2590 | opt->rep.max_successive_merges = v; | |
2591 | } | |
2592 | ||
2593 | void rocksdb_options_set_bloom_locality( | |
2594 | rocksdb_options_t* opt, uint32_t v) { | |
2595 | opt->rep.bloom_locality = v; | |
2596 | } | |
2597 | ||
2598 | void rocksdb_options_set_inplace_update_support( | |
2599 | rocksdb_options_t* opt, unsigned char v) { | |
2600 | opt->rep.inplace_update_support = v; | |
2601 | } | |
2602 | ||
2603 | void rocksdb_options_set_inplace_update_num_locks( | |
2604 | rocksdb_options_t* opt, size_t v) { | |
2605 | opt->rep.inplace_update_num_locks = v; | |
2606 | } | |
2607 | ||
2608 | void rocksdb_options_set_report_bg_io_stats( | |
2609 | rocksdb_options_t* opt, int v) { | |
2610 | opt->rep.report_bg_io_stats = v; | |
2611 | } | |
2612 | ||
2613 | void rocksdb_options_set_compaction_style(rocksdb_options_t *opt, int style) { | |
2614 | opt->rep.compaction_style = static_cast<rocksdb::CompactionStyle>(style); | |
2615 | } | |
2616 | ||
2617 | void rocksdb_options_set_universal_compaction_options(rocksdb_options_t *opt, rocksdb_universal_compaction_options_t *uco) { | |
2618 | opt->rep.compaction_options_universal = *(uco->rep); | |
2619 | } | |
2620 | ||
2621 | void rocksdb_options_set_fifo_compaction_options( | |
2622 | rocksdb_options_t* opt, | |
2623 | rocksdb_fifo_compaction_options_t* fifo) { | |
2624 | opt->rep.compaction_options_fifo = fifo->rep; | |
2625 | } | |
2626 | ||
2627 | char *rocksdb_options_statistics_get_string(rocksdb_options_t *opt) { | |
2628 | rocksdb::Statistics *statistics = opt->rep.statistics.get(); | |
2629 | if (statistics) { | |
2630 | return strdup(statistics->ToString().c_str()); | |
2631 | } | |
2632 | return nullptr; | |
2633 | } | |
2634 | ||
2635 | void rocksdb_options_set_ratelimiter(rocksdb_options_t *opt, rocksdb_ratelimiter_t *limiter) { | |
11fdf7f2 TL |
2636 | if (limiter) { |
2637 | opt->rep.rate_limiter = limiter->rep; | |
2638 | } | |
7c673cae FG |
2639 | } |
2640 | ||
2641 | rocksdb_ratelimiter_t* rocksdb_ratelimiter_create( | |
2642 | int64_t rate_bytes_per_sec, | |
2643 | int64_t refill_period_us, | |
2644 | int32_t fairness) { | |
2645 | rocksdb_ratelimiter_t* rate_limiter = new rocksdb_ratelimiter_t; | |
11fdf7f2 TL |
2646 | rate_limiter->rep.reset( |
2647 | NewGenericRateLimiter(rate_bytes_per_sec, | |
2648 | refill_period_us, fairness)); | |
7c673cae FG |
2649 | return rate_limiter; |
2650 | } | |
2651 | ||
2652 | void rocksdb_ratelimiter_destroy(rocksdb_ratelimiter_t *limiter) { | |
7c673cae FG |
2653 | delete limiter; |
2654 | } | |
2655 | ||
11fdf7f2 TL |
2656 | void rocksdb_set_perf_level(int v) { |
2657 | PerfLevel level = static_cast<PerfLevel>(v); | |
2658 | SetPerfLevel(level); | |
2659 | } | |
2660 | ||
2661 | rocksdb_perfcontext_t* rocksdb_perfcontext_create() { | |
2662 | rocksdb_perfcontext_t* context = new rocksdb_perfcontext_t; | |
2663 | context->rep = rocksdb::get_perf_context(); | |
2664 | return context; | |
2665 | } | |
2666 | ||
2667 | void rocksdb_perfcontext_reset(rocksdb_perfcontext_t* context) { | |
2668 | context->rep->Reset(); | |
2669 | } | |
2670 | ||
2671 | char* rocksdb_perfcontext_report(rocksdb_perfcontext_t* context, | |
2672 | unsigned char exclude_zero_counters) { | |
2673 | return strdup(context->rep->ToString(exclude_zero_counters).c_str()); | |
2674 | } | |
2675 | ||
2676 | uint64_t rocksdb_perfcontext_metric(rocksdb_perfcontext_t* context, | |
2677 | int metric) { | |
2678 | PerfContext* rep = context->rep; | |
2679 | switch (metric) { | |
2680 | case rocksdb_user_key_comparison_count: | |
2681 | return rep->user_key_comparison_count; | |
2682 | case rocksdb_block_cache_hit_count: | |
2683 | return rep->block_cache_hit_count; | |
2684 | case rocksdb_block_read_count: | |
2685 | return rep->block_read_count; | |
2686 | case rocksdb_block_read_byte: | |
2687 | return rep->block_read_byte; | |
2688 | case rocksdb_block_read_time: | |
2689 | return rep->block_read_time; | |
2690 | case rocksdb_block_checksum_time: | |
2691 | return rep->block_checksum_time; | |
2692 | case rocksdb_block_decompress_time: | |
2693 | return rep->block_decompress_time; | |
2694 | case rocksdb_get_read_bytes: | |
2695 | return rep->get_read_bytes; | |
2696 | case rocksdb_multiget_read_bytes: | |
2697 | return rep->multiget_read_bytes; | |
2698 | case rocksdb_iter_read_bytes: | |
2699 | return rep->iter_read_bytes; | |
2700 | case rocksdb_internal_key_skipped_count: | |
2701 | return rep->internal_key_skipped_count; | |
2702 | case rocksdb_internal_delete_skipped_count: | |
2703 | return rep->internal_delete_skipped_count; | |
2704 | case rocksdb_internal_recent_skipped_count: | |
2705 | return rep->internal_recent_skipped_count; | |
2706 | case rocksdb_internal_merge_count: | |
2707 | return rep->internal_merge_count; | |
2708 | case rocksdb_get_snapshot_time: | |
2709 | return rep->get_snapshot_time; | |
2710 | case rocksdb_get_from_memtable_time: | |
2711 | return rep->get_from_memtable_time; | |
2712 | case rocksdb_get_from_memtable_count: | |
2713 | return rep->get_from_memtable_count; | |
2714 | case rocksdb_get_post_process_time: | |
2715 | return rep->get_post_process_time; | |
2716 | case rocksdb_get_from_output_files_time: | |
2717 | return rep->get_from_output_files_time; | |
2718 | case rocksdb_seek_on_memtable_time: | |
2719 | return rep->seek_on_memtable_time; | |
2720 | case rocksdb_seek_on_memtable_count: | |
2721 | return rep->seek_on_memtable_count; | |
2722 | case rocksdb_next_on_memtable_count: | |
2723 | return rep->next_on_memtable_count; | |
2724 | case rocksdb_prev_on_memtable_count: | |
2725 | return rep->prev_on_memtable_count; | |
2726 | case rocksdb_seek_child_seek_time: | |
2727 | return rep->seek_child_seek_time; | |
2728 | case rocksdb_seek_child_seek_count: | |
2729 | return rep->seek_child_seek_count; | |
2730 | case rocksdb_seek_min_heap_time: | |
2731 | return rep->seek_min_heap_time; | |
2732 | case rocksdb_seek_max_heap_time: | |
2733 | return rep->seek_max_heap_time; | |
2734 | case rocksdb_seek_internal_seek_time: | |
2735 | return rep->seek_internal_seek_time; | |
2736 | case rocksdb_find_next_user_entry_time: | |
2737 | return rep->find_next_user_entry_time; | |
2738 | case rocksdb_write_wal_time: | |
2739 | return rep->write_wal_time; | |
2740 | case rocksdb_write_memtable_time: | |
2741 | return rep->write_memtable_time; | |
2742 | case rocksdb_write_delay_time: | |
2743 | return rep->write_delay_time; | |
2744 | case rocksdb_write_pre_and_post_process_time: | |
2745 | return rep->write_pre_and_post_process_time; | |
2746 | case rocksdb_db_mutex_lock_nanos: | |
2747 | return rep->db_mutex_lock_nanos; | |
2748 | case rocksdb_db_condition_wait_nanos: | |
2749 | return rep->db_condition_wait_nanos; | |
2750 | case rocksdb_merge_operator_time_nanos: | |
2751 | return rep->merge_operator_time_nanos; | |
2752 | case rocksdb_read_index_block_nanos: | |
2753 | return rep->read_index_block_nanos; | |
2754 | case rocksdb_read_filter_block_nanos: | |
2755 | return rep->read_filter_block_nanos; | |
2756 | case rocksdb_new_table_block_iter_nanos: | |
2757 | return rep->new_table_block_iter_nanos; | |
2758 | case rocksdb_new_table_iterator_nanos: | |
2759 | return rep->new_table_iterator_nanos; | |
2760 | case rocksdb_block_seek_nanos: | |
2761 | return rep->block_seek_nanos; | |
2762 | case rocksdb_find_table_nanos: | |
2763 | return rep->find_table_nanos; | |
2764 | case rocksdb_bloom_memtable_hit_count: | |
2765 | return rep->bloom_memtable_hit_count; | |
2766 | case rocksdb_bloom_memtable_miss_count: | |
2767 | return rep->bloom_memtable_miss_count; | |
2768 | case rocksdb_bloom_sst_hit_count: | |
2769 | return rep->bloom_sst_hit_count; | |
2770 | case rocksdb_bloom_sst_miss_count: | |
2771 | return rep->bloom_sst_miss_count; | |
2772 | case rocksdb_key_lock_wait_time: | |
2773 | return rep->key_lock_wait_time; | |
2774 | case rocksdb_key_lock_wait_count: | |
2775 | return rep->key_lock_wait_count; | |
2776 | case rocksdb_env_new_sequential_file_nanos: | |
2777 | return rep->env_new_sequential_file_nanos; | |
2778 | case rocksdb_env_new_random_access_file_nanos: | |
2779 | return rep->env_new_random_access_file_nanos; | |
2780 | case rocksdb_env_new_writable_file_nanos: | |
2781 | return rep->env_new_writable_file_nanos; | |
2782 | case rocksdb_env_reuse_writable_file_nanos: | |
2783 | return rep->env_reuse_writable_file_nanos; | |
2784 | case rocksdb_env_new_random_rw_file_nanos: | |
2785 | return rep->env_new_random_rw_file_nanos; | |
2786 | case rocksdb_env_new_directory_nanos: | |
2787 | return rep->env_new_directory_nanos; | |
2788 | case rocksdb_env_file_exists_nanos: | |
2789 | return rep->env_file_exists_nanos; | |
2790 | case rocksdb_env_get_children_nanos: | |
2791 | return rep->env_get_children_nanos; | |
2792 | case rocksdb_env_get_children_file_attributes_nanos: | |
2793 | return rep->env_get_children_file_attributes_nanos; | |
2794 | case rocksdb_env_delete_file_nanos: | |
2795 | return rep->env_delete_file_nanos; | |
2796 | case rocksdb_env_create_dir_nanos: | |
2797 | return rep->env_create_dir_nanos; | |
2798 | case rocksdb_env_create_dir_if_missing_nanos: | |
2799 | return rep->env_create_dir_if_missing_nanos; | |
2800 | case rocksdb_env_delete_dir_nanos: | |
2801 | return rep->env_delete_dir_nanos; | |
2802 | case rocksdb_env_get_file_size_nanos: | |
2803 | return rep->env_get_file_size_nanos; | |
2804 | case rocksdb_env_get_file_modification_time_nanos: | |
2805 | return rep->env_get_file_modification_time_nanos; | |
2806 | case rocksdb_env_rename_file_nanos: | |
2807 | return rep->env_rename_file_nanos; | |
2808 | case rocksdb_env_link_file_nanos: | |
2809 | return rep->env_link_file_nanos; | |
2810 | case rocksdb_env_lock_file_nanos: | |
2811 | return rep->env_lock_file_nanos; | |
2812 | case rocksdb_env_unlock_file_nanos: | |
2813 | return rep->env_unlock_file_nanos; | |
2814 | case rocksdb_env_new_logger_nanos: | |
2815 | return rep->env_new_logger_nanos; | |
2816 | default: | |
2817 | break; | |
2818 | } | |
2819 | return 0; | |
2820 | } | |
2821 | ||
2822 | void rocksdb_perfcontext_destroy(rocksdb_perfcontext_t* context) { | |
2823 | delete context; | |
2824 | } | |
2825 | ||
7c673cae FG |
2826 | /* |
2827 | TODO: | |
2828 | DB::OpenForReadOnly | |
2829 | DB::KeyMayExist | |
2830 | DB::GetOptions | |
2831 | DB::GetSortedWalFiles | |
2832 | DB::GetLatestSequenceNumber | |
2833 | DB::GetUpdatesSince | |
2834 | DB::GetDbIdentity | |
2835 | DB::RunManualCompaction | |
2836 | custom cache | |
2837 | table_properties_collectors | |
2838 | */ | |
2839 | ||
2840 | rocksdb_compactionfilter_t* rocksdb_compactionfilter_create( | |
2841 | void* state, | |
2842 | void (*destructor)(void*), | |
2843 | unsigned char (*filter)( | |
2844 | void*, | |
2845 | int level, | |
2846 | const char* key, size_t key_length, | |
2847 | const char* existing_value, size_t value_length, | |
2848 | char** new_value, size_t *new_value_length, | |
2849 | unsigned char* value_changed), | |
2850 | const char* (*name)(void*)) { | |
2851 | rocksdb_compactionfilter_t* result = new rocksdb_compactionfilter_t; | |
2852 | result->state_ = state; | |
2853 | result->destructor_ = destructor; | |
2854 | result->filter_ = filter; | |
494da23a | 2855 | result->ignore_snapshots_ = true; |
7c673cae FG |
2856 | result->name_ = name; |
2857 | return result; | |
2858 | } | |
2859 | ||
2860 | void rocksdb_compactionfilter_set_ignore_snapshots( | |
2861 | rocksdb_compactionfilter_t* filter, | |
2862 | unsigned char whether_ignore) { | |
2863 | filter->ignore_snapshots_ = whether_ignore; | |
2864 | } | |
2865 | ||
2866 | void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t* filter) { | |
2867 | delete filter; | |
2868 | } | |
2869 | ||
2870 | unsigned char rocksdb_compactionfiltercontext_is_full_compaction( | |
2871 | rocksdb_compactionfiltercontext_t* context) { | |
2872 | return context->rep.is_full_compaction; | |
2873 | } | |
2874 | ||
2875 | unsigned char rocksdb_compactionfiltercontext_is_manual_compaction( | |
2876 | rocksdb_compactionfiltercontext_t* context) { | |
2877 | return context->rep.is_manual_compaction; | |
2878 | } | |
2879 | ||
2880 | rocksdb_compactionfilterfactory_t* rocksdb_compactionfilterfactory_create( | |
2881 | void* state, void (*destructor)(void*), | |
2882 | rocksdb_compactionfilter_t* (*create_compaction_filter)( | |
2883 | void*, rocksdb_compactionfiltercontext_t* context), | |
2884 | const char* (*name)(void*)) { | |
2885 | rocksdb_compactionfilterfactory_t* result = | |
2886 | new rocksdb_compactionfilterfactory_t; | |
2887 | result->state_ = state; | |
2888 | result->destructor_ = destructor; | |
2889 | result->create_compaction_filter_ = create_compaction_filter; | |
2890 | result->name_ = name; | |
2891 | return result; | |
2892 | } | |
2893 | ||
2894 | void rocksdb_compactionfilterfactory_destroy( | |
2895 | rocksdb_compactionfilterfactory_t* factory) { | |
2896 | delete factory; | |
2897 | } | |
2898 | ||
2899 | rocksdb_comparator_t* rocksdb_comparator_create( | |
2900 | void* state, | |
2901 | void (*destructor)(void*), | |
2902 | int (*compare)( | |
2903 | void*, | |
2904 | const char* a, size_t alen, | |
2905 | const char* b, size_t blen), | |
2906 | const char* (*name)(void*)) { | |
2907 | rocksdb_comparator_t* result = new rocksdb_comparator_t; | |
2908 | result->state_ = state; | |
2909 | result->destructor_ = destructor; | |
2910 | result->compare_ = compare; | |
2911 | result->name_ = name; | |
2912 | return result; | |
2913 | } | |
2914 | ||
2915 | void rocksdb_comparator_destroy(rocksdb_comparator_t* cmp) { | |
2916 | delete cmp; | |
2917 | } | |
2918 | ||
2919 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create( | |
2920 | void* state, | |
2921 | void (*destructor)(void*), | |
2922 | char* (*create_filter)( | |
2923 | void*, | |
2924 | const char* const* key_array, const size_t* key_length_array, | |
2925 | int num_keys, | |
2926 | size_t* filter_length), | |
2927 | unsigned char (*key_may_match)( | |
2928 | void*, | |
2929 | const char* key, size_t length, | |
2930 | const char* filter, size_t filter_length), | |
2931 | void (*delete_filter)( | |
2932 | void*, | |
2933 | const char* filter, size_t filter_length), | |
2934 | const char* (*name)(void*)) { | |
2935 | rocksdb_filterpolicy_t* result = new rocksdb_filterpolicy_t; | |
2936 | result->state_ = state; | |
2937 | result->destructor_ = destructor; | |
2938 | result->create_ = create_filter; | |
2939 | result->key_match_ = key_may_match; | |
2940 | result->delete_filter_ = delete_filter; | |
2941 | result->name_ = name; | |
2942 | return result; | |
2943 | } | |
2944 | ||
2945 | void rocksdb_filterpolicy_destroy(rocksdb_filterpolicy_t* filter) { | |
2946 | delete filter; | |
2947 | } | |
2948 | ||
2949 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_bloom_format(int bits_per_key, bool original_format) { | |
2950 | // Make a rocksdb_filterpolicy_t, but override all of its methods so | |
2951 | // they delegate to a NewBloomFilterPolicy() instead of user | |
2952 | // supplied C functions. | |
2953 | struct Wrapper : public rocksdb_filterpolicy_t { | |
2954 | const FilterPolicy* rep_; | |
494da23a | 2955 | ~Wrapper() override { delete rep_; } |
7c673cae FG |
2956 | const char* Name() const override { return rep_->Name(); } |
2957 | void CreateFilter(const Slice* keys, int n, | |
2958 | std::string* dst) const override { | |
2959 | return rep_->CreateFilter(keys, n, dst); | |
2960 | } | |
2961 | bool KeyMayMatch(const Slice& key, const Slice& filter) const override { | |
2962 | return rep_->KeyMayMatch(key, filter); | |
2963 | } | |
2964 | static void DoNothing(void*) { } | |
2965 | }; | |
2966 | Wrapper* wrapper = new Wrapper; | |
2967 | wrapper->rep_ = NewBloomFilterPolicy(bits_per_key, original_format); | |
2968 | wrapper->state_ = nullptr; | |
2969 | wrapper->delete_filter_ = nullptr; | |
2970 | wrapper->destructor_ = &Wrapper::DoNothing; | |
2971 | return wrapper; | |
2972 | } | |
2973 | ||
2974 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_bloom_full(int bits_per_key) { | |
2975 | return rocksdb_filterpolicy_create_bloom_format(bits_per_key, false); | |
2976 | } | |
2977 | ||
2978 | rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_bloom(int bits_per_key) { | |
2979 | return rocksdb_filterpolicy_create_bloom_format(bits_per_key, true); | |
2980 | } | |
2981 | ||
2982 | rocksdb_mergeoperator_t* rocksdb_mergeoperator_create( | |
2983 | void* state, void (*destructor)(void*), | |
2984 | char* (*full_merge)(void*, const char* key, size_t key_length, | |
2985 | const char* existing_value, | |
2986 | size_t existing_value_length, | |
2987 | const char* const* operands_list, | |
2988 | const size_t* operands_list_length, int num_operands, | |
2989 | unsigned char* success, size_t* new_value_length), | |
2990 | char* (*partial_merge)(void*, const char* key, size_t key_length, | |
2991 | const char* const* operands_list, | |
2992 | const size_t* operands_list_length, int num_operands, | |
2993 | unsigned char* success, size_t* new_value_length), | |
2994 | void (*delete_value)(void*, const char* value, size_t value_length), | |
2995 | const char* (*name)(void*)) { | |
2996 | rocksdb_mergeoperator_t* result = new rocksdb_mergeoperator_t; | |
2997 | result->state_ = state; | |
2998 | result->destructor_ = destructor; | |
2999 | result->full_merge_ = full_merge; | |
3000 | result->partial_merge_ = partial_merge; | |
3001 | result->delete_value_ = delete_value; | |
3002 | result->name_ = name; | |
3003 | return result; | |
3004 | } | |
3005 | ||
3006 | void rocksdb_mergeoperator_destroy(rocksdb_mergeoperator_t* merge_operator) { | |
3007 | delete merge_operator; | |
3008 | } | |
3009 | ||
3010 | rocksdb_readoptions_t* rocksdb_readoptions_create() { | |
3011 | return new rocksdb_readoptions_t; | |
3012 | } | |
3013 | ||
3014 | void rocksdb_readoptions_destroy(rocksdb_readoptions_t* opt) { | |
3015 | delete opt; | |
3016 | } | |
3017 | ||
3018 | void rocksdb_readoptions_set_verify_checksums( | |
3019 | rocksdb_readoptions_t* opt, | |
3020 | unsigned char v) { | |
3021 | opt->rep.verify_checksums = v; | |
3022 | } | |
3023 | ||
3024 | void rocksdb_readoptions_set_fill_cache( | |
3025 | rocksdb_readoptions_t* opt, unsigned char v) { | |
3026 | opt->rep.fill_cache = v; | |
3027 | } | |
3028 | ||
3029 | void rocksdb_readoptions_set_snapshot( | |
3030 | rocksdb_readoptions_t* opt, | |
3031 | const rocksdb_snapshot_t* snap) { | |
3032 | opt->rep.snapshot = (snap ? snap->rep : nullptr); | |
3033 | } | |
3034 | ||
3035 | void rocksdb_readoptions_set_iterate_upper_bound( | |
3036 | rocksdb_readoptions_t* opt, | |
3037 | const char* key, size_t keylen) { | |
3038 | if (key == nullptr) { | |
3039 | opt->upper_bound = Slice(); | |
3040 | opt->rep.iterate_upper_bound = nullptr; | |
3041 | ||
3042 | } else { | |
3043 | opt->upper_bound = Slice(key, keylen); | |
3044 | opt->rep.iterate_upper_bound = &opt->upper_bound; | |
3045 | } | |
3046 | } | |
3047 | ||
11fdf7f2 TL |
3048 | void rocksdb_readoptions_set_iterate_lower_bound( |
3049 | rocksdb_readoptions_t *opt, | |
3050 | const char* key, size_t keylen) { | |
3051 | if (key == nullptr) { | |
3052 | opt->lower_bound = Slice(); | |
3053 | opt->rep.iterate_lower_bound = nullptr; | |
3054 | } else { | |
3055 | opt->lower_bound = Slice(key, keylen); | |
3056 | opt->rep.iterate_lower_bound = &opt->lower_bound; | |
3057 | } | |
3058 | } | |
3059 | ||
7c673cae FG |
3060 | void rocksdb_readoptions_set_read_tier( |
3061 | rocksdb_readoptions_t* opt, int v) { | |
3062 | opt->rep.read_tier = static_cast<rocksdb::ReadTier>(v); | |
3063 | } | |
3064 | ||
3065 | void rocksdb_readoptions_set_tailing( | |
3066 | rocksdb_readoptions_t* opt, unsigned char v) { | |
3067 | opt->rep.tailing = v; | |
3068 | } | |
3069 | ||
11fdf7f2 TL |
3070 | void rocksdb_readoptions_set_managed( |
3071 | rocksdb_readoptions_t* opt, unsigned char v) { | |
3072 | opt->rep.managed = v; | |
3073 | } | |
3074 | ||
7c673cae FG |
3075 | void rocksdb_readoptions_set_readahead_size( |
3076 | rocksdb_readoptions_t* opt, size_t v) { | |
3077 | opt->rep.readahead_size = v; | |
3078 | } | |
3079 | ||
11fdf7f2 TL |
3080 | void rocksdb_readoptions_set_prefix_same_as_start( |
3081 | rocksdb_readoptions_t* opt, unsigned char v) { | |
3082 | opt->rep.prefix_same_as_start = v; | |
3083 | } | |
3084 | ||
7c673cae FG |
3085 | void rocksdb_readoptions_set_pin_data(rocksdb_readoptions_t* opt, |
3086 | unsigned char v) { | |
3087 | opt->rep.pin_data = v; | |
3088 | } | |
3089 | ||
3090 | void rocksdb_readoptions_set_total_order_seek(rocksdb_readoptions_t* opt, | |
3091 | unsigned char v) { | |
3092 | opt->rep.total_order_seek = v; | |
3093 | } | |
3094 | ||
11fdf7f2 TL |
3095 | void rocksdb_readoptions_set_max_skippable_internal_keys( |
3096 | rocksdb_readoptions_t* opt, | |
3097 | uint64_t v) { | |
3098 | opt->rep.max_skippable_internal_keys = v; | |
3099 | } | |
3100 | ||
3101 | void rocksdb_readoptions_set_background_purge_on_iterator_cleanup( | |
3102 | rocksdb_readoptions_t* opt, unsigned char v) { | |
3103 | opt->rep.background_purge_on_iterator_cleanup = v; | |
3104 | } | |
3105 | ||
3106 | void rocksdb_readoptions_set_ignore_range_deletions( | |
3107 | rocksdb_readoptions_t* opt, unsigned char v) { | |
3108 | opt->rep.ignore_range_deletions = v; | |
3109 | } | |
3110 | ||
7c673cae FG |
3111 | rocksdb_writeoptions_t* rocksdb_writeoptions_create() { |
3112 | return new rocksdb_writeoptions_t; | |
3113 | } | |
3114 | ||
3115 | void rocksdb_writeoptions_destroy(rocksdb_writeoptions_t* opt) { | |
3116 | delete opt; | |
3117 | } | |
3118 | ||
3119 | void rocksdb_writeoptions_set_sync( | |
3120 | rocksdb_writeoptions_t* opt, unsigned char v) { | |
3121 | opt->rep.sync = v; | |
3122 | } | |
3123 | ||
3124 | void rocksdb_writeoptions_disable_WAL(rocksdb_writeoptions_t* opt, int disable) { | |
3125 | opt->rep.disableWAL = disable; | |
3126 | } | |
3127 | ||
11fdf7f2 TL |
3128 | void rocksdb_writeoptions_set_ignore_missing_column_families( |
3129 | rocksdb_writeoptions_t* opt, | |
3130 | unsigned char v) { | |
3131 | opt->rep.ignore_missing_column_families = v; | |
3132 | } | |
3133 | ||
3134 | void rocksdb_writeoptions_set_no_slowdown( | |
3135 | rocksdb_writeoptions_t* opt, | |
3136 | unsigned char v) { | |
3137 | opt->rep.no_slowdown = v; | |
3138 | } | |
3139 | ||
3140 | void rocksdb_writeoptions_set_low_pri( | |
3141 | rocksdb_writeoptions_t* opt, | |
3142 | unsigned char v) { | |
3143 | opt->rep.low_pri = v; | |
3144 | } | |
3145 | ||
7c673cae FG |
3146 | rocksdb_compactoptions_t* rocksdb_compactoptions_create() { |
3147 | return new rocksdb_compactoptions_t; | |
3148 | } | |
3149 | ||
3150 | void rocksdb_compactoptions_destroy(rocksdb_compactoptions_t* opt) { | |
3151 | delete opt; | |
3152 | } | |
3153 | ||
11fdf7f2 TL |
3154 | void rocksdb_compactoptions_set_bottommost_level_compaction( |
3155 | rocksdb_compactoptions_t* opt, unsigned char v) { | |
3156 | opt->rep.bottommost_level_compaction = static_cast<BottommostLevelCompaction>(v); | |
3157 | } | |
3158 | ||
7c673cae FG |
3159 | void rocksdb_compactoptions_set_exclusive_manual_compaction( |
3160 | rocksdb_compactoptions_t* opt, unsigned char v) { | |
3161 | opt->rep.exclusive_manual_compaction = v; | |
3162 | } | |
3163 | ||
3164 | void rocksdb_compactoptions_set_change_level(rocksdb_compactoptions_t* opt, | |
3165 | unsigned char v) { | |
3166 | opt->rep.change_level = v; | |
3167 | } | |
3168 | ||
3169 | void rocksdb_compactoptions_set_target_level(rocksdb_compactoptions_t* opt, | |
3170 | int n) { | |
3171 | opt->rep.target_level = n; | |
3172 | } | |
3173 | ||
3174 | rocksdb_flushoptions_t* rocksdb_flushoptions_create() { | |
3175 | return new rocksdb_flushoptions_t; | |
3176 | } | |
3177 | ||
3178 | void rocksdb_flushoptions_destroy(rocksdb_flushoptions_t* opt) { | |
3179 | delete opt; | |
3180 | } | |
3181 | ||
3182 | void rocksdb_flushoptions_set_wait( | |
3183 | rocksdb_flushoptions_t* opt, unsigned char v) { | |
3184 | opt->rep.wait = v; | |
3185 | } | |
3186 | ||
3187 | rocksdb_cache_t* rocksdb_cache_create_lru(size_t capacity) { | |
3188 | rocksdb_cache_t* c = new rocksdb_cache_t; | |
3189 | c->rep = NewLRUCache(capacity); | |
3190 | return c; | |
3191 | } | |
3192 | ||
3193 | void rocksdb_cache_destroy(rocksdb_cache_t* cache) { | |
3194 | delete cache; | |
3195 | } | |
3196 | ||
3197 | void rocksdb_cache_set_capacity(rocksdb_cache_t* cache, size_t capacity) { | |
3198 | cache->rep->SetCapacity(capacity); | |
3199 | } | |
3200 | ||
3201 | size_t rocksdb_cache_get_usage(rocksdb_cache_t* cache) { | |
3202 | return cache->rep->GetUsage(); | |
3203 | } | |
3204 | ||
3205 | size_t rocksdb_cache_get_pinned_usage(rocksdb_cache_t* cache) { | |
3206 | return cache->rep->GetPinnedUsage(); | |
3207 | } | |
3208 | ||
11fdf7f2 TL |
3209 | rocksdb_dbpath_t* rocksdb_dbpath_create(const char* path, uint64_t target_size) { |
3210 | rocksdb_dbpath_t* result = new rocksdb_dbpath_t; | |
3211 | result->rep.path = std::string(path); | |
3212 | result->rep.target_size = target_size; | |
3213 | return result; | |
3214 | } | |
3215 | ||
3216 | void rocksdb_dbpath_destroy(rocksdb_dbpath_t* dbpath) { | |
3217 | delete dbpath; | |
3218 | } | |
3219 | ||
7c673cae FG |
3220 | rocksdb_env_t* rocksdb_create_default_env() { |
3221 | rocksdb_env_t* result = new rocksdb_env_t; | |
3222 | result->rep = Env::Default(); | |
3223 | result->is_default = true; | |
3224 | return result; | |
3225 | } | |
3226 | ||
3227 | rocksdb_env_t* rocksdb_create_mem_env() { | |
3228 | rocksdb_env_t* result = new rocksdb_env_t; | |
3229 | result->rep = rocksdb::NewMemEnv(Env::Default()); | |
3230 | result->is_default = false; | |
3231 | return result; | |
3232 | } | |
3233 | ||
3234 | void rocksdb_env_set_background_threads(rocksdb_env_t* env, int n) { | |
3235 | env->rep->SetBackgroundThreads(n); | |
3236 | } | |
3237 | ||
3238 | void rocksdb_env_set_high_priority_background_threads(rocksdb_env_t* env, int n) { | |
3239 | env->rep->SetBackgroundThreads(n, Env::HIGH); | |
3240 | } | |
3241 | ||
3242 | void rocksdb_env_join_all_threads(rocksdb_env_t* env) { | |
3243 | env->rep->WaitForJoin(); | |
3244 | } | |
3245 | ||
3246 | void rocksdb_env_destroy(rocksdb_env_t* env) { | |
3247 | if (!env->is_default) delete env->rep; | |
3248 | delete env; | |
3249 | } | |
3250 | ||
3251 | rocksdb_envoptions_t* rocksdb_envoptions_create() { | |
3252 | rocksdb_envoptions_t* opt = new rocksdb_envoptions_t; | |
3253 | return opt; | |
3254 | } | |
3255 | ||
3256 | void rocksdb_envoptions_destroy(rocksdb_envoptions_t* opt) { delete opt; } | |
3257 | ||
3258 | rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create( | |
3259 | const rocksdb_envoptions_t* env, const rocksdb_options_t* io_options) { | |
3260 | rocksdb_sstfilewriter_t* writer = new rocksdb_sstfilewriter_t; | |
3261 | writer->rep = new SstFileWriter(env->rep, io_options->rep); | |
3262 | return writer; | |
3263 | } | |
3264 | ||
3265 | rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create_with_comparator( | |
3266 | const rocksdb_envoptions_t* env, const rocksdb_options_t* io_options, | |
11fdf7f2 | 3267 | const rocksdb_comparator_t* /*comparator*/) { |
7c673cae FG |
3268 | rocksdb_sstfilewriter_t* writer = new rocksdb_sstfilewriter_t; |
3269 | writer->rep = new SstFileWriter(env->rep, io_options->rep); | |
3270 | return writer; | |
3271 | } | |
3272 | ||
3273 | void rocksdb_sstfilewriter_open(rocksdb_sstfilewriter_t* writer, | |
3274 | const char* name, char** errptr) { | |
3275 | SaveError(errptr, writer->rep->Open(std::string(name))); | |
3276 | } | |
3277 | ||
3278 | void rocksdb_sstfilewriter_add(rocksdb_sstfilewriter_t* writer, const char* key, | |
3279 | size_t keylen, const char* val, size_t vallen, | |
3280 | char** errptr) { | |
11fdf7f2 TL |
3281 | SaveError(errptr, writer->rep->Put(Slice(key, keylen), Slice(val, vallen))); |
3282 | } | |
3283 | ||
3284 | void rocksdb_sstfilewriter_put(rocksdb_sstfilewriter_t* writer, const char* key, | |
3285 | size_t keylen, const char* val, size_t vallen, | |
3286 | char** errptr) { | |
3287 | SaveError(errptr, writer->rep->Put(Slice(key, keylen), Slice(val, vallen))); | |
3288 | } | |
3289 | ||
3290 | void rocksdb_sstfilewriter_merge(rocksdb_sstfilewriter_t* writer, | |
3291 | const char* key, size_t keylen, | |
3292 | const char* val, size_t vallen, | |
3293 | char** errptr) { | |
3294 | SaveError(errptr, writer->rep->Merge(Slice(key, keylen), Slice(val, vallen))); | |
3295 | } | |
3296 | ||
3297 | void rocksdb_sstfilewriter_delete(rocksdb_sstfilewriter_t* writer, | |
3298 | const char* key, size_t keylen, | |
3299 | char** errptr) { | |
3300 | SaveError(errptr, writer->rep->Delete(Slice(key, keylen))); | |
7c673cae FG |
3301 | } |
3302 | ||
3303 | void rocksdb_sstfilewriter_finish(rocksdb_sstfilewriter_t* writer, | |
3304 | char** errptr) { | |
11fdf7f2 TL |
3305 | SaveError(errptr, writer->rep->Finish(nullptr)); |
3306 | } | |
3307 | ||
3308 | void rocksdb_sstfilewriter_file_size(rocksdb_sstfilewriter_t* writer, | |
3309 | uint64_t* file_size) { | |
3310 | *file_size = writer->rep->FileSize(); | |
7c673cae FG |
3311 | } |
3312 | ||
3313 | void rocksdb_sstfilewriter_destroy(rocksdb_sstfilewriter_t* writer) { | |
3314 | delete writer->rep; | |
3315 | delete writer; | |
3316 | } | |
3317 | ||
3318 | rocksdb_ingestexternalfileoptions_t* | |
3319 | rocksdb_ingestexternalfileoptions_create() { | |
3320 | rocksdb_ingestexternalfileoptions_t* opt = | |
3321 | new rocksdb_ingestexternalfileoptions_t; | |
3322 | return opt; | |
3323 | } | |
3324 | ||
3325 | void rocksdb_ingestexternalfileoptions_set_move_files( | |
3326 | rocksdb_ingestexternalfileoptions_t* opt, unsigned char move_files) { | |
3327 | opt->rep.move_files = move_files; | |
3328 | } | |
3329 | ||
3330 | void rocksdb_ingestexternalfileoptions_set_snapshot_consistency( | |
3331 | rocksdb_ingestexternalfileoptions_t* opt, | |
3332 | unsigned char snapshot_consistency) { | |
3333 | opt->rep.snapshot_consistency = snapshot_consistency; | |
3334 | } | |
3335 | ||
3336 | void rocksdb_ingestexternalfileoptions_set_allow_global_seqno( | |
3337 | rocksdb_ingestexternalfileoptions_t* opt, | |
3338 | unsigned char allow_global_seqno) { | |
3339 | opt->rep.allow_global_seqno = allow_global_seqno; | |
3340 | } | |
3341 | ||
3342 | void rocksdb_ingestexternalfileoptions_set_allow_blocking_flush( | |
3343 | rocksdb_ingestexternalfileoptions_t* opt, | |
3344 | unsigned char allow_blocking_flush) { | |
3345 | opt->rep.allow_blocking_flush = allow_blocking_flush; | |
3346 | } | |
3347 | ||
11fdf7f2 TL |
3348 | void rocksdb_ingestexternalfileoptions_set_ingest_behind( |
3349 | rocksdb_ingestexternalfileoptions_t* opt, | |
3350 | unsigned char ingest_behind) { | |
3351 | opt->rep.ingest_behind = ingest_behind; | |
3352 | } | |
3353 | ||
7c673cae FG |
3354 | void rocksdb_ingestexternalfileoptions_destroy( |
3355 | rocksdb_ingestexternalfileoptions_t* opt) { | |
3356 | delete opt; | |
3357 | } | |
3358 | ||
3359 | void rocksdb_ingest_external_file( | |
3360 | rocksdb_t* db, const char* const* file_list, const size_t list_len, | |
3361 | const rocksdb_ingestexternalfileoptions_t* opt, char** errptr) { | |
3362 | std::vector<std::string> files(list_len); | |
3363 | for (size_t i = 0; i < list_len; ++i) { | |
3364 | files[i] = std::string(file_list[i]); | |
3365 | } | |
3366 | SaveError(errptr, db->rep->IngestExternalFile(files, opt->rep)); | |
3367 | } | |
3368 | ||
3369 | void rocksdb_ingest_external_file_cf( | |
3370 | rocksdb_t* db, rocksdb_column_family_handle_t* handle, | |
3371 | const char* const* file_list, const size_t list_len, | |
3372 | const rocksdb_ingestexternalfileoptions_t* opt, char** errptr) { | |
3373 | std::vector<std::string> files(list_len); | |
3374 | for (size_t i = 0; i < list_len; ++i) { | |
3375 | files[i] = std::string(file_list[i]); | |
3376 | } | |
3377 | SaveError(errptr, db->rep->IngestExternalFile(handle->rep, files, opt->rep)); | |
3378 | } | |
3379 | ||
3380 | rocksdb_slicetransform_t* rocksdb_slicetransform_create( | |
3381 | void* state, | |
3382 | void (*destructor)(void*), | |
3383 | char* (*transform)( | |
3384 | void*, | |
3385 | const char* key, size_t length, | |
3386 | size_t* dst_length), | |
3387 | unsigned char (*in_domain)( | |
3388 | void*, | |
3389 | const char* key, size_t length), | |
3390 | unsigned char (*in_range)( | |
3391 | void*, | |
3392 | const char* key, size_t length), | |
3393 | const char* (*name)(void*)) { | |
3394 | rocksdb_slicetransform_t* result = new rocksdb_slicetransform_t; | |
3395 | result->state_ = state; | |
3396 | result->destructor_ = destructor; | |
3397 | result->transform_ = transform; | |
3398 | result->in_domain_ = in_domain; | |
3399 | result->in_range_ = in_range; | |
3400 | result->name_ = name; | |
3401 | return result; | |
3402 | } | |
3403 | ||
3404 | void rocksdb_slicetransform_destroy(rocksdb_slicetransform_t* st) { | |
3405 | delete st; | |
3406 | } | |
3407 | ||
11fdf7f2 TL |
3408 | struct Wrapper : public rocksdb_slicetransform_t { |
3409 | const SliceTransform* rep_; | |
494da23a | 3410 | ~Wrapper() override { delete rep_; } |
11fdf7f2 TL |
3411 | const char* Name() const override { return rep_->Name(); } |
3412 | Slice Transform(const Slice& src) const override { | |
3413 | return rep_->Transform(src); | |
3414 | } | |
3415 | bool InDomain(const Slice& src) const override { | |
3416 | return rep_->InDomain(src); | |
3417 | } | |
3418 | bool InRange(const Slice& src) const override { return rep_->InRange(src); } | |
3419 | static void DoNothing(void*) { } | |
3420 | }; | |
3421 | ||
7c673cae | 3422 | rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix(size_t prefixLen) { |
7c673cae FG |
3423 | Wrapper* wrapper = new Wrapper; |
3424 | wrapper->rep_ = rocksdb::NewFixedPrefixTransform(prefixLen); | |
3425 | wrapper->state_ = nullptr; | |
3426 | wrapper->destructor_ = &Wrapper::DoNothing; | |
3427 | return wrapper; | |
3428 | } | |
3429 | ||
3430 | rocksdb_slicetransform_t* rocksdb_slicetransform_create_noop() { | |
7c673cae FG |
3431 | Wrapper* wrapper = new Wrapper; |
3432 | wrapper->rep_ = rocksdb::NewNoopTransform(); | |
3433 | wrapper->state_ = nullptr; | |
3434 | wrapper->destructor_ = &Wrapper::DoNothing; | |
3435 | return wrapper; | |
3436 | } | |
3437 | ||
3438 | rocksdb_universal_compaction_options_t* rocksdb_universal_compaction_options_create() { | |
3439 | rocksdb_universal_compaction_options_t* result = new rocksdb_universal_compaction_options_t; | |
3440 | result->rep = new rocksdb::CompactionOptionsUniversal; | |
3441 | return result; | |
3442 | } | |
3443 | ||
3444 | void rocksdb_universal_compaction_options_set_size_ratio( | |
3445 | rocksdb_universal_compaction_options_t* uco, int ratio) { | |
3446 | uco->rep->size_ratio = ratio; | |
3447 | } | |
3448 | ||
3449 | void rocksdb_universal_compaction_options_set_min_merge_width( | |
3450 | rocksdb_universal_compaction_options_t* uco, int w) { | |
3451 | uco->rep->min_merge_width = w; | |
3452 | } | |
3453 | ||
3454 | void rocksdb_universal_compaction_options_set_max_merge_width( | |
3455 | rocksdb_universal_compaction_options_t* uco, int w) { | |
3456 | uco->rep->max_merge_width = w; | |
3457 | } | |
3458 | ||
3459 | void rocksdb_universal_compaction_options_set_max_size_amplification_percent( | |
3460 | rocksdb_universal_compaction_options_t* uco, int p) { | |
3461 | uco->rep->max_size_amplification_percent = p; | |
3462 | } | |
3463 | ||
3464 | void rocksdb_universal_compaction_options_set_compression_size_percent( | |
3465 | rocksdb_universal_compaction_options_t* uco, int p) { | |
3466 | uco->rep->compression_size_percent = p; | |
3467 | } | |
3468 | ||
3469 | void rocksdb_universal_compaction_options_set_stop_style( | |
3470 | rocksdb_universal_compaction_options_t* uco, int style) { | |
3471 | uco->rep->stop_style = static_cast<rocksdb::CompactionStopStyle>(style); | |
3472 | } | |
3473 | ||
3474 | void rocksdb_universal_compaction_options_destroy( | |
3475 | rocksdb_universal_compaction_options_t* uco) { | |
3476 | delete uco->rep; | |
3477 | delete uco; | |
3478 | } | |
3479 | ||
3480 | rocksdb_fifo_compaction_options_t* rocksdb_fifo_compaction_options_create() { | |
3481 | rocksdb_fifo_compaction_options_t* result = new rocksdb_fifo_compaction_options_t; | |
3482 | result->rep = CompactionOptionsFIFO(); | |
3483 | return result; | |
3484 | } | |
3485 | ||
3486 | void rocksdb_fifo_compaction_options_set_max_table_files_size( | |
3487 | rocksdb_fifo_compaction_options_t* fifo_opts, uint64_t size) { | |
3488 | fifo_opts->rep.max_table_files_size = size; | |
3489 | } | |
3490 | ||
3491 | void rocksdb_fifo_compaction_options_destroy( | |
3492 | rocksdb_fifo_compaction_options_t* fifo_opts) { | |
3493 | delete fifo_opts; | |
3494 | } | |
3495 | ||
3496 | void rocksdb_options_set_min_level_to_compress(rocksdb_options_t* opt, int level) { | |
3497 | if (level >= 0) { | |
3498 | assert(level <= opt->rep.num_levels); | |
3499 | opt->rep.compression_per_level.resize(opt->rep.num_levels); | |
3500 | for (int i = 0; i < level; i++) { | |
3501 | opt->rep.compression_per_level[i] = rocksdb::kNoCompression; | |
3502 | } | |
3503 | for (int i = level; i < opt->rep.num_levels; i++) { | |
3504 | opt->rep.compression_per_level[i] = opt->rep.compression; | |
3505 | } | |
3506 | } | |
3507 | } | |
3508 | ||
3509 | int rocksdb_livefiles_count( | |
3510 | const rocksdb_livefiles_t* lf) { | |
3511 | return static_cast<int>(lf->rep.size()); | |
3512 | } | |
3513 | ||
3514 | const char* rocksdb_livefiles_name( | |
3515 | const rocksdb_livefiles_t* lf, | |
3516 | int index) { | |
3517 | return lf->rep[index].name.c_str(); | |
3518 | } | |
3519 | ||
3520 | int rocksdb_livefiles_level( | |
3521 | const rocksdb_livefiles_t* lf, | |
3522 | int index) { | |
3523 | return lf->rep[index].level; | |
3524 | } | |
3525 | ||
3526 | size_t rocksdb_livefiles_size( | |
3527 | const rocksdb_livefiles_t* lf, | |
3528 | int index) { | |
3529 | return lf->rep[index].size; | |
3530 | } | |
3531 | ||
3532 | const char* rocksdb_livefiles_smallestkey( | |
3533 | const rocksdb_livefiles_t* lf, | |
3534 | int index, | |
3535 | size_t* size) { | |
3536 | *size = lf->rep[index].smallestkey.size(); | |
3537 | return lf->rep[index].smallestkey.data(); | |
3538 | } | |
3539 | ||
3540 | const char* rocksdb_livefiles_largestkey( | |
3541 | const rocksdb_livefiles_t* lf, | |
3542 | int index, | |
3543 | size_t* size) { | |
3544 | *size = lf->rep[index].largestkey.size(); | |
3545 | return lf->rep[index].largestkey.data(); | |
3546 | } | |
3547 | ||
494da23a TL |
3548 | uint64_t rocksdb_livefiles_entries( |
3549 | const rocksdb_livefiles_t* lf, | |
3550 | int index) { | |
3551 | return lf->rep[index].num_entries; | |
3552 | } | |
3553 | ||
3554 | uint64_t rocksdb_livefiles_deletions( | |
3555 | const rocksdb_livefiles_t* lf, | |
3556 | int index) { | |
3557 | return lf->rep[index].num_deletions; | |
3558 | } | |
3559 | ||
7c673cae FG |
3560 | extern void rocksdb_livefiles_destroy( |
3561 | const rocksdb_livefiles_t* lf) { | |
3562 | delete lf; | |
3563 | } | |
3564 | ||
3565 | void rocksdb_get_options_from_string(const rocksdb_options_t* base_options, | |
3566 | const char* opts_str, | |
3567 | rocksdb_options_t* new_options, | |
3568 | char** errptr) { | |
3569 | SaveError(errptr, | |
3570 | GetOptionsFromString(base_options->rep, std::string(opts_str), | |
3571 | &new_options->rep)); | |
3572 | } | |
3573 | ||
3574 | void rocksdb_delete_file_in_range(rocksdb_t* db, const char* start_key, | |
3575 | size_t start_key_len, const char* limit_key, | |
3576 | size_t limit_key_len, char** errptr) { | |
3577 | Slice a, b; | |
3578 | SaveError( | |
3579 | errptr, | |
3580 | DeleteFilesInRange( | |
3581 | db->rep, db->rep->DefaultColumnFamily(), | |
3582 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
3583 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr))); | |
3584 | } | |
3585 | ||
3586 | void rocksdb_delete_file_in_range_cf( | |
3587 | rocksdb_t* db, rocksdb_column_family_handle_t* column_family, | |
3588 | const char* start_key, size_t start_key_len, const char* limit_key, | |
3589 | size_t limit_key_len, char** errptr) { | |
3590 | Slice a, b; | |
3591 | SaveError( | |
3592 | errptr, | |
3593 | DeleteFilesInRange( | |
3594 | db->rep, column_family->rep, | |
3595 | (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), | |
3596 | (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr))); | |
3597 | } | |
3598 | ||
11fdf7f2 TL |
3599 | rocksdb_transactiondb_options_t* rocksdb_transactiondb_options_create() { |
3600 | return new rocksdb_transactiondb_options_t; | |
3601 | } | |
3602 | ||
3603 | void rocksdb_transactiondb_options_destroy(rocksdb_transactiondb_options_t* opt){ | |
3604 | delete opt; | |
3605 | } | |
3606 | ||
3607 | void rocksdb_transactiondb_options_set_max_num_locks( | |
3608 | rocksdb_transactiondb_options_t* opt, int64_t max_num_locks) { | |
3609 | opt->rep.max_num_locks = max_num_locks; | |
3610 | } | |
3611 | ||
3612 | void rocksdb_transactiondb_options_set_num_stripes( | |
3613 | rocksdb_transactiondb_options_t* opt, size_t num_stripes) { | |
3614 | opt->rep.num_stripes = num_stripes; | |
3615 | } | |
3616 | ||
3617 | void rocksdb_transactiondb_options_set_transaction_lock_timeout( | |
3618 | rocksdb_transactiondb_options_t* opt, int64_t txn_lock_timeout) { | |
3619 | opt->rep.transaction_lock_timeout = txn_lock_timeout; | |
3620 | } | |
3621 | ||
3622 | void rocksdb_transactiondb_options_set_default_lock_timeout( | |
3623 | rocksdb_transactiondb_options_t* opt, int64_t default_lock_timeout) { | |
3624 | opt->rep.default_lock_timeout = default_lock_timeout; | |
3625 | } | |
3626 | ||
3627 | rocksdb_transaction_options_t* rocksdb_transaction_options_create() { | |
3628 | return new rocksdb_transaction_options_t; | |
3629 | } | |
3630 | ||
3631 | void rocksdb_transaction_options_destroy(rocksdb_transaction_options_t* opt) { | |
3632 | delete opt; | |
3633 | } | |
3634 | ||
3635 | void rocksdb_transaction_options_set_set_snapshot( | |
3636 | rocksdb_transaction_options_t* opt, unsigned char v) { | |
3637 | opt->rep.set_snapshot = v; | |
3638 | } | |
3639 | ||
3640 | void rocksdb_transaction_options_set_deadlock_detect( | |
3641 | rocksdb_transaction_options_t* opt, unsigned char v) { | |
3642 | opt->rep.deadlock_detect = v; | |
3643 | } | |
3644 | ||
3645 | void rocksdb_transaction_options_set_lock_timeout( | |
3646 | rocksdb_transaction_options_t* opt, int64_t lock_timeout) { | |
3647 | opt->rep.lock_timeout = lock_timeout; | |
3648 | } | |
3649 | ||
3650 | void rocksdb_transaction_options_set_expiration( | |
3651 | rocksdb_transaction_options_t* opt, int64_t expiration) { | |
3652 | opt->rep.expiration = expiration; | |
3653 | } | |
3654 | ||
3655 | void rocksdb_transaction_options_set_deadlock_detect_depth( | |
3656 | rocksdb_transaction_options_t* opt, int64_t depth) { | |
3657 | opt->rep.deadlock_detect_depth = depth; | |
3658 | } | |
3659 | ||
3660 | void rocksdb_transaction_options_set_max_write_batch_size( | |
3661 | rocksdb_transaction_options_t* opt, size_t size) { | |
3662 | opt->rep.max_write_batch_size = size; | |
3663 | } | |
3664 | ||
3665 | rocksdb_optimistictransaction_options_t* | |
3666 | rocksdb_optimistictransaction_options_create() { | |
3667 | return new rocksdb_optimistictransaction_options_t; | |
3668 | } | |
3669 | ||
3670 | void rocksdb_optimistictransaction_options_destroy( | |
3671 | rocksdb_optimistictransaction_options_t* opt) { | |
3672 | delete opt; | |
3673 | } | |
3674 | ||
3675 | void rocksdb_optimistictransaction_options_set_set_snapshot( | |
3676 | rocksdb_optimistictransaction_options_t* opt, unsigned char v) { | |
3677 | opt->rep.set_snapshot = v; | |
3678 | } | |
3679 | ||
3680 | rocksdb_column_family_handle_t* rocksdb_transactiondb_create_column_family( | |
3681 | rocksdb_transactiondb_t* txn_db, | |
3682 | const rocksdb_options_t* column_family_options, | |
3683 | const char* column_family_name, char** errptr) { | |
3684 | rocksdb_column_family_handle_t* handle = new rocksdb_column_family_handle_t; | |
3685 | SaveError(errptr, txn_db->rep->CreateColumnFamily( | |
3686 | ColumnFamilyOptions(column_family_options->rep), | |
3687 | std::string(column_family_name), &(handle->rep))); | |
3688 | return handle; | |
3689 | } | |
3690 | ||
3691 | rocksdb_transactiondb_t* rocksdb_transactiondb_open( | |
3692 | const rocksdb_options_t* options, | |
3693 | const rocksdb_transactiondb_options_t* txn_db_options, const char* name, | |
3694 | char** errptr) { | |
3695 | TransactionDB* txn_db; | |
3696 | if (SaveError(errptr, TransactionDB::Open(options->rep, txn_db_options->rep, | |
3697 | std::string(name), &txn_db))) { | |
3698 | return nullptr; | |
3699 | } | |
3700 | rocksdb_transactiondb_t* result = new rocksdb_transactiondb_t; | |
3701 | result->rep = txn_db; | |
3702 | return result; | |
3703 | } | |
3704 | ||
494da23a TL |
3705 | rocksdb_transactiondb_t* rocksdb_transactiondb_open_column_families( |
3706 | const rocksdb_options_t* options, | |
3707 | const rocksdb_transactiondb_options_t* txn_db_options, const char* name, | |
3708 | int num_column_families, const char** column_family_names, | |
3709 | const rocksdb_options_t** column_family_options, | |
3710 | rocksdb_column_family_handle_t** column_family_handles, char** errptr) { | |
3711 | std::vector<ColumnFamilyDescriptor> column_families; | |
3712 | for (int i = 0; i < num_column_families; i++) { | |
3713 | column_families.push_back(ColumnFamilyDescriptor( | |
3714 | std::string(column_family_names[i]), | |
3715 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
3716 | } | |
3717 | ||
3718 | TransactionDB* txn_db; | |
3719 | std::vector<ColumnFamilyHandle*> handles; | |
3720 | if (SaveError(errptr, TransactionDB::Open(options->rep, txn_db_options->rep, | |
3721 | std::string(name), column_families, | |
3722 | &handles, &txn_db))) { | |
3723 | return nullptr; | |
3724 | } | |
3725 | ||
3726 | for (size_t i = 0; i < handles.size(); i++) { | |
3727 | rocksdb_column_family_handle_t* c_handle = | |
3728 | new rocksdb_column_family_handle_t; | |
3729 | c_handle->rep = handles[i]; | |
3730 | column_family_handles[i] = c_handle; | |
3731 | } | |
3732 | rocksdb_transactiondb_t* result = new rocksdb_transactiondb_t; | |
3733 | result->rep = txn_db; | |
3734 | return result; | |
3735 | } | |
3736 | ||
11fdf7f2 TL |
3737 | const rocksdb_snapshot_t* rocksdb_transactiondb_create_snapshot( |
3738 | rocksdb_transactiondb_t* txn_db) { | |
3739 | rocksdb_snapshot_t* result = new rocksdb_snapshot_t; | |
3740 | result->rep = txn_db->rep->GetSnapshot(); | |
3741 | return result; | |
3742 | } | |
3743 | ||
3744 | void rocksdb_transactiondb_release_snapshot( | |
3745 | rocksdb_transactiondb_t* txn_db, const rocksdb_snapshot_t* snapshot) { | |
3746 | txn_db->rep->ReleaseSnapshot(snapshot->rep); | |
3747 | delete snapshot; | |
3748 | } | |
3749 | ||
3750 | rocksdb_transaction_t* rocksdb_transaction_begin( | |
3751 | rocksdb_transactiondb_t* txn_db, | |
3752 | const rocksdb_writeoptions_t* write_options, | |
3753 | const rocksdb_transaction_options_t* txn_options, | |
3754 | rocksdb_transaction_t* old_txn) { | |
3755 | if (old_txn == nullptr) { | |
3756 | rocksdb_transaction_t* result = new rocksdb_transaction_t; | |
3757 | result->rep = txn_db->rep->BeginTransaction(write_options->rep, | |
3758 | txn_options->rep, nullptr); | |
3759 | return result; | |
3760 | } | |
3761 | old_txn->rep = txn_db->rep->BeginTransaction(write_options->rep, | |
3762 | txn_options->rep, old_txn->rep); | |
3763 | return old_txn; | |
3764 | } | |
3765 | ||
3766 | void rocksdb_transaction_commit(rocksdb_transaction_t* txn, char** errptr) { | |
3767 | SaveError(errptr, txn->rep->Commit()); | |
3768 | } | |
3769 | ||
3770 | void rocksdb_transaction_rollback(rocksdb_transaction_t* txn, char** errptr) { | |
3771 | SaveError(errptr, txn->rep->Rollback()); | |
3772 | } | |
3773 | ||
3774 | void rocksdb_transaction_set_savepoint(rocksdb_transaction_t* txn) { | |
3775 | txn->rep->SetSavePoint(); | |
3776 | } | |
3777 | ||
3778 | void rocksdb_transaction_rollback_to_savepoint(rocksdb_transaction_t* txn, char** errptr) { | |
3779 | SaveError(errptr, txn->rep->RollbackToSavePoint()); | |
3780 | } | |
3781 | ||
3782 | void rocksdb_transaction_destroy(rocksdb_transaction_t* txn) { | |
3783 | delete txn->rep; | |
3784 | delete txn; | |
3785 | } | |
3786 | ||
3787 | const rocksdb_snapshot_t* rocksdb_transaction_get_snapshot( | |
3788 | rocksdb_transaction_t* txn) { | |
3789 | rocksdb_snapshot_t* result = new rocksdb_snapshot_t; | |
3790 | result->rep = txn->rep->GetSnapshot(); | |
3791 | return result; | |
3792 | } | |
3793 | ||
3794 | // Read a key inside a transaction | |
3795 | char* rocksdb_transaction_get(rocksdb_transaction_t* txn, | |
3796 | const rocksdb_readoptions_t* options, | |
3797 | const char* key, size_t klen, size_t* vlen, | |
3798 | char** errptr) { | |
3799 | char* result = nullptr; | |
3800 | std::string tmp; | |
3801 | Status s = txn->rep->Get(options->rep, Slice(key, klen), &tmp); | |
3802 | if (s.ok()) { | |
3803 | *vlen = tmp.size(); | |
3804 | result = CopyString(tmp); | |
3805 | } else { | |
3806 | *vlen = 0; | |
3807 | if (!s.IsNotFound()) { | |
3808 | SaveError(errptr, s); | |
3809 | } | |
3810 | } | |
3811 | return result; | |
3812 | } | |
3813 | ||
3814 | char* rocksdb_transaction_get_cf(rocksdb_transaction_t* txn, | |
3815 | const rocksdb_readoptions_t* options, | |
3816 | rocksdb_column_family_handle_t* column_family, | |
3817 | const char* key, size_t klen, size_t* vlen, | |
3818 | char** errptr) { | |
3819 | char* result = nullptr; | |
3820 | std::string tmp; | |
3821 | Status s = | |
3822 | txn->rep->Get(options->rep, column_family->rep, Slice(key, klen), &tmp); | |
3823 | if (s.ok()) { | |
3824 | *vlen = tmp.size(); | |
3825 | result = CopyString(tmp); | |
3826 | } else { | |
3827 | *vlen = 0; | |
3828 | if (!s.IsNotFound()) { | |
3829 | SaveError(errptr, s); | |
3830 | } | |
3831 | } | |
3832 | return result; | |
3833 | } | |
3834 | ||
3835 | // Read a key inside a transaction | |
3836 | char* rocksdb_transaction_get_for_update(rocksdb_transaction_t* txn, | |
3837 | const rocksdb_readoptions_t* options, | |
3838 | const char* key, size_t klen, | |
3839 | size_t* vlen, unsigned char exclusive, | |
3840 | char** errptr) { | |
3841 | char* result = nullptr; | |
3842 | std::string tmp; | |
3843 | Status s = | |
3844 | txn->rep->GetForUpdate(options->rep, Slice(key, klen), &tmp, exclusive); | |
3845 | if (s.ok()) { | |
3846 | *vlen = tmp.size(); | |
3847 | result = CopyString(tmp); | |
3848 | } else { | |
3849 | *vlen = 0; | |
3850 | if (!s.IsNotFound()) { | |
3851 | SaveError(errptr, s); | |
3852 | } | |
3853 | } | |
3854 | return result; | |
3855 | } | |
3856 | ||
494da23a TL |
3857 | char* rocksdb_transaction_get_for_update_cf( |
3858 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
3859 | rocksdb_column_family_handle_t* column_family, const char* key, size_t klen, | |
3860 | size_t* vlen, unsigned char exclusive, char** errptr) { | |
3861 | char* result = nullptr; | |
3862 | std::string tmp; | |
3863 | Status s = txn->rep->GetForUpdate(options->rep, column_family->rep, | |
3864 | Slice(key, klen), &tmp, exclusive); | |
3865 | if (s.ok()) { | |
3866 | *vlen = tmp.size(); | |
3867 | result = CopyString(tmp); | |
3868 | } else { | |
3869 | *vlen = 0; | |
3870 | if (!s.IsNotFound()) { | |
3871 | SaveError(errptr, s); | |
3872 | } | |
3873 | } | |
3874 | return result; | |
3875 | } | |
3876 | ||
11fdf7f2 TL |
3877 | // Read a key outside a transaction |
3878 | char* rocksdb_transactiondb_get( | |
3879 | rocksdb_transactiondb_t* txn_db, | |
3880 | const rocksdb_readoptions_t* options, | |
3881 | const char* key, size_t klen, | |
3882 | size_t* vlen, | |
3883 | char** errptr){ | |
3884 | char* result = nullptr; | |
3885 | std::string tmp; | |
3886 | Status s = txn_db->rep->Get(options->rep, Slice(key, klen), &tmp); | |
3887 | if (s.ok()) { | |
3888 | *vlen = tmp.size(); | |
3889 | result = CopyString(tmp); | |
3890 | } else { | |
3891 | *vlen = 0; | |
3892 | if (!s.IsNotFound()) { | |
3893 | SaveError(errptr, s); | |
3894 | } | |
3895 | } | |
3896 | return result; | |
3897 | } | |
3898 | ||
3899 | char* rocksdb_transactiondb_get_cf( | |
3900 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options, | |
3901 | rocksdb_column_family_handle_t* column_family, const char* key, | |
3902 | size_t keylen, size_t* vallen, char** errptr) { | |
3903 | char* result = nullptr; | |
3904 | std::string tmp; | |
3905 | Status s = txn_db->rep->Get(options->rep, column_family->rep, | |
3906 | Slice(key, keylen), &tmp); | |
3907 | if (s.ok()) { | |
3908 | *vallen = tmp.size(); | |
3909 | result = CopyString(tmp); | |
3910 | } else { | |
3911 | *vallen = 0; | |
3912 | if (!s.IsNotFound()) { | |
3913 | SaveError(errptr, s); | |
3914 | } | |
3915 | } | |
3916 | return result; | |
3917 | } | |
3918 | ||
3919 | // Put a key inside a transaction | |
3920 | void rocksdb_transaction_put(rocksdb_transaction_t* txn, const char* key, | |
3921 | size_t klen, const char* val, size_t vlen, | |
3922 | char** errptr) { | |
3923 | SaveError(errptr, txn->rep->Put(Slice(key, klen), Slice(val, vlen))); | |
3924 | } | |
3925 | ||
3926 | void rocksdb_transaction_put_cf(rocksdb_transaction_t* txn, | |
3927 | rocksdb_column_family_handle_t* column_family, | |
3928 | const char* key, size_t klen, const char* val, | |
3929 | size_t vlen, char** errptr) { | |
3930 | SaveError(errptr, txn->rep->Put(column_family->rep, Slice(key, klen), | |
3931 | Slice(val, vlen))); | |
3932 | } | |
3933 | ||
3934 | // Put a key outside a transaction | |
3935 | void rocksdb_transactiondb_put(rocksdb_transactiondb_t* txn_db, | |
3936 | const rocksdb_writeoptions_t* options, | |
3937 | const char* key, size_t klen, const char* val, | |
3938 | size_t vlen, char** errptr) { | |
3939 | SaveError(errptr, | |
3940 | txn_db->rep->Put(options->rep, Slice(key, klen), Slice(val, vlen))); | |
3941 | } | |
3942 | ||
3943 | void rocksdb_transactiondb_put_cf(rocksdb_transactiondb_t* txn_db, | |
3944 | const rocksdb_writeoptions_t* options, | |
3945 | rocksdb_column_family_handle_t* column_family, | |
3946 | const char* key, size_t keylen, | |
3947 | const char* val, size_t vallen, | |
3948 | char** errptr) { | |
3949 | SaveError(errptr, txn_db->rep->Put(options->rep, column_family->rep, | |
3950 | Slice(key, keylen), Slice(val, vallen))); | |
3951 | } | |
3952 | ||
3953 | // Write batch into transaction db | |
3954 | void rocksdb_transactiondb_write( | |
3955 | rocksdb_transactiondb_t* db, | |
3956 | const rocksdb_writeoptions_t* options, | |
3957 | rocksdb_writebatch_t* batch, | |
3958 | char** errptr) { | |
3959 | SaveError(errptr, db->rep->Write(options->rep, &batch->rep)); | |
3960 | } | |
3961 | ||
3962 | // Merge a key inside a transaction | |
3963 | void rocksdb_transaction_merge(rocksdb_transaction_t* txn, const char* key, | |
3964 | size_t klen, const char* val, size_t vlen, | |
3965 | char** errptr) { | |
3966 | SaveError(errptr, txn->rep->Merge(Slice(key, klen), Slice(val, vlen))); | |
3967 | } | |
3968 | ||
494da23a TL |
3969 | void rocksdb_transaction_merge_cf(rocksdb_transaction_t* txn, |
3970 | rocksdb_column_family_handle_t* column_family, | |
3971 | const char* key, size_t klen, const char* val, | |
3972 | size_t vlen, char** errptr) { | |
3973 | SaveError(errptr, txn->rep->Merge(column_family->rep, Slice(key, klen), | |
3974 | Slice(val, vlen))); | |
3975 | } | |
3976 | ||
11fdf7f2 TL |
3977 | // Merge a key outside a transaction |
3978 | void rocksdb_transactiondb_merge(rocksdb_transactiondb_t* txn_db, | |
3979 | const rocksdb_writeoptions_t* options, | |
3980 | const char* key, size_t klen, const char* val, | |
3981 | size_t vlen, char** errptr) { | |
3982 | SaveError(errptr, txn_db->rep->Merge(options->rep, Slice(key, klen), | |
3983 | Slice(val, vlen))); | |
3984 | } | |
3985 | ||
494da23a TL |
3986 | void rocksdb_transactiondb_merge_cf( |
3987 | rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options, | |
3988 | rocksdb_column_family_handle_t* column_family, const char* key, size_t klen, | |
3989 | const char* val, size_t vlen, char** errptr) { | |
3990 | SaveError(errptr, txn_db->rep->Merge(options->rep, column_family->rep, | |
3991 | Slice(key, klen), Slice(val, vlen))); | |
3992 | } | |
3993 | ||
11fdf7f2 TL |
3994 | // Delete a key inside a transaction |
3995 | void rocksdb_transaction_delete(rocksdb_transaction_t* txn, const char* key, | |
3996 | size_t klen, char** errptr) { | |
3997 | SaveError(errptr, txn->rep->Delete(Slice(key, klen))); | |
3998 | } | |
3999 | ||
4000 | void rocksdb_transaction_delete_cf( | |
4001 | rocksdb_transaction_t* txn, rocksdb_column_family_handle_t* column_family, | |
4002 | const char* key, size_t klen, char** errptr) { | |
4003 | SaveError(errptr, txn->rep->Delete(column_family->rep, Slice(key, klen))); | |
4004 | } | |
4005 | ||
4006 | // Delete a key outside a transaction | |
4007 | void rocksdb_transactiondb_delete(rocksdb_transactiondb_t* txn_db, | |
4008 | const rocksdb_writeoptions_t* options, | |
4009 | const char* key, size_t klen, char** errptr) { | |
4010 | SaveError(errptr, txn_db->rep->Delete(options->rep, Slice(key, klen))); | |
4011 | } | |
4012 | ||
4013 | void rocksdb_transactiondb_delete_cf( | |
4014 | rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options, | |
4015 | rocksdb_column_family_handle_t* column_family, const char* key, | |
4016 | size_t keylen, char** errptr) { | |
4017 | SaveError(errptr, txn_db->rep->Delete(options->rep, column_family->rep, | |
4018 | Slice(key, keylen))); | |
4019 | } | |
4020 | ||
4021 | // Create an iterator inside a transaction | |
4022 | rocksdb_iterator_t* rocksdb_transaction_create_iterator( | |
4023 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options) { | |
4024 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
4025 | result->rep = txn->rep->GetIterator(options->rep); | |
4026 | return result; | |
4027 | } | |
4028 | ||
4029 | // Create an iterator inside a transaction with column family | |
4030 | rocksdb_iterator_t* rocksdb_transaction_create_iterator_cf( | |
4031 | rocksdb_transaction_t* txn, const rocksdb_readoptions_t* options, | |
4032 | rocksdb_column_family_handle_t* column_family) { | |
4033 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
4034 | result->rep = txn->rep->GetIterator(options->rep, column_family->rep); | |
4035 | return result; | |
4036 | } | |
4037 | ||
4038 | // Create an iterator outside a transaction | |
4039 | rocksdb_iterator_t* rocksdb_transactiondb_create_iterator( | |
4040 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options) { | |
4041 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
4042 | result->rep = txn_db->rep->NewIterator(options->rep); | |
4043 | return result; | |
4044 | } | |
4045 | ||
494da23a TL |
4046 | rocksdb_iterator_t* rocksdb_transactiondb_create_iterator_cf( |
4047 | rocksdb_transactiondb_t* txn_db, const rocksdb_readoptions_t* options, | |
4048 | rocksdb_column_family_handle_t* column_family) { | |
4049 | rocksdb_iterator_t* result = new rocksdb_iterator_t; | |
4050 | result->rep = txn_db->rep->NewIterator(options->rep, column_family->rep); | |
4051 | return result; | |
4052 | } | |
4053 | ||
11fdf7f2 TL |
4054 | void rocksdb_transactiondb_close(rocksdb_transactiondb_t* txn_db) { |
4055 | delete txn_db->rep; | |
4056 | delete txn_db; | |
4057 | } | |
4058 | ||
4059 | rocksdb_checkpoint_t* rocksdb_transactiondb_checkpoint_object_create( | |
4060 | rocksdb_transactiondb_t* txn_db, char** errptr) { | |
4061 | Checkpoint* checkpoint; | |
4062 | if (SaveError(errptr, Checkpoint::Create(txn_db->rep, &checkpoint))) { | |
4063 | return nullptr; | |
4064 | } | |
4065 | rocksdb_checkpoint_t* result = new rocksdb_checkpoint_t; | |
4066 | result->rep = checkpoint; | |
4067 | return result; | |
4068 | } | |
4069 | ||
4070 | rocksdb_optimistictransactiondb_t* rocksdb_optimistictransactiondb_open( | |
4071 | const rocksdb_options_t* options, const char* name, char** errptr) { | |
4072 | OptimisticTransactionDB* otxn_db; | |
4073 | if (SaveError(errptr, OptimisticTransactionDB::Open( | |
4074 | options->rep, std::string(name), &otxn_db))) { | |
4075 | return nullptr; | |
4076 | } | |
4077 | rocksdb_optimistictransactiondb_t* result = | |
4078 | new rocksdb_optimistictransactiondb_t; | |
4079 | result->rep = otxn_db; | |
4080 | return result; | |
4081 | } | |
4082 | ||
4083 | rocksdb_optimistictransactiondb_t* | |
4084 | rocksdb_optimistictransactiondb_open_column_families( | |
4085 | const rocksdb_options_t* db_options, const char* name, | |
4086 | int num_column_families, const char** column_family_names, | |
4087 | const rocksdb_options_t** column_family_options, | |
4088 | rocksdb_column_family_handle_t** column_family_handles, char** errptr) { | |
4089 | std::vector<ColumnFamilyDescriptor> column_families; | |
4090 | for (int i = 0; i < num_column_families; i++) { | |
4091 | column_families.push_back(ColumnFamilyDescriptor( | |
4092 | std::string(column_family_names[i]), | |
4093 | ColumnFamilyOptions(column_family_options[i]->rep))); | |
4094 | } | |
4095 | ||
4096 | OptimisticTransactionDB* otxn_db; | |
4097 | std::vector<ColumnFamilyHandle*> handles; | |
4098 | if (SaveError(errptr, OptimisticTransactionDB::Open( | |
4099 | DBOptions(db_options->rep), std::string(name), | |
4100 | column_families, &handles, &otxn_db))) { | |
4101 | return nullptr; | |
4102 | } | |
4103 | ||
4104 | for (size_t i = 0; i < handles.size(); i++) { | |
4105 | rocksdb_column_family_handle_t* c_handle = | |
4106 | new rocksdb_column_family_handle_t; | |
4107 | c_handle->rep = handles[i]; | |
4108 | column_family_handles[i] = c_handle; | |
4109 | } | |
4110 | rocksdb_optimistictransactiondb_t* result = | |
4111 | new rocksdb_optimistictransactiondb_t; | |
4112 | result->rep = otxn_db; | |
4113 | return result; | |
4114 | } | |
4115 | ||
4116 | rocksdb_t* rocksdb_optimistictransactiondb_get_base_db( | |
4117 | rocksdb_optimistictransactiondb_t* otxn_db) { | |
4118 | DB* base_db = otxn_db->rep->GetBaseDB(); | |
4119 | ||
4120 | if (base_db != nullptr) { | |
4121 | rocksdb_t* result = new rocksdb_t; | |
4122 | result->rep = base_db; | |
4123 | return result; | |
4124 | } | |
4125 | ||
4126 | return nullptr; | |
4127 | } | |
4128 | ||
4129 | void rocksdb_optimistictransactiondb_close_base_db(rocksdb_t* base_db) { | |
4130 | delete base_db; | |
4131 | } | |
4132 | ||
4133 | rocksdb_transaction_t* rocksdb_optimistictransaction_begin( | |
4134 | rocksdb_optimistictransactiondb_t* otxn_db, | |
4135 | const rocksdb_writeoptions_t* write_options, | |
4136 | const rocksdb_optimistictransaction_options_t* otxn_options, | |
4137 | rocksdb_transaction_t* old_txn) { | |
4138 | if (old_txn == nullptr) { | |
4139 | rocksdb_transaction_t* result = new rocksdb_transaction_t; | |
4140 | result->rep = otxn_db->rep->BeginTransaction(write_options->rep, | |
4141 | otxn_options->rep, nullptr); | |
4142 | return result; | |
4143 | } | |
4144 | old_txn->rep = otxn_db->rep->BeginTransaction( | |
4145 | write_options->rep, otxn_options->rep, old_txn->rep); | |
4146 | return old_txn; | |
4147 | } | |
4148 | ||
4149 | void rocksdb_optimistictransactiondb_close( | |
4150 | rocksdb_optimistictransactiondb_t* otxn_db) { | |
4151 | delete otxn_db->rep; | |
4152 | delete otxn_db; | |
4153 | } | |
4154 | ||
7c673cae FG |
4155 | void rocksdb_free(void* ptr) { free(ptr); } |
4156 | ||
11fdf7f2 TL |
4157 | rocksdb_pinnableslice_t* rocksdb_get_pinned( |
4158 | rocksdb_t* db, const rocksdb_readoptions_t* options, const char* key, | |
4159 | size_t keylen, char** errptr) { | |
4160 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
4161 | Status s = db->rep->Get(options->rep, db->rep->DefaultColumnFamily(), | |
4162 | Slice(key, keylen), &v->rep); | |
4163 | if (!s.ok()) { | |
4164 | delete (v); | |
4165 | if (!s.IsNotFound()) { | |
4166 | SaveError(errptr, s); | |
4167 | } | |
4168 | return nullptr; | |
4169 | } | |
4170 | return v; | |
4171 | } | |
4172 | ||
4173 | rocksdb_pinnableslice_t* rocksdb_get_pinned_cf( | |
4174 | rocksdb_t* db, const rocksdb_readoptions_t* options, | |
4175 | rocksdb_column_family_handle_t* column_family, const char* key, | |
4176 | size_t keylen, char** errptr) { | |
4177 | rocksdb_pinnableslice_t* v = new (rocksdb_pinnableslice_t); | |
4178 | Status s = db->rep->Get(options->rep, column_family->rep, Slice(key, keylen), | |
4179 | &v->rep); | |
4180 | if (!s.ok()) { | |
4181 | delete v; | |
4182 | if (!s.IsNotFound()) { | |
4183 | SaveError(errptr, s); | |
4184 | } | |
4185 | return nullptr; | |
4186 | } | |
4187 | return v; | |
4188 | } | |
4189 | ||
4190 | void rocksdb_pinnableslice_destroy(rocksdb_pinnableslice_t* v) { delete v; } | |
4191 | ||
4192 | const char* rocksdb_pinnableslice_value(const rocksdb_pinnableslice_t* v, | |
4193 | size_t* vlen) { | |
4194 | if (!v) { | |
4195 | *vlen = 0; | |
4196 | return nullptr; | |
4197 | } | |
4198 | ||
4199 | *vlen = v->rep.size(); | |
4200 | return v->rep.data(); | |
4201 | } | |
4202 | ||
4203 | // container to keep databases and caches in order to use rocksdb::MemoryUtil | |
4204 | struct rocksdb_memory_consumers_t { | |
4205 | std::vector<rocksdb_t*> dbs; | |
4206 | std::unordered_set<rocksdb_cache_t*> caches; | |
4207 | }; | |
4208 | ||
4209 | // initializes new container of memory consumers | |
4210 | rocksdb_memory_consumers_t* rocksdb_memory_consumers_create() { | |
4211 | return new rocksdb_memory_consumers_t; | |
4212 | } | |
4213 | ||
4214 | // adds datatabase to the container of memory consumers | |
4215 | void rocksdb_memory_consumers_add_db(rocksdb_memory_consumers_t* consumers, | |
4216 | rocksdb_t* db) { | |
4217 | consumers->dbs.push_back(db); | |
4218 | } | |
4219 | ||
4220 | // adds cache to the container of memory consumers | |
4221 | void rocksdb_memory_consumers_add_cache(rocksdb_memory_consumers_t* consumers, | |
4222 | rocksdb_cache_t* cache) { | |
4223 | consumers->caches.insert(cache); | |
4224 | } | |
4225 | ||
4226 | // deletes container with memory consumers | |
4227 | void rocksdb_memory_consumers_destroy(rocksdb_memory_consumers_t* consumers) { | |
4228 | delete consumers; | |
4229 | } | |
4230 | ||
4231 | // contains memory usage statistics provided by rocksdb::MemoryUtil | |
4232 | struct rocksdb_memory_usage_t { | |
4233 | uint64_t mem_table_total; | |
4234 | uint64_t mem_table_unflushed; | |
4235 | uint64_t mem_table_readers_total; | |
4236 | uint64_t cache_total; | |
4237 | }; | |
4238 | ||
4239 | // estimates amount of memory occupied by consumers (dbs and caches) | |
4240 | rocksdb_memory_usage_t* rocksdb_approximate_memory_usage_create( | |
4241 | rocksdb_memory_consumers_t* consumers, char** errptr) { | |
4242 | ||
4243 | vector<DB*> dbs; | |
4244 | for (auto db : consumers->dbs) { | |
4245 | dbs.push_back(db->rep); | |
4246 | } | |
4247 | ||
4248 | unordered_set<const Cache*> cache_set; | |
4249 | for (auto cache : consumers->caches) { | |
4250 | cache_set.insert(const_cast<const Cache*>(cache->rep.get())); | |
4251 | } | |
4252 | ||
4253 | std::map<rocksdb::MemoryUtil::UsageType, uint64_t> usage_by_type; | |
4254 | ||
4255 | auto status = MemoryUtil::GetApproximateMemoryUsageByType(dbs, cache_set, | |
4256 | &usage_by_type); | |
4257 | if (SaveError(errptr, status)) { | |
4258 | return nullptr; | |
4259 | } | |
4260 | ||
4261 | auto result = new rocksdb_memory_usage_t; | |
4262 | result->mem_table_total = usage_by_type[MemoryUtil::kMemTableTotal]; | |
4263 | result->mem_table_unflushed = usage_by_type[MemoryUtil::kMemTableUnFlushed]; | |
4264 | result->mem_table_readers_total = usage_by_type[MemoryUtil::kTableReadersTotal]; | |
4265 | result->cache_total = usage_by_type[MemoryUtil::kCacheTotal]; | |
4266 | return result; | |
4267 | } | |
4268 | ||
4269 | uint64_t rocksdb_approximate_memory_usage_get_mem_table_total( | |
4270 | rocksdb_memory_usage_t* memory_usage) { | |
4271 | return memory_usage->mem_table_total; | |
4272 | } | |
4273 | ||
4274 | uint64_t rocksdb_approximate_memory_usage_get_mem_table_unflushed( | |
4275 | rocksdb_memory_usage_t* memory_usage) { | |
4276 | return memory_usage->mem_table_unflushed; | |
4277 | } | |
4278 | ||
4279 | uint64_t rocksdb_approximate_memory_usage_get_mem_table_readers_total( | |
4280 | rocksdb_memory_usage_t* memory_usage) { | |
4281 | return memory_usage->mem_table_readers_total; | |
4282 | } | |
4283 | ||
4284 | uint64_t rocksdb_approximate_memory_usage_get_cache_total( | |
4285 | rocksdb_memory_usage_t* memory_usage) { | |
4286 | return memory_usage->cache_total; | |
4287 | } | |
4288 | ||
4289 | // deletes container with memory usage estimates | |
4290 | void rocksdb_approximate_memory_usage_destroy(rocksdb_memory_usage_t* usage) { | |
4291 | delete usage; | |
4292 | } | |
4293 | ||
7c673cae FG |
4294 | } // end extern "C" |
4295 | ||
4296 | #endif // !ROCKSDB_LITE |