@ -1414,7 +1414,6 @@ Status DBImpl::RecoverLogFiles(const std::vector<uint64_t>& log_numbers,
bool stop_replay_by_wal_filter = false ;
bool stop_replay_by_wal_filter = false ;
bool stop_replay_for_corruption = false ;
bool stop_replay_for_corruption = false ;
bool flushed = false ;
bool flushed = false ;
SequenceNumber recovered_sequence = 0 ;
for ( auto log_number : log_numbers ) {
for ( auto log_number : log_numbers ) {
// The previous incarnation may not have written any MANIFEST
// The previous incarnation may not have written any MANIFEST
// records after allocating this log number. So we manually
// records after allocating this log number. So we manually
@ -1493,13 +1492,13 @@ Status DBImpl::RecoverLogFiles(const std::vector<uint64_t>& log_numbers,
WriteBatchInternal : : SetContents ( & batch , record ) ;
WriteBatchInternal : : SetContents ( & batch , record ) ;
SequenceNumber sequence = WriteBatchInternal : : Sequence ( & batch ) ;
SequenceNumber sequence = WriteBatchInternal : : Sequence ( & batch ) ;
// In point-in-time recovery mode, if sequence id of log files are
// consecutive, we continue recovery despite corruption. This could happen
// when we open and write to a corrupted DB, where sequence id will start
// from the last sequence id we recovered.
if ( db_options_ . wal_recovery_mode = =
if ( db_options_ . wal_recovery_mode = =
WALRecoveryMode : : kPointInTimeRecovery ) {
WALRecoveryMode : : kPointInTimeRecovery ) {
if ( sequence = = recovered_sequence + 1 ) {
// In point-in-time recovery mode, if sequence id of log files are
// consecutive, we continue recovery despite corruption. This could
// happen when we open and write to a corrupted DB, where sequence id
// will start from the last sequence id we recovered.
if ( sequence = = * next_sequence ) {
stop_replay_for_corruption = false ;
stop_replay_for_corruption = false ;
}
}
if ( stop_replay_for_corruption ) {
if ( stop_replay_for_corruption ) {
@ -1508,14 +1507,17 @@ Status DBImpl::RecoverLogFiles(const std::vector<uint64_t>& log_numbers,
}
}
}
}
recovered_sequence = sequence ;
bool no_prev_seq = true ;
bool no_prev_seq = true ;
if ( ! db_options_ . allow_2pc ) {
* next_sequence = sequence ;
} else {
if ( * next_sequence = = kMaxSequenceNumber ) {
if ( * next_sequence = = kMaxSequenceNumber ) {
* next_sequence = sequence ;
* next_sequence = sequence ;
} else {
} else {
no_prev_seq = false ;
no_prev_seq = false ;
WriteBatchInternal : : SetSequence ( & batch , * next_sequence ) ;
WriteBatchInternal : : SetSequence ( & batch , * next_sequence ) ;
}
}
}
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
if ( db_options_ . wal_filter ! = nullptr ) {
if ( db_options_ . wal_filter ! = nullptr ) {
@ -1605,9 +1607,11 @@ Status DBImpl::RecoverLogFiles(const std::vector<uint64_t>& log_numbers,
// after replaying the file, this file may be a stale file. We ignore
// after replaying the file, this file may be a stale file. We ignore
// sequence IDs from the file. Otherwise, if a newer stale log file that
// sequence IDs from the file. Otherwise, if a newer stale log file that
// has been deleted, the sequenceID may be wrong.
// has been deleted, the sequenceID may be wrong.
if ( db_options_ . allow_2pc ) {
if ( no_prev_seq & & ! has_valid_writes ) {
if ( no_prev_seq & & ! has_valid_writes ) {
* next_sequence = kMaxSequenceNumber ;
* next_sequence = kMaxSequenceNumber ;
}
}
}
MaybeIgnoreError ( & status ) ;
MaybeIgnoreError ( & status ) ;
if ( ! status . ok ( ) ) {
if ( ! status . ok ( ) ) {
// We are treating this as a failure while reading since we read valid
// We are treating this as a failure while reading since we read valid