@ -1936,10 +1936,14 @@ Compaction* VersionSet::PickCompaction() {
// Find compactions needed by seeks
// Find compactions needed by seeks
if ( c = = NULL & & ( current_ - > file_to_compact_ ! = NULL ) ) {
if ( c = = NULL & & ( current_ - > file_to_compact_ ! = NULL ) ) {
level = current_ - > file_to_compact_level_ ;
level = current_ - > file_to_compact_level_ ;
// Only allow one level 0 compaction at a time.
if ( level ! = 0 | | compactions_in_progress_ [ 0 ] . empty ( ) ) {
c = new Compaction ( level , MaxFileSizeForLevel ( level ) ,
c = new Compaction ( level , MaxFileSizeForLevel ( level ) ,
MaxGrandParentOverlapBytes ( level ) , NumberLevels ( ) , true ) ;
MaxGrandParentOverlapBytes ( level ) , NumberLevels ( ) , true ) ;
c - > inputs_ [ 0 ] . push_back ( current_ - > file_to_compact_ ) ;
c - > inputs_ [ 0 ] . push_back ( current_ - > file_to_compact_ ) ;
}
}
}
if ( c = = NULL ) {
if ( c = = NULL ) {
return NULL ;
return NULL ;
@ -1949,26 +1953,22 @@ Compaction* VersionSet::PickCompaction() {
c - > input_version_ - > Ref ( ) ;
c - > input_version_ - > Ref ( ) ;
// Files in level 0 may overlap each other, so pick up all overlapping ones
// Files in level 0 may overlap each other, so pick up all overlapping ones
// Two level 0 compaction won't run at the same time, so don't need to worry
// about files on level 0 being compacted.
if ( level = = 0 ) {
if ( level = = 0 ) {
assert ( compactions_in_progress_ [ 0 ] . empty ( ) ) ;
InternalKey smallest , largest ;
InternalKey smallest , largest ;
GetRange ( c - > inputs_ [ 0 ] , & smallest , & largest ) ;
GetRange ( c - > inputs_ [ 0 ] , & smallest , & largest ) ;
// Note that the next call will discard the file we placed in
// Note that the next call will discard the file we placed in
// c->inputs_[0] earlier and replace it with an overlapping set
// c->inputs_[0] earlier and replace it with an overlapping set
// which will include the picked file.
// which will include the picked file.
c - > inputs_ [ 0 ] . clear ( ) ;
c - > inputs_ [ 0 ] . clear ( ) ;
std : : vector < FileMetaData * > more ;
current_ - > GetOverlappingInputs ( 0 , & smallest , & largest , & c - > inputs_ [ 0 ] ) ;
current_ - > GetOverlappingInputs ( 0 , & smallest , & largest , & more ) ;
if ( ParentRangeInCompaction ( & smallest , & largest ,
if ( ParentRangeInCompaction ( & smallest , & largest ,
level , & c - > parent_index_ ) ) {
level , & c - > parent_index_ ) ) {
delete c ;
delete c ;
return NULL ;
return NULL ;
}
}
for ( unsigned int i = 0 ; i < more . size ( ) ; i + + ) {
FileMetaData * f = more [ i ] ;
if ( ! f - > being_compacted ) {
c - > inputs_ [ 0 ] . push_back ( f ) ;
}
}
assert ( ! c - > inputs_ [ 0 ] . empty ( ) ) ;
assert ( ! c - > inputs_ [ 0 ] . empty ( ) ) ;
}
}