Skip to content
Go to file

Latest commit

Add a new feature to allow MySQL to block queries until the given HLC bound has been applied to the local engine. Blocked queries are queued up on a condition variable that is signaled when an HLC value is applied to the local engine state.
This feature is controlled by two query attributes which are unsigned integers:
* hlc_ts_lower_bound
* hlc_wait_timeout_ms
The semantics of the two options (hlc_ts_lower_bound + hlc_wait_timeout_ms):
* hlc_ts_lower_bound is set, hlc_wait_timeout_ms is not set -> Error immediately if the HLC is not present in the engine
* hlc_ts_lower_bound is set, hlc_wait_timeout_ms == 0 -> error immediately if the HLC is not present in the engine
* hlc_ts_lower_bound is set, hlc_wait_timeout_ms > 0 -> Block query execution for the timeout duration or until the given HLC is applied to the engine if the HLC is not present in the engine at the start of the txn.

A per-database struct is used to track the maximum applied HLC value for that database, and a condition variable that waiters can wait on and be awoken when the maximum applied HLC value is updates. When the waiters are awoken, they check the atomically updated maximum applied HLC value and re-block if the maximum applied HLC value is still less than the requested HLC value. As an optimization, if the delta between the requested HLC value and the maximum applied HLC value is large enough, the thread sleeps rather than enqueueing on the list of waiters. This prevents huge thundering herds of waiters waking, only for most of those waiters to block again.

The key point is this implementation optimizes the writer path in the applier thread to avoid long-held locks in the COMMIT path.

A few caveats, similar to the existing functionality to reject reads for which the desired lower bound HLC isn't yet present in the engine, this feature does not apply to cross database or transactional reads due to the fact that the database applied HLC map isn't fully in sync with engine snapshots used by transactional reads and cross database operations.

A new PSI stage is added to indicate in performance schema and SHOW PROCESSLIST which queries are currently blocked and queries that are blocked can be killed normally (Have MTR tests for this).

Finally, the call to HybridLogicalClock::update_database_hlc() is moved from process_commit_stage_queue to process_after_commit_stage_queue so that the commit lock is not held while executing mysql_cond_broadcast() which walks the entire list of waiting threads in the kernel (at least in Linux while running pthreads).

Reviewed By: bhatvinay

Differential Revision: D24607393

fbshipit-source-id: c7c7e39b07f


Failed to load latest commit information.
Latest commit message
Commit time


MySQL Server 5.6

This is a release of MySQL, a dual-license SQL database server.
For the avoidance of doubt, this particular copy of the software 
is released under the version 2 of the GNU General Public License. 
MySQL is brought to you by Oracle.

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

License information can be found in the COPYING file.

MySQL FOSS License Exception
We want free and open source software applications under certain
licenses to be able to use specified GPL-licensed MySQL client
libraries despite the fact that not all such FOSS licenses are
compatible with version 2 of the GNU General Public License.  
Therefore there are special exceptions to the terms and conditions 
of the GPLv2 as applied to these client libraries, which are 
identified and described in more detail in the FOSS License 
Exception at 

This distribution may include materials developed by third
parties. For license and attribution notices for these
materials, please refer to the documentation that accompanies
this distribution (see the "Licenses for Third-Party Components"
appendix) or view the online documentation at 

GPLv2 Disclaimer
For the avoidance of doubt, except that if any license choice
other than GPL or LGPL is available it will apply instead, 
Oracle elects to use only the General Public License version 2 
(GPLv2) at this time for any software where a choice of GPL 
license versions is made available with the language indicating 
that GPLv2 or any later version may be used, or where a choice 
of which version of the GPL is applied is otherwise unspecified.

For further information about MySQL or additional documentation, 
- The latest information about MySQL:
- The current MySQL documentation:

Some Reference Manual sections of special interest:
- If you are migrating from an older version of MySQL, please 
  read the "Upgrading from..." section.
- To see what MySQL can do, take a look at the features section.
- For installation instructions, see the Installing and Upgrading
- For the new features/bugfix history, see the MySQL Change History 

You can browse the MySQL Reference Manual online or download it 
in any of several formats at the URL given earlier in this file.
Source distributions include a local copy of the manual in the
Docs directory.
You can’t perform that action at this time.