@ -14,7 +14,8 @@
namespace rocksdb {
# ifndef ROCKSDB_LITE
class ExternalSSTFileBasicTest : public DBTestBase {
class ExternalSSTFileBasicTest : public DBTestBase ,
public : : testing : : WithParamInterface < bool > {
public :
ExternalSSTFileBasicTest ( ) : DBTestBase ( " /external_sst_file_test " ) {
sst_files_dir_ = dbname_ + " /sst_files/ " ;
@ -41,7 +42,7 @@ class ExternalSSTFileBasicTest : public DBTestBase {
const Options options , std : : vector < int > keys ,
const std : : vector < ValueType > & value_types ,
std : : vector < std : : pair < int , int > > range_deletions , int file_id ,
std : : map < std : : string , std : : string > * true_data ) {
bool write_global_seqno , std : : map < std : : string , std : : string > * true_data ) {
assert ( value_types . size ( ) = = 1 | | keys . size ( ) = = value_types . size ( ) ) ;
std : : string file_path = sst_files_dir_ + ToString ( file_id ) ;
SstFileWriter sst_file_writer ( EnvOptions ( ) , options ) ;
@ -105,6 +106,7 @@ class ExternalSSTFileBasicTest : public DBTestBase {
if ( s . ok ( ) ) {
IngestExternalFileOptions ifo ;
ifo . allow_global_seqno = true ;
ifo . write_global_seqno = write_global_seqno ;
s = db_ - > IngestExternalFile ( { file_path } , ifo ) ;
}
return s ;
@ -113,17 +115,18 @@ class ExternalSSTFileBasicTest : public DBTestBase {
Status GenerateAndAddExternalFile (
const Options options , std : : vector < int > keys ,
const std : : vector < ValueType > & value_types , int file_id ,
std : : map < std : : string , std : : string > * true_data ) {
bool write_global_seqno , std : : map < std : : string , std : : string > * true_data ) {
return GenerateAndAddExternalFile ( options , keys , value_types , { } , file_id ,
true_data ) ;
write_global_seqno , true_data ) ;
}
Status GenerateAndAddExternalFile (
const Options options , std : : vector < int > keys , const ValueType value_type ,
int file_id , std : : map < std : : string , std : : string > * true_data ) {
int file_id , bool write_global_seqno ,
std : : map < std : : string , std : : string > * true_data ) {
return GenerateAndAddExternalFile ( options , keys ,
std : : vector < ValueType > ( 1 , value_type ) ,
file_id , true_data ) ;
file_id , write_global_seqno , true_data ) ;
}
~ ExternalSSTFileBasicTest ( ) { test : : DestroyDir ( env_ , sst_files_dir_ ) ; }
@ -245,7 +248,8 @@ TEST_F(ExternalSSTFileBasicTest, NoCopy) {
}
}
TEST_F ( ExternalSSTFileBasicTest , IngestFileWithGlobalSeqnoPickedSeqno ) {
TEST_P ( ExternalSSTFileBasicTest , IngestFileWithGlobalSeqnoPickedSeqno ) {
bool write_global_seqno = GetParam ( ) ;
do {
Options options = CurrentOptions ( ) ;
DestroyAndReopen ( options ) ;
@ -255,33 +259,37 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithGlobalSeqnoPickedSeqno) {
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 2 , 3 , 4 , 5 , 6 } ,
ValueType : : kTypeValue , file_id + + ,
& true_data ) ) ;
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 10 , 11 , 12 , 13 } ,
ValueType : : kTypeValue , file_id + + ,
& true_data ) ) ;
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 1 , 4 , 6 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 4 , 6 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 1 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 11 , 15 , 19 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 11 , 15 , 19 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 120 , 130 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 120 , 130 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 1 , 130 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 130 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 3 ) ;
@ -292,18 +300,21 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithGlobalSeqnoPickedSeqno) {
}
SequenceNumber last_seqno = dbfull ( ) - > GetLatestSequenceNumber ( ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 60 , 61 , 62 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 60 , 61 , 62 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 40 , 41 , 42 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 40 , 41 , 42 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 1 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 20 , 30 , 40 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 20 , 30 , 40 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 2 ) ;
@ -311,35 +322,39 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithGlobalSeqnoPickedSeqno) {
// 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 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1000 , 1002 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & 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 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 2000 , 3002 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & 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 } ,
ValueType : : kTypeValue , file_id + + ,
& true_data ) ) ;
write_global_seqno , & 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 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 5000 , 5001 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & 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 ( ) ) ;
} while ( ChangeOptionsForFileIngestionTest ( ) ) ;
}
TEST_F ( ExternalSSTFileBasicTest , IngestFileWithMultipleValueType ) {
TEST_P ( ExternalSSTFileBasicTest , IngestFileWithMultipleValueType ) {
bool write_global_seqno = GetParam ( ) ;
do {
Options options = CurrentOptions ( ) ;
options . merge_operator . reset ( new TestPutOperator ( ) ) ;
@ -350,52 +365,57 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMultipleValueType) {
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 2 , 3 , 4 , 5 , 6 } ,
ValueType : : kTypeValue , file_id + + ,
& true_data ) ) ;
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 10 , 11 , 12 , 13 } ,
ValueType : : kTypeValue , file_id + + ,
& true_data ) ) ;
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 1 , 4 , 6 } , ValueType : : kTypeMerge , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 4 , 6 } ,
ValueType : : kTypeMerge , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 1 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 11 , 15 , 19 } ,
ValueType : : kTypeDeletion , file_id + + ,
& true_data ) ) ;
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 120 , 130 } , ValueType : : kTypeMerge , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 120 , 130 } ,
ValueType : : kTypeMerge , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 1 , 130 } , ValueType : : kTypeDeletion , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1 , 130 } ,
ValueType : : kTypeDeletion , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 3 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 120 } ,
{ ValueType : : kTypeValue } , { { 120 , 135 } } ,
file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 120 } , { ValueType : : kTypeValue } , { { 120 , 135 } } , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 4 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { } , { } , { { 110 , 120 } } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno ,
& true_data ) ) ;
// The range deletion ends on a key, but it doesn't actually delete
// this key because the largest key in the range is exclusive. Still,
// it counts as an overlap so a new seqno will be assigned.
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 5 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { } , { } , { { 100 , 109 } } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno ,
& true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 5 ) ;
@ -406,19 +426,21 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMultipleValueType) {
}
SequenceNumber last_seqno = dbfull ( ) - > GetLatestSequenceNumber ( ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 60 , 61 , 62 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 60 , 61 , 62 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 40 , 41 , 42 } , ValueType : : kTypeMerge , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 40 , 41 , 42 } ,
ValueType : : kTypeMerge , file_id + + ,
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 1 ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 20 , 30 , 40 } ,
ValueType : : kTypeDeletion , file_id + + ,
& true_data ) ) ;
write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 2 ) ;
@ -426,35 +448,39 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMultipleValueType) {
// 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 } , ValueType : : kTypeMerge , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 1000 , 1002 } ,
ValueType : : kTypeMerge , file_id + + ,
write_global_seqno , & 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 } , ValueType : : kTypeMerge , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 2000 , 3002 } ,
ValueType : : kTypeMerge , file_id + + ,
write_global_seqno , & 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 } ,
ValueType : : kTypeMerge , file_id + + ,
& true_data ) ) ;
write_global_seqno , & 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 } , ValueType : : kTypeValue , file_id + + , & true_data ) ) ;
ASSERT_OK ( GenerateAndAddExternalFile ( options , { 5000 , 5001 } ,
ValueType : : kTypeValue , file_id + + ,
write_global_seqno , & 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 ( ) ) ;
} while ( ChangeOptionsForFileIngestionTest ( ) ) ;
}
TEST_F ( ExternalSSTFileBasicTest , IngestFileWithMixedValueType ) {
TEST_P ( ExternalSSTFileBasicTest , IngestFileWithMixedValueType ) {
bool write_global_seqno = GetParam ( ) ;
do {
Options options = CurrentOptions ( ) ;
options . merge_operator . reset ( new TestPutOperator ( ) ) ;
@ -467,7 +493,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
options , { 1 , 2 , 3 , 4 , 5 , 6 } ,
{ ValueType : : kTypeValue , ValueType : : kTypeMerge , ValueType : : kTypeValue ,
ValueType : : kTypeMerge , ValueType : : kTypeValue , ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
@ -475,33 +501,35 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
options , { 10 , 11 , 12 , 13 } ,
{ ValueType : : kTypeValue , ValueType : : kTypeMerge , ValueType : : kTypeValue ,
ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 0 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 1 , 4 , 6 } , { ValueType : : kTypeDeletion , ValueType : : kTypeValue ,
ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
options , { 1 , 4 , 6 } ,
{ ValueType : : kTypeDeletion , ValueType : : kTypeValue ,
ValueType : : kTypeMerge } ,
file_id + + , write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 1 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 11 , 15 , 19 } , { ValueType : : kTypeDeletion , ValueType : : kTypeMerge ,
ValueType : : kTypeValue } ,
file_id + + , & true_data ) ) ;
options , { 11 , 15 , 19 } ,
{ ValueType : : kTypeDeletion , ValueType : : kTypeMerge ,
ValueType : : kTypeValue } ,
file_id + + , write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 120 , 130 } , { ValueType : : kTypeValue , ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 2 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 1 , 130 } , { ValueType : : kTypeMerge , ValueType : : kTypeDeletion } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 3 ) ;
@ -509,14 +537,14 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
options , { 150 , 151 , 152 } ,
{ ValueType : : kTypeValue , ValueType : : kTypeMerge ,
ValueType : : kTypeDeletion } ,
{ { 150 , 160 } , { 180 , 190 } } , file_id + + , & true_data ) ) ;
{ { 150 , 160 } , { 180 , 190 } } , file_id + + , write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 3 ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 150 , 151 , 152 } ,
{ ValueType : : kTypeValue , ValueType : : kTypeMerge , ValueType : : kTypeValue } ,
{ { 200 , 250 } } , file_id + + , & true_data ) ) ;
{ { 200 , 250 } } , file_id + + , write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 4 ) ;
@ -524,7 +552,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
options , { 300 , 301 , 302 } ,
{ ValueType : : kTypeValue , ValueType : : kTypeMerge ,
ValueType : : kTypeDeletion } ,
{ { 1 , 2 } , { 152 , 154 } } , file_id + + , & true_data ) ) ;
{ { 1 , 2 } , { 152 , 154 } } , file_id + + , write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , 5 ) ;
@ -538,7 +566,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 60 , 61 , 62 } ,
{ ValueType : : kTypeValue , ValueType : : kTypeMerge , ValueType : : kTypeValue } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// File doesn't overwrite any keys, no seqno needed
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno ) ;
@ -546,7 +574,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
options , { 40 , 41 , 42 } ,
{ ValueType : : kTypeValue , ValueType : : kTypeDeletion ,
ValueType : : kTypeDeletion } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 1 ) ;
@ -554,7 +582,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
options , { 20 , 30 , 40 } ,
{ ValueType : : kTypeDeletion , ValueType : : kTypeDeletion ,
ValueType : : kTypeDeletion } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// File overwrites some keys, a seqno will be assigned
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 2 ) ;
@ -564,13 +592,13 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
// keys in the DB or not because we have a snapshot
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 1000 , 1002 } , { ValueType : : kTypeValue , ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & 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 } , { ValueType : : kTypeValue , ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 4 ) ;
@ -578,7 +606,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
options , { 1 , 20 , 40 , 100 , 150 } ,
{ ValueType : : kTypeDeletion , ValueType : : kTypeDeletion ,
ValueType : : kTypeValue , ValueType : : kTypeMerge , ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
// A global seqno will be assigned anyway because of the snapshot
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno + 5 ) ;
@ -586,13 +614,13 @@ TEST_F(ExternalSSTFileBasicTest, IngestFileWithMixedValueType) {
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 5000 , 5001 } , { ValueType : : kTypeValue , ValueType : : kTypeMerge } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & 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 ( ) ) ;
} while ( ChangeOptionsForFileIngestionTest ( ) ) ;
}
TEST_F ( ExternalSSTFileBasicTest , FadviseTrigger ) {
@ -635,7 +663,7 @@ TEST_F(ExternalSSTFileBasicTest, FadviseTrigger) {
rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ;
}
TEST_F ( ExternalSSTFileBasicTest , IngestionWithRangeDeletions ) {
TEST_P ( ExternalSSTFileBasicTest , IngestionWithRangeDeletions ) {
int kNumLevels = 7 ;
Options options = CurrentOptions ( ) ;
options . disable_auto_compactions = true ;
@ -662,12 +690,13 @@ TEST_F(ExternalSSTFileBasicTest, IngestionWithRangeDeletions) {
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( kNumLevels - 2 ) ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( kNumLevels - 1 ) ) ;
bool write_global_seqno = GetParam ( ) ;
// overlaps with L0 file but not memtable, so flush is skipped and file is
// ingested into L0
SequenceNumber last_seqno = dbfull ( ) - > GetLatestSequenceNumber ( ) ;
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 60 , 90 } , { ValueType : : kTypeValue , ValueType : : kTypeValue } ,
{ { 65 , 70 } , { 70 , 85 } } , file_id + + , & true_data ) ) ;
{ { 65 , 70 } , { 70 , 85 } } , file_id + + , write_global_seqno , & true_data ) ) ;
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , + + last_seqno ) ;
ASSERT_EQ ( 2 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 0 , NumTableFilesAtLevel ( kNumLevels - 2 ) ) ;
@ -677,7 +706,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestionWithRangeDeletions) {
// file is ingested into L5
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 10 , 40 } , { ValueType : : kTypeValue , ValueType : : kTypeValue } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , + + last_seqno ) ;
ASSERT_EQ ( 2 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( kNumLevels - 2 ) ) ;
@ -686,7 +715,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestionWithRangeDeletions) {
// overlaps with L5 file but not memtable or L0 file, so flush is skipped and
// file is ingested into L4
ASSERT_OK ( GenerateAndAddExternalFile ( options , { } , { } , { { 5 , 15 } } , file_id + + ,
& true_data ) ) ;
write_global_seqno , & true_data ) ) ;
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , + + last_seqno ) ;
ASSERT_EQ ( 2 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( kNumLevels - 2 ) ) ;
@ -698,7 +727,7 @@ TEST_F(ExternalSSTFileBasicTest, IngestionWithRangeDeletions) {
// count increases by two.
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 100 , 140 } , { ValueType : : kTypeValue , ValueType : : kTypeValue } ,
file_id + + , & true_data ) ) ;
file_id + + , write_global_seqno , & true_data ) ) ;
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , + + last_seqno ) ;
ASSERT_EQ ( 4 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( kNumLevels - 2 ) ) ;
@ -711,13 +740,16 @@ TEST_F(ExternalSSTFileBasicTest, IngestionWithRangeDeletions) {
// seqnum.
ASSERT_OK ( GenerateAndAddExternalFile (
options , { 151 , 175 } , { ValueType : : kTypeValue , ValueType : : kTypeValue } ,
{ { 160 , 200 } } , file_id + + , & true_data ) ) ;
{ { 160 , 200 } } , file_id + + , write_global_seqno , & true_data ) ) ;
ASSERT_EQ ( dbfull ( ) - > GetLatestSequenceNumber ( ) , last_seqno ) ;
ASSERT_EQ ( 4 , NumTableFilesAtLevel ( 0 ) ) ;
ASSERT_EQ ( 1 , NumTableFilesAtLevel ( kNumLevels - 2 ) ) ;
ASSERT_EQ ( 2 , NumTableFilesAtLevel ( options . num_levels - 1 ) ) ;
}
INSTANTIATE_TEST_CASE_P ( ExternalSSTFileBasicTest , ExternalSSTFileBasicTest ,
testing : : Bool ( ) ) ;
# endif // ROCKSDB_LITE
} // namespace rocksdb