@ -64,13 +64,13 @@ Status ExternalSstFileIngestionJob::Prepare(
std : : sort (
std : : sort (
sorted_files . begin ( ) , sorted_files . end ( ) ,
sorted_files . begin ( ) , sorted_files . end ( ) ,
[ & ucmp ] ( const IngestedFileInfo * info1 , const IngestedFileInfo * info2 ) {
[ & ucmp ] ( const IngestedFileInfo * info1 , const IngestedFileInfo * info2 ) {
return ucmp - > Compare ( info1 - > smallest_user _key ,
return sstableKeyCompare ( ucmp , info1 - > smallest_internal _key ,
info2 - > smallest_user _key ) < 0 ;
info2 - > smallest_internal _key ) < 0 ;
} ) ;
} ) ;
for ( size_t i = 0 ; i < num_files - 1 ; i + + ) {
for ( size_t i = 0 ; i < num_files - 1 ; i + + ) {
if ( ucmp - > Compare ( sorted_files [ i ] - > largest_user _key ,
if ( sstableKeyCompare ( ucmp , sorted_files [ i ] - > largest_internal _key ,
sorted_files [ i + 1 ] - > smallest_user _key ) > = 0 ) {
sorted_files [ i + 1 ] - > smallest_internal _key ) > = 0 ) {
return Status : : NotSupported ( " Files have overlapping ranges " ) ;
return Status : : NotSupported ( " Files have overlapping ranges " ) ;
}
}
}
}
@ -81,8 +81,8 @@ Status ExternalSstFileIngestionJob::Prepare(
return Status : : InvalidArgument ( " File contain no entries " ) ;
return Status : : InvalidArgument ( " File contain no entries " ) ;
}
}
if ( ! f . smallest_internal_key ( ) . Valid ( ) | |
if ( ! f . smallest_internal_key . Valid ( ) | |
! f . largest_internal_key ( ) . Valid ( ) ) {
! f . largest_internal_key . Valid ( ) ) {
return Status : : Corruption ( " Generated table have corrupted keys " ) ;
return Status : : Corruption ( " Generated table have corrupted keys " ) ;
}
}
}
}
@ -178,8 +178,8 @@ Status ExternalSstFileIngestionJob::NeedsFlush(bool* flush_needed,
SuperVersion * super_version ) {
SuperVersion * super_version ) {
autovector < Range > ranges ;
autovector < Range > ranges ;
for ( const IngestedFileInfo & file_to_ingest : files_to_ingest_ ) {
for ( const IngestedFileInfo & file_to_ingest : files_to_ingest_ ) {
ranges . emplace_back ( file_to_ingest . smallest_user_key ,
ranges . emplace_back ( file_to_ingest . smallest_internal_key . user_key ( ) ,
file_to_ingest . largest_user_key ) ;
file_to_ingest . largest_internal_key . user_key ( ) ) ;
}
}
Status status =
Status status =
cfd_ - > RangesOverlapWithMemtables ( ranges , super_version , flush_needed ) ;
cfd_ - > RangesOverlapWithMemtables ( ranges , super_version , flush_needed ) ;
@ -238,8 +238,8 @@ Status ExternalSstFileIngestionJob::Run() {
return status ;
return status ;
}
}
edit_ . AddFile ( f . picked_level , f . fd . GetNumber ( ) , f . fd . GetPathId ( ) ,
edit_ . AddFile ( f . picked_level , f . fd . GetNumber ( ) , f . fd . GetPathId ( ) ,
f . fd . GetFileSize ( ) , f . smallest_internal_key ( ) ,
f . fd . GetFileSize ( ) , f . smallest_internal_key ,
f . largest_internal_key ( ) , f . assigned_seqno , f . assigned_seqno ,
f . largest_internal_key , f . assigned_seqno , f . assigned_seqno ,
false ) ;
false ) ;
}
}
return status ;
return status ;
@ -414,6 +414,8 @@ Status ExternalSstFileIngestionJob::GetIngestedFileInfo(
table_reader - > NewRangeTombstoneIterator ( ro ) ) ;
table_reader - > NewRangeTombstoneIterator ( ro ) ) ;
// Get first (smallest) and last (largest) key from file.
// Get first (smallest) and last (largest) key from file.
file_to_ingest - > smallest_internal_key = InternalKey ( " " , 0 , ValueType : : kTypeValue ) ;
file_to_ingest - > largest_internal_key = InternalKey ( " " , 0 , ValueType : : kTypeValue ) ;
bool bounds_set = false ;
bool bounds_set = false ;
iter - > SeekToFirst ( ) ;
iter - > SeekToFirst ( ) ;
if ( iter - > Valid ( ) ) {
if ( iter - > Valid ( ) ) {
@ -423,7 +425,7 @@ Status ExternalSstFileIngestionJob::GetIngestedFileInfo(
if ( key . sequence ! = 0 ) {
if ( key . sequence ! = 0 ) {
return Status : : Corruption ( " external file have non zero sequence number " ) ;
return Status : : Corruption ( " external file have non zero sequence number " ) ;
}
}
file_to_ingest - > smallest_user_key = key . user_key . ToString ( ) ;
file_to_ingest - > smallest_internal_key . SetFrom ( key ) ;
iter - > SeekToLast ( ) ;
iter - > SeekToLast ( ) ;
if ( ! ParseInternalKey ( iter - > key ( ) , & key ) ) {
if ( ! ParseInternalKey ( iter - > key ( ) , & key ) ) {
@ -432,7 +434,7 @@ Status ExternalSstFileIngestionJob::GetIngestedFileInfo(
if ( key . sequence ! = 0 ) {
if ( key . sequence ! = 0 ) {
return Status : : Corruption ( " external file have non zero sequence number " ) ;
return Status : : Corruption ( " external file have non zero sequence number " ) ;
}
}
file_to_ingest - > largest_user_key = key . user_key . ToString ( ) ;
file_to_ingest - > largest_internal_key . SetFrom ( key ) ;
bounds_set = true ;
bounds_set = true ;
}
}
@ -448,13 +450,13 @@ Status ExternalSstFileIngestionJob::GetIngestedFileInfo(
}
}
RangeTombstone tombstone ( key , range_del_iter - > value ( ) ) ;
RangeTombstone tombstone ( key , range_del_iter - > value ( ) ) ;
if ( ! bounds_set | | ucmp - > Compare ( tombstone . start_key_ ,
InternalKey start_key = tombstone . SerializeKey ( ) ;
file_to_ingest - > smallest_user _key ) < 0 ) {
if ( ! bounds_set | | sstableKeyCompare ( ucmp , start_key , file_to_ingest - > smallest_internal _key ) < 0 ) {
file_to_ingest - > smallest_user _key = tombstone . start_key_ . ToString ( ) ;
file_to_ingest - > smallest_internal _key = start_key ;
}
}
if ( ! bounds_set | | ucmp - > Compare ( tombstone . end_key_ ,
InternalKey end_key = tombstone . SerializeEndKey ( ) ;
file_to_ingest - > largest_user _key ) > 0 ) {
if ( ! bounds_set | | sstableKeyCompare ( ucmp , end_key , file_to_ingest - > largest_internal _key ) > 0 ) {
file_to_ingest - > largest_user _key = tombstone . end_key_ . ToString ( ) ;
file_to_ingest - > largest_internal _key = end_key ;
}
}
bounds_set = true ;
bounds_set = true ;
}
}
@ -496,7 +498,7 @@ Status ExternalSstFileIngestionJob::AssignLevelAndSeqnoForIngestedFile(
if ( vstorage - > NumLevelFiles ( lvl ) > 0 ) {
if ( vstorage - > NumLevelFiles ( lvl ) > 0 ) {
bool overlap_with_level = false ;
bool overlap_with_level = false ;
status = sv - > current - > OverlapWithLevelIterator ( ro , env_options_ ,
status = sv - > current - > OverlapWithLevelIterator ( ro , env_options_ ,
file_to_ingest - > smallest_user_key , file_to_ingest - > largest_user_key ,
file_to_ingest - > smallest_internal_key . user_key ( ) , file_to_ingest - > largest_internal_key . user_key ( ) ,
lvl , & overlap_with_level ) ;
lvl , & overlap_with_level ) ;
if ( ! status . ok ( ) ) {
if ( ! status . ok ( ) ) {
return status ;
return status ;
@ -630,8 +632,8 @@ bool ExternalSstFileIngestionJob::IngestedFileFitInLevel(
}
}
auto * vstorage = cfd_ - > current ( ) - > storage_info ( ) ;
auto * vstorage = cfd_ - > current ( ) - > storage_info ( ) ;
Slice file_smallest_user_key ( file_to_ingest - > smallest_user_key ) ;
Slice file_smallest_user_key ( file_to_ingest - > smallest_internal_key . user_key ( ) ) ;
Slice file_largest_user_key ( file_to_ingest - > largest_user_key ) ;
Slice file_largest_user_key ( file_to_ingest - > largest_internal_key . user_key ( ) ) ;
if ( vstorage - > OverlapInLevel ( level , & file_smallest_user_key ,
if ( vstorage - > OverlapInLevel ( level , & file_smallest_user_key ,
& file_largest_user_key ) ) {
& file_largest_user_key ) ) {