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