Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduler no throw in destruction and avoid updated min-tso query hang #4367

Merged
merged 7 commits into from
Mar 23, 2022

Conversation

fzhedu
Copy link
Contributor

@fzhedu fzhedu commented Mar 21, 2022

Signed-off-by: fzhedu fzhedu@gmail.com

What problem does this PR solve?

Issue Number: close #4366

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 21, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • bestwoody
  • windtalker

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. labels Mar 21, 2022
@fzhedu fzhedu requested a review from fuzhe1989 March 21, 2022 13:52
@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 21, 2022
@fzhedu fzhedu requested a review from windtalker March 21, 2022 13:52
@fzhedu fzhedu added the needs-cherry-pick-release-6.0 Type: Need cherry pick to release-6.0 label Mar 21, 2022
Signed-off-by: fzhedu <fzhedu@gmail.com>
Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not a good idea to schedule new task in the deconstructor, deconstructor should only do the clean up things. Can you find a way that deconstructor only release the used_threads, and some other threads to schedue the new task?

@@ -87,42 +87,29 @@ void MinTSOScheduler::deleteCancelledQuery(const UInt64 tso, MPPTaskManager & ta
waiting_set.erase(tso);
GET_METRIC(tiflash_task_scheduler, type_waiting_queries_count).Set(waiting_set.size());
GET_METRIC(tiflash_task_scheduler, type_active_queries_count).Set(active_set.size());
LOG_FMT_DEBUG(log, "{} query {} (is min = {}) is deleted from active set {} left {} or waiting set {} left {}.", is_cancelled ? "Cancelled" : "Finished", tso, tso == min_tso, active_set.find(tso) != active_set.end(), active_set.size(), waiting_set.find(tso) != waiting_set.end(), waiting_set.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both active_set.find(tso) != active_set.end() and waiting_set.find(tso) != waiting_set.end() will return false because you already erase them in L86-L87

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o, my error

/// NOTE: if the cancelled query hang, it will block the min_tso, possibly resulting in deadlock. so here force scheduling waiting tasks of the updated min_tso query.
if (updateMinTSO(tso, true, "when cancelling it."))
/// NOTE: if updated min_tso query has waiting tasks, they should be scheduled, especially when the soft-limited threads are amost used and active tasks are in resources deadlock which cannot release threads soon.
if (updateMinTSO(tso, true, is_cancelled ? "when cancelling it" : "as deleting it"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as deleting it => as finish it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if (isWaiting)
{
/// cancel this task, then TiDB will finally notify this tiflash node canceling all tasks of this tso and update metrics.
task->cancel(msg);
Copy link
Contributor

@bestwoody bestwoody Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will cancel triger OPs of waiting_set again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, conduct the cancel processing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since cancel will also triger OPs of waiting_set, will L197 waiting_set.erase(tso) be a duplicated op?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it comments: /// avoid the left waiting tasks of this query reaching here many times.

Signed-off-by: fzhedu <fzhedu@gmail.com>
@fzhedu fzhedu requested a review from windtalker March 22, 2022 06:39
@fzhedu
Copy link
Contributor Author

fzhedu commented Mar 22, 2022

/run-all-tests

@fzhedu fzhedu requested a review from bestwoody March 22, 2022 06:39
@sre-bot
Copy link
Collaborator

sre-bot commented Mar 22, 2022

Coverage for changed files

Filename                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dbms/src/Flash/Mpp/MPPTaskManager.cpp                  98                97     1.02%          12                11     8.33%         176               175     0.57%          70                70     0.00%
dbms/src/Flash/Mpp/MinTSOScheduler.cpp                307               274    10.75%           7                 6    14.29%         184               162    11.96%         146               141     3.42%
dbms/src/Flash/Mpp/MinTSOScheduler.h                    4                 1    75.00%           2                 0   100.00%           4                 0   100.00%           4                 3    25.00%
libs/libcommon/include/common/logger_useful.h          12                 0   100.00%           4                 0   100.00%          15                 3    80.00%           6                 1    83.33%
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                 421               372    11.64%          25                17    32.00%         379               340    10.29%         226               215     4.87%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
17039      9575             43.81%    191885  97032        49.43%

full coverage report (for internal network access only)

Copy link
Contributor

@bestwoody bestwoody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 22, 2022
Signed-off-by: fzhedu <fzhedu@gmail.com>
@fzhedu
Copy link
Contributor Author

fzhedu commented Mar 22, 2022

terminated as expected.

520 [2022/03/22 18:11:04.507 +08:00] [FATAL] [MinTSOScheduler.cpp:124] ["MinTSOScheduler:estimated_thread_usage should not be smaller than 0, actually is 12."] [thread_id=11]
521 [2022/03/22 18:11:04.507 +08:00] [ERROR] [<unknown>] ["BaseDaemon:(from thread 11) Terminate called without an active exception\n"] [thread_id=16]
522 [2022/03/22 18:11:04.507 +08:00] [ERROR] [<unknown>] [BaseDaemon:########################################] [thread_id=16]
523 [2022/03/22 18:11:04.507 +08:00] [ERROR] [<unknown>] ["BaseDaemon:(from thread 11) Received signal Abort trap: 6 (6)."] [thread_id=16]
524 [2022/03/22 18:11:04.511 +08:00] [ERROR] [<unknown>] ["BaseDaemon:\n  0x7fff20587946\t___pthread_kill [libsystem_kernel.dylib+140733733271878]"] [thread_id=16]

@fzhedu
Copy link
Contributor Author

fzhedu commented Mar 22, 2022

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented Mar 22, 2022

Coverage for changed files

Filename                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dbms/src/Flash/Mpp/MPPTask.cpp                        412               412     0.00%          21                21     0.00%         343               343     0.00%         186               186     0.00%
dbms/src/Flash/Mpp/MPPTaskManager.cpp                  98                97     1.02%          12                11     8.33%         176               175     0.57%          70                70     0.00%
dbms/src/Flash/Mpp/MinTSOScheduler.cpp                306               273    10.78%           7                 6    14.29%         183               161    12.02%         148               143     3.38%
dbms/src/Flash/Mpp/MinTSOScheduler.h                    4                 1    75.00%           2                 0   100.00%           4                 0   100.00%           4                 3    25.00%
libs/libcommon/include/common/logger_useful.h          12                 1    91.67%           4                 0   100.00%          15                 3    80.00%           6                 2    66.67%
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                 832               784     5.77%          46                38    17.39%         721               682     5.41%         414               404     2.42%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
17039      9575             43.81%    191887  97043        49.43%

full coverage report (for internal network access only)

{
std::unique_lock lock(schedule_mu);
schedule_cv.wait(lock, [&] { return schedule_state != ScheduleState::WAITING; });
time_cost = stopwatch.elapsedSeconds();
GET_METRIC(tiflash_task_scheduler_waiting_duration_seconds).Observe(time_cost);
if (schedule_state == ScheduleState::FAILED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to distinguish the cases that task is failed to schedule due to resource exhausted or due to the related query is cancelled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will add a enum flagh: EXCEEDED

Signed-off-by: fzhedu <fzhedu@gmail.com>
@fzhedu fzhedu requested a review from windtalker March 23, 2022 05:55
@fzhedu
Copy link
Contributor Author

fzhedu commented Mar 23, 2022

/run-all-tests

if (schedule_state == ScheduleState::EXCEEDED)
{
throw Exception("{} is failed to schedule because of exceeding the thread hard limit in min-tso scheduler.", id.toString());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not throw error if the schedule state is FAILED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the later processing in MppTask->runImp() will throw because this query is to be cancelled, whose state is not RUNNING..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But after the task is scheduled with FAILED schedule state, two threads are running concurrently with

  1. runImpl thread begin to run
  2. cancel thread mark MPPTask as cancelled
    There is no guarantee that rumImpl thread will see the Cancelled status right after it is waked up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to this goal.

@sre-bot
Copy link
Collaborator

sre-bot commented Mar 23, 2022

Coverage for changed files

Filename                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dbms/src/Flash/Mpp/MPPTask.cpp                        412               412     0.00%          21                21     0.00%         343               343     0.00%         186               186     0.00%
dbms/src/Flash/Mpp/MPPTask.h                            3                 3     0.00%           3                 3     0.00%           3                 3     0.00%           0                 0         -
dbms/src/Flash/Mpp/MPPTaskManager.cpp                  98                97     1.02%          12                11     8.33%         176               175     0.57%          70                70     0.00%
dbms/src/Flash/Mpp/MinTSOScheduler.cpp                306               273    10.78%           7                 6    14.29%         183               161    12.02%         148               143     3.38%
dbms/src/Flash/Mpp/MinTSOScheduler.h                    4                 1    75.00%           2                 0   100.00%           4                 0   100.00%           4                 3    25.00%
libs/libcommon/include/common/logger_useful.h          12                 0   100.00%           4                 0   100.00%          15                 3    80.00%           6                 0   100.00%
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                 835               786     5.87%          49                41    16.33%         724               685     5.39%         414               402     2.90%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
17039      9574             43.81%    191887  97040        49.43%

full coverage report (for internal network access only)

@fzhedu
Copy link
Contributor Author

fzhedu commented Mar 23, 2022

/run-all-tests

@fzhedu fzhedu requested a review from windtalker March 23, 2022 10:06
@sre-bot
Copy link
Collaborator

sre-bot commented Mar 23, 2022

Coverage for changed files

Filename                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dbms/src/Flash/Mpp/MPPTask.cpp                        415               415     0.00%          21                21     0.00%         348               348     0.00%         188               188     0.00%
dbms/src/Flash/Mpp/MPPTask.h                            3                 3     0.00%           3                 3     0.00%           3                 3     0.00%           0                 0         -
dbms/src/Flash/Mpp/MPPTaskManager.cpp                  98                97     1.02%          12                11     8.33%         176               175     0.57%          70                70     0.00%
dbms/src/Flash/Mpp/MinTSOScheduler.cpp                306               273    10.78%           7                 6    14.29%         183               161    12.02%         148               143     3.38%
dbms/src/Flash/Mpp/MinTSOScheduler.h                    4                 1    75.00%           2                 0   100.00%           4                 0   100.00%           4                 3    25.00%
libs/libcommon/include/common/logger_useful.h          12                 0   100.00%           4                 0   100.00%          15                 3    80.00%           6                 0   100.00%
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                 838               789     5.85%          49                41    16.33%         729               690     5.35%         416               404     2.88%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
17033      9568             43.83%    191923  97041        49.44%

full coverage report (for internal network access only)

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 23, 2022
@windtalker
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

@windtalker: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 3e563cc

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 23, 2022
@ti-chi-bot
Copy link
Member

@fzhedu: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@sre-bot
Copy link
Collaborator

sre-bot commented Mar 23, 2022

Coverage for changed files

Filename                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
dbms/src/Flash/Mpp/MPPTask.cpp                        415               415     0.00%          21                21     0.00%         348               348     0.00%         188               188     0.00%
dbms/src/Flash/Mpp/MPPTask.h                            3                 3     0.00%           3                 3     0.00%           3                 3     0.00%           0                 0         -
dbms/src/Flash/Mpp/MPPTaskManager.cpp                  98                97     1.02%          12                11     8.33%         176               175     0.57%          70                70     0.00%
dbms/src/Flash/Mpp/MinTSOScheduler.cpp                306               273    10.78%           7                 6    14.29%         183               161    12.02%         148               143     3.38%
dbms/src/Flash/Mpp/MinTSOScheduler.h                    4                 1    75.00%           2                 0   100.00%           4                 0   100.00%           4                 3    25.00%
libs/libcommon/include/common/logger_useful.h          12                 0   100.00%           4                 0   100.00%          15                 3    80.00%           6                 0   100.00%
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                 838               789     5.85%          49                41    16.33%         729               690     5.35%         416               404     2.88%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
17033      9568             43.83%    191927  97026        49.45%

full coverage report (for internal network access only)

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #4399.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-6.0 Type: Need cherry pick to release-6.0 release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

updated min-tso query hang and tiflash crash
5 participants