@ -42,17 +42,15 @@ class BlobFileBuilderTest : public testing::Test {
protected :
BlobFileBuilderTest ( ) : mock_env_ ( Env : : Default ( ) ) , fs_ ( & mock_env_ ) { }
void VerifyBlobFile ( const ImmutableCFOptions & immutable_cf_options ,
uint64_t blob_file_number , uint32_t column_family_id ,
void VerifyBlobFile ( uint64_t blob_file_number ,
const std : : string & blob_file_path ,
uint32_t column_family_id ,
CompressionType blob_compression_type ,
const std : : vector < std : : pair < std : : string , std : : string > > &
expected_key_value_pairs ,
const std : : vector < std : : string > & blob_indexes ) {
assert ( expected_key_value_pairs . size ( ) = = blob_indexes . size ( ) ) ;
const std : : string blob_file_path = BlobFileName (
immutable_cf_options . cf_paths . front ( ) . path , blob_file_number ) ;
std : : unique_ptr < FSRandomAccessFile > file ;
constexpr IODebugContext * dbg = nullptr ;
ASSERT_OK (
@ -137,12 +135,14 @@ TEST_F(BlobFileBuilderTest, BuildAndCheckOneFile) {
constexpr Env : : IOPriority io_priority = Env : : IO_HIGH ;
constexpr Env : : WriteLifeTimeHint write_hint = Env : : WLTH_MEDIUM ;
std : : vector < std : : string > blob_file_paths ;
std : : vector < BlobFileAddition > blob_file_additions ;
BlobFileBuilder builder (
TestFileNumberGenerator ( ) , & mock_env_ , & fs_ , & immutable_cf_options ,
& mutable_cf_options , & file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint , & blob_file_additions ) ;
BlobFileBuilder builder ( TestFileNumberGenerator ( ) , & mock_env_ , & fs_ ,
& immutable_cf_options , & mutable_cf_options ,
& file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint ,
& blob_file_paths , & blob_file_additions ) ;
std : : vector < std : : pair < std : : string , std : : string > > expected_key_value_pairs (
number_of_blobs ) ;
@ -168,12 +168,20 @@ TEST_F(BlobFileBuilderTest, BuildAndCheckOneFile) {
ASSERT_OK ( builder . Finish ( ) ) ;
// Check the metadata generated
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_paths . size ( ) , 1 ) ;
const std : : string & blob_file_path = blob_file_paths [ 0 ] ;
ASSERT_EQ ( blob_file_path ,
BlobFileName ( immutable_cf_options . cf_paths . front ( ) . path ,
blob_file_number ) ) ;
ASSERT_EQ ( blob_file_additions . size ( ) , 1 ) ;
const auto & blob_file_addition = blob_file_additions [ 0 ] ;
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_addition . GetBlobFileNumber ( ) , blob_file_number ) ;
ASSERT_EQ ( blob_file_addition . GetTotalBlobCount ( ) , number_of_blobs ) ;
ASSERT_EQ (
@ -181,7 +189,7 @@ TEST_F(BlobFileBuilderTest, BuildAndCheckOneFile) {
number_of_blobs * ( BlobLogRecord : : kHeaderSize + key_size + value_size ) ) ;
// Verify the contents of the new blob file as well as the blob references
VerifyBlobFile ( immutable_cf_options , blob_file_number , column_family_id ,
VerifyBlobFile ( blob_file_number , blob_file_path , column_family_id ,
kNoCompression , expected_key_value_pairs , blob_indexes ) ;
}
@ -210,12 +218,14 @@ TEST_F(BlobFileBuilderTest, BuildAndCheckMultipleFiles) {
constexpr Env : : IOPriority io_priority = Env : : IO_HIGH ;
constexpr Env : : WriteLifeTimeHint write_hint = Env : : WLTH_MEDIUM ;
std : : vector < std : : string > blob_file_paths ;
std : : vector < BlobFileAddition > blob_file_additions ;
BlobFileBuilder builder (
TestFileNumberGenerator ( ) , & mock_env_ , & fs_ , & immutable_cf_options ,
& mutable_cf_options , & file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint , & blob_file_additions ) ;
BlobFileBuilder builder ( TestFileNumberGenerator ( ) , & mock_env_ , & fs_ ,
& immutable_cf_options , & mutable_cf_options ,
& file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint ,
& blob_file_paths , & blob_file_additions ) ;
std : : vector < std : : pair < std : : string , std : : string > > expected_key_value_pairs (
number_of_blobs ) ;
@ -241,12 +251,19 @@ TEST_F(BlobFileBuilderTest, BuildAndCheckMultipleFiles) {
ASSERT_OK ( builder . Finish ( ) ) ;
// Check the metadata generated
ASSERT_EQ ( blob_file_paths . size ( ) , number_of_blobs ) ;
ASSERT_EQ ( blob_file_additions . size ( ) , number_of_blobs ) ;
for ( size_t i = 0 ; i < number_of_blobs ; + + i ) {
const uint64_t blob_file_number = i + 2 ;
ASSERT_EQ ( blob_file_paths [ i ] ,
BlobFileName ( immutable_cf_options . cf_paths . front ( ) . path ,
blob_file_number ) ) ;
const auto & blob_file_addition = blob_file_additions [ i ] ;
ASSERT_EQ ( blob_file_addition . GetBlobFileNumber ( ) , i + 2 ) ;
ASSERT_EQ ( blob_file_addition . GetBlobFileNumber ( ) , blob_file_number ) ;
ASSERT_EQ ( blob_file_addition . GetTotalBlobCount ( ) , 1 ) ;
ASSERT_EQ ( blob_file_addition . GetTotalBlobBytes ( ) ,
BlobLogRecord : : kHeaderSize + key_size + value_size ) ;
@ -258,8 +275,8 @@ TEST_F(BlobFileBuilderTest, BuildAndCheckMultipleFiles) {
expected_key_value_pairs [ i ] } ;
std : : vector < std : : string > blob_index { blob_indexes [ i ] } ;
VerifyBlobFile ( immutable_cf_options , i + 2 , column_family_id ,
kNoCompression , expected_key_value_pair , blob_index ) ;
VerifyBlobFile ( i + 2 , blob_file_paths [ i ] , column_family_id , kNoCompression ,
expected_key_value_pair , blob_index ) ;
}
}
@ -286,12 +303,14 @@ TEST_F(BlobFileBuilderTest, InlinedValues) {
constexpr Env : : IOPriority io_priority = Env : : IO_HIGH ;
constexpr Env : : WriteLifeTimeHint write_hint = Env : : WLTH_MEDIUM ;
std : : vector < std : : string > blob_file_paths ;
std : : vector < BlobFileAddition > blob_file_additions ;
BlobFileBuilder builder (
TestFileNumberGenerator ( ) , & mock_env_ , & fs_ , & immutable_cf_options ,
& mutable_cf_options , & file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint , & blob_file_additions ) ;
BlobFileBuilder builder ( TestFileNumberGenerator ( ) , & mock_env_ , & fs_ ,
& immutable_cf_options , & mutable_cf_options ,
& file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint ,
& blob_file_paths , & blob_file_additions ) ;
for ( size_t i = 0 ; i < number_of_blobs ; + + i ) {
const std : : string key = std : : to_string ( i ) ;
@ -308,6 +327,7 @@ TEST_F(BlobFileBuilderTest, InlinedValues) {
ASSERT_OK ( builder . Finish ( ) ) ;
// Check the metadata generated
ASSERT_TRUE ( blob_file_paths . empty ( ) ) ;
ASSERT_TRUE ( blob_file_additions . empty ( ) ) ;
}
@ -335,12 +355,14 @@ TEST_F(BlobFileBuilderTest, Compression) {
constexpr Env : : IOPriority io_priority = Env : : IO_HIGH ;
constexpr Env : : WriteLifeTimeHint write_hint = Env : : WLTH_MEDIUM ;
std : : vector < std : : string > blob_file_paths ;
std : : vector < BlobFileAddition > blob_file_additions ;
BlobFileBuilder builder (
TestFileNumberGenerator ( ) , & mock_env_ , & fs_ , & immutable_cf_options ,
& mutable_cf_options , & file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint , & blob_file_additions ) ;
BlobFileBuilder builder ( TestFileNumberGenerator ( ) , & mock_env_ , & fs_ ,
& immutable_cf_options , & mutable_cf_options ,
& file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint ,
& blob_file_paths , & blob_file_additions ) ;
const std : : string key ( " 1 " ) ;
const std : : string uncompressed_value ( value_size , ' x ' ) ;
@ -353,12 +375,20 @@ TEST_F(BlobFileBuilderTest, Compression) {
ASSERT_OK ( builder . Finish ( ) ) ;
// Check the metadata generated
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_paths . size ( ) , 1 ) ;
const std : : string & blob_file_path = blob_file_paths [ 0 ] ;
ASSERT_EQ ( blob_file_path ,
BlobFileName ( immutable_cf_options . cf_paths . front ( ) . path ,
blob_file_number ) ) ;
ASSERT_EQ ( blob_file_additions . size ( ) , 1 ) ;
const auto & blob_file_addition = blob_file_additions [ 0 ] ;
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_addition . GetBlobFileNumber ( ) , blob_file_number ) ;
ASSERT_EQ ( blob_file_addition . GetTotalBlobCount ( ) , 1 ) ;
@ -381,7 +411,7 @@ TEST_F(BlobFileBuilderTest, Compression) {
{ key , compressed_value } } ;
std : : vector < std : : string > blob_indexes { blob_index } ;
VerifyBlobFile ( immutable_cf_options , blob_file_number , column_family_id ,
VerifyBlobFile ( blob_file_number , blob_file_path , column_family_id ,
kSnappyCompression , expected_key_value_pairs , blob_indexes ) ;
}
@ -407,12 +437,14 @@ TEST_F(BlobFileBuilderTest, CompressionError) {
constexpr Env : : IOPriority io_priority = Env : : IO_HIGH ;
constexpr Env : : WriteLifeTimeHint write_hint = Env : : WLTH_MEDIUM ;
std : : vector < std : : string > blob_file_paths ;
std : : vector < BlobFileAddition > blob_file_additions ;
BlobFileBuilder builder (
TestFileNumberGenerator ( ) , & mock_env_ , & fs_ , & immutable_cf_options ,
& mutable_cf_options , & file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint , & blob_file_additions ) ;
BlobFileBuilder builder ( TestFileNumberGenerator ( ) , & mock_env_ , & fs_ ,
& immutable_cf_options , & mutable_cf_options ,
& file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint ,
& blob_file_paths , & blob_file_additions ) ;
SyncPoint : : GetInstance ( ) - > SetCallBack ( " CompressData:TamperWithReturnValue " ,
[ ] ( void * arg ) {
@ -430,6 +462,15 @@ TEST_F(BlobFileBuilderTest, CompressionError) {
SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
SyncPoint : : GetInstance ( ) - > ClearAllCallBacks ( ) ;
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_paths . size ( ) , 1 ) ;
ASSERT_EQ ( blob_file_paths [ 0 ] ,
BlobFileName ( immutable_cf_options . cf_paths . front ( ) . path ,
blob_file_number ) ) ;
ASSERT_TRUE ( blob_file_additions . empty ( ) ) ;
}
TEST_F ( BlobFileBuilderTest , Checksum ) {
@ -473,12 +514,14 @@ TEST_F(BlobFileBuilderTest, Checksum) {
constexpr Env : : IOPriority io_priority = Env : : IO_HIGH ;
constexpr Env : : WriteLifeTimeHint write_hint = Env : : WLTH_MEDIUM ;
std : : vector < std : : string > blob_file_paths ;
std : : vector < BlobFileAddition > blob_file_additions ;
BlobFileBuilder builder (
TestFileNumberGenerator ( ) , & mock_env_ , & fs_ , & immutable_cf_options ,
& mutable_cf_options , & file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint , & blob_file_additions ) ;
BlobFileBuilder builder ( TestFileNumberGenerator ( ) , & mock_env_ , & fs_ ,
& immutable_cf_options , & mutable_cf_options ,
& file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint ,
& blob_file_paths , & blob_file_additions ) ;
const std : : string key ( " 1 " ) ;
const std : : string value ( " deadbeef " ) ;
@ -491,12 +534,20 @@ TEST_F(BlobFileBuilderTest, Checksum) {
ASSERT_OK ( builder . Finish ( ) ) ;
// Check the metadata generated
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_paths . size ( ) , 1 ) ;
const std : : string & blob_file_path = blob_file_paths [ 0 ] ;
ASSERT_EQ ( blob_file_path ,
BlobFileName ( immutable_cf_options . cf_paths . front ( ) . path ,
blob_file_number ) ) ;
ASSERT_EQ ( blob_file_additions . size ( ) , 1 ) ;
const auto & blob_file_addition = blob_file_additions [ 0 ] ;
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_addition . GetBlobFileNumber ( ) , blob_file_number ) ;
ASSERT_EQ ( blob_file_addition . GetTotalBlobCount ( ) , 1 ) ;
ASSERT_EQ ( blob_file_addition . GetTotalBlobBytes ( ) ,
@ -509,7 +560,7 @@ TEST_F(BlobFileBuilderTest, Checksum) {
{ key , value } } ;
std : : vector < std : : string > blob_indexes { blob_index } ;
VerifyBlobFile ( immutable_cf_options , blob_file_number , column_family_id ,
VerifyBlobFile ( blob_file_number , blob_file_path , column_family_id ,
kNoCompression , expected_key_value_pairs , blob_indexes ) ;
}
@ -561,13 +612,14 @@ TEST_P(BlobFileBuilderIOErrorTest, IOError) {
constexpr Env : : IOPriority io_priority = Env : : IO_HIGH ;
constexpr Env : : WriteLifeTimeHint write_hint = Env : : WLTH_MEDIUM ;
std : : vector < std : : string > blob_file_paths ;
std : : vector < BlobFileAddition > blob_file_additions ;
BlobFileBuilder builder ( TestFileNumberGenerator ( ) , & fault_injection_env_ ,
& fs_ , & immutable_cf_options , & mutable_cf_options ,
& file_options_ , job_id , column_family_id ,
column_family_name , io_priority , write_hint ,
& blob_file_additions ) ;
& blob_file_paths , & blob_file_ additions ) ;
SyncPoint : : GetInstance ( ) - > SetCallBack ( sync_point_ , [ this ] ( void * /* arg */ ) {
fault_injection_env_ . SetFilesystemActive ( false ,
@ -584,6 +636,19 @@ TEST_P(BlobFileBuilderIOErrorTest, IOError) {
SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
SyncPoint : : GetInstance ( ) - > ClearAllCallBacks ( ) ;
if ( sync_point_ = = " BlobFileBuilder::OpenBlobFileIfNeeded:NewWritableFile " ) {
ASSERT_TRUE ( blob_file_paths . empty ( ) ) ;
} else {
constexpr uint64_t blob_file_number = 2 ;
ASSERT_EQ ( blob_file_paths . size ( ) , 1 ) ;
ASSERT_EQ ( blob_file_paths [ 0 ] ,
BlobFileName ( immutable_cf_options . cf_paths . front ( ) . path ,
blob_file_number ) ) ;
}
ASSERT_TRUE ( blob_file_additions . empty ( ) ) ;
}
} // namespace ROCKSDB_NAMESPACE