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
This commit is contained in:
Akanksha Mahajan 2022-02-18 20:13:41 -08:00 committed by Facebook GitHub Bot
parent d3a2f284d9
commit 3699b171e4
3 changed files with 50 additions and 14 deletions

View File

@ -73,6 +73,7 @@
* `ColumnFamilyOptions::OldDefaults` and `DBOptions::OldDefaults` are marked deprecated, as they are no longer maintained. * `ColumnFamilyOptions::OldDefaults` and `DBOptions::OldDefaults` are marked deprecated, as they are no longer maintained.
* Add subcompaction callback APIs: `OnSubcompactionBegin()` and `OnSubcompactionCompleted()`. * Add subcompaction callback APIs: `OnSubcompactionBegin()` and `OnSubcompactionCompleted()`.
* Add file Temperature information to `FileOperationInfo` in event listener API. * 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. * 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 ### Behavior Changes

View File

@ -1114,7 +1114,7 @@ class DB {
// Flags for DB::GetSizeApproximation that specify whether memtable // Flags for DB::GetSizeApproximation that specify whether memtable
// stats should be included, or file stats approximation or both // stats should be included, or file stats approximation or both
enum SizeApproximationFlags : uint8_t { enum class SizeApproximationFlags : uint8_t {
NONE = 0, NONE = 0,
INCLUDE_MEMTABLES = 1 << 0, INCLUDE_MEMTABLES = 1 << 0,
INCLUDE_FILES = 1 << 1 INCLUDE_FILES = 1 << 1
@ -1138,17 +1138,13 @@ class DB {
virtual Status GetApproximateSizes(ColumnFamilyHandle* column_family, virtual Status GetApproximateSizes(ColumnFamilyHandle* column_family,
const Range* ranges, int n, const Range* ranges, int n,
uint64_t* sizes, uint64_t* sizes,
uint8_t include_flags = INCLUDE_FILES) { SizeApproximationFlags include_flags =
SizeApproximationOptions options; SizeApproximationFlags::INCLUDE_FILES);
options.include_memtables =
(include_flags & SizeApproximationFlags::INCLUDE_MEMTABLES) != 0; virtual Status GetApproximateSizes(
options.include_files = const Range* ranges, int n, uint64_t* sizes,
(include_flags & SizeApproximationFlags::INCLUDE_FILES) != 0; SizeApproximationFlags include_flags =
return GetApproximateSizes(options, column_family, ranges, n, sizes); SizeApproximationFlags::INCLUDE_FILES) {
}
virtual Status GetApproximateSizes(const Range* ranges, int n,
uint64_t* sizes,
uint8_t include_flags = INCLUDE_FILES) {
return GetApproximateSizes(DefaultColumnFamily(), ranges, n, sizes, return GetApproximateSizes(DefaultColumnFamily(), ranges, n, sizes,
include_flags); include_flags);
} }
@ -1671,6 +1667,32 @@ class DB {
#endif // !ROCKSDB_LITE #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. // Destroy the contents of the specified database.
// Be very careful using this method. // Be very careful using this method.
Status DestroyDB(const std::string& name, const Options& options, Status DestroyDB(const std::string& name, const Options& options,

View File

@ -2725,9 +2725,22 @@ jlongArray Java_org_rocksdb_RocksDB_getApproximateSizes(
} }
auto sizes = std::unique_ptr<uint64_t[]>(new uint64_t[range_count]); 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(), db->GetApproximateSizes(cf_handle, ranges.get(),
static_cast<int>(range_count), sizes.get(), static_cast<int>(range_count), sizes.get(),
static_cast<uint8_t>(jinclude_flags)); include_flags);
// release LongArrayElements // release LongArrayElements
env->ReleaseLongArrayElements(jrange_slice_handles, jranges, JNI_ABORT); env->ReleaseLongArrayElements(jrange_slice_handles, jranges, JNI_ABORT);