diff --git a/HISTORY.md b/HISTORY.md index 9c21101c59..714d1a1fe3 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 289a65e073..abd6257468 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 b4d93228af..ec09114408 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);