diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-10-16 19:00:43 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2020-05-29 21:53:54 +0400 |
commit | c2798784931a59f996275e14220b74f450828b4b (patch) | |
tree | 09a17f66e2c1d4d46cea518692e70272d2cd4015 /sql/table.h | |
parent | 609a0d3db3fecc12c2d63b52bec3e3a305e6c702 (diff) | |
download | mariadb-git-c2798784931a59f996275e14220b74f450828b4b.tar.gz |
Thread safe histograms loading
Previously multiple threads were allowed to load histograms concurrently.
There were no known problems caused by this. But given amount of data
races in this code, it'd happen sooner or later.
To avoid scalability bottleneck, histograms loading is protected by
per-TABLE_SHARE atomic variable.
Whenever histograms were loaded by preceding statement (hot-path), a
scalable load-acquire check is performed.
Whenever histograms have to be loaded anew, mutual exclusion for loaders
is established by atomic variable. If histograms are being loaded
concurrently, statement waits until load is completed.
- Table_statistics::total_hist_size moved to TABLE_STATISTICS_CB: only
meaningful within TABLE_SHARE (not used for collected stats).
- TABLE_STATISTICS_CB::histograms_can_be_read and
TABLE_STATISTICS_CB::histograms_are_read are replaced with a tri state
atomic variable.
- Simplified away alloc_histograms_for_table_share().
Note: there's still likely a data race if a thread attempts accessing
histograms data after it failed to load it (because of concurrent load).
It was there previously and goes out of the scope of this effort. One way
of fixing it could be reviving TABLE::histograms_are_read and adding
appropriate checks whenever it is needed.
Part of MDEV-19061 - table_share used for reading statistical tables is
not protected
Diffstat (limited to 'sql/table.h')
-rw-r--r-- | sql/table.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sql/table.h b/sql/table.h index 85ba7b29ce2..93795113fab 100644 --- a/sql/table.h +++ b/sql/table.h @@ -659,13 +659,25 @@ class TABLE_STATISTICS_CB }; class Statistics_state stats_state; + class Statistics_state hist_state; public: MEM_ROOT mem_root; /* MEM_ROOT to allocate statistical data for the table */ Table_statistics *table_stats; /* Structure to access the statistical data */ - bool histograms_can_be_read; - bool histograms_are_read; + ulong total_hist_size; /* Total size of all histograms */ + bool histograms_are_ready() const + { + return !total_hist_size || hist_state.is_ready(); + } + + bool start_histograms_load() + { + return total_hist_size && hist_state.start_load(); + } + + void end_histograms_load() { hist_state.end_load(); } + void abort_histograms_load() { hist_state.abort_load(); } bool stats_are_ready() const { return stats_state.is_ready(); } bool start_stats_load() { return stats_state.start_load(); } void end_stats_load() { stats_state.end_load(); } |