@ -594,6 +594,17 @@ class BackupableDBTest : public testing::Test {
return db ;
return db ;
}
}
void CloseAndReopenDB ( ) {
// Close DB
db_ . reset ( ) ;
// Open DB
test_db_env_ - > SetLimitWrittenFiles ( 1000000 ) ;
DB * db ;
ASSERT_OK ( DB : : Open ( options_ , dbname_ , & db ) ) ;
db_ . reset ( db ) ;
}
void OpenDBAndBackupEngine ( bool destroy_old_data = false , bool dummy = false ,
void OpenDBAndBackupEngine ( bool destroy_old_data = false , bool dummy = false ,
ShareOption shared_option = kShareNoChecksum ) {
ShareOption shared_option = kShareNoChecksum ) {
// reset all the defaults
// reset all the defaults
@ -1186,12 +1197,14 @@ TEST_F(BackupableDBTest, TableFileCorruptedBeforeBackup) {
kNoShare ) ;
kNoShare ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
CloseAndReopenDB ( ) ;
// corrupt a random table file in the DB directory
// corrupt a random table file in the DB directory
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
// file_checksum_gen_factory is null, and thus table checksum is not
// file_checksum_gen_factory is null, and thus table checksum is not
// verified for creating a new backup; no correction is detected
// verified for creating a new backup; no correction is detected
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
CloseDBAndBackupEngine ( ) ;
CloseDBAndBackupEngine ( ) ;
// delete old files in db
// delete old files in db
ASSERT_OK ( DestroyDB ( dbname_ , options_ ) ) ;
ASSERT_OK ( DestroyDB ( dbname_ , options_ ) ) ;
@ -1201,12 +1214,12 @@ TEST_F(BackupableDBTest, TableFileCorruptedBeforeBackup) {
kNoShare ) ;
kNoShare ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
CloseAndReopenDB ( ) ;
// corrupt a random table file in the DB directory
// corrupt a random table file in the DB directory
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
// table file checksum is enabled so we should be able to detect any
// table file checksum is enabled so we should be able to detect any
// corruption
// corruption
ASSERT_NOK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
ASSERT_NOK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
CloseDBAndBackupEngine ( ) ;
CloseDBAndBackupEngine ( ) ;
}
}
@ -1219,11 +1232,13 @@ TEST_P(BackupableDBTestWithParam, TableFileCorruptedBeforeBackup) {
OpenDBAndBackupEngine ( true /* destroy_old_data */ ) ;
OpenDBAndBackupEngine ( true /* destroy_old_data */ ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
CloseAndReopenDB ( ) ;
// corrupt a random table file in the DB directory
// corrupt a random table file in the DB directory
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
// cannot detect corruption since DB manifest has no table checksums
// cannot detect corruption since DB manifest has no table checksums
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
ASSERT_OK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
CloseDBAndBackupEngine ( ) ;
CloseDBAndBackupEngine ( ) ;
// delete old files in db
// delete old files in db
ASSERT_OK ( DestroyDB ( dbname_ , options_ ) ) ;
ASSERT_OK ( DestroyDB ( dbname_ , options_ ) ) ;
@ -1232,11 +1247,11 @@ TEST_P(BackupableDBTestWithParam, TableFileCorruptedBeforeBackup) {
OpenDBAndBackupEngine ( true /* destroy_old_data */ ) ;
OpenDBAndBackupEngine ( true /* destroy_old_data */ ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
FillDB ( db_ . get ( ) , 0 , keys_iteration ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
ASSERT_OK ( db_ - > Flush ( FlushOptions ( ) ) ) ;
CloseAndReopenDB ( ) ;
// corrupt a random table file in the DB directory
// corrupt a random table file in the DB directory
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
ASSERT_OK ( CorruptRandomTableFileInDB ( ) ) ;
// corruption is detected
// corruption is detected
ASSERT_NOK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
ASSERT_NOK ( backup_engine_ - > CreateNewBackup ( db_ . get ( ) ) ) ;
CloseDBAndBackupEngine ( ) ;
CloseDBAndBackupEngine ( ) ;
}
}