Skip to content

Commit e0f9d5a

Browse files
committed
Add yield to union iterator
Summary: This was detected by the stall detection (8.0.23 based callstack): ``` W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] Scheduler 12 stalled by worker 0x7f6367d5d640 W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] Stack trace for 1 thread(s) [1422783 mysqld]: W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 00000000001204d0 ppoll W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 000000000289d67f vio_io_wait(Vio*, enum_vio_io_event, timeout_t) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 0000000002952296 vio_socket_io_wait(Vio*, enum_vio_io_event) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 0000000002385fb2 net_write_packet(NET*, unsigned char const*, unsigned long) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 00000000025b2c44 SELECT_LEX_UNIT::ExecuteIteratorQuery(THD*) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 000000000258d2db Sql_cmd_dml::execute(THD*) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 000000000254f179 mysql_execute_command(THD*, bool, unsigned long long*) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 0000000002545936 dispatch_sql_command(THD*, Parser_state*, unsigned long long*) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 000000000269d931 dispatch_command(THD*, COM_DATA const*, enum_server_command) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 000000000269c3e0 do_command(THD*) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 0000000005c4ffa7 mysql::thread_pool::TpConnHandler::processEvent(void*) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 0000000005c5395f mysql::thread_pool::TpTask::execute() W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 0000000005c5c299 mysql::thread_pool::TpWorkerPool::processWorker(void*) W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 0000000004867855 pfs_spawn_thread(void*) [clone .llvm.11916604799980067416] W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 000000000009ac0e start_thread W0205 14:38:40.101111 2319640 TpScheduler.cpp:431] @ 000000000012d1db __clone3 ``` Cleaned up existing yield code to use a common default yield condition. Test Plan: MTR Addressing thread pool test failures in D43100276. Reviewers: sunxiayi, prerit Reviewed By: prerit Subscribers: webscalesql-eng@fb.com Differential Revision: https://phabricator.intern.facebook.com/D43071441 Tasks: T104018812
1 parent 89762d5 commit e0f9d5a

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎sql/iterators/hash_join_iterator.cc‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,6 @@ static bool WriteRowToChunk(
323323
}
324324
}
325325

326-
// Helper to check if yielding is OK for this query.
327-
static bool YieldCondition() {
328-
// Allow yielding in all cases.
329-
return true;
330-
}
331-
332326
// Write all the remaining rows from the given iterator out to chunk files
333327
// on disk. If the function returns true, an unrecoverable error occurred
334328
// (IO error etc.).
@@ -346,7 +340,7 @@ static bool WriteRowsToChunks(
346340
return true;
347341
}
348342

349-
thd->check_yield(YieldCondition);
343+
thd->check_yield();
350344

351345
if (res == -1) {
352346
return false; // EOF; success.
@@ -467,7 +461,7 @@ bool HashJoinIterator::BuildHashTable() {
467461
return true;
468462
}
469463

470-
thd()->check_yield(YieldCondition);
464+
thd()->check_yield();
471465

472466
if (res == -1) {
473467
m_build_iterator_has_more_rows = false;

‎sql/sql_class.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,13 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup) {
27402740
}
27412741
}
27422742

2743+
/**
2744+
Default yield condition.
2745+
*/
2746+
bool THD::always_yield() {
2747+
return true;
2748+
}
2749+
27432750
void THD::check_yield(std::function<bool()> cond) {
27442751
yield_cond = std::move(cond);
27452752
thd_wait_begin(this, THD_WAIT_YIELD);

‎sql/sql_class.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5139,10 +5139,15 @@ class THD : public MDL_context_owner,
51395139
ulonglong readmission_count = 0;
51405140
std::function<bool()> yield_cond;
51415141

5142+
/**
5143+
Default yield condition.
5144+
*/
5145+
static bool always_yield();
5146+
51425147
/**
51435148
Check if we should exit and reenter admission control.
51445149
*/
5145-
void check_yield(std::function<bool()> cond);
5150+
void check_yield(std::function<bool()> cond = always_yield);
51465151

51475152
/**
51485153
Periodic calls to update pfs stats on processing a number of rows.

‎sql/sql_union.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,8 @@ bool Query_expression::ExecuteIteratorQuery(THD *thd) {
13101310
return true;
13111311
}
13121312

1313+
thd->check_yield();
1314+
13131315
++*send_records_ptr;
13141316

13151317
if (query_result->send_data(thd, *fields)) {

0 commit comments

Comments
 (0)