From 3699b171e47560c5e3fa41e4fe41a1d94c71fad0 Mon Sep 17 00:00:00 2001 From: Akanksha Mahajan Date: Fri, 18 Feb 2022 20:13:41 -0800 Subject: [PATCH] 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 --- HISTORY.md | 1 + include/rocksdb/db.h | 46 +++++++++++++++++++++++++++++---------- java/rocksjni/rocksjni.cc | 17 +++++++++++++-- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 9c21101c5..714d1a1fe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/include/rocksdb/db.h b/include/rocksdb/db.h index 289a65e07..abd625746 100644 --- a/include/rocksdb/db.h +++ b/include/rocksdb/db.h @@ -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(static_cast(lhs) & + static_cast(rhs)); +} +inline DB::SizeApproximationFlags operator|(DB::SizeApproximationFlags lhs, + DB::SizeApproximationFlags rhs) { + return static_cast(static_cast(lhs) | + static_cast(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, diff --git a/java/rocksjni/rocksjni.cc b/java/rocksjni/rocksjni.cc index b4d93228a..ec0911440 100644 --- a/java/rocksjni/rocksjni.cc +++ b/java/rocksjni/rocksjni.cc @@ -2725,9 +2725,22 @@ jlongArray Java_org_rocksdb_RocksDB_getApproximateSizes( } auto sizes = std::unique_ptr(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(range_count), sizes.get(), - static_cast(jinclude_flags)); + static_cast(range_count), sizes.get(), + include_flags); // release LongArrayElements env->ReleaseLongArrayElements(jrange_slice_handles, jranges, JNI_ABORT);