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

PS-9384: Sporadic crashes in Jenkins on start up due to race betweet … #1949

Merged

Conversation

kamil-holubicki
Copy link
Contributor

…dict_stats_thread and cost model initialization

https://perconadev.atlassian.net/browse/PS-9384

Problem:

Both debug and release version of server crash sporadically while running different tests in Jenkins with stacktraces referencing to Cost_model_server::init() being called from InnoDB's dict_stats_thread().

Analysis:

Investigation has shown that there is a race condition between code handling auto-updating of histograms from InnoDB background thread and the main thread performing server start-up. The code responsible for updating histogram, which was introduced by Upstream in 8.4.0, initializes LEX structure to perform its duties and tries to use global Optimizer cost model object as part of this. OTOH the main thread performing server start-up concurrently initializes and destroys this global object several times after this background thread has been started and sets it to the final working state much later in the process of start-up, before we start accepting user queries. Not surprisingly concurrent usage of this global object and its init/deinit cause crashes.

In theory, the problem exists in Upstream but probably is normally invisible there, as to trigger it, some updates to tables are needed, so persistent stats recalculation and histogram update are requested. And in the Upstream this probably can normally happen only after user requests start being processed (by which time global cost model object has proper stable state).

While in Percona Server, we have telemetry component enabled by default, and code which on first start up of server updates mysql.component table, which triggers stats/histogram update request. As result this race becomes visible. OTOH this specific scenario should only affect the first start of the server for installation, and not later restarts. But if there are other components which update tables during initialization/start up time the issue might become more prominent.

Solution:

Delay processing of requests to update stats/histograms in background thread until server is fully operational (and thus global optimizer cost model is fully initialized and stable).

…dict_stats_thread and cost model initialization

https://perconadev.atlassian.net/browse/PS-9384

Problem:
--------
Both debug and release version of server crash sporadically while running
different tests in Jenkins with stacktraces referencing to
Cost_model_server::init() being called from InnoDB's dict_stats_thread().

Analysis:
---------
Investigation has shown that there is a race condition between code handling
auto-updating of histograms from InnoDB background thread and the main thread
performing server start-up. The code responsible for updating histogram, which
was introduced by Upstream in 8.4.0, initializes LEX structure to perform its
duties and tries to use global Optimizer cost model object as part of this.
OTOH the main thread performing server start-up concurrently initializes and
destroys this global object several times after this background thread has
been started and sets it to the final working state much later in the process
of start-up, before we start accepting user queries. Not surprisingly
concurrent usage of this global object and its init/deinit cause crashes.

In theory, the problem exists in Upstream but probably is normally invisible
there, as to trigger it, some updates to tables are needed, so persistent
stats recalculation and histogram update are requested. And in the Upstream
this probably can normally happen only after user requests start being
processed (by which time global cost model object has proper stable state).

While in Percona Server, we have telemetry component enabled by default, and
code which on first start up of server updates mysql.component table, which
triggers stats/histogram update request. As result this race becomes visible.
OTOH this specific scenario should only affect the first start of the server
for installation, and not later restarts. But if there are other components
which update tables during initialization/start up time the issue might
become more prominent.

Solution:
---------
Delay processing of requests to update stats/histograms in background
thread until server is fully operational (and thus global optimizer
cost model is fully initialized and stable).
@it-percona-cla
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@dlenev dlenev left a comment

Choose a reason for hiding this comment

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

LGTM.

@kamil-holubicki kamil-holubicki merged commit 9645665 into percona:release-8.4.0 Sep 11, 2024
5 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants