| 3697 | } |
| 3698 | |
| 3699 | Status ImpalaServer::StartShutdown( |
| 3700 | int64_t relative_deadline_s, ShutdownStatusPB* shutdown_status) { |
| 3701 | DCHECK_GE(relative_deadline_s, -1); |
| 3702 | if (relative_deadline_s == -1) relative_deadline_s = FLAGS_shutdown_deadline_s; |
| 3703 | int64_t now = MonotonicMillis(); |
| 3704 | int64_t new_deadline = now + relative_deadline_s * 1000L; |
| 3705 | |
| 3706 | bool set_deadline = false; |
| 3707 | bool set_grace = false; |
| 3708 | int64_t curr_deadline = shutdown_deadline_.Load(); |
| 3709 | while (curr_deadline == 0 || curr_deadline > new_deadline) { |
| 3710 | // Set the deadline - it was either unset or later than the new one. |
| 3711 | if (shutdown_deadline_.CompareAndSwap(curr_deadline, new_deadline)) { |
| 3712 | set_deadline = true; |
| 3713 | break; |
| 3714 | } |
| 3715 | curr_deadline = shutdown_deadline_.Load(); |
| 3716 | } |
| 3717 | |
| 3718 | // Dump the data cache before shutdown. |
| 3719 | discard_result(ExecEnv::GetInstance()->disk_io_mgr()->DumpDataCache()); |
| 3720 | |
| 3721 | while (shutting_down_.Load() == 0) { |
| 3722 | if (!shutting_down_.CompareAndSwap(0, now)) continue; |
| 3723 | unique_ptr<Thread> t; |
| 3724 | Status status = |
| 3725 | Thread::Create("shutdown", "shutdown", [this] { ShutdownThread(); }, &t, false); |
| 3726 | if (!status.ok()) { |
| 3727 | LOG(ERROR) << "Failed to create shutdown thread: " << status.GetDetail(); |
| 3728 | return status; |
| 3729 | } |
| 3730 | set_grace = true; |
| 3731 | break; |
| 3732 | } |
| 3733 | *shutdown_status = GetShutdownStatus(); |
| 3734 | // Show the full grace/limit times to avoid showing confusing intermediate values |
| 3735 | // to the person running the statement. |
| 3736 | if (set_grace) { |
| 3737 | shutdown_status->set_grace_remaining_ms(FLAGS_shutdown_grace_period_s * 1000L); |
| 3738 | } |
| 3739 | if (set_deadline) { |
| 3740 | shutdown_status->set_deadline_remaining_ms(relative_deadline_s * 1000L); |
| 3741 | if (FLAGS_shutdown_query_cancel_period_s > 0) { |
| 3742 | shutdown_status->set_cancel_deadline_remaining_ms( |
| 3743 | relative_deadline_s * 1000L - GetShutdownCancelThreshold()); |
| 3744 | } |
| 3745 | } |
| 3746 | return Status::OK(); |
| 3747 | } |
| 3748 | |
| 3749 | bool ImpalaServer::CancelQueriesForGracefulShutdown() { |
| 3750 | LOG(INFO) << "Start to cancel all running queries for graceful shutdown."; |