Change enum SizeApproximationFlags to enum class (#9604)

Summary:
Change enum SizeApproximationFlags to enum and class and add
overloaded operators for the transition between enum class and uint8_t

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9604

Test Plan: Circle CI jobs

Reviewed By: riversand963

Differential Revision: D34360281

Pulled By: akankshamahajan15

fbshipit-source-id: 6351dfdb717ae3c4530d324c3d37a8ecb01dd1ef
main
Akanksha Mahajan 3 years ago committed by Facebook GitHub Bot
parent d3a2f284d9
commit 3699b171e4
  1. 1
      HISTORY.md
  2. 46
      include/rocksdb/db.h
  3. 15
      java/rocksjni/rocksjni.cc

@ -73,6 +73,7 @@
* `ColumnFamilyOptions::OldDefaults` and `DBOptions::OldDefaults` are marked deprecated, as they are no longer maintained.
* Add subcompaction callback APIs: `OnSubcompactionBegin()` and `OnSubcompactionCompleted()`.
* Add file Temperature information to `FileOperationInfo` in event listener API.
* Change the type of SizeApproximationFlags from enum to enum class. Also update the signature of DB::GetApproximateSizes API from uint8_t to SizeApproximationFlags.
* Add Temperature hints information from RocksDB in API `NewSequentialFile()`. backup and checkpoint operations need to open the source files with `NewSequentialFile()`, which will have the temperature hints. Other operations are not covered.
### Behavior Changes

@ -1114,7 +1114,7 @@ class DB {
// Flags for DB::GetSizeApproximation that specify whether memtable
// stats should be included, or file stats approximation or both
enum SizeApproximationFlags : uint8_t {
enum class SizeApproximationFlags : uint8_t {
NONE = 0,
INCLUDE_MEMTABLES = 1 << 0,
INCLUDE_FILES = 1 << 1
@ -1138,17 +1138,13 @@ class DB {
virtual Status GetApproximateSizes(ColumnFamilyHandle* column_family,
const Range* ranges, int n,
uint64_t* sizes,
uint8_t include_flags = INCLUDE_FILES) {
SizeApproximationOptions options;
options.include_memtables =
(include_flags & SizeApproximationFlags::INCLUDE_MEMTABLES) != 0;
options.include_files =
(include_flags & SizeApproximationFlags::INCLUDE_FILES) != 0;
return GetApproximateSizes(options, column_family, ranges, n, sizes);
}
virtual Status GetApproximateSizes(const Range* ranges, int n,
uint64_t* sizes,
uint8_t include_flags = INCLUDE_FILES) {
SizeApproximationFlags include_flags =
SizeApproximationFlags::INCLUDE_FILES);
virtual Status GetApproximateSizes(
const Range* ranges, int n, uint64_t* sizes,
SizeApproximationFlags include_flags =
SizeApproximationFlags::INCLUDE_FILES) {
return GetApproximateSizes(DefaultColumnFamily(), ranges, n, sizes,
include_flags);
}
@ -1671,6 +1667,32 @@ class DB {
#endif // !ROCKSDB_LITE
};
// Overloaded operators for enum class SizeApproximationFlags.
inline DB::SizeApproximationFlags operator&(DB::SizeApproximationFlags lhs,
DB::SizeApproximationFlags rhs) {
return static_cast<DB::SizeApproximationFlags>(static_cast<uint8_t>(lhs) &
static_cast<uint8_t>(rhs));
}
inline DB::SizeApproximationFlags operator|(DB::SizeApproximationFlags lhs,
DB::SizeApproximationFlags rhs) {
return static_cast<DB::SizeApproximationFlags>(static_cast<uint8_t>(lhs) |
static_cast<uint8_t>(rhs));
}
inline Status DB::GetApproximateSizes(ColumnFamilyHandle* column_family,
const Range* ranges, int n,
uint64_t* sizes,
SizeApproximationFlags include_flags) {
SizeApproximationOptions options;
options.include_memtables =
((include_flags & SizeApproximationFlags::INCLUDE_MEMTABLES) !=
SizeApproximationFlags::NONE);
options.include_files =
((include_flags & SizeApproximationFlags::INCLUDE_FILES) !=
SizeApproximationFlags::NONE);
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,

@ -2725,9 +2725,22 @@ jlongArray Java_org_rocksdb_RocksDB_getApproximateSizes(
}
auto sizes = std::unique_ptr<uint64_t[]>(new uint64_t[range_count]);
ROCKSDB_NAMESPACE::DB::SizeApproximationFlags include_flags =
ROCKSDB_NAMESPACE::DB::SizeApproximationFlags::NONE;
if (jinclude_flags & 1) {
include_flags =
ROCKSDB_NAMESPACE::DB::SizeApproximationFlags::INCLUDE_MEMTABLES;
}
if (jinclude_flags & 2) {
include_flags =
(include_flags |
ROCKSDB_NAMESPACE::DB::SizeApproximationFlags::INCLUDE_FILES);
}
db->GetApproximateSizes(cf_handle, ranges.get(),
static_cast<int>(range_count), sizes.get(),
static_cast<uint8_t>(jinclude_flags));
include_flags);
// release LongArrayElements
env->ReleaseLongArrayElements(jrange_slice_handles, jranges, JNI_ABORT);

Loading…
Cancel
Save