@ -1192,10 +1192,8 @@ TEST_F(VersionSetTest, WalEditsNotAppliedToVersion) {
edits . back ( ) - > AddWal ( i , WalMetadata ( i ) ) ;
}
// Delete the first half of the WALs.
for ( uint64_t i = 1 ; i < = kNumWals ; i + + ) {
edits . emplace_back ( new VersionEdit ) ;
edits . back ( ) - > DeleteWal ( i ) ;
}
edits . emplace_back ( new VersionEdit ) ;
edits . back ( ) - > DeleteWalsBefore ( kNumWals / 2 + 1 ) ;
autovector < Version * > versions ;
SyncPoint : : GetInstance ( ) - > SetCallBack (
@ -1228,10 +1226,8 @@ TEST_F(VersionSetTest, NonWalEditsAppliedToVersion) {
edits . back ( ) - > AddWal ( i , WalMetadata ( i ) ) ;
}
// Delete the first half of the WALs.
for ( uint64_t i = 1 ; i < = kNumWals ; i + + ) {
edits . emplace_back ( new VersionEdit ) ;
edits . back ( ) - > DeleteWal ( i ) ;
}
edits . emplace_back ( new VersionEdit ) ;
edits . back ( ) - > DeleteWalsBefore ( kNumWals / 2 + 1 ) ;
edits . emplace_back ( new VersionEdit ) ;
edits . back ( ) - > SetDBId ( kDBId ) ;
@ -1411,7 +1407,7 @@ TEST_F(VersionSetTest, WalDeletion) {
// Delete the closed WAL.
{
VersionEdit edit ;
edit . DeleteWal ( kClosedLogNumber ) ;
edit . DeleteWalsBefore ( kNon ClosedLogNumber ) ;
ASSERT_OK ( LogAndApplyToDefaultCF ( edit ) ) ;
@ -1549,39 +1545,83 @@ TEST_F(VersionSetTest, AddWalWithSmallerSize) {
}
}
TEST_F ( VersionSetTest , DeleteNonExistingWal ) {
TEST_F ( VersionSetTest , DeleteWalsBefore NonExistingWalNumber ) {
NewDB ( ) ;
constexpr WalNumber kLogNumber = 10 ;
constexpr WalNumber kNonExistingNumber = 11 ;
constexpr WalNumber kLogNumber0 = 10 ;
constexpr WalNumber kLogNumber1 = 20 ;
constexpr WalNumber kNonExistingNumber = 15 ;
constexpr uint64_t kSizeInBytes = 111 ;
{
// Add closed WALs.
VersionEdit edit ;
WalMetadata wal ( kSizeInBytes ) ;
edit . AddWal ( kLogNumber0 , wal ) ;
edit . AddWal ( kLogNumber1 , wal ) ;
ASSERT_OK ( LogAndApplyToDefaultCF ( edit ) ) ;
}
{
// Delete WALs before a non-existing WAL.
VersionEdit edit ;
edit . DeleteWalsBefore ( kNonExistingNumber ) ;
ASSERT_OK ( LogAndApplyToDefaultCF ( edit ) ) ;
}
// Recover a new VersionSet, WAL0 is deleted, WAL1 is not.
{
std : : unique_ptr < VersionSet > new_versions (
new VersionSet ( dbname_ , & db_options_ , env_options_ , table_cache_ . get ( ) ,
& write_buffer_manager_ , & write_controller_ ,
/*block_cache_tracer=*/ nullptr , /*io_tracer=*/ nullptr ) ) ;
ASSERT_OK ( new_versions - > Recover ( column_families_ , false ) ) ;
const auto & wals = new_versions - > GetWalSet ( ) . GetWals ( ) ;
ASSERT_EQ ( wals . size ( ) , 1 ) ;
ASSERT_TRUE ( wals . find ( kLogNumber1 ) ! = wals . end ( ) ) ;
}
}
TEST_F ( VersionSetTest , DeleteAllWals ) {
NewDB ( ) ;
constexpr WalNumber kMaxLogNumber = 10 ;
constexpr uint64_t kSizeInBytes = 111 ;
{
// Add a closed WAL.
VersionEdit edit ;
WalMetadata wal ( kSizeInBytes ) ;
edit . AddWal ( kLogNumber , wal ) ;
edit . AddWal ( kMax LogNumber , wal ) ;
ASSERT_OK ( LogAndApplyToDefaultCF ( edit ) ) ;
}
{
// Delete a non-existing WAL.
VersionEdit edit ;
edit . DeleteWal ( kNonExistingNumber ) ;
edit . DeleteWalsBefore ( kMaxLogNumber + 10 ) ;
Status s = LogAndApplyToDefaultCF ( edit ) ;
ASSERT_TRUE ( s . IsCorruption ( ) ) ;
ASSERT_TRUE ( s . ToString ( ) . find ( " WAL 11 must exist before deletion " ) ! =
std : : string : : npos )
< < s . ToString ( ) ;
ASSERT_OK ( LogAndApplyToDefaultCF ( edit ) ) ;
}
// Recover a new VersionSet, all WALs are deleted.
{
std : : unique_ptr < VersionSet > new_versions (
new VersionSet ( dbname_ , & db_options_ , env_options_ , table_cache_ . get ( ) ,
& write_buffer_manager_ , & write_controller_ ,
/*block_cache_tracer=*/ nullptr , /*io_tracer=*/ nullptr ) ) ;
ASSERT_OK ( new_versions - > Recover ( column_families_ , false ) ) ;
const auto & wals = new_versions - > GetWalSet ( ) . GetWals ( ) ;
ASSERT_EQ ( wals . size ( ) , 0 ) ;
}
}
TEST_F ( VersionSetTest , AtomicGroupWithWalEdits ) {
NewDB ( ) ;
constexpr int kAtomicGroupSize = 10 ;
constexpr int kAtomicGroupSize = 7 ;
constexpr uint64_t kNumWals = 5 ;
const std : : string kDBId = " db_db " ;
@ -1599,11 +1639,9 @@ TEST_F(VersionSetTest, AtomicGroupWithWalEdits) {
edits . back ( ) - > SetDBId ( kDBId ) ;
edits . back ( ) - > MarkAtomicGroup ( - - remaining ) ;
// Delete the first added 4 WALs.
for ( uint64_t i = 1 ; i < kNumWals ; i + + ) {
edits . emplace_back ( new VersionEdit ) ;
edits . back ( ) - > DeleteWal ( i ) ;
edits . back ( ) - > MarkAtomicGroup ( - - remaining ) ;
}
edits . emplace_back ( new VersionEdit ) ;
edits . back ( ) - > DeleteWalsBefore ( kNumWals ) ;
edits . back ( ) - > MarkAtomicGroup ( - - remaining ) ;
ASSERT_EQ ( remaining , 0 ) ;
Status s = LogAndApplyToDefaultCF ( edits ) ;