@ -180,9 +180,17 @@ struct CompactionJob::SubcompactionState {
uint64_t overlapped_bytes = 0 ;
uint64_t overlapped_bytes = 0 ;
// A flag determine whether the key has been seen in ShouldStopBefore()
// A flag determine whether the key has been seen in ShouldStopBefore()
bool seen_key = false ;
bool seen_key = false ;
// sub compaction job id, which is used to identify different sub-compaction
SubcompactionState ( Compaction * c , Slice * _start , Slice * _end , uint64_t size )
// within the same compaction job.
: compaction ( c ) , start ( _start ) , end ( _end ) , approx_size ( size ) {
const uint32_t sub_job_id ;
SubcompactionState ( Compaction * c , Slice * _start , Slice * _end , uint64_t size ,
uint32_t _sub_job_id )
: compaction ( c ) ,
start ( _start ) ,
end ( _end ) ,
approx_size ( size ) ,
sub_job_id ( _sub_job_id ) {
assert ( compaction ! = nullptr ) ;
assert ( compaction ! = nullptr ) ;
}
}
@ -449,7 +457,8 @@ void CompactionJob::Prepare() {
for ( size_t i = 0 ; i < = boundaries_ . size ( ) ; i + + ) {
for ( size_t i = 0 ; i < = boundaries_ . size ( ) ; i + + ) {
Slice * start = i = = 0 ? nullptr : & boundaries_ [ i - 1 ] ;
Slice * start = i = = 0 ? nullptr : & boundaries_ [ i - 1 ] ;
Slice * end = i = = boundaries_ . size ( ) ? nullptr : & boundaries_ [ i ] ;
Slice * end = i = = boundaries_ . size ( ) ? nullptr : & boundaries_ [ i ] ;
compact_ - > sub_compact_states . emplace_back ( c , start , end , sizes_ [ i ] ) ;
compact_ - > sub_compact_states . emplace_back ( c , start , end , sizes_ [ i ] ,
static_cast < uint32_t > ( i ) ) ;
}
}
RecordInHistogram ( stats_ , NUM_SUBCOMPACTIONS_SCHEDULED ,
RecordInHistogram ( stats_ , NUM_SUBCOMPACTIONS_SCHEDULED ,
compact_ - > sub_compact_states . size ( ) ) ;
compact_ - > sub_compact_states . size ( ) ) ;
@ -458,7 +467,8 @@ void CompactionJob::Prepare() {
constexpr Slice * end = nullptr ;
constexpr Slice * end = nullptr ;
constexpr uint64_t size = 0 ;
constexpr uint64_t size = 0 ;
compact_ - > sub_compact_states . emplace_back ( c , start , end , size ) ;
compact_ - > sub_compact_states . emplace_back ( c , start , end , size ,
/*sub_job_id*/ 0 ) ;
}
}
}
}
@ -973,7 +983,8 @@ void CompactionJob::ProcessKeyValueCompactionWithCompactionService(
compaction_input . column_family . name . c_str ( ) , job_id_ ,
compaction_input . column_family . name . c_str ( ) , job_id_ ,
compaction_input . output_level , input_files_oss . str ( ) . c_str ( ) ) ;
compaction_input . output_level , input_files_oss . str ( ) . c_str ( ) ) ;
CompactionServiceJobStatus compaction_status =
CompactionServiceJobStatus compaction_status =
db_options_ . compaction_service - > Start ( compaction_input_binary , job_id_ ) ;
db_options_ . compaction_service - > Start ( compaction_input_binary ,
GetCompactionId ( sub_compact ) ) ;
if ( compaction_status ! = CompactionServiceJobStatus : : kSuccess ) {
if ( compaction_status ! = CompactionServiceJobStatus : : kSuccess ) {
sub_compact - > status =
sub_compact - > status =
Status : : Incomplete ( " CompactionService failed to start compaction job. " ) ;
Status : : Incomplete ( " CompactionService failed to start compaction job. " ) ;
@ -982,7 +993,7 @@ void CompactionJob::ProcessKeyValueCompactionWithCompactionService(
std : : string compaction_result_binary ;
std : : string compaction_result_binary ;
compaction_status = db_options_ . compaction_service - > WaitForComplete (
compaction_status = db_options_ . compaction_service - > WaitForComplete (
job_id_ , & compaction_result_binary ) ;
GetCompactionId ( sub_compact ) , & compaction_result_binary ) ;
CompactionServiceResult compaction_result ;
CompactionServiceResult compaction_result ;
s = CompactionServiceResult : : Read ( compaction_result_binary ,
s = CompactionServiceResult : : Read ( compaction_result_binary ,
@ -1446,6 +1457,10 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) {
sub_compact - > status = status ;
sub_compact - > status = status ;
}
}
uint64_t CompactionJob : : GetCompactionId ( SubcompactionState * sub_compact ) {
return ( uint64_t ) job_id_ < < 32 | sub_compact - > sub_job_id ;
}
void CompactionJob : : RecordDroppedKeys (
void CompactionJob : : RecordDroppedKeys (
const CompactionIterationStats & c_iter_stats ,
const CompactionIterationStats & c_iter_stats ,
CompactionJobStats * compaction_job_stats ) {
CompactionJobStats * compaction_job_stats ) {
@ -2217,8 +2232,8 @@ Status CompactionServiceCompactionJob::Run() {
Slice end = compaction_input_ . end ;
Slice end = compaction_input_ . end ;
compact_ - > sub_compact_states . emplace_back (
compact_ - > sub_compact_states . emplace_back (
c , compaction_input_ . has_begin ? & begin : nullptr ,
c , compaction_input_ . has_begin ? & begin : nullptr ,
compaction_input_ . has_end ? & end : nullptr ,
compaction_input_ . has_end ? & end : nullptr , compaction_input_ . approx_size ,
compaction_input_ . approx_size ) ;
/*sub_job_id*/ 0 ) ;
log_buffer_ - > FlushBufferToLog ( ) ;
log_buffer_ - > FlushBufferToLog ( ) ;
LogCompaction ( ) ;
LogCompaction ( ) ;