@ -182,92 +182,94 @@ TEST_F(ExternalSSTFileBasicTest, NoCopy) {
}
TEST_F ( ExternalSSTFileBasicTest , IngestFileWithGlobalSeqnoPickedSeqno ) {
Options options = CurrentOptions ( ) ;
DestroyAndReopen ( options ) ;
std : : map < std : : string , std : : string > true_data ;
int file_id = 1 ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 2 , 3 , 4 , 5 , 6 } , file_id + + ,
& true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 10 , 11 , 12 , 13 } , file_id + + ,
& true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 1 , 4 , 6 } , file_id + + , & true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 1 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 11 , 15 , 19 } , file_id + + , & true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 120 , 130 } , file_id + + , & true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 1 , 130 } , file_id + + , & true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 3 ) ;
// Write some keys through normal write path
for ( int i = 0 ; i < 50 ; i + + ) {
ASSERT_OK ( Put ( Key ( i ) , " memtable " ) ) ;
true_data [ Key ( i ) ] = " memtable " ;
}
SequenceNumber last_seqno = dbfull ( ) - > GetLatestSequenceNumber ( ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 60 , 61 , 62 } , file_id + + , & true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 40 , 41 , 42 } , file_id + + , & true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 1 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 20 , 30 , 40 } , file_id + + , & true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 2 ) ;
const Snapshot * snapshot = db_ - > GetSnapshot ( ) ;
// We will need a seqno for the file regardless if the file overwrite
// keys in the DB or not because we have a snapshot
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 1000 , 1002 } , file_id + + , & true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 3 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 2000 , 3002 } , file_id + + , & true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 4 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 20 , 40 , 100 , 150 } ,
file_id + + , & true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 5 ) ;
db_ - > ReleaseSnapshot ( snapshot ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 5000 , 5001 } , file_id + + , & true_data ) ) ;
// No snapshot anymore, no need to assign a seqno
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 5 ) ;
size_t kcnt = 0 ;
VerifyDBFromMap ( true_data , & kcnt , false ) ;
do {
Options options = CurrentOptions ( ) ;
DestroyAndReopen ( options ) ;
std : : map < std : : string , std : : string > true_data ;
int file_id = 1 ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 2 , 3 , 4 , 5 , 6 } , file_id + + ,
& true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 10 , 11 , 12 , 13 } , file_id + + ,
& true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 1 , 4 , 6 } , file_id + + , & true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 1 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 11 , 15 , 19 } , file_id + + ,
& true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 120 , 130 } , file_id + + , & true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK (
GenerateAndAddExternalFile ( options , { 1 , 130 } , file_id + + , & true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 3 ) ;
// Write some keys through normal write path
for ( int i = 0 ; i < 50 ; i + + ) {
ASSERT_OK ( Put ( Key ( i ) , " memtable " ) ) ;
true_data [ Key ( i ) ] = " memtable " ;
}
SequenceNumber last_seqno = dbfull ( ) - > GetLatestSequenceNumber ( ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 60 , 61 , 62 } , file_id + + ,
& true_data ) ) ;
// File dont overwrite any keys, No seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 40 , 41 , 42 } , file_id + + ,
& true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 1 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 20 , 30 , 40 } , file_id + + ,
& true_data ) ) ;
// File overwrite some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 2 ) ;
const Snapshot * snapshot = db_ - > GetSnapshot ( ) ;
// We will need a seqno for the file regardless if the file overwrite
// keys in the DB or not because we have a snapshot
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1000 , 1002 } , file_id + + ,
& true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 3 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 2000 , 3002 } , file_id + + ,
& true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 4 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 20 , 40 , 100 , 150 } ,
file_id + + , & true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 5 ) ;
db_ - > ReleaseSnapshot ( snapshot ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 5000 , 5001 } , file_id + + ,
& true_data ) ) ;
// No snapshot anymore, no need to assign a seqno
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 5 ) ;
size_t kcnt = 0 ;
VerifyDBFromMap ( true_data , & kcnt , false ) ;
} while ( ChangeCompactOptions ( ) ) ;
}
TEST_F ( ExternalSSTFileBasicTest , FadviseTrigger ) {