@ -27,7 +27,7 @@
# include "util/xfunc.h"
# include "util/xfunc.h"
namespace rocksdb {
namespace rocksdb {
class DB Test : public testing : : Test {
class Checkpoint Test : public testing : : Test {
protected :
protected :
// Sequence of option configurations to try
// Sequence of option configurations to try
enum OptionConfig {
enum OptionConfig {
@ -43,7 +43,7 @@ class DBTest : public testing::Test {
Options last_options_ ;
Options last_options_ ;
std : : vector < ColumnFamilyHandle * > handles_ ;
std : : vector < ColumnFamilyHandle * > handles_ ;
DB Test( ) : env_ ( Env : : Default ( ) ) {
Checkpoint Test( ) : env_ ( Env : : Default ( ) ) {
env_ - > SetBackgroundThreads ( 1 , Env : : LOW ) ;
env_ - > SetBackgroundThreads ( 1 , Env : : LOW ) ;
env_ - > SetBackgroundThreads ( 1 , Env : : HIGH ) ;
env_ - > SetBackgroundThreads ( 1 , Env : : HIGH ) ;
dbname_ = test : : TmpDir ( env_ ) + " /db_test " ;
dbname_ = test : : TmpDir ( env_ ) + " /db_test " ;
@ -58,7 +58,7 @@ class DBTest : public testing::Test {
Reopen ( options ) ;
Reopen ( options ) ;
}
}
~ DB Test( ) {
~ Checkpoint Test( ) {
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency ( { } ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency ( { } ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearAllCallBacks ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > ClearAllCallBacks ( ) ;
@ -216,69 +216,67 @@ class DBTest : public testing::Test {
}
}
} ;
} ;
TEST_F ( DBTest , GetSnapshotLink ) {
TEST_F ( CheckpointTest , GetSnapshotLink ) {
Options options ;
Options options ;
const std : : string snapshot_name = test : : TmpDir ( env_ ) + " /snapshot " ;
const std : : string snapshot_name = test : : TmpDir ( env_ ) + " /snapshot " ;
DB * snapshotDB ;
DB * snapshotDB ;
ReadOptions roptions ;
ReadOptions roptions ;
std : : string result ;
std : : string result ;
Checkpoint * checkpoint ;
Checkpoint * checkpoint ;
options = CurrentOptions ( ) ;
delete db_ ;
db_ = nullptr ;
ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ;
ASSERT_OK ( DestroyDB ( snapshot_name , options ) ) ;
env_ - > DeleteDir ( snapshot_name ) ;
// Create a database
options = CurrentOptions ( ) ;
Status s ;
delete db_ ;
options . create_if_missing = true ;
db_ = nullptr ;
ASSERT_OK ( DB : : Open ( options , dbname_ , & db_ ) ) ;
ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ;
std : : string key = std : : string ( " foo " ) ;
ASSERT_OK ( DestroyDB ( snapshot_name , options ) ) ;
ASSERT_OK ( Put ( key , " v1 " ) ) ;
env_ - > DeleteDir ( snapshot_name ) ;
// Take a snapshot
ASSERT_OK ( Checkpoint : : Create ( db_ , & checkpoint ) ) ;
ASSERT_OK ( checkpoint - > CreateCheckpoint ( snapshot_name ) ) ;
ASSERT_OK ( Put ( key , " v2 " ) ) ;
ASSERT_EQ ( " v2 " , Get ( key ) ) ;
ASSERT_OK ( Flush ( ) ) ;
ASSERT_EQ ( " v2 " , Get ( key ) ) ;
// Open snapshot and verify contents while DB is running
options . create_if_missing = false ;
ASSERT_OK ( DB : : Open ( options , snapshot_name , & snapshotDB ) ) ;
ASSERT_OK ( snapshotDB - > Get ( roptions , key , & result ) ) ;
ASSERT_EQ ( " v1 " , result ) ;
delete snapshotDB ;
snapshotDB = nullptr ;
delete db_ ;
db_ = nullptr ;
// Destroy original DB
// Create a database
ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ;
Status s ;
options . create_if_missing = true ;
ASSERT_OK ( DB : : Open ( options , dbname_ , & db_ ) ) ;
std : : string key = std : : string ( " foo " ) ;
ASSERT_OK ( Put ( key , " v1 " ) ) ;
// Take a snapshot
ASSERT_OK ( Checkpoint : : Create ( db_ , & checkpoint ) ) ;
ASSERT_OK ( checkpoint - > CreateCheckpoint ( snapshot_name ) ) ;
ASSERT_OK ( Put ( key , " v2 " ) ) ;
ASSERT_EQ ( " v2 " , Get ( key ) ) ;
ASSERT_OK ( Flush ( ) ) ;
ASSERT_EQ ( " v2 " , Get ( key ) ) ;
// Open snapshot and verify contents while DB is running
options . create_if_missing = false ;
ASSERT_OK ( DB : : Open ( options , snapshot_name , & snapshotDB ) ) ;
ASSERT_OK ( snapshotDB - > Get ( roptions , key , & result ) ) ;
ASSERT_EQ ( " v1 " , result ) ;
delete snapshotDB ;
snapshotDB = nullptr ;
delete db_ ;
db_ = nullptr ;
// Open snapshot and verify contents
// Destroy original DB
options . create_if_missing = false ;
ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ;
dbname_ = snapshot_name ;
ASSERT_OK ( DB : : Open ( options , dbname_ , & db_ ) ) ;
ASSERT_EQ ( " v1 " , Get ( key ) ) ;
delete db_ ;
db_ = nullptr ;
ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ;
delete checkpoint ;
// Restore DB name
// Open snapshot and verify contents
dbname_ = test : : TmpDir ( env_ ) + " /db_test " ;
options . create_if_missing = false ;
dbname_ = snapshot_name ;
ASSERT_OK ( DB : : Open ( options , dbname_ , & db_ ) ) ;
ASSERT_EQ ( " v1 " , Get ( key ) ) ;
delete db_ ;
db_ = nullptr ;
ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ;
delete checkpoint ;
// Restore DB name
dbname_ = test : : TmpDir ( env_ ) + " /db_test " ;
}
}
TEST_F ( DBTest , CheckpointCF ) {
TEST_F ( Checkpoint Test, CheckpointCF ) {
Options options = CurrentOptions ( ) ;
Options options = CurrentOptions ( ) ;
CreateAndReopenWithCF ( { " one " , " two " , " three " , " four " , " five " } , options ) ;
CreateAndReopenWithCF ( { " one " , " two " , " three " , " four " , " five " } , options ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency (
rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency (
{ { " DBTest::CheckpointCF:2 " ,
{ { " CheckpointTest::CheckpointCF:2 " , " DBImpl::GetLiveFiles:2 " } ,
" DBImpl::GetLiveFiles:2 " } ,
{ " DBImpl::GetLiveFiles:1 " , " CheckpointTest::CheckpointCF:1 " } } ) ;
{ " DBImpl::GetLiveFiles:1 " ,
" DBTest::CheckpointCF:1 " } } ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
@ -306,14 +304,14 @@ TEST_F(DBTest, CheckpointCF) {
ASSERT_OK ( checkpoint - > CreateCheckpoint ( snapshot_name ) ) ;
ASSERT_OK ( checkpoint - > CreateCheckpoint ( snapshot_name ) ) ;
delete checkpoint ;
delete checkpoint ;
} ) ;
} ) ;
TEST_SYNC_POINT ( " DB Test::CheckpointCF:1" ) ;
TEST_SYNC_POINT ( " Checkpoint Test::CheckpointCF:1" ) ;
ASSERT_OK ( Put ( 0 , " Default " , " Default1 " ) ) ;
ASSERT_OK ( Put ( 0 , " Default " , " Default1 " ) ) ;
ASSERT_OK ( Put ( 1 , " one " , " eleven " ) ) ;
ASSERT_OK ( Put ( 1 , " one " , " eleven " ) ) ;
ASSERT_OK ( Put ( 2 , " two " , " twelve " ) ) ;
ASSERT_OK ( Put ( 2 , " two " , " twelve " ) ) ;
ASSERT_OK ( Put ( 3 , " three " , " thirteen " ) ) ;
ASSERT_OK ( Put ( 3 , " three " , " thirteen " ) ) ;
ASSERT_OK ( Put ( 4 , " four " , " fourteen " ) ) ;
ASSERT_OK ( Put ( 4 , " four " , " fourteen " ) ) ;
ASSERT_OK ( Put ( 5 , " five " , " fifteen " ) ) ;
ASSERT_OK ( Put ( 5 , " five " , " fifteen " ) ) ;
TEST_SYNC_POINT ( " DB Test::CheckpointCF:2" ) ;
TEST_SYNC_POINT ( " Checkpoint Test::CheckpointCF:2" ) ;
t . join ( ) ;
t . join ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
ASSERT_OK ( Put ( 1 , " one " , " twentyone " ) ) ;
ASSERT_OK ( Put ( 1 , " one " , " twentyone " ) ) ;
@ -347,7 +345,7 @@ TEST_F(DBTest, CheckpointCF) {
ASSERT_OK ( DestroyDB ( snapshot_name , options ) ) ;
ASSERT_OK ( DestroyDB ( snapshot_name , options ) ) ;
}
}
TEST_F ( DB Test, CurrentFileModifiedWhileCheckpointing ) {
TEST_F ( Checkpoint Test, CurrentFileModifiedWhileCheckpointing ) {
const std : : string kSnapshotName = test : : TmpDir ( env_ ) + " /snapshot " ;
const std : : string kSnapshotName = test : : TmpDir ( env_ ) + " /snapshot " ;
ASSERT_OK ( DestroyDB ( kSnapshotName , CurrentOptions ( ) ) ) ;
ASSERT_OK ( DestroyDB ( kSnapshotName , CurrentOptions ( ) ) ) ;
env_ - > DeleteDir ( kSnapshotName ) ;
env_ - > DeleteDir ( kSnapshotName ) ;
@ -361,7 +359,7 @@ TEST_F(DBTest, CurrentFileModifiedWhileCheckpointing) {
// the db so the checkpoint thread won't hit the WriteManifest
// the db so the checkpoint thread won't hit the WriteManifest
// syncpoints.
// syncpoints.
{ " DBImpl::GetLiveFiles:1 " ,
{ " DBImpl::GetLiveFiles:1 " ,
" DB Test::CurrentFileModifiedWhileCheckpointing:PrePut" } ,
" Checkpoint Test::CurrentFileModifiedWhileCheckpointing:PrePut" } ,
// Roll the manifest during checkpointing right after live files are
// Roll the manifest during checkpointing right after live files are
// snapshotted.
// snapshotted.
{ " CheckpointImpl::CreateCheckpoint:SavedLiveFiles1 " ,
{ " CheckpointImpl::CreateCheckpoint:SavedLiveFiles1 " ,
@ -376,7 +374,8 @@ TEST_F(DBTest, CurrentFileModifiedWhileCheckpointing) {
ASSERT_OK ( checkpoint - > CreateCheckpoint ( kSnapshotName ) ) ;
ASSERT_OK ( checkpoint - > CreateCheckpoint ( kSnapshotName ) ) ;
delete checkpoint ;
delete checkpoint ;
} ) ;
} ) ;
TEST_SYNC_POINT ( " DBTest::CurrentFileModifiedWhileCheckpointing:PrePut " ) ;
TEST_SYNC_POINT (
" CheckpointTest::CurrentFileModifiedWhileCheckpointing:PrePut " ) ;
ASSERT_OK ( Put ( " Default " , " Default1 " ) ) ;
ASSERT_OK ( Put ( " Default " , " Default1 " ) ) ;
ASSERT_OK ( Flush ( ) ) ;
ASSERT_OK ( Flush ( ) ) ;
t . join ( ) ;
t . join ( ) ;
@ -391,16 +390,17 @@ TEST_F(DBTest, CurrentFileModifiedWhileCheckpointing) {
snapshotDB = nullptr ;
snapshotDB = nullptr ;
}
}
TEST_F ( DBTest , CurrentFileModifiedWhileCheckpointing2PC ) {
TEST_F ( CheckpointTest , CurrentFileModifiedWhileCheckpointing2PC ) {
Close ( ) ;
const std : : string kSnapshotName = test : : TmpDir ( env_ ) + " /snapshot " ;
const std : : string kSnapshotName = test : : TmpDir ( env_ ) + " /snapshot " ;
const std : : string dbname = test : : TmpDir ( ) + " /transaction_testdb " ;
const std : : string dbname = test : : TmpDir ( ) + " /transaction_testdb " ;
ASSERT_OK ( DestroyDB ( kSnapshotName , CurrentOptions ( ) ) ) ;
ASSERT_OK ( DestroyDB ( kSnapshotName , CurrentOptions ( ) ) ) ;
ASSERT_OK ( DestroyDB ( dbname , CurrentOptions ( ) ) ) ;
ASSERT_OK ( DestroyDB ( dbname , CurrentOptions ( ) ) ) ;
env_ - > DeleteDir ( kSnapshotName ) ;
env_ - > DeleteDir ( kSnapshotName ) ;
env_ - > DeleteDir ( dbname ) ;
env_ - > DeleteDir ( dbname ) ;
Close ( ) ;
Options options = CurrentOptions ( ) ;
Options options = CurrentOptions ( ) ;
options . allow_2pc = true ;
// allow_2pc is implicitly set with tx prepare
// allow_2pc is implicitly set with tx prepare
// options.allow_2pc = true;
// options.allow_2pc = true;
TransactionDBOptions txn_db_options ;
TransactionDBOptions txn_db_options ;
@ -443,11 +443,12 @@ TEST_F(DBTest, CurrentFileModifiedWhileCheckpointing2PC) {
if ( i = = 88888 ) {
if ( i = = 88888 ) {
ASSERT_OK ( txn - > Prepare ( ) ) ;
ASSERT_OK ( txn - > Prepare ( ) ) ;
}
}
delete tx ;
}
}
rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency (
rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency (
{ { " CheckpointImpl::CreateCheckpoint:SavedLiveFiles1 " ,
{ { " CheckpointImpl::CreateCheckpoint:SavedLiveFiles1 " ,
" DB Test::CurrentFileModifiedWhileCheckpointing2PC:PreCommit" } ,
" Checkpoint Test::CurrentFileModifiedWhileCheckpointing2PC:PreCommit" } ,
{ " DB Test::CurrentFileModifiedWhileCheckpointing2PC:PostCommit" ,
{ " Checkpoint Test::CurrentFileModifiedWhileCheckpointing2PC:PostCommit" ,
" CheckpointImpl::CreateCheckpoint:SavedLiveFiles2 " } } ) ;
" CheckpointImpl::CreateCheckpoint:SavedLiveFiles2 " } } ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > EnableProcessing ( ) ;
std : : thread t ( [ & ] ( ) {
std : : thread t ( [ & ] ( ) {
@ -456,10 +457,12 @@ TEST_F(DBTest, CurrentFileModifiedWhileCheckpointing2PC) {
ASSERT_OK ( checkpoint - > CreateCheckpoint ( kSnapshotName ) ) ;
ASSERT_OK ( checkpoint - > CreateCheckpoint ( kSnapshotName ) ) ;
delete checkpoint ;
delete checkpoint ;
} ) ;
} ) ;
TEST_SYNC_POINT ( " DBTest::CurrentFileModifiedWhileCheckpointing2PC:PreCommit " ) ;
TEST_SYNC_POINT (
" CheckpointTest::CurrentFileModifiedWhileCheckpointing2PC:PreCommit " ) ;
ASSERT_OK ( txn - > Commit ( ) ) ;
ASSERT_OK ( txn - > Commit ( ) ) ;
delete txn ;
TEST_SYNC_POINT (
TEST_SYNC_POINT (
" DB Test::CurrentFileModifiedWhileCheckpointing2PC:PostCommit" ) ;
" Checkpoint Test::CurrentFileModifiedWhileCheckpointing2PC:PostCommit" ) ;
t . join ( ) ;
t . join ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
@ -503,6 +506,7 @@ TEST_F(DBTest, CurrentFileModifiedWhileCheckpointing2PC) {
delete cf_handles [ 2 ] ;
delete cf_handles [ 2 ] ;
delete snapshotDB ;
delete snapshotDB ;
snapshotDB = nullptr ;
snapshotDB = nullptr ;
delete txdb ;
}
}
} // namespace rocksdb
} // namespace rocksdb