MySQL 8.4.1
Source Code Documentation
ha_mock.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PLUGIN_SECONDARY_ENGINE_MOCK_HA_MOCK_H_
25#define PLUGIN_SECONDARY_ENGINE_MOCK_HA_MOCK_H_
26
27#include "my_base.h"
28#include "sql/handler.h"
29#include "thr_lock.h"
30
31class THD;
32struct TABLE;
33struct TABLE_SHARE;
34
35namespace dd {
36class Table;
37}
38
39namespace mock {
40
41/**
42 * The MOCK storage engine is used for testing MySQL server functionality
43 * related to secondary storage engines.
44 *
45 * There are currently no secondary storage engines mature enough to be merged
46 * into mysql-trunk. Therefore, this bare-minimum storage engine, with no
47 * actual functionality and implementing only the absolutely necessary handler
48 * interfaces to allow setting it as a secondary engine of a table, was created
49 * to facilitate pushing MySQL server code changes to mysql-trunk with test
50 * coverage without depending on ongoing work of other storage engines.
51 *
52 * @note This mock storage engine does not support being set as a primary
53 * storage engine.
54 */
55class ha_mock : public handler {
56 public:
58
59 private:
60 int create(const char *, TABLE *, HA_CREATE_INFO *, dd::Table *) override {
62 }
63
64 int open(const char *name, int mode, unsigned int test_if_locked,
65 const dd::Table *table_def) override;
66
67 int close() override { return 0; }
68
69 int rnd_init(bool) override { return 0; }
70
71 int rnd_next(unsigned char *) override { return HA_ERR_END_OF_FILE; }
72
73 int rnd_pos(unsigned char *, unsigned char *) override {
75 }
76
77 int info(unsigned int) override;
78
79 ha_rows records_in_range(unsigned int index, key_range *min_key,
80 key_range *max_key) override;
81
82 void position(const unsigned char *) override {}
83
84 unsigned long index_flags(unsigned int, unsigned int, bool) const override;
85
87 thr_lock_type lock_type) override;
88
89 Table_flags table_flags() const override;
90
91 const char *table_type() const override { return "MOCK"; }
92
93 /**
94 * Load table into the secondary engine.
95 *
96 * @param[in] table - table to be loaded
97 * @param[out] skip_metadata_update - should the DD metadata be updated for
98 * the load of this table
99 * @return 0 if success
100 */
101 int load_table(const TABLE &table, bool *skip_metadata_update) override;
102
103 /**
104 * Unload the table from secondary engine
105 *
106 * @param[in] db_name database name
107 * @param[in] table_name table name
108 * @param[in] error_if_not_loaded - whether to report an error if the table is
109 * already not present in the secondary engine.
110 * @return 0 if success
111 */
112 int unload_table(const char *db_name, const char *table_name,
113 bool error_if_not_loaded) override;
114
116};
117
118} // namespace mock
119
120#endif // PLUGIN_SECONDARY_ENGINE_MOCK_HA_MOCK_H_
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:47
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4573
TABLE_SHARE * table_share
Definition: handler.h:4580
ulonglong Table_flags
Definition: handler.h:4577
TABLE * table
Definition: handler.h:4581
The MOCK storage engine is used for testing MySQL server functionality related to secondary storage e...
Definition: ha_mock.h:55
int rnd_init(bool) override
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
Definition: ha_mock.h:69
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_mock.h:91
int create(const char *, TABLE *, HA_CREATE_INFO *, dd::Table *) override
Create table (implementation).
Definition: ha_mock.h:60
int unload_table(const char *db_name, const char *table_name, bool error_if_not_loaded) override
Unload the table from secondary engine.
Definition: ha_mock.cc:222
THR_LOCK_DATA m_lock
Definition: ha_mock.h:115
int close() override
Definition: ha_mock.h:67
void position(const unsigned char *) override
Definition: ha_mock.h:82
int info(unsigned int) override
Definition: ha_mock.cc:161
int load_table(const TABLE &table, bool *skip_metadata_update) override
Load table into the secondary engine.
Definition: ha_mock.cc:209
int rnd_pos(unsigned char *, unsigned char *) override
Definition: ha_mock.h:73
ha_rows records_in_range(unsigned int index, key_range *min_key, key_range *max_key) override
Definition: ha_mock.cc:195
unsigned long index_flags(unsigned int, unsigned int, bool) const override
Definition: ha_mock.cc:177
Table_flags table_flags() const override
Definition: ha_mock.cc:171
ha_mock(handlerton *hton, TABLE_SHARE *table_share)
Definition: ha_mock.cc:146
int rnd_next(unsigned char *) override
Definition: ha_mock.h:71
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, thr_lock_type lock_type) override
Is not invoked for non-transactional temporary tables.
Definition: ha_mock.cc:201
int open(const char *name, int mode, unsigned int test_if_locked, const dd::Table *table_def) override
Definition: ha_mock.cc:149
A table definition from the master.
Definition: rpl_utility.h:248
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1141
#define HA_ERR_WRONG_COMMAND
Command not supported.
Definition: my_base.h:841
#define HA_ERR_END_OF_FILE
end in next/prev/first/last
Definition: my_base.h:853
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Definition: ha_mock.cc:144
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
mode
Definition: file_handle.h:61
case opt name
Definition: sslopt-case.h:29
Struct to hold information about the table that should be created.
Definition: handler.h:3202
This structure is shared between different table objects.
Definition: table.h:701
Definition: table.h:1406
Definition: thr_lock.h:124
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2734
Definition: my_base.h:1125
thr_lock_type
Definition: thr_lock.h:51