You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2021/01/21 08:57:40 UTC
[impala] 02/05: IMPALA-10259: Fixed DCHECK error for backend in
terminal state
This is an automated email from the ASF dual-hosted git repository.
stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 8ecb61e4bda0b0f712da67f43eea70e5b583f167
Author: wzhou-code <wz...@cloudera.com>
AuthorDate: Tue Dec 22 15:45:07 2020 -0800
IMPALA-10259: Fixed DCHECK error for backend in terminal state
This issue happened for core ASAN build.
According to log message, one backend sent status report with
instance_exec_status as done for all assigned instances without
error, then it sent last status report with error. The coordinator
treat the backend state as done after it processed the status report
with instance_exec_status as done, but did not apply last status
report with error to the overall backend state.
This caused backend to receive a response with status as OK for the
last status report, hence hit DCHECK error.
This patch fix the race for updating the 'Query State' and updating
the fragment instance state when hitting error during execution of
fragment instance. The backends will not send status report with
fragment instance state as "completed" without error after hitting
error.
Testing:
- Manual tests
I could only reproduce the situation by adding some artificial
delays in the beginning of QueryState::ErrorDuringExecute()
when repeatedly running test case test_spilling.py::
TestSpillingDebugActionDimensions::test_spilling_naaj for
Impala ASAN build.
Verified that the issue did not happen after applying this
patch.
- Passed exhaustive test.
Change-Id: Ic12a80e20ddc11e32349edfec2bd16338c24b841
Reviewed-on: http://gerrit.cloudera.org:8080/16900
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
be/src/runtime/fragment-instance-state.cc | 22 ++++++++++++++++------
be/src/runtime/fragment-instance-state.h | 9 ++++++++-
be/src/runtime/query-state.cc | 10 ++++++----
be/src/runtime/query-state.h | 9 ++++++++-
4 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/be/src/runtime/fragment-instance-state.cc b/be/src/runtime/fragment-instance-state.cc
index 4f306b9..ca7ab1c 100644
--- a/be/src/runtime/fragment-instance-state.cc
+++ b/be/src/runtime/fragment-instance-state.cc
@@ -109,22 +109,31 @@ done:
// logged in RuntimeState:error_log_.
Close();
- // Must update the fragment instance state first before updating the 'Query State'.
- // Otherwise, there is a race when reading the 'done' flag with GetStatusReport().
- // This may lead to the "final" profile being sent with the 'done' flag as false.
DCHECK_EQ(is_prepared,
current_state_.Load() > FInstanceExecStatePB::WAITING_FOR_PREPARE);
- UpdateState(StateEvent::EXEC_END);
if (!status.ok()) {
if (!is_prepared) {
+ UpdateState(StateEvent::EXEC_END);
+
// Tell the managing 'QueryState' that we hit an error during Prepare().
query_state_->ErrorDuringPrepare(status, instance_id());
} else {
+ // Must set exec_failed_ first, then update the 'Query State' before updating the
+ // fragment instance state. Otherwise, there is a race when reading the 'done' flag
+ // with GetStatusReport(). This may lead to report the instance as "completed"
+ // without error, or the "final" profile being sent with the 'done' flag as false.
+
+ exec_failed_.Store(true);
// Tell the managing 'QueryState' that we hit an error during execution.
query_state_->ErrorDuringExecute(status, instance_id());
+
+ UpdateState(StateEvent::EXEC_END);
+ query_state_->DoneRemainingExecuting();
}
} else {
+ UpdateState(StateEvent::EXEC_END);
+
// Tell the managing 'QueryState' that we're done with executing.
query_state_->DoneExecuting();
}
@@ -257,7 +266,8 @@ Status FragmentInstanceState::Prepare() {
}
void FragmentInstanceState::GetStatusReport(FragmentInstanceExecStatusPB* instance_status,
- TRuntimeProfileTree* unagg_profile, AggregatedRuntimeProfile* agg_profile) {
+ TRuntimeProfileTree* unagg_profile, AggregatedRuntimeProfile* agg_profile,
+ const Status& overall_status) {
DCHECK_NE(unagg_profile == nullptr, agg_profile == nullptr);
DFAKE_SCOPED_LOCK(report_status_lock_);
DCHECK(!final_report_sent_);
@@ -274,7 +284,7 @@ void FragmentInstanceState::GetStatusReport(FragmentInstanceExecStatusPB* instan
}
const TUniqueId& finstance_id = instance_id();
TUniqueIdToUniqueIdPB(finstance_id, instance_status->mutable_fragment_instance_id());
- const bool done = IsDone();
+ const bool done = IsDone() || (ExecFailed() && !overall_status.ok());
instance_status->set_done(done);
instance_status->set_current_state(current_state());
DCHECK(profile() != nullptr);
diff --git a/be/src/runtime/fragment-instance-state.h b/be/src/runtime/fragment-instance-state.h
index 58b5a4b..c3210af 100644
--- a/be/src/runtime/fragment-instance-state.h
+++ b/be/src/runtime/fragment-instance-state.h
@@ -105,7 +105,8 @@ class FragmentInstanceState {
/// Thrift runtime profile is stored in either 'unagg_profile' or 'agg_profile',
/// depending on whether aggregated profiles are enabled.
void GetStatusReport(FragmentInstanceExecStatusPB* instance_status,
- TRuntimeProfileTree* unagg_profile, AggregatedRuntimeProfile* agg_profile);
+ TRuntimeProfileTree* unagg_profile, AggregatedRuntimeProfile* agg_profile,
+ const Status& overall_status);
/// After each call to GetStatusReport(), the query state thread should call one of the
/// following to indicate if the report rpc was successful. Note that in the case of
@@ -142,6 +143,7 @@ class FragmentInstanceState {
FInstanceExecStatePB current_state() const { return current_state_.Load(); }
bool final_report_sent() const { return final_report_sent_; }
bool IsDone() const { return current_state_.Load() == FInstanceExecStatePB::FINISHED; }
+ bool ExecFailed() const { return exec_failed_.Load(); }
ObjectPool* obj_pool();
int64_t scan_ranges_complete() const { return scan_ranges_complete_; }
int64_t peak_mem_consumption() const { return peak_mem_consumption_; }
@@ -255,6 +257,11 @@ class FragmentInstanceState {
/// fragment instance thread in UpdateState() and read by the profile reporting threads.
AtomicEnum<FInstanceExecStatePB> current_state_{FInstanceExecStatePB::WAITING_FOR_EXEC};
+ /// Set to true when hitting an error during execution for the fragment instance.
+ /// It's used to work around the race when updating the fragment instance state and
+ /// updating the 'Query State'.
+ AtomicBool exec_failed_{false};
+
/// Output sink for rows sent to this fragment. Created in Prepare(), lives in
/// obj_pool().
DataSink* sink_ = nullptr;
diff --git a/be/src/runtime/query-state.cc b/be/src/runtime/query-state.cc
index 9d3a07f..222e394 100644
--- a/be/src/runtime/query-state.cc
+++ b/be/src/runtime/query-state.cc
@@ -507,6 +507,7 @@ void QueryState::ConstructReport(bool instances_started,
TUniqueIdToUniqueIdPB(query_id(), report->mutable_query_id());
DCHECK(exec_rpc_params_.has_coord_state_idx());
report->set_coord_state_idx(exec_rpc_params_.coord_state_idx());
+ Status report_overall_status;
{
unique_lock<SpinLock> l(status_lock_);
@@ -515,6 +516,7 @@ void QueryState::ConstructReport(bool instances_started,
if (UNLIKELY(!debug_action_status.ok())) overall_status_ = debug_action_status;
overall_status_.ToProto(report->mutable_overall_status());
+ report_overall_status = overall_status_;
if (IsValidFInstanceId(failed_finstance_id_)) {
TUniqueIdToUniqueIdPB(failed_finstance_id_, report->mutable_fragment_instance_id());
}
@@ -562,11 +564,12 @@ void QueryState::ConstructReport(bool instances_started,
agg_profile = AggregatedRuntimeProfile::Create(&agg_profile_pool,
"tmp profile", it->second->instance_ctxs().size(), /*is_root=*/ true);
}
- fis->GetStatusReport(instance_status, nullptr, agg_profile);
+ fis->GetStatusReport(
+ instance_status, nullptr, agg_profile, report_overall_status);
} else {
profiles_forest->profile_trees.emplace_back();
- fis->GetStatusReport(
- instance_status, &profiles_forest->profile_trees.back(), nullptr);
+ fis->GetStatusReport(instance_status, &profiles_forest->profile_trees.back(),
+ nullptr, report_overall_status);
}
}
@@ -777,7 +780,6 @@ void QueryState::ErrorDuringExecute(const Status& status, const TUniqueId& finst
failed_finstance_id_ = finst_id;
}
}
- instances_finished_barrier_->NotifyRemaining();
}
Status QueryState::WaitForPrepare() {
diff --git a/be/src/runtime/query-state.h b/be/src/runtime/query-state.h
index 49a1d1a..542da91 100644
--- a/be/src/runtime/query-state.h
+++ b/be/src/runtime/query-state.h
@@ -254,6 +254,11 @@ class QueryState {
/// Called by a FragmentInstanceState thread to notify that it's done executing.
void DoneExecuting() { discard_result(instances_finished_barrier_->Notify()); }
+ /// Called by a FragmentInstanceState thread to notify anyone waiting on
+ /// WaitForFinishOrTimeout() or waiting on WaitForFinish().
+ /// This function must be called after calling ErrorDuringExecute().
+ void DoneRemainingExecuting() { instances_finished_barrier_->NotifyRemaining(); }
+
/// Called to notify that an error was encountered during codegen. This is called by the
/// first fragment instance thread that invoked its corresponding FragmentState's
/// Codegen() and encountered the error.
@@ -267,7 +272,9 @@ class QueryState {
/// Called by a fragment instance thread to notify that it hit an error during Execute()
/// Updates the query status and records the failed instance ID if they're not set
- /// already. Also notifies anyone waiting on WaitForFinishOrTimeout().
+ /// already.
+ /// Caller must call DoneRemainingExecuting() after calling this function to notify
+ /// anyone waiting on WaitForFinishOrTimeout() or waiting on WaitForFinish().
void ErrorDuringExecute(const Status& status, const TUniqueId& finst_id);
/// Get maximum reservation allowed for this query. MAX_INT64 means effectively