@ -287,6 +287,75 @@ TEST(DeleteFileTest, DeleteLogFiles) {
CloseDB ( ) ;
}
TEST ( DeleteFileTest , DeleteNonDefaultColumnFamily ) {
CloseDB ( ) ;
DBOptions db_options ;
db_options . create_if_missing = true ;
db_options . create_missing_column_families = true ;
std : : vector < ColumnFamilyDescriptor > column_families ;
column_families . emplace_back ( ) ;
column_families . emplace_back ( " new_cf " , ColumnFamilyOptions ( ) ) ;
std : : vector < rocksdb : : ColumnFamilyHandle * > handles ;
rocksdb : : DB * db ;
ASSERT_OK ( DB : : Open ( db_options , dbname_ , column_families , & handles , & db ) ) ;
Random rnd ( 5 ) ;
for ( int i = 0 ; i < 1000 ; + + i ) {
ASSERT_OK ( db - > Put ( WriteOptions ( ) , handles [ 1 ] , test : : RandomKey ( & rnd , 10 ) ,
test : : RandomKey ( & rnd , 10 ) ) ) ;
}
ASSERT_OK ( db - > Flush ( FlushOptions ( ) , handles [ 1 ] ) ) ;
for ( int i = 0 ; i < 1000 ; + + i ) {
ASSERT_OK ( db - > Put ( WriteOptions ( ) , handles [ 1 ] , test : : RandomKey ( & rnd , 10 ) ,
test : : RandomKey ( & rnd , 10 ) ) ) ;
}
ASSERT_OK ( db - > Flush ( FlushOptions ( ) , handles [ 1 ] ) ) ;
std : : vector < LiveFileMetaData > metadata ;
db - > GetLiveFilesMetaData ( & metadata ) ;
ASSERT_EQ ( 2U , metadata . size ( ) ) ;
ASSERT_EQ ( " new_cf " , metadata [ 0 ] . column_family_name ) ;
ASSERT_EQ ( " new_cf " , metadata [ 1 ] . column_family_name ) ;
auto old_file = metadata [ 0 ] . smallest_seqno < metadata [ 1 ] . smallest_seqno
? metadata [ 0 ] . name
: metadata [ 1 ] . name ;
auto new_file = metadata [ 0 ] . smallest_seqno > metadata [ 1 ] . smallest_seqno
? metadata [ 0 ] . name
: metadata [ 1 ] . name ;
ASSERT_TRUE ( db - > DeleteFile ( new_file ) . IsInvalidArgument ( ) ) ;
ASSERT_OK ( db - > DeleteFile ( old_file ) ) ;
{
std : : unique_ptr < Iterator > itr ( db - > NewIterator ( ReadOptions ( ) , handles [ 1 ] ) ) ;
int count = 0 ;
for ( itr - > SeekToFirst ( ) ; itr - > Valid ( ) ; itr - > Next ( ) ) {
ASSERT_OK ( itr - > status ( ) ) ;
+ + count ;
}
ASSERT_EQ ( count , 1000 ) ;
}
delete handles [ 0 ] ;
delete handles [ 1 ] ;
delete db ;
ASSERT_OK ( DB : : Open ( db_options , dbname_ , column_families , & handles , & db ) ) ;
{
std : : unique_ptr < Iterator > itr ( db - > NewIterator ( ReadOptions ( ) , handles [ 1 ] ) ) ;
int count = 0 ;
for ( itr - > SeekToFirst ( ) ; itr - > Valid ( ) ; itr - > Next ( ) ) {
ASSERT_OK ( itr - > status ( ) ) ;
+ + count ;
}
ASSERT_EQ ( count , 1000 ) ;
}
delete handles [ 0 ] ;
delete handles [ 1 ] ;
delete db ;
}
} //namespace rocksdb
int main ( int argc , char * * argv ) {