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