Skip to content

Commit

Permalink
[feature] expose get_approximate_sizes_with_options api
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzzbing authored and notempty1 committed Aug 28, 2023
1 parent 41b3a1d commit 6c1e1ae
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
20 changes: 20 additions & 0 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,26 @@ void rocksdb_approximate_sizes_cf(
delete[] ranges;
}

void rocksdb_approximate_sizes_cf_with_options(
rocksdb_t* db, rocksdb_column_family_handle_t* column_family,
int num_ranges, const char* const* range_start_key,
const size_t* range_start_key_len, const char* const* range_limit_key,
const size_t* range_limit_key_len, uint64_t* sizes, bool include_memtables,
bool include_files, double files_size_error_margin, char** errptr) {
Range* ranges = new Range[num_ranges];
for (int i = 0; i < num_ranges; i++) {
ranges[i].start = Slice(range_start_key[i], range_start_key_len[i]);
ranges[i].limit = Slice(range_limit_key[i], range_limit_key_len[i]);
}
Status s = db->rep->GetApproximateSizesWithOptions(
column_family->rep, ranges, num_ranges, sizes, include_memtables,
include_files, files_size_error_margin);
if (!s.ok()) {
SaveError(errptr, s);
}
delete[] ranges;
}

void rocksdb_delete_file(rocksdb_t* db, const char* name) {
db->rep->DeleteFile(name);
}
Expand Down
7 changes: 7 additions & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,13 @@ extern ROCKSDB_LIBRARY_API void rocksdb_approximate_sizes_cf(
const size_t* range_start_key_len, const char* const* range_limit_key,
const size_t* range_limit_key_len, uint64_t* sizes, char** errptr);

extern ROCKSDB_LIBRARY_API void rocksdb_approximate_sizes_cf_with_options(
rocksdb_t* db, rocksdb_column_family_handle_t* column_family,
int num_ranges, const char* const* range_start_key,
const size_t* range_start_key_len, const char* const* range_limit_key,
const size_t* range_limit_key_len, uint64_t* sizes, bool include_memtables,
bool include_files, double files_size_error_margin, char** errptr);

extern ROCKSDB_LIBRARY_API void rocksdb_compact_range(rocksdb_t* db,
const char* start_key,
size_t start_key_len,
Expand Down
24 changes: 24 additions & 0 deletions include/rocksdb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,19 @@ class DB {
include_flags);
}

virtual Status GetApproximateSizesWithOptions(
ColumnFamilyHandle* column_family, const Range* ranges, int n,
uint64_t* sizes, bool include_memtables, bool include_files,
double files_size_error_margin);

virtual Status GetApproximateSizesWithOptions(
const Range* ranges, int n, uint64_t* sizes, bool include_memtables,
bool include_files, double files_size_error_margin) {
return GetApproximateSizesWithOptions(
DefaultColumnFamily(), ranges, n, sizes, include_memtables,
include_files, files_size_error_margin);
}

// The method is similar to GetApproximateSizes, except it
// returns approximate number of records in memtables.
virtual void GetApproximateMemTableStats(ColumnFamilyHandle* column_family,
Expand Down Expand Up @@ -1929,6 +1942,17 @@ inline Status DB::GetApproximateSizes(ColumnFamilyHandle* column_family,
return GetApproximateSizes(options, column_family, ranges, n, sizes);
}

inline Status DB::GetApproximateSizesWithOptions(
ColumnFamilyHandle* column_family, const Range* ranges, int n,
uint64_t* sizes, bool include_memtables, bool include_files,
double files_size_error_margin) {
SizeApproximationOptions options;
options.include_memtables = include_memtables;
options.include_files = include_files;
options.files_size_error_margin = files_size_error_margin;
return GetApproximateSizes(options, column_family, ranges, n, sizes);
}

// Destroy the contents of the specified database.
// Be very careful using this method.
Status DestroyDB(const std::string& name, const Options& options,
Expand Down
11 changes: 9 additions & 2 deletions memory/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
// size, it uses malloc to directly get the requested size.

#pragma once
#ifndef OS_WIN
#include <sys/mman.h>
#endif
#include <assert.h>
#include <stdint.h>

#include <cerrno>
#include <cstddef>
#include <deque>
#include <vector>

#include "memory/allocator.h"
#include "port/mmap.h"
Expand Down Expand Up @@ -88,7 +94,8 @@ class Arena : public Allocator {
static size_t OptimizeBlockSize(size_t block_size);

private:
alignas(std::max_align_t) char inline_block_[kInlineSize];
char inline_block_[kInlineSize]
__attribute__((__aligned__(alignof(max_align_t))));
// Number of bytes allocated in one block
const size_t kBlockSize;
// Allocated memory blocks
Expand Down

0 comments on commit 6c1e1ae

Please sign in to comment.