@ -158,13 +158,13 @@ void CompactionIterator::Next() {
if ( merge_out_iter_ . Valid ( ) ) {
if ( merge_out_iter_ . Valid ( ) ) {
key_ = merge_out_iter_ . key ( ) ;
key_ = merge_out_iter_ . key ( ) ;
value_ = merge_out_iter_ . value ( ) ;
value_ = merge_out_iter_ . value ( ) ;
Status s = ParseInternalKey ( key_ , & ikey_ ) ;
Status s = ParseInternalKey ( key_ , & ikey_ , allow_data_in_errors_ ) ;
// MergeUntil stops when it encounters a corrupt key and does not
// MergeUntil stops when it encounters a corrupt key and does not
// include them in the result, so we expect the keys here to be valid.
// include them in the result, so we expect the keys here to be valid.
assert ( s . ok ( ) ) ;
assert ( s . ok ( ) ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
ROCKS_LOG_FATAL ( info_log_ , " Invalid key (%s) in compaction " ,
ROCKS_LOG_FATAL ( info_log_ , " Invalid key in compaction. %s " ,
key_ . ToString ( true ) . c_str ( ) ) ;
s . getState ( ) ) ;
}
}
// Keep current_key_ in sync.
// Keep current_key_ in sync.
@ -277,22 +277,14 @@ void CompactionIterator::NextFromInput() {
value_ = input_ - > value ( ) ;
value_ = input_ - > value ( ) ;
iter_stats_ . num_input_records + + ;
iter_stats_ . num_input_records + + ;
Status pikS tatus = ParseInternalKey ( key_ , & ikey_ ) ;
Status pik_s tatus = ParseInternalKey ( key_ , & ikey_ , allow_data_in_errors _ ) ;
if ( ! pikS tatus . ok ( ) ) {
if ( ! pik_s tatus . ok ( ) ) {
iter_stats_ . num_input_corrupt_records + + ;
iter_stats_ . num_input_corrupt_records + + ;
// If `expect_valid_internal_key_` is false, return the corrupted key
// If `expect_valid_internal_key_` is false, return the corrupted key
// and let the caller decide what to do with it.
// and let the caller decide what to do with it.
// TODO(noetzli): We should have a more elegant solution for this.
if ( expect_valid_internal_key_ ) {
if ( expect_valid_internal_key_ ) {
std : : string msg ( " Corrupted internal key not expected. " ) ;
status_ = pik_status ;
if ( allow_data_in_errors_ ) {
msg . append ( " Corrupt key: " + ikey_ . user_key . ToString ( /*hex=*/ true ) +
" . " ) ;
msg . append ( " key type: " + std : : to_string ( ikey_ . type ) + " . " ) ;
msg . append ( " seq: " + std : : to_string ( ikey_ . sequence ) + " . " ) ;
}
status_ = Status : : Corruption ( msg . c_str ( ) ) ;
return ;
return ;
}
}
key_ = current_key_ . SetInternalKey ( key_ ) ;
key_ = current_key_ . SetInternalKey ( key_ ) ;
@ -469,7 +461,8 @@ void CompactionIterator::NextFromInput() {
// Check whether the next key exists, is not corrupt, and is the same key
// Check whether the next key exists, is not corrupt, and is the same key
// as the single delete.
// as the single delete.
if ( input_ - > Valid ( ) & &
if ( input_ - > Valid ( ) & &
ParseInternalKey ( input_ - > key ( ) , & next_ikey ) = = Status : : OK ( ) & &
ParseInternalKey ( input_ - > key ( ) , & next_ikey , allow_data_in_errors_ )
. ok ( ) & &
cmp_ - > Equal ( ikey_ . user_key , next_ikey . user_key ) ) {
cmp_ - > Equal ( ikey_ . user_key , next_ikey . user_key ) ) {
// Check whether the next key belongs to the same snapshot as the
// Check whether the next key belongs to the same snapshot as the
// SingleDelete.
// SingleDelete.
@ -630,7 +623,8 @@ void CompactionIterator::NextFromInput() {
// than *full_history_ts_low_.
// than *full_history_ts_low_.
while ( ! IsPausingManualCompaction ( ) & & ! IsShuttingDown ( ) & &
while ( ! IsPausingManualCompaction ( ) & & ! IsShuttingDown ( ) & &
input_ - > Valid ( ) & &
input_ - > Valid ( ) & &
( ParseInternalKey ( input_ - > key ( ) , & next_ikey ) = = Status : : OK ( ) ) & &
( ParseInternalKey ( input_ - > key ( ) , & next_ikey , allow_data_in_errors_ )
. ok ( ) ) & &
0 = = cmp_ - > CompareWithoutTimestamp ( ikey_ . user_key ,
0 = = cmp_ - > CompareWithoutTimestamp ( ikey_ . user_key ,
next_ikey . user_key ) & &
next_ikey . user_key ) & &
( prev_snapshot = = 0 | |
( prev_snapshot = = 0 | |
@ -640,7 +634,8 @@ void CompactionIterator::NextFromInput() {
// If you find you still need to output a row with this key, we need to output the
// If you find you still need to output a row with this key, we need to output the
// delete too
// delete too
if ( input_ - > Valid ( ) & &
if ( input_ - > Valid ( ) & &
( ParseInternalKey ( input_ - > key ( ) , & next_ikey ) = = Status : : OK ( ) ) & &
( ParseInternalKey ( input_ - > key ( ) , & next_ikey , allow_data_in_errors_ )
. ok ( ) ) & &
0 = = cmp_ - > CompareWithoutTimestamp ( ikey_ . user_key ,
0 = = cmp_ - > CompareWithoutTimestamp ( ikey_ . user_key ,
next_ikey . user_key ) ) {
next_ikey . user_key ) ) {
valid_ = true ;
valid_ = true ;
@ -658,8 +653,9 @@ void CompactionIterator::NextFromInput() {
// have hit (A)
// have hit (A)
// We encapsulate the merge related state machine in a different
// We encapsulate the merge related state machine in a different
// object to minimize change to the existing flow.
// object to minimize change to the existing flow.
Status s = merge_helper_ - > MergeUntil ( input_ , range_del_agg_ ,
Status s =
prev_snapshot , bottommost_level_ ) ;
merge_helper_ - > MergeUntil ( input_ , range_del_agg_ , prev_snapshot ,
bottommost_level_ , allow_data_in_errors_ ) ;
merge_out_iter_ . SeekToFirst ( ) ;
merge_out_iter_ . SeekToFirst ( ) ;
if ( ! s . ok ( ) & & ! s . IsMergeInProgress ( ) ) {
if ( ! s . ok ( ) & & ! s . IsMergeInProgress ( ) ) {
@ -670,13 +666,13 @@ void CompactionIterator::NextFromInput() {
// These will be correctly set below.
// These will be correctly set below.
key_ = merge_out_iter_ . key ( ) ;
key_ = merge_out_iter_ . key ( ) ;
value_ = merge_out_iter_ . value ( ) ;
value_ = merge_out_iter_ . value ( ) ;
pikS tatus = ParseInternalKey ( key_ , & ikey_ ) ;
pik_s tatus = ParseInternalKey ( key_ , & ikey_ , allow_data_in_errors _ ) ;
// MergeUntil stops when it encounters a corrupt key and does not
// MergeUntil stops when it encounters a corrupt key and does not
// include them in the result, so we expect the keys here to valid.
// include them in the result, so we expect the keys here to valid.
assert ( pikS tatus . ok ( ) ) ;
assert ( pik_s tatus . ok ( ) ) ;
if ( ! pikS tatus . ok ( ) ) {
if ( ! pik_s tatus . ok ( ) ) {
ROCKS_LOG_FATAL ( info_log_ , " Invalid key (%s) in compaction " ,
ROCKS_LOG_FATAL ( info_log_ , " Invalid key in compaction. %s " ,
key_ . ToString ( true ) . c_str ( ) ) ;
pik_status . getState ( ) ) ;
}
}
// Keep current_key_ in sync.
// Keep current_key_ in sync.
current_key_ . UpdateInternalKey ( ikey_ . sequence , ikey_ . type ) ;
current_key_ . UpdateInternalKey ( ikey_ . sequence , ikey_ . type ) ;