MySQL  8.0.19
Source Code Documentation
fsp0space.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2013, 2019, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/fsp0space.h
28  General shared tablespace implementation.
29 
30  Created 2013-7-26 by Kevin Lewis
31  *******************************************************/
32 
33 #ifndef fsp0space_h
34 #define fsp0space_h
35 
36 #include "fsp0file.h"
37 #include "fsp0fsp.h"
38 #include "fsp0types.h"
39 #include "univ.i"
40 #include "ut0new.h"
41 
42 #include <vector>
43 
44 /** Data structure that contains the information about shared tablespaces.
45 Currently this can be the system tablespace or a temporary table tablespace */
46 class Tablespace {
47  public:
48  typedef std::vector<Datafile, ut_allocator<Datafile>> files_t;
49 
50  /** Data file information - each Datafile can be accessed globally */
52 
54  : m_files(),
55  m_name(),
57  m_path(),
58  m_flags(),
60  /* No op */
61  }
62 
63  virtual ~Tablespace() {
64  shutdown();
65  ut_ad(m_files.empty());
67  if (m_name != NULL) {
68  ut_free(m_name);
69  m_name = NULL;
70  }
71  if (m_path != NULL) {
72  ut_free(m_path);
73  m_path = NULL;
74  }
75  }
76 
77  // Disable copying
78  Tablespace(const Tablespace &);
80 
81  /** Set tablespace name
82  @param[in] name tablespace name */
83  void set_name(const char *name) {
84  ut_ad(m_name == NULL);
86  ut_ad(m_name != NULL);
87  }
88 
89  /** Get tablespace name
90  @return tablespace name */
91  const char *name() const { return (m_name); }
92 
93  /** Set tablespace path and filename members.
94  @param[in] path where tablespace file(s) resides
95  @param[in] len length of the file path */
96  void set_path(const char *path, size_t len) {
97  ut_ad(m_path == NULL);
98  m_path = mem_strdupl(path, len);
99  ut_ad(m_path != NULL);
100 
102  }
103 
104  /** Set tablespace path and filename members.
105  @param[in] path where tablespace file(s) resides */
106  void set_path(const char *path) { set_path(path, strlen(path)); }
107 
108  /** Get tablespace path
109  @return tablespace path */
110  const char *path() const { return (m_path); }
111 
112  /** Set the space id of the tablespace
113  @param[in] space_id tablespace ID to set */
117  }
118 
119  /** Get the space id of the tablespace
120  @return m_space_id space id of the tablespace */
121  space_id_t space_id() const { return (m_space_id); }
122 
123  /** Set the tablespace flags
124  @param[in] fsp_flags tablespace flags */
125  void set_flags(uint32_t fsp_flags) {
126  ut_ad(fsp_flags_is_valid(fsp_flags));
127  m_flags = fsp_flags;
128  }
129 
130  /** Get the tablespace flags
131  @return m_flags tablespace flags */
132  uint32_t flags() const { return (m_flags); }
133 
134  /** Set Ignore Read Only Status for tablespace.
135  @param[in] read_only_status read only status indicator */
136  void set_ignore_read_only(bool read_only_status) {
137  m_ignore_read_only = read_only_status;
138  }
139 
140  /** Free the memory allocated by the Tablespace object */
141  void shutdown();
142 
143  /** @return the sum of the file sizes of each Datafile */
145  page_no_t sum = 0;
146 
147  for (files_t::const_iterator it = m_files.begin(); it != m_files.end();
148  ++it) {
149  sum += it->m_size;
150  }
151 
152  return (sum);
153  }
154 
155  /** Open or Create the data files if they do not exist.
156  @param[in] is_temp whether this is a temporary tablespace
157  @return DB_SUCCESS or error code */
158  dberr_t open_or_create(bool is_temp) MY_ATTRIBUTE((warn_unused_result));
159 
160  /** Delete all the data files. */
161  void delete_files();
162 
163  /** Check if two tablespaces have common data file names.
164  @param[in] other_space Tablespace to check against this.
165  @return true if they have the same data filenames and paths */
166  bool intersection(const Tablespace *other_space);
167 
168  /** Use the ADD DATAFILE path to create a Datafile object and add
169  it to the front of m_files. Parse the datafile path into a path
170  and a basename with extension 'ibd'. This datafile_path provided
171  may be an absolute or relative path, but it must end with the
172  extension .ibd and have a basename of at least 1 byte.
173 
174  Set tablespace m_path member and add a Datafile with the filename.
175  @param[in] datafile_added full path of the tablespace file. */
176  dberr_t add_datafile(const char *datafile_added);
177 
178  /* Return a pointer to the first Datafile for this Tablespace
179  @return pointer to the first Datafile for this Tablespace*/
181  ut_a(!m_files.empty());
182  return (&m_files.front());
183  }
184 
185  private:
186  /**
187  @param[in] filename Name to lookup in the data files.
188  @return true if the filename exists in the data files */
189  bool find(const char *filename);
190 
191  /** Note that the data file was found.
192  @param[in] file data file object */
193  void file_found(Datafile &file);
194 
195  /* DATA MEMBERS */
196 
197  /** Name of the tablespace. */
198  char *m_name;
199 
200  /** Tablespace ID */
202 
203  /** Path where tablespace files will reside, not including a filename.*/
204  char *m_path;
205 
206  /** Tablespace flags */
207  uint32_t m_flags;
208 
209  protected:
210  /** Ignore server read only configuration for this tablespace. */
212 };
213 
214 #endif /* fsp0space_h */
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
Tablespace::file_found
void file_found(Datafile &file)
Note that the data file was found.
Definition: fsp0space.cc:73
Tablespace
Data structure that contains the information about shared tablespaces.
Definition: fsp0space.h:46
NULL
#define NULL
Definition: types.h:55
ut_a
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:53
ut_ad
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
Tablespace::delete_files
void delete_files()
Delete all the data files.
Definition: fsp0space.cc:167
fsp0fsp.h
fsp_flags_is_valid
bool fsp_flags_is_valid(uint32_t flags)
Validate the tablespace flags.
Tablespace::m_space_id
space_id_t m_space_id
Tablespace ID.
Definition: fsp0space.h:201
fsp0types.h
Tablespace::set_path
void set_path(const char *path)
Set tablespace path and filename members.
Definition: fsp0space.h:106
dberr_t
dberr_t
Definition: db0err.h:38
Tablespace::flags
uint32_t flags() const
Get the tablespace flags.
Definition: fsp0space.h:132
Tablespace::set_space_id
void set_space_id(space_id_t space_id)
Set the space id of the tablespace.
Definition: fsp0space.h:114
Tablespace::find
bool find(const char *filename)
Find a filename in the list of Datafiles for a tablespace.
Definition: fsp0space.cc:154
Tablespace::name
const char * name() const
Get tablespace name.
Definition: fsp0space.h:91
Tablespace::intersection
bool intersection(const Tablespace *other_space)
Check if two tablespaces have common data file names.
Definition: fsp0space.cc:45
Tablespace::set_ignore_read_only
void set_ignore_read_only(bool read_only_status)
Set Ignore Read Only Status for tablespace.
Definition: fsp0space.h:136
Tablespace::m_ignore_read_only
bool m_ignore_read_only
Ignore server read only configuration for this tablespace.
Definition: fsp0space.h:211
Tablespace::m_name
char * m_name
Name of the tablespace.
Definition: fsp0space.h:198
Fil_path::normalize
static void normalize(std::string &path)
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\'...
Definition: fil0fil.h:667
Tablespace::m_flags
uint32_t m_flags
Tablespace flags.
Definition: fsp0space.h:207
Tablespace::operator=
Tablespace & operator=(const Tablespace &)
Tablespace::shutdown
void shutdown()
Free the memory allocated by the Tablespace object.
Definition: fsp0space.cc:59
fsp0file.h
Tablespace::get_sum_of_sizes
page_no_t get_sum_of_sizes() const
Definition: fsp0space.h:144
ut0new.h
Tablespace::add_datafile
dberr_t add_datafile(const char *datafile_added)
Use the ADD DATAFILE path to create a Datafile object and add it to the front of m_files.
Definition: fsp0space.cc:193
Tablespace::open_or_create
dberr_t open_or_create(bool is_temp)
Open or Create the data files if they do not exist.
Definition: fsp0space.cc:85
Tablespace::first_datafile
Datafile * first_datafile()
Definition: fsp0space.h:180
mem_strdup
UNIV_INLINE char * mem_strdup(const char *str)
Duplicates a NUL-terminated string.
Tablespace::m_files
files_t m_files
Data file information - each Datafile can be accessed globally.
Definition: fsp0space.h:51
Datafile
Data file control information.
Definition: fsp0file.h:72
mem_strdupl
UNIV_INLINE char * mem_strdupl(const char *str, ulint len)
Makes a NUL-terminated copy of a nonterminated string.
Tablespace::path
const char * path() const
Get tablespace path.
Definition: fsp0space.h:110
Tablespace::files_t
std::vector< Datafile, ut_allocator< Datafile > > files_t
Definition: fsp0space.h:48
Tablespace::set_flags
void set_flags(uint32_t fsp_flags)
Set the tablespace flags.
Definition: fsp0space.h:125
space_id_t
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
Tablespace::space_id
space_id_t space_id() const
Get the space id of the tablespace.
Definition: fsp0space.h:121
SPACE_UNKNOWN
constexpr space_id_t SPACE_UNKNOWN
Unknown space id.
Definition: fil0fil.h:890
Tablespace::m_path
char * m_path
Path where tablespace files will reside, not including a filename.
Definition: fsp0space.h:204
Tablespace::Tablespace
Tablespace()
Definition: fsp0space.h:53
Tablespace::set_name
void set_name(const char *name)
Set tablespace name.
Definition: fsp0space.h:83
ut_free
#define ut_free(ptr)
Definition: ut0new.h:1095
Tablespace::set_path
void set_path(const char *path, size_t len)
Set tablespace path and filename members.
Definition: fsp0space.h:96
Tablespace::~Tablespace
virtual ~Tablespace()
Definition: fsp0space.h:63
filename
const char * filename
Definition: pfs_example_component_population.cc:64
false
#define false
Definition: config_static.h:43