@ -25,6 +25,7 @@
# include "cache/lru_cache.h"
# include "db/blob/blob_index.h"
# include "db/blob/blob_log_format.h"
# include "db/db_impl/db_impl.h"
# include "db/db_test_util.h"
# include "db/dbformat.h"
@ -1027,10 +1028,10 @@ TEST_F(DBTest, FailMoreDbPaths) {
}
void CheckColumnFamilyMeta (
const ColumnFamilyMetaData & cf_meta ,
const ColumnFamilyMetaData & cf_meta , const std : : string & cf_name ,
const std : : vector < std : : vector < FileMetaData > > & files_by_level ,
uint64_t start_time , uint64_t end_time ) {
ASSERT_EQ ( cf_meta . name , kDefaultColumnFamilyN ame) ;
ASSERT_EQ ( cf_meta . name , cf_n ame) ;
ASSERT_EQ ( cf_meta . levels . size ( ) , files_by_level . size ( ) ) ;
uint64_t cf_size = 0 ;
@ -1124,6 +1125,53 @@ void CheckLiveFilesMeta(
}
# ifndef ROCKSDB_LITE
void AddBlobFile ( const ColumnFamilyHandle * cfh , uint64_t blob_file_number ,
uint64_t total_blob_count , uint64_t total_blob_bytes ,
const std : : string & checksum_method ,
const std : : string & checksum_value ,
uint64_t garbage_blob_count = 0 ,
uint64_t garbage_blob_bytes = 0 ) {
ColumnFamilyData * cfd =
( static_cast < const ColumnFamilyHandleImpl * > ( cfh ) ) - > cfd ( ) ;
assert ( cfd ) ;
Version * const version = cfd - > current ( ) ;
assert ( version ) ;
VersionStorageInfo * const storage_info = version - > storage_info ( ) ;
assert ( storage_info ) ;
// Add a live blob file.
auto shared_meta = SharedBlobFileMetaData : : Create (
blob_file_number , total_blob_count , total_blob_bytes , checksum_method ,
checksum_value ) ;
auto meta = BlobFileMetaData : : Create ( std : : move ( shared_meta ) ,
BlobFileMetaData : : LinkedSsts ( ) ,
garbage_blob_count , garbage_blob_bytes ) ;
storage_info - > AddBlobFile ( std : : move ( meta ) ) ;
}
static void CheckBlobMetaData (
const BlobMetaData & bmd , uint64_t blob_file_number ,
uint64_t total_blob_count , uint64_t total_blob_bytes ,
const std : : string & checksum_method , const std : : string & checksum_value ,
uint64_t garbage_blob_count = 0 , uint64_t garbage_blob_bytes = 0 ) {
ASSERT_EQ ( bmd . blob_file_number , blob_file_number ) ;
ASSERT_EQ ( bmd . blob_file_name , BlobFileName ( " " , blob_file_number ) ) ;
ASSERT_EQ ( bmd . blob_file_size ,
total_blob_bytes + BlobLogHeader : : kSize + BlobLogFooter : : kSize ) ;
ASSERT_EQ ( bmd . total_blob_count , total_blob_count ) ;
ASSERT_EQ ( bmd . total_blob_bytes , total_blob_bytes ) ;
ASSERT_EQ ( bmd . garbage_blob_count , garbage_blob_count ) ;
ASSERT_EQ ( bmd . garbage_blob_bytes , garbage_blob_bytes ) ;
ASSERT_EQ ( bmd . checksum_method , checksum_method ) ;
ASSERT_EQ ( bmd . checksum_value , checksum_value ) ;
}
TEST_F ( DBTest , MetaDataTest ) {
Options options = CurrentOptions ( ) ;
options . create_if_missing = true ;
@ -1164,13 +1212,69 @@ TEST_F(DBTest, MetaDataTest) {
ColumnFamilyMetaData cf_meta ;
db_ - > GetColumnFamilyMetaData ( & cf_meta ) ;
CheckColumnFamilyMeta ( cf_meta , files_by_level , start_time , end_time ) ;
CheckColumnFamilyMeta ( cf_meta , kDefaultColumnFamilyName , files_by_level ,
start_time , end_time ) ;
std : : vector < LiveFileMetaData > live_file_meta ;
db_ - > GetLiveFilesMetaData ( & live_file_meta ) ;
CheckLiveFilesMeta ( live_file_meta , files_by_level ) ;
}
TEST_F ( DBTest , AllMetaDataTest ) {
Options options = CurrentOptions ( ) ;
options . create_if_missing = true ;
options . disable_auto_compactions = true ;
DestroyAndReopen ( options ) ;
CreateAndReopenWithCF ( { " pikachu " } , options ) ;
constexpr uint64_t blob_file_number = 234 ;
constexpr uint64_t total_blob_count = 555 ;
constexpr uint64_t total_blob_bytes = 66666 ;
constexpr char checksum_method [ ] = " CRC32 " ;
constexpr char checksum_value [ ] = " \x3d \x87 \xff \x57 " ;
int64_t temp_time = 0 ;
options . env - > GetCurrentTime ( & temp_time ) . PermitUncheckedError ( ) ;
uint64_t start_time = static_cast < uint64_t > ( temp_time ) ;
Random rnd ( 301 ) ;
for ( int cf = 0 ; cf < 2 ; cf + + ) {
AddBlobFile ( handles_ [ cf ] , blob_file_number * ( cf + 1 ) ,
total_blob_count * ( cf + 1 ) , total_blob_bytes * ( cf + 1 ) ,
checksum_method , checksum_value ) ;
}
std : : vector < ColumnFamilyMetaData > all_meta ;
db_ - > GetAllColumnFamilyMetaData ( & all_meta ) ;
std : : vector < std : : vector < FileMetaData > > default_files_by_level ;
std : : vector < std : : vector < FileMetaData > > pikachu_files_by_level ;
dbfull ( ) - > TEST_GetFilesMetaData ( handles_ [ 0 ] , & default_files_by_level ) ;
dbfull ( ) - > TEST_GetFilesMetaData ( handles_ [ 1 ] , & pikachu_files_by_level ) ;
options . env - > GetCurrentTime ( & temp_time ) . PermitUncheckedError ( ) ;
uint64_t end_time = static_cast < uint64_t > ( temp_time ) ;
ASSERT_EQ ( all_meta . size ( ) , 2 ) ;
for ( int cf = 0 ; cf < 2 ; cf + + ) {
const auto & cfmd = all_meta [ cf ] ;
if ( cf = = 0 ) {
CheckColumnFamilyMeta ( cfmd , " default " , default_files_by_level , start_time ,
end_time ) ;
} else {
CheckColumnFamilyMeta ( cfmd , " pikachu " , pikachu_files_by_level , start_time ,
end_time ) ;
}
ASSERT_EQ ( cfmd . blob_files . size ( ) , 1U ) ;
const auto & bmd = cfmd . blob_files [ 0 ] ;
ASSERT_EQ ( cfmd . blob_file_count , 1U ) ;
ASSERT_EQ ( cfmd . blob_file_size , bmd . blob_file_size ) ;
ASSERT_EQ ( NormalizePath ( bmd . blob_file_path ) , NormalizePath ( dbname_ ) ) ;
CheckBlobMetaData ( bmd , blob_file_number * ( cf + 1 ) ,
total_blob_count * ( cf + 1 ) , total_blob_bytes * ( cf + 1 ) ,
checksum_method , checksum_value ) ;
}
}
namespace {
void MinLevelHelper ( DBTest * self , Options & options ) {
Random rnd ( 301 ) ;
@ -2344,41 +2448,19 @@ TEST_F(DBTest, GetLiveBlobFiles) {
Options options = CurrentOptions ( ) ;
options . stats_dump_period_sec = 0 ;
Reopen ( options ) ;
VersionSet * const versions = dbfull ( ) - > TEST_GetVersionSet ( ) ;
assert ( versions ) ;
assert ( versions - > GetColumnFamilySet ( ) ) ;
ColumnFamilyData * const cfd = versions - > GetColumnFamilySet ( ) - > GetDefault ( ) ;
assert ( cfd ) ;
Version * const version = cfd - > current ( ) ;
assert ( version ) ;
VersionStorageInfo * const storage_info = version - > storage_info ( ) ;
assert ( storage_info ) ;
// Add a live blob file.
constexpr uint64_t blob_file_number = 234 ;
constexpr uint64_t total_blob_count = 555 ;
constexpr uint64_t total_blob_bytes = 66666 ;
constexpr char checksum_method [ ] = " CRC32 " ;
constexpr char checksum_value [ ] = " \x3d \x87 \xff \x57 " ;
auto shared_meta = SharedBlobFileMetaData : : Create (
blob_file_number , total_blob_count , total_blob_bytes , checksum_method ,
checksum_value ) ;
constexpr uint64_t garbage_blob_count = 0 ;
constexpr uint64_t garbage_blob_bytes = 0 ;
auto meta = BlobFileMetaData : : Create ( std : : move ( shared_meta ) ,
BlobFileMetaData : : LinkedSsts ( ) ,
garbage_blob_count , garbage_blob_bytes ) ;
storage_info - > AddBlobFile ( std : : move ( meta ) ) ;
Reopen ( options ) ;
AddBlobFile ( db_ - > DefaultColumnFamily ( ) , blob_file_number , total_blob_count ,
total_blob_bytes , checksum_method , checksum_value ,
garbage_blob_count , garbage_blob_bytes ) ;
// Make sure it appears in the results returned by GetLiveFiles.
uint64_t manifest_size = 0 ;
std : : vector < std : : string > files ;
@ -2386,6 +2468,19 @@ TEST_F(DBTest, GetLiveBlobFiles) {
ASSERT_FALSE ( files . empty ( ) ) ;
ASSERT_EQ ( files [ 0 ] , BlobFileName ( " " , blob_file_number ) ) ;
ColumnFamilyMetaData cfmd ;
db_ - > GetColumnFamilyMetaData ( & cfmd ) ;
ASSERT_EQ ( cfmd . blob_files . size ( ) , 1 ) ;
const BlobMetaData & bmd = cfmd . blob_files [ 0 ] ;
CheckBlobMetaData ( bmd , blob_file_number , total_blob_count , total_blob_bytes ,
checksum_method , checksum_value , garbage_blob_count ,
garbage_blob_bytes ) ;
ASSERT_EQ ( NormalizePath ( bmd . blob_file_path ) , NormalizePath ( dbname_ ) ) ;
ASSERT_EQ ( cfmd . blob_file_count , 1U ) ;
ASSERT_EQ ( cfmd . blob_file_size , bmd . blob_file_size ) ;
}
# endif