@ -5073,8 +5073,8 @@ class RecoveryTestHelper {
ASSERT_OK ( db_options . env - > NewWritableFile ( fname , & file , env_options ) ) ;
ASSERT_OK ( db_options . env - > NewWritableFile ( fname , & file , env_options ) ) ;
unique_ptr < WritableFileWriter > file_writer (
unique_ptr < WritableFileWriter > file_writer (
new WritableFileWriter ( std : : move ( file ) , env_options ) ) ;
new WritableFileWriter ( std : : move ( file ) , env_options ) ) ;
current_log_writer . reset ( new log : : Writer (
current_log_writer . reset (
std : : move ( file_writer ) , current_log_number ,
new log : : Writer ( std : : move ( file_writer ) , current_log_number ,
db_options . recycle_log_file_num > 0 ) ) ;
db_options . recycle_log_file_num > 0 ) ) ;
for ( int i = 0 ; i < kKeysPerWALFile ; i + + ) {
for ( int i = 0 ; i < kKeysPerWALFile ; i + + ) {
@ -9891,15 +9891,13 @@ TEST_F(DBTest, PauseBackgroundWorkTest) {
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
namespace {
namespace {
void ValidateKeyExistence ( DB * db ,
void ValidateKeyExistence ( DB * db , const std : : vector < Slice > & keys_must_exist ,
const std : : vector < Slice > & keys_must_exist ,
const std : : vector < Slice > & keys_must_not_exist ) {
const std : : vector < Slice > & keys_must_not_exist ) {
// Ensure that expected keys exist
// Ensure that expected keys exist
std : : vector < std : : string > values ;
std : : vector < std : : string > values ;
if ( keys_must_exist . size ( ) > 0 ) {
if ( keys_must_exist . size ( ) > 0 ) {
std : : vector < Status > status_list = db - > MultiGet ( ReadOptions ( ) ,
std : : vector < Status > status_list =
keys_must_exist ,
db - > MultiGet ( ReadOptions ( ) , keys_must_exist , & values ) ;
& values ) ;
for ( size_t i = 0 ; i < keys_must_exist . size ( ) ; i + + ) {
for ( size_t i = 0 ; i < keys_must_exist . size ( ) ; i + + ) {
ASSERT_OK ( status_list [ i ] ) ;
ASSERT_OK ( status_list [ i ] ) ;
}
}
@ -9907,9 +9905,8 @@ namespace {
// Ensure that given keys don't exist
// Ensure that given keys don't exist
if ( keys_must_not_exist . size ( ) > 0 ) {
if ( keys_must_not_exist . size ( ) > 0 ) {
std : : vector < Status > status_list = db - > MultiGet ( ReadOptions ( ) ,
std : : vector < Status > status_list =
keys_must_not_exist ,
db - > MultiGet ( ReadOptions ( ) , keys_must_not_exist , & values ) ;
& values ) ;
for ( size_t i = 0 ; i < keys_must_not_exist . size ( ) ; i + + ) {
for ( size_t i = 0 ; i < keys_must_not_exist . size ( ) ; i + + ) {
ASSERT_TRUE ( status_list [ i ] . IsNotFound ( ) ) ;
ASSERT_TRUE ( status_list [ i ] . IsNotFound ( ) ) ;
}
}
@ -9929,21 +9926,22 @@ TEST_F(DBTest, WalFilterTest) {
size_t apply_option_at_record_index_ ;
size_t apply_option_at_record_index_ ;
// Current record index, incremented with each record encountered.
// Current record index, incremented with each record encountered.
size_t current_record_index_ ;
size_t current_record_index_ ;
public :
public :
TestWalFilter ( WalFilter : : WalProcessingOption wal_processing_option ,
TestWalFilter ( WalFilter : : WalProcessingOption wal_processing_option ,
size_t apply_option_for_record_index ) :
size_t apply_option_for_record_index )
wal_processing_option_ ( wal_processing_option ) ,
: wal_processing_option_ ( wal_processing_option ) ,
apply_option_at_record_index_ ( apply_option_for_record_index ) ,
apply_option_at_record_index_ ( apply_option_for_record_index ) ,
current_record_index_ ( 0 ) { }
current_record_index_ ( 0 ) { }
virtual WalProcessingOption LogRecord ( const WriteBatch & batch ,
virtual WalProcessingOption LogRecord ( const WriteBatch & batch ,
WriteBatch * new_batch , bool * batch_changed ) const override {
WriteBatch * new_batch ,
bool * batch_changed ) const override {
WalFilter : : WalProcessingOption option_to_return ;
WalFilter : : WalProcessingOption option_to_return ;
if ( current_record_index_ = = apply_option_at_record_index_ ) {
if ( current_record_index_ = = apply_option_at_record_index_ ) {
option_to_return = wal_processing_option_ ;
option_to_return = wal_processing_option_ ;
}
} else {
else {
option_to_return = WalProcessingOption : : kContinueProcessing ;
option_to_return = WalProcessingOption : : kContinueProcessing ;
}
}
@ -9955,9 +9953,7 @@ TEST_F(DBTest, WalFilterTest) {
return option_to_return ;
return option_to_return ;
}
}
virtual const char * Name ( ) const override {
virtual const char * Name ( ) const override { return " TestWalFilter " ; }
return " TestWalFilter " ;
}
} ;
} ;
// Create 3 batches with two keys each
// Create 3 batches with two keys each
@ -9972,7 +9968,8 @@ TEST_F(DBTest, WalFilterTest) {
// Test with all WAL processing options
// Test with all WAL processing options
for ( int option = 0 ;
for ( int option = 0 ;
option < static_cast < int > ( WalFilter : : WalProcessingOption : : kWalProcessingOptionMax ) ;
option < static_cast < int > (
WalFilter : : WalProcessingOption : : kWalProcessingOptionMax ) ;
option + + ) {
option + + ) {
Options options = OptionsForLogIterTest ( ) ;
Options options = OptionsForLogIterTest ( ) ;
DestroyAndReopen ( options ) ;
DestroyAndReopen ( options ) ;
@ -9999,8 +9996,8 @@ TEST_F(DBTest, WalFilterTest) {
// Reopen database with option to use WAL filter
// Reopen database with option to use WAL filter
options = OptionsForLogIterTest ( ) ;
options = OptionsForLogIterTest ( ) ;
options . wal_filter = & test_wal_filter ;
options . wal_filter = & test_wal_filter ;
Status status = TryReopenWithColumnFamilies ( { " default " , " pikachu " } ,
Status status =
options ) ;
TryReopenWithColumnFamilies ( { " default " , " pikachu " } , options ) ;
if ( wal_processing_option = =
if ( wal_processing_option = =
WalFilter : : WalProcessingOption : : kCorruptedRecord ) {
WalFilter : : WalProcessingOption : : kCorruptedRecord ) {
assert ( ! status . ok ( ) ) ;
assert ( ! status . ok ( ) ) ;
@ -10029,7 +10026,8 @@ TEST_F(DBTest, WalFilterTest) {
break ;
break ;
}
}
case WalFilter : : WalProcessingOption : : kIgnoreCurrentRecord : {
case WalFilter : : WalProcessingOption : : kIgnoreCurrentRecord : {
fprintf ( stderr , " Testing with ignoring record % " ROCKSDB_PRIszt " only \n " ,
fprintf ( stderr ,
" Testing with ignoring record % " ROCKSDB_PRIszt " only \n " ,
apply_option_for_record_index ) ;
apply_option_for_record_index ) ;
// We expect the record with apply_option_for_record_index to be not
// We expect the record with apply_option_for_record_index to be not
// found.
// found.
@ -10037,8 +10035,7 @@ TEST_F(DBTest, WalFilterTest) {
for ( size_t j = 0 ; j < batch_keys [ i ] . size ( ) ; j + + ) {
for ( size_t j = 0 ; j < batch_keys [ i ] . size ( ) ; j + + ) {
if ( i = = apply_option_for_record_index ) {
if ( i = = apply_option_for_record_index ) {
keys_must_not_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
keys_must_not_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
}
} else {
else {
keys_must_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
keys_must_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
}
}
}
}
@ -10046,7 +10043,9 @@ TEST_F(DBTest, WalFilterTest) {
break ;
break ;
}
}
case WalFilter : : WalProcessingOption : : kStopReplay : {
case WalFilter : : WalProcessingOption : : kStopReplay : {
fprintf ( stderr , " Testing with stopping replay from record % " ROCKSDB_PRIszt " \n " ,
fprintf ( stderr ,
" Testing with stopping replay from record % " ROCKSDB_PRIszt
" \n " ,
apply_option_for_record_index ) ;
apply_option_for_record_index ) ;
// We expect records beyond apply_option_for_record_index to be not
// We expect records beyond apply_option_for_record_index to be not
// found.
// found.
@ -10054,8 +10053,7 @@ TEST_F(DBTest, WalFilterTest) {
for ( size_t j = 0 ; j < batch_keys [ i ] . size ( ) ; j + + ) {
for ( size_t j = 0 ; j < batch_keys [ i ] . size ( ) ; j + + ) {
if ( i > = apply_option_for_record_index ) {
if ( i > = apply_option_for_record_index ) {
keys_must_not_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
keys_must_not_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
}
} else {
else {
keys_must_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
keys_must_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
}
}
}
}
@ -10097,10 +10095,11 @@ TEST_F(DBTest, WalFilterTestWithChangeBatch) {
size_t num_keys_to_add_in_new_batch_ ;
size_t num_keys_to_add_in_new_batch_ ;
// Number of keys added to new batch
// Number of keys added to new batch
size_t num_keys_added_ ;
size_t num_keys_added_ ;
public :
public :
ChangeBatchHandler ( WriteBatch * new_write_batch ,
ChangeBatchHandler ( WriteBatch * new_write_batch ,
size_t num_keys_to_add_in_new_batch ) :
size_t num_keys_to_add_in_new_batch )
new_write_batch_ ( new_write_batch ) ,
: new_write_batch_ ( new_write_batch ) ,
num_keys_to_add_in_new_batch_ ( num_keys_to_add_in_new_batch ) ,
num_keys_to_add_in_new_batch_ ( num_keys_to_add_in_new_batch ) ,
num_keys_added_ ( 0 ) { }
num_keys_added_ ( 0 ) { }
virtual void Put ( const Slice & key , const Slice & value ) override {
virtual void Put ( const Slice & key , const Slice & value ) override {
@ -10119,17 +10118,17 @@ TEST_F(DBTest, WalFilterTestWithChangeBatch) {
size_t num_keys_to_add_in_new_batch_ ;
size_t num_keys_to_add_in_new_batch_ ;
// Current record index, incremented with each record encountered.
// Current record index, incremented with each record encountered.
size_t current_record_index_ ;
size_t current_record_index_ ;
public :
public :
TestWalFilterWithChangeBatch (
TestWalFilterWithChangeBatch ( size_t change_records_from_index ,
size_t change_records_from_index ,
size_t num_keys_to_add_in_new_batch )
size_t num_keys_to_add_in_new_batch ) :
: change_records_from_index_ ( change_records_from_index ) ,
change_records_from_index_ ( change_records_from_index ) ,
num_keys_to_add_in_new_batch_ ( num_keys_to_add_in_new_batch ) ,
num_keys_to_add_in_new_batch_ ( num_keys_to_add_in_new_batch ) ,
current_record_index_ ( 0 ) { }
current_record_index_ ( 0 ) { }
virtual WalProcessingOption LogRecord ( const WriteBatch & batch ,
virtual WalProcessingOption LogRecord ( const WriteBatch & batch ,
WriteBatch * new_batch , bool * batch_changed ) const override {
WriteBatch * new_batch ,
bool * batch_changed ) const override {
if ( current_record_index_ > = change_records_from_index_ ) {
if ( current_record_index_ > = change_records_from_index_ ) {
ChangeBatchHandler handler ( new_batch , num_keys_to_add_in_new_batch_ ) ;
ChangeBatchHandler handler ( new_batch , num_keys_to_add_in_new_batch_ ) ;
batch . Iterate ( & handler ) ;
batch . Iterate ( & handler ) ;
@ -10139,7 +10138,8 @@ TEST_F(DBTest, WalFilterTestWithChangeBatch) {
// Filter is passed as a const object for RocksDB to not modify the
// Filter is passed as a const object for RocksDB to not modify the
// object, however we modify it for our own purpose here and hence
// object, however we modify it for our own purpose here and hence
// cast the constness away.
// cast the constness away.
( const_cast < TestWalFilterWithChangeBatch * > ( this ) - > current_record_index_ ) + + ;
( const_cast < TestWalFilterWithChangeBatch * > ( this )
- > current_record_index_ ) + + ;
return WalProcessingOption : : kContinueProcessing ;
return WalProcessingOption : : kContinueProcessing ;
}
}
@ -10193,8 +10193,7 @@ TEST_F(DBTest, WalFilterTestWithChangeBatch) {
for ( size_t j = 0 ; j < batch_keys [ i ] . size ( ) ; j + + ) {
for ( size_t j = 0 ; j < batch_keys [ i ] . size ( ) ; j + + ) {
if ( i > = change_records_from_index & & j > = num_keys_to_add_in_new_batch ) {
if ( i > = change_records_from_index & & j > = num_keys_to_add_in_new_batch ) {
keys_must_not_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
keys_must_not_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
}
} else {
else {
keys_must_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
keys_must_exist . push_back ( Slice ( batch_keys [ i ] [ j ] ) ) ;
}
}
}
}
@ -10225,7 +10224,8 @@ TEST_F(DBTest, WalFilterTestWithChangeBatchExtraKeys) {
class TestWalFilterWithChangeBatchAddExtraKeys : public WalFilter {
class TestWalFilterWithChangeBatchAddExtraKeys : public WalFilter {
public :
public :
virtual WalProcessingOption LogRecord ( const WriteBatch & batch ,
virtual WalProcessingOption LogRecord ( const WriteBatch & batch ,
WriteBatch * new_batch , bool * batch_changed ) const override {
WriteBatch * new_batch ,
bool * batch_changed ) const override {
* new_batch = batch ;
* new_batch = batch ;
new_batch - > Put ( " key_extra " , " value_extra " ) ;
new_batch - > Put ( " key_extra " , " value_extra " ) ;
* batch_changed = true ;
* batch_changed = true ;
@ -10265,8 +10265,7 @@ TEST_F(DBTest, WalFilterTestWithChangeBatchExtraKeys) {
// Reopen database with option to use WAL filter
// Reopen database with option to use WAL filter
options = OptionsForLogIterTest ( ) ;
options = OptionsForLogIterTest ( ) ;
options . wal_filter = & test_wal_filter_extra_keys ;
options . wal_filter = & test_wal_filter_extra_keys ;
Status status =
Status status = TryReopenWithColumnFamilies ( { " default " , " pikachu " } , options ) ;
TryReopenWithColumnFamilies ( { " default " , " pikachu " } , options ) ;
ASSERT_TRUE ( status . IsNotSupported ( ) ) ;
ASSERT_TRUE ( status . IsNotSupported ( ) ) ;
// Reopen without filter, now reopen should succeed - previous
// Reopen without filter, now reopen should succeed - previous