MySQL 9.1.0
Source Code Documentation
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/kv_store_logger.h
25TempTable key-value store logger implementation. */
26
27#ifndef TEMPTABLE_KV_STORE_LOGGER_H
28#define TEMPTABLE_KV_STORE_LOGGER_H
29
30#include <thread>
31#include <vector>
32
33#include "my_dbug.h"
35
36namespace temptable {
37
38/** Default Key_value_store logging facility which turns to no-op in non-debug
39 * builds.
40 */
41template <typename T, bool DebugBuild>
43 protected:
45 // no-op
46 }
47 void dbug_print() {
48 // no-op
49 }
50};
51
52/** Key_value_store logging facility debug builds only. */
53template <typename T>
54class Key_value_store_logger<T, true> {
55 /** Container of stats that we will be collecting. */
56 std::vector<Key_value_store_stats> m_stats;
57
58 public:
59 /** Returns a snapshot of stats collected. To keep up with the thread-safety
60 * guarantee promise, snapshot must be made under the lock.
61 *
62 * @return Stats snapshot.
63 * */
64 std::vector<Key_value_store_stats> stats() {
65 auto &kv_store_lock = static_cast<T &>(*this).m_lock;
66 typename T::Exclusive_or_shared_lock lock(kv_store_lock);
67 return m_stats;
68 }
69
70 protected:
71 /** Appends a new entry to stats container with the given event.
72 *
73 * [in] event Type of event to be logged.
74 * */
76 const auto &kv_store = static_cast<T &>(*this).m_kv_store;
77 m_stats.push_back({event, kv_store.size(), kv_store.bucket_count(),
78 kv_store.load_factor(), kv_store.max_load_factor(),
79 kv_store.max_bucket_count(),
81 }
82
83 /** DBUG_PRINT's the stats of underlying key-value store implementation.
84 * */
85 void dbug_print() {
86 const auto &kv_store = static_cast<T &>(*this).m_kv_store;
88 "temptable_api_kv_store",
89 ("this=%p size=%zu; bucket_count=%zu load_factor=%f "
90 "max_load_factor=%f "
91 "max_bucket_count=%zu",
92 this, kv_store.size(), kv_store.bucket_count(), kv_store.load_factor(),
93 kv_store.max_load_factor(), kv_store.max_bucket_count()));
94 }
95};
96
97} // namespace temptable
98
99#endif /* TEMPTABLE_KV_STORE_LOGGER_H */
std::vector< Key_value_store_stats > m_stats
Container of stats that we will be collecting.
Definition: kv_store_logger.h:56
std::vector< Key_value_store_stats > stats()
Returns a snapshot of stats collected.
Definition: kv_store_logger.h:64
void log(Key_value_store_stats::Event event)
Appends a new entry to stats container with the given event.
Definition: kv_store_logger.h:75
void dbug_print()
DBUG_PRINT's the stats of underlying key-value store implementation.
Definition: kv_store_logger.h:85
Default Key_value_store logging facility which turns to no-op in non-debug builds.
Definition: kv_store_logger.h:42
void dbug_print()
Definition: kv_store_logger.h:47
void log(Key_value_store_stats::Event)
Definition: kv_store_logger.h:44
TempTable key-value store stats description.
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
pid_type get_id()
Definition: process.h:48
Definition: allocator.h:48
static std::mutex lock
Definition: net_ns.cc:56
required string event
Definition: replication_group_member_actions.proto:32
Event
Definition: kv_store_stats.h:40