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