MySQL 8.0.39
Source Code Documentation
sdi_file.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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 DD__SDI_FILE_INCLUDED
25#define DD__SDI_FILE_INCLUDED
26
27#include <stddef.h>
28#include <utility>
29
31#include "prealloced_array.h" // Prealloced_array
32#include "sql/dd/impl/sdi.h" // dd::Sdi_type
33#include "sql/dd/object_id.h" // dd::Object_id
34#include "sql/dd/string_type.h" // dd::String_type
35
36class THD;
37struct handlerton;
39
40namespace dd {
41class Entity_object;
42class Schema;
43class Table;
44
45namespace sdi_file {
46/** Number of character (not bytes) of a tablename which will
47 contrubute to the sdi file name. The whole name is not needed as
48 the Object_id is added so that uniqueness is ensured */
49const size_t FILENAME_PREFIX_CHARS = 16;
50
51/** File name extension for sdi files. */
52const String_type EXT = ".sdi";
53
54/**
55 Formats an sdi filename according to the mysql conventions for an entity
56 name and schema name, where the schema may be "".
57
58 @param id object id if dd object
59 @param entity_name name (as returned by dd::Entity_object::name())
60 of dd object.
61 @param schema name of schema, or "" for schemaless entities (schemata).
62 @retval filename to use for sdi file
63 */
64String_type sdi_filename(Object_id id, const String_type &entity_name,
65 const String_type &schema);
66
67/**
68 Stores sdi for table in a file.
69
70 @param sdi json string to store
71 @param table dd object from which sdi was generated
72 @param schema object which table belongs to
73 @retval true if an error occurs
74 @retval false otherwise
75*/
76bool store_tbl_sdi(const Sdi_type &sdi, const dd::Table &table,
77 const dd::Schema &schema);
78
79/**
80 Remove a file name from the file system.
81
82 @param fname file name to remove from file system.
83 @retval true if an error occurs
84 @retval false otherwise
85*/
86bool remove(const String_type &fname);
87
88/**
89 Removes sdi file for a table.
90
91 @param table dd object for which to remove sdi
92 @param schema object which table belongs to
93 @retval true if an error occurs
94 @retval false otherwise
95*/
96bool drop_tbl_sdi(const dd::Table &table, const dd::Schema &schema);
97
98/**
99 Read an sdi file from disk and store in a buffer.
100
101 @param thd thread handle
102 @param fname path to sdi file to load
103 @param buf where to store file content
104 @retval true if an error occurs
105 @retval false otherwise
106*/
107bool load(THD *thd, const dd::String_type &fname, dd::String_type *buf);
108
109/**
110 Instantiation of std::pair to represent the full path to an sdi
111 file. Member first is the path, second is true if the path is inside
112 datadir, false otherwise.
113*/
114typedef std::pair<dd::String_type, bool> Path_type;
115
116/**
117 Typedef for container type to use as out-parameter when expanding
118 sdi file patterns into paths.
119*/
121
122/**
123 Expand an sdi filename pattern into the set of full paths that
124 match. The paths and a bool indicating if the path is inside data
125 dir is appended to the Paths_type collection provided as argument.
126
127 @param thd thread handle
128 @param pattern filenam pattern to expand
129 @param paths collection of expanded file paths
130 @retval true if an error occurs
131 @retval false otherwise
132*/
133bool expand_pattern(THD *thd, const MYSQL_LEX_STRING &pattern,
134 Paths_type *paths);
135
136/**
137 Check that the MYD and MYI files for table exists.
138
139 @param schema_name schema name
140 @param table_name table name
141 @retval true if an error occurs
142 @retval false otherwise
143 */
144bool check_data_files_exist(const dd::String_type &schema_name,
146} // namespace sdi_file
147} // namespace dd
148#endif // !DD__SDI_FILE_INCLUDED
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: schema.h:63
Definition: table.h:47
Definition: buf0block_hint.cc:30
borrowable::session_track::Schema< true > Schema
Definition: classic_protocol_session_track.h:277
bool drop_tbl_sdi(const dd::Table &table, const dd::Schema &schema)
Removes sdi file for a table.
Definition: sdi_file.cc:303
bool check_data_files_exist(const dd::String_type &schema_name, const dd::String_type &table_name)
Check that the MYD and MYI files for table exists.
Definition: sdi_file.cc:354
const size_t FILENAME_PREFIX_CHARS
Number of character (not bytes) of a tablename which will contrubute to the sdi file name.
Definition: sdi_file.h:49
bool load(THD *, const dd::String_type &fname, dd::String_type *buf)
Read an sdi file from disk and store in a buffer.
Definition: sdi_file.cc:308
String_type sdi_filename(Object_id id, const String_type &entity_name, const String_type &schema)
Formats an sdi filename according to the mysql conventions for an entity name and schema name,...
Definition: sdi_file.cc:252
bool remove(const String_type &fname)
Remove a file name from the file system.
Definition: sdi_file.cc:285
const String_type EXT
File name extension for sdi files.
Definition: sdi_file.h:52
Prealloced_array< Path_type, 3 > Paths_type
Typedef for container type to use as out-parameter when expanding sdi file patterns into paths.
Definition: sdi_file.h:120
bool store_tbl_sdi(const dd::Sdi_type &sdi, const dd::Table &table, const dd::Schema &schema)
Stores sdi for table in a file.
Definition: sdi_file.cc:279
std::pair< dd::String_type, bool > Path_type
Instantiation of std::pair to represent the full path to an sdi file.
Definition: sdi_file.h:114
bool expand_pattern(THD *thd, const LEX_STRING &pattern, Paths_type *paths)
Expand an sdi filename pattern into the set of full paths that match.
Definition: sdi_file.cc:340
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
unsigned long long Object_id
Definition: object_id.h:31
String_type Sdi_type
Definition: sdi.h:48
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
const char * table_name
Definition: rules_table_service.cc:56
Exposes SDI-related functionality to the rest of the dictionary code.
Definition: mysql_lex_string.h:40
Definition: mysql_lex_string.h:35
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622