MySQL 8.0.39
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 int load_table(const TABLE &table) override;
94
95 int unload_table(const char *db_name, const char *table_name,
96 bool error_if_not_loaded) override;
97
99};
100
101} // namespace mock
102
103#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:34
Definition: table.h:47
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4414
TABLE_SHARE * table_share
Definition: handler.h:4421
ulonglong Table_flags
Definition: handler.h:4418
TABLE * table
Definition: handler.h:4422
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 load_table(const TABLE &table) override
Loads a table into its defined secondary storage engine.
Definition: ha_mock.cc:203
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
Unloads a table from its defined secondary storage engine.
Definition: ha_mock.cc:215
THR_LOCK_DATA m_lock
Definition: ha_mock.h:98
int close() override
Definition: ha_mock.h:67
void position(const unsigned char *) override
Definition: ha_mock.h:82
int info(unsigned int) override
General method to gather info from handler.
Definition: ha_mock.cc:155
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
Find number of records in a range.
Definition: ha_mock.cc:189
unsigned long index_flags(unsigned int, unsigned int, bool) const override
Definition: ha_mock.cc:171
Table_flags table_flags() const override
Definition: ha_mock.cc:165
ha_mock(handlerton *hton, TABLE_SHARE *table_share)
Definition: ha_mock.cc:140
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:195
int open(const char *name, int mode, unsigned int test_if_locked, const dd::Table *table_def) override
Definition: ha_mock.cc:143
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:1140
#define HA_ERR_WRONG_COMMAND
Command not supported.
Definition: my_base.h:840
#define HA_ERR_END_OF_FILE
end in next/prev/first/last
Definition: my_base.h:852
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Definition: ha_mock.cc:138
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:60
case opt name
Definition: sslopt-case.h:33
Struct to hold information about the table that should be created.
Definition: handler.h:3045
This structure is shared between different table objects.
Definition: table.h:690
Definition: table.h:1399
Definition: thr_lock.h:124
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622
Definition: my_base.h:1124
thr_lock_type
Definition: thr_lock.h:51