MySQL 8.4.0
Source Code Documentation
sharded_kv_store_logger.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify it under
4the terms of the GNU General Public License, version 2.0, as published by the
5Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
18for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/** @file storage/temptable/include/temptable/sharded_kv_store_logger.h
25TempTable sharded key-value store logger implementation. */
26
27#ifndef TEMPTABLE_SHARDED_KV_STORE_LOGGER_H
28#define TEMPTABLE_SHARDED_KV_STORE_LOGGER_H
29
30#include <algorithm>
31#include <string>
32#include <thread>
33
34#include "my_dbug.h"
36
37namespace temptable {
38
39/** Default Sharded_key_value_store logging facility which turns to no-op in
40 * non-debug builds. */
41template <typename T, bool DebugBuild>
43 void dbug_print() {
44 // no-op
45 }
46};
47
48/** Sharded_key_value_store logging facility debug builds only. */
49template <typename T>
51 /** DBUG_PRINT's the stats of each shard and additionally some further stats
52 * which are deduced from it, e.g. ratio between insertions and removals.
53 * */
54 void dbug_print() {
55 // As representation of std::thread::id is implementation defined, we have
56 // to convert it to a string first before passing it over to DBUG_PRINT
57 // machinery. Conversion to string can be done with the overloaded
58 // std::thread::id::operator<< which is part of the library
59 // implementation.
60 auto std_thread_id_to_str = [](const std::thread::id &id) {
61 std::stringstream ss;
62 ss << id;
63 return ss.str();
64 };
65
66 auto &kv_store_shards = static_cast<T &>(*this).m_kv_store_shard;
67 uint32_t shard_id [[maybe_unused]] = 0;
68 for (auto &kv : kv_store_shards) {
69 auto kv_shard_stats = kv.shard.stats();
70 size_t nr_of_emplace_events = std::count_if(
71 kv_shard_stats.begin(), kv_shard_stats.end(), [](auto &stat) {
72 return stat.event == Key_value_store_stats::Event::EMPLACE;
73 });
74
75 // Silence the -Wunused-variable false-positive warning (bug) from clang.
76 // MY_COMPILER_CLANG_WORKAROUND_FALSE_POSITIVE_UNUSED_VARIABLE_WARNING
77 // documentation contains more details (e.g. specific bug-number from LLVM
78 // Bugzilla)
81 size_t nr_of_erase_events = kv_shard_stats.size() - nr_of_emplace_events;
83
84 DBUG_PRINT("temptable_api_sharded_kv_store",
85 ("shard_id=%u insertions=%zu removals=%zu", shard_id,
86 nr_of_emplace_events, nr_of_erase_events));
87 for (auto &stat : kv_shard_stats) {
89 "temptable_api_sharded_kv_store_debug",
90 ("shard_id=%u event=%d size=%zu bucket_count=%zu load_factor=%f "
91 "max_load_factor=%f "
92 "max_bucket_count=%zu thread_id=%s",
93 shard_id, static_cast<int>(stat.event), stat.size,
94 stat.bucket_count, stat.load_factor, stat.max_load_factor,
95 stat.max_bucket_count,
96 std_thread_id_to_str(stat.thread_id).c_str()));
97 }
98 shard_id++;
99 }
100 }
101};
102
103} // namespace temptable
104
105#endif /* TEMPTABLE_SHARDED_KV_STORE_LOGGER_H */
TempTable key-value store stats description.
#define MY_COMPILER_DIAGNOSTIC_PUSH()
save the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:285
#define MY_COMPILER_DIAGNOSTIC_POP()
restore the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:286
#define MY_COMPILER_CLANG_WORKAROUND_FALSE_POSITIVE_UNUSED_VARIABLE_WARNING()
ignore -Wunused-variable compiler warnings for @see @ref
Definition: my_compiler.h:356
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
Definition: allocator.h:45
void dbug_print()
DBUG_PRINT's the stats of each shard and additionally some further stats which are deduced from it,...
Definition: sharded_kv_store_logger.h:54
Default Sharded_key_value_store logging facility which turns to no-op in non-debug builds.
Definition: sharded_kv_store_logger.h:42
void dbug_print()
Definition: sharded_kv_store_logger.h:43
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510