Skip to content

Possible hangs in DBImpl::CloseHelper while recovery in progress #11440

Closed

Description

@lkf8005

RocksDB Version: 6.29.3
OS: Linux Kernel 3.10.0-1127.el7.x86_64

In ErrorHandler::RecoverFromRetryableBGIOError,if end_recovery_ flag is true, recovery_thread_ will exist and recovery_in_prog _ flag remain false.

So, in DBImpl::CloseHelper,after error_handler_.CancelErrorRecovery() and join recovery_thread_,code path will hang on bg_cv_Wait().

Activity

  1. lkf8005 commented on May 12, 2023

    @lkf8005
    Author

    In ErrorHandler::RecoverFromRetryableBGIOError, we should alway set recovery_in_prog _=false before return

  2. lkf8005 commented on May 12, 2023

    @lkf8005
    Author

    // Automatic recover from Retryable BG IO error. Must be called after db
    // mutex is released.
    void ErrorHandler::RecoverFromRetryableBGIOError() {
    #ifndef ROCKSDB_LITE
    TEST_SYNC_POINT("RecoverFromRetryableBGIOError:BeforeStart");
    InstrumentedMutexLock l(db_mutex_);
    if (end_recovery_) {
    recovery_in_prog_ = false;
    EventHelpers::NotifyOnErrorRecoveryEnd(db_options_.listeners, bg_error_,
    Status::ShutdownInProgress(),
    db_mutex_);
    return;
    }
    DBRecoverContext context = recover_context_;
    int resume_count = db_options_.max_bgerror_resume_count;
    uint64_t wait_interval = db_options_.bgerror_resume_retry_interval;
    uint64_t retry_count = 0;
    // Recover from the retryable error. Create a separate thread to do it.
    while (resume_count > 0) {
    if (end_recovery_) {
    recovery_in_prog_ = false;
    EventHelpers::NotifyOnErrorRecoveryEnd(db_options_.listeners, bg_error_,
    Status::ShutdownInProgress(),
    db_mutex_);
    return;
    }
    TEST_SYNC_POINT("RecoverFromRetryableBGIOError:BeforeResume0");
    TEST_SYNC_POINT("RecoverFromRetryableBGIOError:BeforeResume1");
    recovery_io_error_ = IOStatus::OK();
    recovery_error_ = Status::OK();
    retry_count++;
    Status s = db_->ResumeImpl(context);
    if (bg_error_stats_ != nullptr) {
    RecordTick(bg_error_stats_.get(),
    ERROR_HANDLER_AUTORESUME_RETRY_TOTAL_COUNT);
    }
    if (s.IsShutdownInProgress() ||
    bg_error_.severity() >= Status::Severity::kFatalError) {
    // If DB shutdown in progress or the error severity is higher than
    // Hard Error, stop auto resume and returns.
    recovery_in_prog_ = false;
    if (bg_error_stats_ != nullptr) {
    RecordInHistogram(bg_error_stats_.get(),
    ERROR_HANDLER_AUTORESUME_RETRY_COUNT, retry_count);
    }
    EventHelpers::NotifyOnErrorRecoveryEnd(db_options_.listeners, bg_error_,
    bg_error_, db_mutex_);
    return;
    }
    if (!recovery_io_error_.ok() &&
    recovery_error_.severity() <= Status::Severity::kHardError &&
    recovery_io_error_.GetRetryable()) {
    // If new BG IO error happens during auto recovery and it is retryable
    // and its severity is Hard Error or lower, the auto resmue sleep for
    // a period of time and redo auto resume if it is allowed.
    TEST_SYNC_POINT("RecoverFromRetryableBGIOError:BeforeWait0");
    TEST_SYNC_POINT("RecoverFromRetryableBGIOError:BeforeWait1");
    int64_t wait_until = db_options_.clock->NowMicros() + wait_interval;
    cv_.TimedWait(wait_until);
    } else {
    // There are three possibility: 1) recover_io_error is set during resume
    // and the error is not retryable, 2) recover is successful, 3) other
    // error happens during resume and cannot be resumed here.
    if (recovery_io_error_.ok() && recovery_error_.ok() && s.ok()) {
    // recover from the retryable IO error and no other BG errors. Clean
    // the bg_error and notify user.
    TEST_SYNC_POINT("RecoverFromRetryableBGIOError:RecoverSuccess");
    Status old_bg_error = bg_error_;
    bg_error_ = Status::OK();
    bg_error_.PermitUncheckedError();
    EventHelpers::NotifyOnErrorRecoveryEnd(
    db_options_.listeners, old_bg_error, bg_error_, db_mutex_);
    if (bg_error_stats_ != nullptr) {
    RecordTick(bg_error_stats_.get(),
    ERROR_HANDLER_AUTORESUME_SUCCESS_COUNT);
    RecordInHistogram(bg_error_stats_.get(),
    ERROR_HANDLER_AUTORESUME_RETRY_COUNT, retry_count);
    }
    recovery_in_prog_ = false;
    if (soft_error_no_bg_work_) {
    soft_error_no_bg_work_ = false;
    }
    return;
    } else {
    // In this case: 1) recovery_io_error is more serious or not retryable
    // 2) other Non IO recovery_error happens. The auto recovery stops.
    recovery_in_prog_ = false;
    if (bg_error_stats_ != nullptr) {
    RecordInHistogram(bg_error_stats_.get(),
    ERROR_HANDLER_AUTORESUME_RETRY_COUNT, retry_count);
    }
    EventHelpers::NotifyOnErrorRecoveryEnd(
    db_options_.listeners, bg_error_,
    !recovery_io_error_.ok()
    ? recovery_io_error_
    : (!recovery_error_.ok() ? recovery_error_ : s),
    db_mutex_);
    return;
    }
    }
    resume_count--;
    }
    recovery_in_prog_ = false;
    EventHelpers::NotifyOnErrorRecoveryEnd(
    db_options_.listeners, bg_error_,
    Status::Aborted("Exceeded resume retry count"), db_mutex_);
    TEST_SYNC_POINT("RecoverFromRetryableBGIOError:LoopOut");
    if (bg_error_stats_ != nullptr) {
    RecordInHistogram(bg_error_stats_.get(),
    ERROR_HANDLER_AUTORESUME_RETRY_COUNT, retry_count);
    }
    return;
    #else
    return;
    #endif
    }

  3. self-assigned this
    on May 13, 2023
  4. added
    bug
    on May 13, 2023
  5. jowlyzhang commented on Sep 26, 2023

    @jowlyzhang
    Contributor

    Closing this as the fix is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions