MySQL 26.7.0
Source Code Documentation
fil0fil.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2026, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/fil0fil.h
29 The low-level file system
30
31 Created 10/25/1995 Heikki Tuuri
32 *******************************************************/
33
34#ifndef fil0fil_h
35#define fil0fil_h
36
37#include "univ.i"
38
39#include "dict0types.h"
41#include "fil0types.h"
42#include "mem0mem.h" /* mem_strdup */
43#include "page0size.h"
44#ifndef UNIV_HOTBACKUP
45#include "ibuf0types.h"
46#endif /* !UNIV_HOTBACKUP */
47#include "srv0srv.h"
48#include "srv0start.h"
49#include "ut0expected.h"
50#include "ut0new.h"
51
53#include "sql/dd/object_id.h"
54
55#include <atomic>
56#include <cstdint>
57#include <limits>
58#include <list>
59#include <optional>
60#include <span>
61#include <unordered_set>
62#include <variant>
63#include <vector>
64
65extern ulong srv_fast_shutdown;
66
67/** Maximum number of tablespaces to be scanned by a thread while scanning
68for available tablespaces during server startup. This is a hard maximum.
69If the number of files to be scanned is more than
70FIL_SCAN_MAX_TABLESPACES_PER_THREAD,
71then additional threads will be spawned to scan the additional files in
72parallel. */
74
75/** Maximum number of threads that will be used for scanning the tablespace
76files. This can be further adjusted depending on the number of available
77cores. */
78constexpr size_t FIL_SCAN_MAX_THREADS = 16;
79
80/** Number of threads per core. */
81constexpr size_t FIL_SCAN_THREADS_PER_CORE = 2;
82
83/** Calculate the number of threads that can be spawned to scan the given
84number of files taking into the consideration, number of cores available
85on the machine.
86@param[in] num_files Number of files to be scanned
87@return number of threads to be spawned for scanning the files */
88size_t fil_get_scan_threads(size_t num_files);
89
90/** This tablespace name is used internally during file discovery to open a
91general tablespace before the data dictionary is recovered and available. */
92static constexpr char general_space_name[] = "innodb_general";
93
94/** This tablespace name is used as the prefix for implicit undo tablespaces
95and during file discovery to open an undo tablespace before the DD is
96recovered and available. */
97static constexpr char undo_space_name[] = "innodb_undo";
98
99extern volatile bool recv_recovery_on;
100
101/** Initial size of an UNDO tablespace when it is created new
102or truncated under low load.
103page size | FSP_EXTENT_SIZE | Initial Size | Pages
104----------+------------------+--------------+-------
105 4 KB | 256 pages = 1 MB | 16 MB | 4096
106 8 KB | 128 pages = 1 MB | 16 MB | 2048
107 16 KB | 64 pages = 1 MB | 16 MB | 1024
108 32 KB | 64 pages = 2 MB | 16 MB | 512
109 64 KB | 64 pages = 4 MB | 16 MB | 256 */
110constexpr uint32_t UNDO_INITIAL_SIZE = 16 * 1024 * 1024;
111#define UNDO_INITIAL_SIZE_IN_PAGES \
112 os_offset_t { UNDO_INITIAL_SIZE / srv_page_size }
113
114#ifdef UNIV_HOTBACKUP
115#include <unordered_set>
116using Dir_set = std::unordered_set<std::string>;
117extern Dir_set rem_gen_ts_dirs;
118extern bool replay_in_datadir;
119#endif /* UNIV_HOTBACKUP */
120
121// Forward declaration
122struct trx_t;
123class page_id_t;
124
125using Filenames = std::vector<std::string, ut::allocator<std::string>>;
126using Space_ids = std::vector<space_id_t, ut::allocator<space_id_t>>;
127
128/** Value of fil_space_t::magic_n */
129constexpr size_t FIL_SPACE_MAGIC_N = 89472;
130
131/** Value of fil_node_t::magic_n */
132constexpr size_t FIL_NODE_MAGIC_N = 89389;
133
134/** Real paths of dirs directly under the MySQL datadir (symlinks resolved) */
136 public:
137 /** Build the set of dirs directly under the MySQL datadir.
138 @return set of real paths of dirs directly under MySQL datadir */
139 [[nodiscard]] static Dirs_in_datadir make();
140
141 /** Check whether a dir path matches with one of the dirs directly under the
142 MySQL datadir.
143 @param[in] discovered_dir directory path to check
144 @return true if discovered_dir resolves to a known schema directory */
145 [[nodiscard]] bool contains(const std::string &discovered_dir) const;
146
147 private:
148 using Dirs = std::unordered_set<std::string>;
149
150 /** Normalized paths of all dirs directly under the MySQL datadir. */
152};
153
154/** Result of comparing a path. */
155enum class Fil_state {
156 /** The path matches what was found during the scan. */
157 MATCHES,
158
159 /** No MLOG_FILE_DELETE record and the file could not be found. */
160 MISSING,
161
162 /** Space ID matches but the paths don't match. */
163 MOVED,
164
165 /** Space ID and paths match but dd_table data dir flag is false despite the
166 file being outside default data dir */
168
169 /** In case of error during comparison. */
171};
172
173class fil_space_t;
174
175/** Node of a tablespace encapsulating handle required for any IO operations on
176this node. */
178 public:
179 fil_node_t(fil_space_t *space, const char *name, uint32_t node_order,
180 bool is_raw, page_no_t size_in_pages, page_no_t max_pages,
181 uint32_t block_size)
182 : space(space),
184 m_order(node_order),
185 is_raw_disk(is_raw),
186 flush_size(size_in_pages),
187 init_size(size_in_pages),
188 m_max_size_in_pages(max_pages),
189 m_block_size(block_size),
190 m_cached_size_in_pages(size_in_pages) {}
191
193 : space(other.space),
194 name(other.name),
195 m_order(other.m_order),
197 flush_size(other.flush_size),
198 init_size(other.init_size),
203 magic_n(other.magic_n),
204 m_handle(std::move(other.m_handle)),
205 m_is_open(other.m_is_open),
212 ut_a(!m_is_open);
213 ut_a(!m_handle);
214 ut_a(!other.LRU.prev);
215 ut_a(!other.LRU.next);
216 other.name = nullptr;
217 }
218
220 if (name) {
221 ut::free(name);
222 }
223 }
224 using modification_counter_t = int64_t;
225
226 /** Returns true if the node can be closed. */
227 [[nodiscard]] bool can_be_closed() const;
228
229 /** Returns true if the node is fully flushed, that is it is flushed up to the
230 modification_counter. */
231 [[nodiscard]] bool is_flushed() const;
232
233 /** Sets node to flushed state without actually flushing it. */
234 void pretend_is_flushed();
235
236 /** Increment modification counter for this node. */
238
239 /** Determine if flush is needed for the node.
240 @return true if flush is needed, false otherwise */
241 [[nodiscard]] bool is_flush_needed() const;
242
243 /** Waits for any pending flushes.
244 @param[in] shard Reference to Fil_shard that will be used to release and
245 re-acquire mutex while we are waiting for the pending
246 flushes. */
247 void wait_for_all_flushes_to_finish(class Fil_shard &shard);
248
249 /** Assures the node will be flushed at least to m_modification_counter.
250 @param[in] shard Reference to Fil_shard that will be used to release and
251 re-acquire mutex while we are waiting for the pending
252 flushes. */
253 void flush(class Fil_shard &shard);
254
255 [[nodiscard]] bool needs_flushes_for_durability() const {
256 return m_is_open && m_handle->needs_flushes_for_durability();
257 }
258
259 /** Posts a synchronous READ or WRITE IO operation on the node.
260 It is blocking call and returns the status code of the IO operation.
261 @param[in] type IO request type, compression and encryption
262 information.
263 @param[in,out] buf A buffer where to store read data or from where
264 to write. Data from this buffer might be first
265 transformed before writing it. It must be aligned
266 in memory to OS block size (UNIV_SECTOR_SIZE).
267 Additionally, for reads, it must be aligned to
268 physical page size, too. The memory pointed is
269 managed by the caller and must remain valid until
270 the call returns.
271 @param[in] buffer_len Size of the buffer. It must not cross the node
272 boundary; It always has to be a multiply of OS
273 block size (UNIV_SECTOR_SIZE). In case of write of
274 an already compressed data, it is a length of the
275 compressed data buffer. Otherwise it should be
276 physical page size. Actual number of bytes
277 written can be smaller if the tablespace has
278 compression enabled and data was not compressed
279 already.
280 @param[in] page_no Page number where to read from or write into.
281 @return DB_SUCCESS on successful IO completion, otherwise error code */
282 [[nodiscard]] dberr_t post_io_sync(IORequest &type, byte *buf,
283 size_t buffer_len,
284 page_no_t page_no) const;
285
286#ifdef UNIV_LINUX
287 /** Posts a synchronous vectored WRITE IO operation on the node.
288 It is blocking call and returns the status code of the IO operation. This call
289 does write operation on group of pages which are not supposed to be encrypted
290 or compressed.
291 @param[in] buffers Buffers where pages to be written to storage
292 are present. Each buffer should be of physical
293 page size of tablespace. Each buffer must be
294 aligned in memory to OS block size
295 (UNIV_SECTOR_SIZE). These buffers are meant to
296 be written unencrypted and uncompressed. The
297 memory pointed is managed by the caller and
298 must remain valid until the call returns.
299 @param[in] first_page_number Offset page in the file storage where writing
300 starts */
301 [[nodiscard]] dberr_t write_pages(std::span<const byte *> buffers,
302 page_no_t first_page_number);
303#endif /* UNIV_LINUX */
304
305#ifndef UNIV_HOTBACKUP
306 /** Posts an asynchronous READ or WRITE IO operation on the node.
307 The operation may return error code immediately or DB_SUCCESS when the IO was
308 submitted for asynchronous completion. After the asynchronous IO is complete,
309 the `os_aio_handler` will return a reference to the current node, @p
310 callback value supplied, the @p type and status code for the
311 result of the IO operation.
312 @param[in] type IO request type, compression and encryption
313 information.
314 @param[in,out] buf A buffer where to store read data or from where
315 to write. Data from this buffer might be first
316 transformed before writing it. It must be aligned
317 in memory to OS block size (UNIV_SECTOR_SIZE).
318 Additionally, for reads, it must be aligned to
319 physical page size, too. The memory pointed is
320 managed by the caller and must remain valid until
321 the @p callback begins execution.
322 @param[in] buffer_len Size of the buffer. It must not cross the node
323 boundary; It always has to be a multiply of OS
324 block size (UNIV_SECTOR_SIZE). In case of write of
325 an already compressed data, it is a length of the
326 compressed data buffer. Otherwise it should be
327 physical page size. Actual number of bytes
328 written can be smaller if the tablespace has
329 compression enabled and data was not compressed
330 already.
331 @param[in] page_no Page number where to read from or write into.
332 @param[in] callback A callback to be called exactly once when the
333 result of this IO operation is known. It may be a
334 success if the read or write succeeded or a subset
335 of `dberr_t` errors if the write or read could not
336 be executed or if it failed. It can be called
337 synchronously in this thread before returning from
338 this method, or can be executed asynchronously
339 from another thread, when @p sync is false, before
340 or after this call returns.
341 @return DB_SUCCESS if IO was successfully posted, error code otherwise */
342 [[nodiscard]] dberr_t post_io_async(
343 IORequest &type, byte *buf, size_t buffer_len, page_no_t page_no,
344 std::function<void(dberr_t)> callback) const;
345#endif /* !UNIV_HOTBACKUP */
346
347 /** Returns true iff the node is currently opened and allows IO operations. */
348 [[nodiscard]] bool is_open() const { return m_is_open; }
349
350 /** Must the node be opened only for read only mode? Files can be opened for
351 read and write, unless the srv_read_only_mode is used. With srv_read_only_mode
352 all files are read-only, but the temporary tables, as they are not altering
353 the physical database data, they do not generate UNDO etc, so can be used even
354 in the read-only mode.*/
355 [[nodiscard]] bool is_read_only() const;
356
357 /** Opens the node for incoming IO operations. The node will be opened for
358 read-only if `is_read_only()` returns true, and for read-write otherwise.
359 @return true if node is successfully opened */
360 [[nodiscard]] bool open();
361
362 /** Closes the node, the IO operations will not be permitted. It is up to the
363 user to provide synchronization with open(), IO calls and wait for pending IO
364 operations to finish first before calling the `close`. */
365 void close();
366
367 /** Truncates the node. Sets the truncated node to have size of @p size bytes,
368 that are all zeroed.
369 @param[in] new_size_in_pages Size in pages to set the node size to after the
370 truncation. */
371 [[nodiscard]] bool truncate(page_no_t new_size_in_pages);
372
373 /** Makes the @p number_of_pages pages, starting with page number @p
374 first_page contain all zeros. This can be used to efficiently extend the node
375 size. It may be implemented more efficiently than actually writing buffers
376 with zeros.
377 @param[in] first_page ID of first page to be overwritten with zeros.
378 @param[in] number_of_pages Number of pages to overwrite with zeros. */
379 [[nodiscard]] dberr_t fill_range_with_zeros(page_no_t first_page,
380 page_no_t number_of_pages);
381
383
384 /* Get the block_size for the storage.
385 @return block_size of the storage. */
386 [[nodiscard]] size_t get_block_size() const { return m_block_size; }
387
388 /** Check if punch_hole is supported by storage.
389 @return true if punch hole is supported, false otherwise. */
390 [[nodiscard]] bool get_punch_hole() const { return m_punch_hole; }
392
393 /** tablespace containing this node */
395
396 /** file name; protected by Fil_shard::m_mutex and log_sys->mutex. */
397 char *name;
398
399 /** Number of the file in the tablespace's nodes list */
400 const size_t m_order;
401
402 /** whether the node actually is a raw device or disk partition */
403 const bool is_raw_disk;
404
405 /** @see m_cached_size_in_pages */
406 [[nodiscard]] page_no_t get_cached_size_in_pages() const {
408 }
409
410 /** In addition to updating @see m_cached_size_in_pages it also updates
411 the size of the fil_space_t it belongs to */
412 void set_cached_node_size(size_t new_pages_count_to_cache);
413
414 /** Size of the node when last flushed, used to force the flush when node
415 grows to keep the filesystem metadata synced when using O_DIRECT_NO_FSYNC */
417
418 /** initial size of the node in database pages;
419 FIL_IBD_FILE_INITIAL_SIZE by default */
421
422 /** maximum size of the node in database pages */
424
425 /** count of pending I/O's; is_open must be true if nonzero */
427
428 /** Set to true when the node is being flushed. */
430
431 /** Set to true when a node is being extended. */
433
434 /** link to the fil_system->LRU list (keeping track of open files) */
436
437 /** FIL_NODE_MAGIC_N */
439
440 private:
441 /** Determine if flush is needed.
442 @param[in] flush_upto expectation up to which flush is to be done
443 @return true if flush is not done up to flush_upto, false otherwise */
444 [[nodiscard]] bool is_flush_needed(modification_counter_t flush_upto) const;
445
446 /** Waits for the current flush (if any) to finish, unless the file is already
447 flushed up to flush_upto
448 @param[in] shard Reference to Fil_shard that will be used to release
449 and re-acquire mutex while we are waiting for the
450 current flush to finish.
451 @param[in] flush_upto Wait until current flush finished or until
452 m_flush_counter reached flush_upto */
454 modification_counter_t flush_upto);
455
456 /** Map error code returned from read/write APIs to dberr_t code.
457 @param[in] err error code returned from read/write APIs
458 @return corresponding dberr_t error code */
459 [[nodiscard]] static dberr_t map_status_io_to_db_err(
461
462 /** file handle (not null iff is_open) */
464
465 /** event that groups and serializes calls to fsync */
467
468 /** whether this node is open. */
469 bool m_is_open{false};
470
471 /** number of writes to the node since the system was started */
473
474 /** the m_modification_counter of the latest flush to disk */
476
477 /** number of threads waiting for chance to flush */
479
480 /** block size to use for punching holes */
481 const size_t m_block_size;
482
483 /** whether the file system of this node supports PUNCH HOLE */
484 bool m_punch_hole{false};
485
486 /** Size of the node in physical pages, excluding any partial last page.
487 The field is initialized with the fresh result of
488 Tablespace_nodes_interface::get_node_info(), and updated by InnoDB whenever
489 it is performing Fil_shard::space_truncate() or Fil_shard::space_extend(),
490 to match the desired size.
491 The size of the physical page is validated to flags in the tablespace header,
492 i.e. it is impossible to continue if size of the page declared in the header
493 doesn't match the expectation.
494 However, the number of pages declared in the header, and cached in the
495 m_fsp_cache.m_size_in_header, doesn't have to match m_cached_size_in_pages.
496 In other words:
497 1. m_fsp_cache.m_size_in_header matches what is in the header.
498 2. m_cached_size_in_pages matches what Tablespace_nodes_interface last said,
499 about the real length of the tablespace (until we extend the space, in which
500 case we increase m_cached_size_in_pages to match the new size and an answer
501 Tablespace_nodes_interface would give if we asked it). */
503};
504
505/** Tablespace or log data space */
507 public:
509 using Files = std::vector<fil_node_t, ut::allocator<fil_node_t>>;
510
511 fil_space_t();
512 ~fil_space_t();
513
514 /** @return true if the instance is queued for deletion. Guarantees the space
515 is not deleted as long as the fil_shard mutex is not released. */
516 [[nodiscard]] bool is_deleted() const;
517
518 /** @return true if the instance was not queued for deletion. It does not
519 guarantee it is not queued for deletion at the moment. */
520 [[nodiscard]] bool was_not_deleted() const;
521
522 /** Marks the space object for deletion. It will bump the space object version
523 and cause all pages in buffer pool that reference to the current space
524 object version to be stale and be freed on first encounter. */
525 void set_deleted();
526
527#ifndef UNIV_HOTBACKUP
528 /** Returns current version of the space object. It is being bumped when the
529 space is truncated or deleted. Guarantees the version returned is up to date
530 as long as fil_shard mutex is not released.*/
531 [[nodiscard]] uint32_t get_current_version() const;
532
533 /** Returns current version of the space object. It is being bumped when the
534 space is truncated or deleted. It does not guarantee the version is current
535 one.*/
536 [[nodiscard]] uint32_t get_recent_version() const;
537
538 /** Bumps the space object version and cause all pages in buffer pool that
539 reference the current space object version to be stale and be freed on
540 first encounter. */
541 void bump_version();
542
543 /** @return true if this space does not have any more references. Guarantees
544 the result only if true was returned. */
545 [[nodiscard]] bool has_no_references() const;
546
547 /** @return Current number of references to the space. This method
548 should be called only while shutting down the server. Only when there is no
549 background nor user session activity the returned value will be valid. */
550 [[nodiscard]] size_t get_reference_count() const;
551
552 /** Increment the page reference count. */
554 /* We assume space is protected from being removed either through
555 n_pending_ops or m_n_ref_count already bumped, OR MDL latch is
556 protecting it, OR it is a private space. Bumping the n_pending_ops
557 can be done only under fil shard mutex and stopping new bumps is also
558 done under this mutex */
559 const auto o = m_n_ref_count.fetch_add(1);
561 }
562
563 /** Decrement the page reference count. */
565 const auto o = m_n_ref_count.fetch_sub(1);
566 ut_a(o >= 1);
567 }
568#endif /* !UNIV_HOTBACKUP */
569
570#ifdef UNIV_DEBUG
571 /** Print the extent descriptor pages of this tablespace into
572 the given output stream.
573 @param[in] out the output stream.
574 @return the output stream. */
575 std::ostream &print_xdes_pages(std::ostream &out) const;
576
577 /** Print the extent descriptor pages of this tablespace into
578 the given file.
579 @param[in] filename the output file name. */
580 void print_xdes_pages(const char *filename) const;
581#endif /* UNIV_DEBUG */
582
583 /** Get the file node corresponding to the given page number of the
584 tablespace. Note that the size of nodes in tablespaces is rounded down to the
585 extend size.
586 @param[in,out] page_no Caller passes the page number within a tablespace.
587 After return, it contains the page number within
588 the returned file node. For tablespaces containing
589 only one file, the given page_no will not change.
590 @return The file node object if the file is found with the page_no, or it must
591 be opened to check if it contains page_no. `nullptr` if the file is not found
592 or does not contain the page. */
593 [[nodiscard]] fil_node_t *get_node_for_page_no(page_no_t &page_no) noexcept;
594
595 /** @overload fil_node_t *get_node_for_page_no(page_no_t &page_no) noexcept*/
596 [[nodiscard]] const fil_node_t *get_node_for_page_no(
597 page_no_t &page_no) const noexcept;
598
599#ifndef UNIV_HOTBACKUP
600 /** Checks if the space has encryption flag enabled in the tablespace flags or
601 @p validate is true. If not, it just returns `DB_SUCCESS`. Otherwise opens the
602 first node, reads the first page out of it, runs validation of data stored
603 inside the tablespace header against the data used to construct this object,
604 which should come from the DD, checks if the stored space version is correct.
605 It checks if re-encryption is needed if the default master key ID was used to
606 encrypt it.
607 @param[in] validate Should the validation of the space ID and flags be
608 performed? This is forced if the tablespace flags have
609 the encryption flag even if false is passed.
610 @param[in] old_space If specified, the space version checks will not be
611 performed. To be used for files from the MySQL Server 5.7
612 or older, during upgrade process only.
613 @param[out] needs_reencryption Is set to true if the tablespace re-encryption
614 is required to be performed after this call ends and the
615 space is added to the `fil` tablespaces mappings and
616 `fil_encryption_reencrypt` requires the space to be
617 present in these mappings.
618 @return DB_SUCCESS or error */
619 [[nodiscard]] dberr_t validate_to_dd(bool validate, bool old_space,
620 bool &needs_reencryption);
621#endif
622
623 /** Assures the FSP header of the tablespace is correct and fills the
624 FSP-related data cache. If the tablespace was already validated, does nothing.
625 The first node in the tablespace must be already opened and prevented from
626 being closed - it will be used to read the first page directly from the
627 storage of the first node. The file can be prevented from being closed by
628 calling `prepare_file_for_io()` on it or by having the shard's mutex. The page
629 will be read from the first node directly.
630 @return DB_SUCCESS or error */
631 [[nodiscard]] dberr_t validate_first_page();
632
633 /** Sets the validation flag to true. It should be called from places where we
634 are certain the space header is valid, like in case we just filled it in or
635 have just verified it is valid. */
637
638 /** Returns true iff the tablespace was already validated by checking the
639 content of the first page. */
640 [[nodiscard]] bool is_validated() const { return m_validated; }
641
643 using Flush_observers = std::vector<Observer *, ut::allocator<Observer *>>;
644
645 /** When the tablespace was extended last. */
647
648 /** Extend undo tablespaces by so many pages. */
650
651 /** When an undo tablespace has been initialized with required header pages,
652 that size is recorded here. Auto-truncation happens when the file size
653 becomes bigger than both this and srv_max_undo_log_size. */
655
656 /** Tablespace name */
657 char *name{};
658
659 /** Tablespace ID */
661
662 private:
663#ifndef UNIV_HOTBACKUP
664 /** All pages in the buffer pool that reference this fil_space_t instance with
665 version before this version can be lazily freed or reused as free pages.
666 They should be rejected if there is an attempt to write them to disk.
667
668 Writes to m_version are guarded by the exclusive MDL/table lock latches
669 acquired by the caller, as stated in docs. Note that the Fil_shard mutex seems
670 to be latched in 2 of 3 usages only, so is not really an alternative.
671
672 Existence of the space object during reads is assured during these operations:
673 1. when read by the buf_page_init_low on page read/creation - the caller must
674 have acquired shared MDL/table lock latches.
675 2. when read on buf_page_t::is_stale() on page access for a query or for purge
676 operation. The caller must have acquired shared MDL/table lock latches.
677 3. when read on buf_page_t::is_stale() on page access from LRU list, flush
678 list or whatever else. Here, the fact that the page has latched the space
679 using the reference counting system is what guards the space existence.
680
681 When reading the value for the page being created with buf_page_init_low we
682 have the MDL latches on table that is in tablespace or the tablespace alone,
683 so we won't be able to bump m_version until they are released, so we will
684 read the current value of the version. When reading the value for the page
685 validation with buf_page_t::is_stale(), we will either:
686 a) have the MDL latches required in at least S mode in case we need to be
687 certain if the page is stale, to use it in a query or in purge operation, or
688 b) in case we don't not have the MDL latches, we may read an outdated value.
689 This happens for pages that are seen during for example LRU or flush page
690 scans. These pages are not needed for the query itself. The read is to decide
691 if the page can be safely discarded. Reading incorrect value can lead to no
692 action being executed. Reading incorrect value can't lead to page being
693 incorrectly evicted.
694 */
695 std::atomic<uint32_t> m_version{};
696
697 /** Number of buf_page_t entries that point to this instance.
698
699 This field is guarded by the Fil_shard mutex and the "reference
700 count system". The reference count system here is allowing to take a "latch"
701 on the space by incrementing the reference count, and release it by
702 decrementing it.
703
704 The increments are possible from two places:
705 1. buf_page_init_low is covered by the existing MDL/table lock latches only
706 and the fact that the space it is using is a current version of the space
707 (the version itself is also guarded by these MDL/table lock latches). It
708 implicitly acquires the "reference count system" latch after this operation.
709 2. buf_page_t::buf_page_t(const buf_page_t&) copy constructor - increases the
710 value, but it assumes the page being copied from has "reference count system"
711 latch so the reference count is greater than 0 during this constructor call.
712
713 For decrementing the reference count is itself a latch allowing for the safe
714 decrement.
715
716 The value is checked for being 0 in Fil_shard::checkpoint under the Fil_shard
717 mutex, and only if the space is deleted.
718 Observing m_n_ref_count==0 might trigger freeing the object. No other thread
719 can be during the process of incrementing m_n_ref_count from 0 to 1 in
720 parallel to this check. This is impossible for following reasons. Recall the
721 only two places where we do increments listed above:
722 1. If the space is deleted, then MDL/table lock latches guarantee there are
723 no users that would be able to see it as the current version of space and thus
724 will not attempt to increase the reference value from 0.
725 2. The buf_page_t copy constructor can increase it, but it assumes the page
726 being copied from has "reference count system" latch so the reference count is
727 greater than 0 during this constructor call.
728
729 There is also an opposite race possible: while we check for ref count being
730 zero, another thread may be decrementing it in parallel, and we might miss
731 that if we check too soon. This is benign, as it will result in us not
732 reclaiming the memory we could (but not have to) free, and will return to the
733 check on next checkpoint.
734 */
735 std::atomic_size_t m_n_ref_count{};
736#endif /* !UNIV_HOTBACKUP */
737
738 /** true if the tablespace is marked for deletion. */
739 std::atomic_bool m_deleted{};
740
741 /** true if bulk operation is in progress. */
742 std::atomic_bool m_is_bulk{false};
743
744 /** true if bulk operation is in progress. */
745 std::atomic<uint64_t> m_bulk_extend_size;
746
747 public:
748 /** Begin bulk operation on the space.
749 @param[in] extend_size space extension size for bulk operation */
750 void begin_bulk_operation(uint64_t extend_size) {
751 m_is_bulk.store(true);
752 m_bulk_extend_size.store(extend_size);
753 }
754
755 /** End bulk operation on the space. */
756 void end_bulk_operation() { m_is_bulk.store(false); }
757
758 /** @return true, if bulk operation in progress. */
759 [[nodiscard]] bool is_bulk_operation_in_progress() const {
760 return m_is_bulk.load();
761 }
762
763 /** @return automatic extension size for space. */
764 [[nodiscard]] uint64_t get_auto_extend_size() const;
765
766 /** @return the limit on this space size (usually PAGE_MAX_NO) */
767 [[nodiscard]] page_no_t get_max_size_in_pages() const;
768
769 /** @return true if added space should be initialized while extending space.
770 */
771 [[nodiscard]] bool initialize_while_extending() const;
772
773 /** true if we want to rename the .ibd file of tablespace and
774 want to temporarily prevent other threads from opening the file that is being
775 renamed. */
777
778 /** Throttles writing to log a message about long waiting for file to perform
779 rename. */
781
782 /** We set this true when we start deleting a single-table
783 tablespace. When this is set following new ops are not allowed:
784 * read IO request
785 * ibuf merge
786 * file flush
787 Note that we can still possibly have new write operations because we
788 don't check this flag when doing flush batches. */
790
791#ifdef UNIV_DEBUG
792 /** Reference count for operations who want to skip redo log in
793 the file space in order to make fsp_space_modify_check pass. */
795#endif /* UNIV_DEBUG */
796
797 /** Purpose */
799
800 /** Files attached to this tablespace. Note: Only the system tablespace
801 can have multiple files, this is a legacy issue. */
803
804 /** Tablespace file size in pages; 0 if not known yet */
806
807 /** Returns true if the FSP-related cache is already filled in and valid. */
808 [[nodiscard]] bool is_fsp_cache_valid() const;
809
810 /** Ensures the FSP-related cache is filled in and valid upon this call
811 return. */
813
814 [[nodiscard]] page_no_t get_cached_fsp_size_in_header() const;
815
817
818 /** Length of the FSP_FREE list */
819 [[nodiscard]] uint32_t get_cached_fsp_free_len() const;
820
821 void set_cached_fsp_free_len(uint32_t new_free_len);
822
823 void inc_cached_fsp_free_len(uint32_t delta);
824
826
827 /** Contents of FSP_FREE_LIMIT */
828 [[nodiscard]] page_no_t get_cached_fsp_free_limit() const;
829
830 void set_cached_fsp_free_limit(page_no_t new_free_limit);
831
832 /** Fills the cache of the FSP-related data that is stored in the first page
833 of the tablespace header.
834 @param[in] first_page Pointer to buffer with the content of the first page.
835 The buffer must be at least the length of the smallest page possible. */
836 void fill_fsp_cache(const byte *first_page);
837
838 private:
839 /** Reads the specified page directly from the disk, without using `fil_io` or
840 Buffer Pool caching. Requires the page to be located in the first file and
841 requires this file to be already opened and prevented from being closed. The
842 file can be prevented from being closed by calling `prepare_file_for_io()` on
843 it or by having the shard's mutex.
844 The returned buffer's length is `page_size_t{flags}.physical()`.
845 @param[in] page_no Page number to read from the disk. */
847 page_no_t page_no) const;
848
849 /* Specifies once the tablespace was validated to have a correct header in the
850 first page. */
852
853 /** Structure to hold cached data for the FSP subsystem. */
854 struct fsp_cache {
855 /** FSP_SIZE in the tablespace header; */
857
858 /** Length of the FSP_FREE list */
859 uint32_t m_free_len{};
860
861 /** Contents of FSP_FREE_LIMIT */
863
864 /* Specifies if the cache was filled with valid data already. It will not be
865 filled during recovery until the tablespace pages are all recovered. */
868
869 public:
870 /** Autoextend size */
872
873 /** Tablespace flags; see fsp_flags_is_valid() and
874 page_size_t(ulint) (constructor).
875 This is protected by space->latch and tablespace MDL */
876 uint32_t flags{};
877
878 /** Number of reserved free extents for ongoing operations like
879 B-tree page split */
881
882 /** This is positive when flushing the tablespace to disk;
883 dropping of the tablespace is forbidden if this is positive */
885
886 /** This is positive when we have pending operations against this
887 tablespace. The pending operations can be ibuf merges or lock
888 validation code trying to read a block. Dropping of the tablespace
889 is forbidden if this is positive. Protected by Fil_shard::m_mutex. */
890 uint32_t n_pending_ops{};
891
892#ifndef UNIV_HOTBACKUP
893 /** Latch protecting the file space storage allocation */
895#endif /* !UNIV_HOTBACKUP */
896
897 /** List of spaces with at least one unflushed file we have
898 written to */
900
901 /** true if this space is currently in unflushed_spaces */
903
904 /** Compression algorithm */
906
907 /** Encryption metadata */
909
910 /** Encryption is in progress */
912
913 /** Flush lsn of header page. It is used only during recovery */
915
916 /** FIL_SPACE_MAGIC_N */
918
919 /** System tablespace */
921
922 /** Check if the tablespace is compressed.
923 @return true if compressed, false otherwise. */
924 [[nodiscard]] bool is_compressed() const noexcept {
926 }
927
928 /** Check if the tablespace is encrypted.
929 @return true if encrypted, false otherwise. */
930 [[nodiscard]] bool is_encrypted() const noexcept {
932 }
933
934 /** Check if the encryption details, like the encryption key, type and
935 other details, that are needed to carry out encryption are available.
936 @return true if encryption can be done, false otherwise. */
937 [[nodiscard]] bool can_encrypt() const noexcept {
939 }
940};
941
942/** Common InnoDB file extensions */
945 IBD = 1,
946 CFG = 2,
947 CFP = 3,
948 IBT = 4,
949 IBU = 5,
950 DWR = 6,
951 BWR = 7
953
954extern const char *dot_ext[];
955
956#define DOT_IBD dot_ext[IBD]
957#define DOT_CFG dot_ext[CFG]
958#define DOT_CFP dot_ext[CFP]
959#define DOT_IBT dot_ext[IBT]
960#define DOT_IBU dot_ext[IBU]
961#define DOT_DWR dot_ext[DWR]
962
963#ifdef _WIN32
964/* Initialization of m_abs_path() produces warning C4351:
965"new behavior: elements of array '...' will be default initialized."
966See https://msdn.microsoft.com/en-us/library/1ywe7hcy.aspx */
967#pragma warning(disable : 4351)
968#endif /* _WIN32 */
969
970/** Wrapper for a path to a directory that may or may not exist. */
971class Fil_path {
972 public:
973 /** schema '/' table separator */
974 static constexpr auto DB_SEPARATOR = '/';
975
976 /** OS specific path separator. */
977 static constexpr auto OS_SEPARATOR = OS_PATH_SEPARATOR;
978
979 /** Directory separators that are supported. */
980 static constexpr auto SEPARATOR = "\\/";
981#ifdef _WIN32
982 static constexpr auto DOT_SLASH = ".\\";
983 static constexpr auto DOT_DOT_SLASH = "..\\";
984 static constexpr auto SLASH_DOT_DOT_SLASH = "\\..\\";
985#else
986 static constexpr auto DOT_SLASH = "./";
987 static constexpr auto DOT_DOT_SLASH = "../";
988 static constexpr auto SLASH_DOT_DOT_SLASH = "/../";
989#endif /* _WIN32 */
990
991 /** Various types of file paths. */
993
994 /** Default constructor. Defaults to MySQL_datadir_path. */
995 Fil_path();
996
997 /** Constructor
998 @param[in] path Path, not necessarily NUL terminated
999 @param[in] len Length of path
1000 @param[in] normalize_path If false, it's the callers responsibility to
1001 ensure that the path is normalized. */
1002 explicit Fil_path(const char *path, size_t len, bool normalize_path = false);
1003
1004 /** Constructor
1005 @param[in] path Path, not necessarily NUL terminated
1006 @param[in] normalize_path If false, it's the callers responsibility to
1007 ensure that the path is normalized. */
1008 explicit Fil_path(const char *path, bool normalize_path = false);
1009
1010 /** Constructor
1011 @param[in] path pathname (may also include the file basename)
1012 @param[in] normalize_path If false, it's the callers responsibility to
1013 ensure that the path is normalized. */
1014 explicit Fil_path(const std::string &path, bool normalize_path = false);
1015
1016 /** Implicit type conversion
1017 @return pointer to m_path.c_str() */
1018 [[nodiscard]] operator const char *() const { return m_path.c_str(); }
1019
1020 /** Explicit type conversion
1021 @return pointer to m_path.c_str() */
1022 [[nodiscard]] const char *operator()() const { return m_path.c_str(); }
1023
1024 /** @return the value of m_path */
1025 [[nodiscard]] const std::string &path() const { return (m_path); }
1026
1027 /** @return the length of m_path */
1028 [[nodiscard]] size_t len() const { return (m_path.length()); }
1029
1030 /** Return the absolute path by value. If m_abs_path is null, calculate
1031 it and return it by value without trying to reset this const object.
1032 m_abs_path can be empty if the path did not exist when this object
1033 was constructed.
1034 @return the absolute path by value. */
1035 [[nodiscard]] const std::string abs_path() const {
1036 if (m_abs_path.empty()) {
1037 return (get_real_path(m_path));
1038 }
1039
1040 return (m_abs_path);
1041 }
1042
1043 /** @return the length of m_abs_path */
1044 [[nodiscard]] size_t abs_len() const { return (m_abs_path.length()); }
1045
1046 /** Determine if this path is equal to the other path.
1047 @param[in] other path to compare to
1048 @return true if the paths are the same */
1049 bool operator==(const Fil_path &other) const { return (is_same_as(other)); }
1050
1051 /** Check if m_path is the same as this other path.
1052 @param[in] other directory path to compare to
1053 @return true if m_path is the same as path */
1054 [[nodiscard]] bool is_same_as(const Fil_path &other) const;
1055
1056 /** Check if this path is the same as the other path.
1057 @param[in] other directory path to compare to
1058 @return true if this path is the same as the other path */
1059 [[nodiscard]] bool is_same_as(const std::string &other) const;
1060
1061 /** Get the absolute directory of this path */
1062 [[nodiscard]] Fil_path get_abs_directory() const;
1063
1064 /** Check if the directory to path is same as directory as the other path.
1065 @param[in] other directory path to compare to
1066 @return true if this path directory is the same as the other path directory */
1067 [[nodiscard]] bool is_dir_same_as(const Fil_path &other) const;
1068
1069 /** Check if two path strings are equal. Put them into Fil_path objects
1070 so that they can be compared correctly.
1071 @param[in] first first path to check
1072 @param[in] second socond path to check
1073 @return true if these two paths are the same */
1074 [[nodiscard]] static bool is_same_as(const std::string &first,
1075 const std::string &second) {
1076 if (first.empty() || second.empty()) {
1077 return (false);
1078 }
1079
1080 Fil_path first_path(first);
1081 std::string first_abs = first_path.abs_path();
1082 trim_separator(first_abs);
1083
1084 Fil_path second_path(second);
1085 std::string second_abs = second_path.abs_path();
1086 trim_separator(second_abs);
1087
1088 return (first_abs == second_abs);
1089 }
1090
1091 /** Splits the path into directory and file name parts.
1092 @param[in] path path to split
1093 @return [directory, file] for the path */
1094 [[nodiscard]] static std::pair<std::string, std::string> split(
1095 const std::string &path);
1096
1097 /** Check if m_path is the parent of the other path.
1098 @param[in] other path to compare to
1099 @return true if m_path is an ancestor of name */
1100 [[nodiscard]] bool is_ancestor(const Fil_path &other) const;
1101
1102 /** Check if this Fil_path is an ancestor of the other path.
1103 @param[in] other path to compare to
1104 @return true if this Fil_path is an ancestor of the other path */
1105 [[nodiscard]] bool is_ancestor(const std::string &other) const;
1106
1107 /** Check if the first path is an ancestor of the second.
1108 Do not assume that these paths have been converted to real paths
1109 and are ready to compare. If the two paths are the same
1110 we will return false.
1111 @param[in] first Parent path to check
1112 @param[in] second Descendent path to check
1113 @return true if the first path is an ancestor of the second */
1114 [[nodiscard]] static bool is_ancestor(const std::string &first,
1115 const std::string &second) {
1116 if (first.empty() || second.empty()) {
1117 return (false);
1118 }
1119
1120 Fil_path ancestor(first);
1121 Fil_path descendant(second);
1122
1123 return (ancestor.is_ancestor(descendant));
1124 }
1125
1126 /** @return true if m_path exists and is a directory. */
1127 [[nodiscard]] bool is_directory_and_exists() const;
1128
1129 /** This validation is only for ':'.
1130 @return true if the path is valid. */
1131 [[nodiscard]] bool is_valid() const;
1132
1133 /** Determine if m_path contains a circular section like "/anydir/../"
1134 Fil_path::normalize() must be run before this.
1135 @return true if a circular section if found, false if not */
1136 [[nodiscard]] bool is_circular() const;
1137
1138 /** Determine if the file or directory is considered HIDDEN.
1139 Most file systems identify the HIDDEN attribute by a '.' preceding the
1140 basename. On Windows, a HIDDEN path is identified by a file attribute.
1141 We will use the preceding '.' to indicate a HIDDEN attribute on ALL
1142 file systems so that InnoDB tablespaces and their directory structure
1143 remain portable.
1144 @param[in] path The full or relative path of a file or directory.
1145 @return true if the directory or path is HIDDEN. */
1146 static bool is_hidden(std::string path);
1147
1148#ifdef _WIN32
1149 /** Use the WIN32_FIND_DATA struncture to determine if the file or
1150 directory is HIDDEN. Consider a SYSTEM attribute also as an indicator
1151 that it is HIDDEN to InnoDB.
1152 @param[in] dirent A directory entry obtained from a call to FindFirstFile()
1153 or FindNextFile()
1154 @return true if the directory or path is HIDDEN. */
1155 static bool is_hidden(WIN32_FIND_DATA &dirent);
1156#endif /* WIN32 */
1157
1158 /** Remove quotes e.g., 'a;b' or "a;b" -> a;b.
1159 This will only remove the quotes if they are matching on the whole string.
1160 This will not work if each delimited string is quoted since this is called
1161 before the string is parsed.
1162 @return pathspec with the quotes stripped */
1163 static std::string remove_quotes(const char *pathspec) {
1164 std::string path(pathspec);
1165
1166 ut_ad(!path.empty());
1167
1168 if (path.size() >= 2 && ((path.front() == '\'' && path.back() == '\'') ||
1169 (path.front() == '"' && path.back() == '"'))) {
1170 path.erase(0, 1);
1171 path.erase(path.size() - 1);
1172 }
1173
1174 return (path);
1175 }
1176
1177 /** Determine if a path is a relative path or not.
1178 @param[in] path OS directory or file path to evaluate
1179 @retval true if the path is relative
1180 @retval false if the path is absolute or file_name_only */
1181 [[nodiscard]] static bool is_relative_path(const std::string &path) {
1182 return (type_of_path(path) == relative);
1183 }
1184
1185 /** @return true if the path is an absolute path. */
1186 [[nodiscard]] bool is_absolute_path() const {
1187 return (type_of_path(m_path) == absolute);
1188 }
1189
1190 /** Determine if a path is an absolute path or not.
1191 @param[in] path OS directory or file path to evaluate
1192 @retval true if the path is absolute
1193 @retval false if the path is relative or file_name_only */
1194 [[nodiscard]] static bool is_absolute_path(const std::string &path) {
1195 return (type_of_path(path) == absolute);
1196 }
1197
1198 /** Determine what type of path is provided.
1199 @param[in] path OS directory or file path to evaluate
1200 @return the type of filepath; 'absolute', 'relative',
1201 'file_name_only', or 'invalid' if the path is empty. */
1202 [[nodiscard]] static path_type type_of_path(const std::string &path) {
1203 if (path.empty()) {
1204 return (invalid);
1205 }
1206
1207 /* The most likely type is a file name only with no separators. */
1208 auto first_separator = path.find_first_of(SEPARATOR);
1209 if (first_separator == std::string::npos) {
1210 return (file_name_only);
1211 }
1212
1213 /* Any string that starts with an OS_SEPARATOR is
1214 an absolute path. This includes any OS and even
1215 paths like "\\Host\share" on Windows. */
1216 if (first_separator == 0) {
1217 return (absolute);
1218 }
1219
1220#ifdef _WIN32
1221 /* Windows may have an absolute path like 'A:\' */
1222 if (path.length() >= 3 && isalpha(path.at(0)) && path.at(1) == ':' &&
1223 (path.at(2) == '\\' || path.at(2) == '/')) {
1224 return (absolute);
1225 }
1226#endif /* _WIN32 */
1227
1228 /* Since it contains separators and is not an absolute path,
1229 it must be a relative path. */
1230 return (relative);
1231 }
1232
1233 /* Check if the path is prefixed with pattern.
1234 @return true if prefix matches */
1235 [[nodiscard]] static bool has_prefix(const std::string &path,
1236 const std::string prefix) {
1237 return (path.size() >= prefix.size() &&
1238 std::equal(prefix.begin(), prefix.end(), path.begin()));
1239 }
1240
1241 /** Normalize a directory path for the current OS:
1242 On Windows, we convert '/' to '\', else we convert '\' to '/'.
1243 @param[in,out] path Directory and file path */
1244 static void normalize(std::string &path) {
1245 for (auto &c : path) {
1246 if (c == OS_PATH_SEPARATOR_ALT) {
1247 c = OS_SEPARATOR;
1248 }
1249 }
1250 }
1251
1252 /** Normalize a directory path for the current OS:
1253 On Windows, we convert '/' to '\', else we convert '\' to '/'.
1254 @param[in,out] path A NUL terminated path */
1255 static void normalize(char *path) {
1256 for (auto ptr = path; *ptr; ++ptr) {
1257 if (*ptr == OS_PATH_SEPARATOR_ALT) {
1258 *ptr = OS_SEPARATOR;
1259 }
1260 }
1261 }
1262
1263 /** Convert a path string to lower case using the CHARSET my_charset_filename.
1264 @param[in,out] path Directory and file path */
1265 static void to_lower(std::string &path) {
1266 for (auto &c : path) {
1268 }
1269 }
1270
1271 /** @return true if the path exists and is a file . */
1272 [[nodiscard]] static os_file_type_t get_file_type(const std::string &path);
1273
1274 /** Get the real path for a directory or a file name. This path can be
1275 used to compare with another absolute path. It will be converted to
1276 lower case on case insensitive file systems and if it is a directory,
1277 it will end with a directory separator. The call to my_realpath() may
1278 fail on non-Windows platforms if the path does not exist. If so, the
1279 parameter 'force' determines what to return.
1280 @param[in] path directory or filename to convert to a real path
1281 @param[in] force if true and my_realpath() fails, use the path provided.
1282 if false and my_realpath() fails, return a null string.
1283 @return the absolute path prepared for making comparisons with other real
1284 paths. */
1285 [[nodiscard]] static std::string get_real_path(const std::string &path,
1286 bool force = true);
1287
1288 /** Get the basename of the file path. This is the file name without any
1289 directory separators. In other words, the file name after the last separator.
1290 @param[in] filepath The name of a file, optionally with a path. */
1291 [[nodiscard]] static std::string get_basename(const std::string &filepath);
1292
1293 /** Separate the portion of a directory path that exists and the portion that
1294 does not exist.
1295 @param[in] path Path to evaluate
1296 @param[in,out] ghost The portion of the path that does not exist.
1297 @return the existing portion of a path. */
1298 [[nodiscard]] static std::string get_existing_path(const std::string &path,
1299 std::string &ghost);
1300
1301 /** Check if the name is an undo tablespace name.
1302 @param[in] name Tablespace name
1303 @return true if it is an undo tablespace name */
1304 [[nodiscard]] static bool is_undo_tablespace_name(const std::string &name);
1305
1306 /** Check if the file has the specified suffix
1307 @param[in] sfx suffix to look for
1308 @param[in] path Filename to check
1309 @return true if it has the ".ibd" suffix. */
1310 static bool has_suffix(ib_file_suffix sfx, const std::string &path) {
1311 const auto suffix = dot_ext[sfx];
1312 size_t len = strlen(suffix);
1313
1314 return (path.size() >= len &&
1315 path.compare(path.size() - len, len, suffix) == 0);
1316 }
1317
1318 /** Check if the file has the specified suffix and truncate
1319 @param[in] sfx suffix to look for
1320 @param[in,out] path Filename to check
1321 @return true if the suffix is found and truncated. */
1322 static bool truncate_suffix(ib_file_suffix sfx, std::string &path) {
1323 const auto suffix = dot_ext[sfx];
1324 size_t len = strlen(suffix);
1325
1326 if (path.size() < len ||
1327 path.compare(path.size() - len, len, suffix) != 0) {
1328 return (false);
1329 }
1330
1331 path.resize(path.size() - len);
1332 return (true);
1333 }
1334
1335 /** Check if a character is a path separator ('\' or '/')
1336 @param[in] c Character to check
1337 @return true if it is a separator */
1338 static bool is_separator(char c) { return (c == '\\' || c == '/'); }
1339
1340 /** If the last character of a directory path is a separator ('\' or '/')
1341 trim it off the string.
1342 @param[in] path file system path */
1343 static void trim_separator(std::string &path) {
1344 if (!path.empty() && is_separator(path.back())) {
1345 path.resize(path.size() - 1);
1346 }
1347 }
1348
1349 /** If the last character of a directory path is NOT a separator,
1350 append a separator to the path.
1351 NOTE: We leave it up to the caller to assure that the path is a directory
1352 and not a file since if that directory does not yet exist, this function
1353 cannot tell the difference.
1354 @param[in] path file system path */
1355 static void append_separator(std::string &path) {
1356 if (!path.empty() && !is_separator(path.back())) {
1357 path.push_back(OS_SEPARATOR);
1358 }
1359 }
1360
1361 /** Allocate and build a file name from a path, a table or
1362 tablespace name and a suffix.
1363 @param[in] path_in nullptr or the directory path or
1364 the full path and filename
1365 @param[in] name_in nullptr if path is full, or
1366 Table/Tablespace name
1367 @param[in] ext the file extension to use
1368 @param[in] trim whether last name on the path should
1369 be trimmed
1370 @return own: file name; must be freed by ut::free() */
1371 [[nodiscard]] static char *make(const std::string &path_in,
1372 const std::string &name_in,
1373 ib_file_suffix ext, bool trim = false);
1374
1375 /** Allocate and build a CFG file name from a path.
1376 @param[in] path_in Full path to the filename
1377 @return own: file name; must be freed by ut::free() */
1378 [[nodiscard]] static char *make_cfg(const std::string &path_in) {
1379 return (make(path_in, "", CFG));
1380 }
1381
1382 /** Allocate and build a CFP file name from a path.
1383 @param[in] path_in Full path to the filename
1384 @return own: file name; must be freed by ut::free() */
1385 [[nodiscard]] static char *make_cfp(const std::string &path_in) {
1386 return (make(path_in, "", CFP));
1387 }
1388
1389 /** Allocate and build a file name from a path, a table or
1390 tablespace name and a suffix.
1391 @param[in] path_in nullptr or the directory path or
1392 the full path and filename
1393 @param[in] name_in nullptr if path is full, or
1394 Table/Tablespace name
1395 @return own: file name; must be freed by ut::free() */
1396 [[nodiscard]] static char *make_ibd(const std::string &path_in,
1397 const std::string &name_in) {
1398 return (make(path_in, name_in, IBD));
1399 }
1400
1401 /** Allocate and build a file name from a path, a table or
1402 tablespace name and a suffix.
1403 @param[in] name_in Table/Tablespace name
1404 @return own: file name; must be freed by ut::free() */
1405 [[nodiscard]] static char *make_ibd_from_table_name(
1406 const std::string &name_in) {
1407 return (make("", name_in, IBD));
1408 }
1409
1410 /** Create an IBD path name after replacing the basename in an old path
1411 with a new basename. The old_path is a full path name including the
1412 extension. The tablename is in the normal form "schema/tablename".
1413 @param[in] path_in Pathname
1414 @param[in] name_in Contains new base name
1415 @param[in] extn File extension
1416 @return new full pathname */
1417 [[nodiscard]] static std::string make_new_path(const std::string &path_in,
1418 const std::string &name_in,
1419 ib_file_suffix extn);
1420
1421 /** Parse file-per-table file name and build Innodb dictionary table name.
1422 @param[in] file_path File name with complete path
1423 @param[in] extn File extension
1424 @param[out] dict_name Innodb dictionary table name
1425 @return true, if successful. */
1426 static bool parse_file_path(const std::string &file_path, ib_file_suffix extn,
1427 std::string &dict_name);
1428
1429 /** This function reduces a null-terminated full remote path name
1430 into the path that is sent by MySQL for DATA DIRECTORY clause.
1431 It replaces the 'databasename/tablename.ibd' found at the end of the
1432 path with just 'tablename'.
1433
1434 Since the result is always smaller than the path sent in, no new
1435 memory is allocated. The caller should allocate memory for the path
1436 sent in. This function manipulates that path in place. If the path
1437 format is not as expected, set data_dir_path to "" and return.
1438
1439 The result is used to inform a SHOW CREATE TABLE command.
1440 @param[in,out] data_dir_path Full path/data_dir_path */
1441 static void make_data_dir_path(char *data_dir_path);
1442
1443#ifndef UNIV_HOTBACKUP
1444 /** Check if the filepath provided is in a valid placement.
1445 This routine is run during file discovery at startup.
1446 1) File-per-table must be in a dir named for the schema.
1447 2) File-per-table must not be in the datadir.
1448 3) General tablespace must not be under the datadir.
1449 @param[in] space_name tablespace name
1450 @param[in] space_id tablespace ID
1451 @param[in] fsp_flags tablespace flags
1452 @param[in] path scanned realpath to an existing file to validate
1453 @retval true if the filepath is a valid datafile location */
1454 static bool is_valid_location(const char *space_name, space_id_t space_id,
1455 uint32_t fsp_flags, const std::string &path);
1456
1457 /** Check if the implicit filepath is immediately within a dir named for
1458 the schema.
1459 @param[in] space_name tablespace name
1460 @param[in] path scanned realpath to an existing file to validate
1461 @retval true if the filepath is valid */
1462 static bool is_valid_location_within_db(const char *space_name,
1463 const std::string &path);
1464
1465 /** Convert filename to the file system charset format.
1466 @param[in,out] name Filename to convert */
1467 static void convert_to_filename_charset(std::string &name);
1468
1469 /** Convert to lower case using the file system charset.
1470 @param[in,out] path Filepath to convert */
1471 static void convert_to_lower_case(std::string &path);
1472
1473#endif /* !UNIV_HOTBACKUP */
1474
1475 protected:
1476 /** Path to a file or directory. */
1477 std::string m_path;
1478
1479 /** A full absolute path to the same file. */
1480 std::string m_abs_path;
1481};
1482
1483/** The MySQL server --datadir value */
1485
1486/** The MySQL server --innodb-undo-directory value */
1488
1489/** The undo path is different from any other known directory. */
1490extern bool MySQL_undo_path_is_unique;
1491
1492/** Initial size of a single-table tablespace in pages */
1493constexpr size_t FIL_IBD_FILE_INITIAL_SIZE = 7;
1494constexpr size_t FIL_IBT_FILE_INITIAL_SIZE = 5;
1495
1496/** An empty tablespace (CREATE TABLESPACE) has minimum
1497of 4 pages and an empty CREATE TABLE (file_per_table) has 6 pages.
1498Minimum of these two is 4 */
1500
1501/** 'null' (undefined) page offset in the context of file spaces */
1503
1504/* Space address data type; this is intended to be used when
1505addresses accurate to a byte are stored in file pages. If the page part
1506of the address is FIL_NULL, the address is considered undefined. */
1507
1508/** 'type' definition in C: an address stored in a file page is a
1509string of bytes */
1511
1512/** File space address */
1514 /* Default constructor */
1516
1517 /** Constructor
1518 @param[in] p Logical page number
1519 @param[in] boff Offset within the page */
1520 fil_addr_t(page_no_t p, uint32_t boff) : page(p), boffset(boff) {}
1521
1522 /** Compare to instances
1523 @param[in] rhs Instance to compare with
1524 @return true if the page number and page offset are equal */
1525 bool is_equal(const fil_addr_t &rhs) const {
1526 return (page == rhs.page && boffset == rhs.boffset);
1527 }
1528
1529 /** Check if the file address is null.
1530 @return true if null */
1531 bool is_null() const { return (page == FIL_NULL && boffset == 0); }
1532
1533 /** Print a string representation.
1534 @param[in,out] out Stream to write to */
1535 std::ostream &print(std::ostream &out) const {
1536 out << "[fil_addr_t: page=" << page << ", boffset=" << boffset << "]";
1537
1538 return (out);
1539 }
1540
1541 /** Page number within a space */
1543
1544 /** Byte offset within the page */
1545 uint32_t boffset;
1546};
1547
1548/* For printing fil_addr_t to a stream.
1549@param[in,out] out Stream to write to
1550@param[in] obj fil_addr_t instance to write */
1551inline std::ostream &operator<<(std::ostream &out, const fil_addr_t &obj) {
1552 return (obj.print(out));
1553}
1554
1555/** The null file address */
1557
1558using page_type_t = uint16_t;
1559
1560/** File page types (values of FIL_PAGE_TYPE) @{ */
1561/** B-tree node */
1562constexpr page_type_t FIL_PAGE_INDEX = 17855;
1563
1564/** R-tree node */
1565constexpr page_type_t FIL_PAGE_RTREE = 17854;
1566
1567/** Tablespace SDI Index page */
1568constexpr page_type_t FIL_PAGE_SDI = 17853;
1569
1570/** This page type is unused. */
1572
1573/** Undo log page */
1575
1576/** Index node */
1578
1579/** Insert buffer free list */
1581
1582/* File page types introduced in MySQL/InnoDB 5.1.7 */
1583/** Freshly allocated page */
1585
1586/** Insert buffer bitmap */
1588
1589/** System page */
1591
1592/** Transaction system data */
1594
1595/** File space header */
1597
1598/** Extent descriptor page */
1600
1601/** Uncompressed BLOB page */
1603
1604/** First compressed BLOB page */
1606
1607/** Subsequent compressed BLOB page */
1609
1610/** In old tablespaces, garbage in FIL_PAGE_TYPE is replaced with
1611this value when flushing pages. */
1613
1614/** Compressed page */
1616
1617/** Encrypted page */
1619
1620/** Compressed and Encrypted page */
1622
1623/** Encrypted R-tree page */
1625
1626/** Uncompressed SDI BLOB page */
1628
1629/** Compressed SDI BLOB page */
1631
1632/** Legacy doublewrite buffer page. */
1634
1635/** Rollback Segment Array page */
1637
1638/** Index pages of uncompressed LOB */
1640
1641/** Data pages of uncompressed LOB */
1643
1644/** The first page of an uncompressed LOB */
1646
1647/** The first page of a compressed LOB */
1649
1650/** Data pages of compressed LOB */
1652
1653/** Index pages of compressed LOB. This page contains an array of
1654z_index_entry_t objects.*/
1656
1657/** Fragment pages of compressed LOB. */
1659
1660/** Index pages of fragment pages (compressed LOB). */
1662
1663/** Note the highest valid non-index page_type_t. */
1665
1666/** Check whether the page type is index (Btree or Rtree or SDI) type */
1667inline bool fil_page_type_is_index(page_type_t page_type) {
1668 return page_type == FIL_PAGE_INDEX || page_type == FIL_PAGE_SDI ||
1669 page_type == FIL_PAGE_RTREE;
1670}
1671
1672/** Get the file page type.
1673@param[in] page File page
1674@return page type */
1676 return (static_cast<page_type_t>(mach_read_from_2(page + FIL_PAGE_TYPE)));
1677}
1678
1679/** Check whether the page is index page (either regular Btree index or Rtree
1680index.
1681@param[in] page page frame whose page type is to be checked. */
1682inline bool fil_page_index_page_check(const byte *page) {
1684 const bool is_idx = fil_page_type_is_index(type);
1685 return is_idx;
1686}
1687
1688/** @} */
1689
1690/** Number of pending tablespace flushes */
1691extern std::atomic<std::uint64_t> fil_n_pending_tablespace_flushes;
1692
1693/** Number of files currently open */
1694extern std::atomic_size_t fil_n_files_open;
1695
1696/** Look up a tablespace.
1697The caller should hold an InnoDB table lock or a MDL that prevents
1698the tablespace from being dropped during the operation,
1699or the caller should be in single-threaded crash recovery mode
1700(no user connections that could drop tablespaces).
1701If this is not the case, fil_space_acquire() and fil_space_release()
1702should be used instead.
1703@param[in] space_id Tablespace ID
1704@return tablespace, or nullptr if not found */
1705[[nodiscard]] fil_space_t *fil_space_get(space_id_t space_id);
1706
1707#ifndef UNIV_HOTBACKUP
1708/** Returns the latch of a file space.
1709@param[in] space_id Tablespace ID
1710@return latch protecting storage allocation */
1711[[nodiscard]] rw_lock_t *fil_space_get_latch(space_id_t space_id);
1712
1713#ifdef UNIV_DEBUG
1714/** Gets the type of a file space.
1715@param[in] space_id Tablespace ID
1716@return file type */
1717[[nodiscard]] fil_type_t fil_space_get_type(space_id_t space_id);
1718#endif /* UNIV_DEBUG */
1719
1720/** Note that a tablespace has been imported.
1721It is initially marked as FIL_TYPE_IMPORT so that no logging is
1722done during the import process when the space ID is stamped to each page.
1723Now we change it to FIL_TYPE_TABLESPACE to start redo and undo logging.
1724NOTE: temporary tablespaces are never imported.
1725@param[in] space_id Tablespace ID */
1726void fil_space_set_imported(space_id_t space_id);
1727#endif /* !UNIV_HOTBACKUP */
1728
1729/** Attach a node to a tablespace.
1730@param[in] name file name (file must be closed)
1731@param[in,out] space space where to attach to. Must not be null.
1732@param[in] is_raw true if a raw device or a raw disk partition
1733@param[in] max_pages maximum number of pages in file */
1734void fil_node_create(const char *name, fil_space_t *space, bool is_raw,
1735 page_no_t max_pages);
1736
1737/** Create a space memory object and put it to the fil_system hash table.
1738The tablespace name is independent from the tablespace file-name.
1739Error messages are issued to the server log.
1740@param[in] name Tablespace name
1741@param[in] space_id Tablespace ID
1742@param[in] flags Tablespace flags
1743@param[in] purpose Tablespace purpose
1744@return pointer to created tablespace, to be filled in with fil_node_create()
1745@retval nullptr on failure (such as when the same tablespace exists) */
1746[[nodiscard]] fil_space_t *fil_space_create(const char *name,
1747 space_id_t space_id, uint32_t flags,
1748 fil_type_t purpose);
1749
1750/** Assigns a new space id for a new single-table tablespace. This works
1751simply by incrementing the global counter. If 4 billion id's is not enough,
1752we may need to recycle id's.
1753@param[out] space_id Set this to the new tablespace ID
1754@return true if assigned, false if not */
1755[[nodiscard]] bool fil_assign_new_space_id(space_id_t *space_id);
1756
1757/** Returns the path from the first fil_node_t found with this space ID.
1758The caller is responsible for freeing the memory allocated here for the
1759value returned.
1760@param[in] space_id Tablespace ID
1761@return own: A copy of fil_node_t::path, nullptr if space ID is zero
1762 or not found. */
1763[[nodiscard]] char *fil_space_get_first_path(space_id_t space_id);
1764
1765/** Returns the size of the space in pages. If the tablespace is not present
1766in the `fil` subsystem mappings, a value of 0 is returned.
1767@param[in] space_id Tablespace ID
1768@return space size, 0 if space not found */
1769[[nodiscard]] page_no_t fil_space_get_size(space_id_t space_id);
1770
1771/** Returns the size of an undo space just after it was initialized.
1772@param[in] space_id Tablespace ID
1773@return initial space size, 0 if space not found */
1775
1776/** This is called for an undo tablespace after it has been initialized
1777or opened. It sets the minimum size in pages at which it should be truncated
1778and the number of pages that it should be extended. An undo tablespace is
1779extended by larger amounts than normal tablespaces. It starts at 16Mb and
1780is increased during aggressive growth and decreased when the growth is slower.
1781@param[in] space_id Tablespace ID
1782@param[in] use_current If true, use the current size in pages as the initial
1783 size. If false, use UNDO_INITIAL_SIZE_IN_PAGES. */
1784void fil_space_set_undo_size(space_id_t space_id, bool use_current);
1785
1786/** Returns the flags of the space. The tablespace must be cached
1787in the memory cache.
1788@param[in] space_id Tablespace ID for which to get the flags
1789@return flags, ULINT_UNDEFINED if space not found */
1790[[nodiscard]] uint32_t fil_space_get_flags(space_id_t space_id);
1791
1792/** Sets the flags of the tablespace. The tablespace must be locked
1793in MDL_EXCLUSIVE MODE.
1794@param[in] space tablespace in-memory struct
1795@param[in] flags tablespace flags */
1796void fil_space_set_flags(fil_space_t *space, uint32_t flags);
1797
1798/** Looks up the tablespace, acquires the space, opens each node of a
1799tablespace if not already open, validates the first page if it was not
1800validated yet and fills the FSP-related cache if it was not filled yet. A
1801`fil_space_release()` needs to be called on the returned space.
1802@param[in] space_id Tablespace ID
1803@return The opened and acquired space object or an error if tablespace is
1804missing, being deleted, its nodes can't be opened or validation resulted in
1805errors. */
1807
1808/** Close each file of a tablespace if open.
1809@param[in] space_id Tablespace ID */
1810void fil_space_close(space_id_t space_id);
1811
1812/** Returns the page size of the space and whether it is compressed or not.
1813The tablespace must be cached in the memory cache.
1814@param[in] space_id Tablespace ID
1815@param[out] found true if tablespace was found
1816@return page size */
1817[[nodiscard]] const page_size_t fil_space_get_page_size(space_id_t space_id,
1818 bool *found);
1819
1820/** Initializes the tablespace memory cache.
1821@param[in] max_n_open Maximum number of open files */
1822void fil_init(ulint max_n_open);
1823
1824/** Changes the maximum opened files limit.
1825@param[in, out] new_max_open_files New value for the open files limit. If the
1826limit cannot be changed, the value is changed to a minimum value recommended.
1827@return true if the new limit was set. */
1828bool fil_open_files_limit_update(size_t &new_max_open_files);
1829
1830/** Initializes the tablespace memory cache. */
1831void fil_close();
1832
1833/** Closes all open files. There must not be any pending i/o's or not flushed
1834modifications in the files. */
1835void fil_close_all_files();
1836
1837/** Iterate over the files in all the tablespaces. */
1839 public:
1840 using Function = std::function<dberr_t(fil_node_t *)>;
1841
1842 /** For each data file.
1843 @param[in] f Callback */
1844 template <typename F>
1846 return iterate([=](fil_node_t *file) { return (f(file)); });
1847 }
1848
1849 /** Iterate through all persistent tablespace files (FIL_TYPE_TABLESPACE)
1850 returning the nodes via callback function f.
1851 @param[in] f Callback
1852 @return any error returned by the callback function. */
1853 static dberr_t iterate(Function &&f);
1854};
1855
1856/** Sets the max tablespace id counter if the given number is bigger than the
1857previous value.
1858@param[in] max_id Maximum known tablespace ID */
1860
1861#ifndef UNIV_HOTBACKUP
1862
1863/** Write the flushed LSN to the page header of the first page in the
1864system tablespace. Assumes the Buffer Pool is empty, or at least does not
1865contain the first page of the System Tablespace.
1866@param[in] lsn Flushed LSN
1867@return DB_SUCCESS or error number */
1868[[nodiscard]] dberr_t fil_write_flushed_lsn(lsn_t lsn);
1869
1870#else /* !UNIV_HOTBACKUP */
1871/** Frees a space object from the tablespace memory cache.
1872Closes a tablespaces' files but does not delete them.
1873There must not be any pending i/o's or flushes on the files.
1874@param[in] space_id Tablespace ID
1875@return true if success */
1876bool meb_fil_space_free(space_id_t space_id);
1877
1878/** Extends all tablespaces to the size stored in the space header. During the
1879mysqlbackup --apply-log phase we extended the spaces on-demand so that log
1880records could be applied, but that may have left spaces still too small
1881compared to the size stored in the space header. */
1882void meb_extend_tablespaces_to_stored_len();
1883
1884/** Process a file name passed as an input
1885@param[in] name absolute path of tablespace file
1886@param[in] space_id the tablespace ID */
1887void meb_fil_name_process(const char *name, space_id_t space_id);
1888
1889#endif /* !UNIV_HOTBACKUP */
1890
1891/** Acquire a tablespace when it could be dropped concurrently.
1892Used by background threads that do not necessarily hold proper locks
1893for concurrency control.
1894@param[in] space_id Tablespace ID
1895@return the tablespace, or nullptr if missing or being deleted */
1896[[nodiscard]] fil_space_t *fil_space_acquire(space_id_t space_id);
1897
1898/** Acquire a tablespace that may not exist.
1899Used by background threads that do not necessarily hold proper locks
1900for concurrency control.
1901@param[in] space_id Tablespace ID
1902@return the tablespace, or nullptr if missing or being deleted */
1903[[nodiscard]] fil_space_t *fil_space_acquire_silent(space_id_t space_id);
1904
1905/** Release a tablespace acquired with fil_space_acquire().
1906@param[in,out] space Tablespace to release */
1907void fil_space_release(fil_space_t *space);
1908
1909/** Fetch the file name opened for an undo space number from the file map.
1910@param[in] space_num Undo tablespace Number
1911@param[out] space_id Undo tablespace ID
1912@param[out] name the scanned filename
1913@return true if the space_num was found. The name is set to an
1914empty string if the space_num is not found. */
1916 space_id_t &space_id, std::string &name);
1917
1918/** Basically recreates the tablespace`s only node and set it to the needed
1919size in place. The content of the prefix up to new size is overwritten with
1920zeros.
1921@param[in] space_id Tablespace ID to truncate
1922@param[in] size_in_pages Truncate size.
1923@return true if truncate was successful. */
1924[[nodiscard]] bool fil_truncate_tablespace(space_id_t space_id,
1925 page_no_t size_in_pages);
1926
1927/** Closes a single-table tablespace. The tablespace must be cached in the
1928memory cache. Free all pages used by the tablespace.
1929@param[in] space_id Tablespace ID
1930@return DB_SUCCESS or error */
1931[[nodiscard]] dberr_t fil_close_tablespace(space_id_t space_id);
1932
1933/** Discards a single-table tablespace. The tablespace must be cached in the
1934memory cache. Discarding is like deleting a tablespace, but
1935
1936 1. We do not drop the table from the data dictionary;
1937
1938 2. We remove all insert buffer entries for the tablespace immediately;
1939 in DROP TABLE they are only removed gradually in the background;
1940
1941 3. When the user does IMPORT TABLESPACE, the tablespace will have the
1942 same id as it originally had.
1943
1944 4. Free all the pages in use by the tablespace if rename=true.
1945@param[in] space_id Tablespace ID
1946@return DB_SUCCESS or error */
1947[[nodiscard]] dberr_t fil_discard_tablespace(space_id_t space_id);
1948
1949/** Test if a tablespace file can be renamed to a new filepath by checking
1950if that the old filepath exists and the new filepath does not exist.
1951Any unexpected errors are reported as DB_ERROR.
1952@param[in] space_id Tablespace ID
1953@param[in] old_path Old filepath
1954@param[in] new_path New filepath
1955@param[in] is_discarded Whether the tablespace is discarded
1956@return innodb error code */
1957[[nodiscard]] dberr_t fil_rename_tablespace_check(space_id_t space_id,
1958 const char *old_path,
1959 const char *new_path,
1960 bool is_discarded);
1961
1962/** Rename a single-table tablespace.
1963The tablespace must exist in the memory cache.
1964@param[in] space_id Tablespace ID
1965@param[in] old_path Old file name
1966@param[in] new_name New tablespace name in the schema/name format
1967@param[in] new_path_in New file name, or nullptr if it is located in
1968 the normal data directory
1969@return InnoDB error code */
1970[[nodiscard]] dberr_t fil_rename_tablespace(space_id_t space_id,
1971 const char *old_path,
1972 const char *new_name,
1973 const char *new_path_in);
1974
1975/** Create an IBD tablespace file.
1976@param[in] space_id Tablespace ID
1977@param[in] name Tablespace name in dbname/tablename format.
1978 For general tablespaces, the 'dbname/' part
1979 may be missing.
1980@param[in] path Path and filename of the datafile to create.
1981@param[in] flags Tablespace flags
1982@param[in] size Initial size of the tablespace file in pages,
1983 must be >= FIL_IBD_FILE_INITIAL_SIZE
1984@return DB_SUCCESS or error code */
1985[[nodiscard]] dberr_t fil_ibd_create(space_id_t space_id, const char *name,
1986 const char *path, uint32_t flags,
1987 page_no_t size);
1988
1989/** Create a session temporary tablespace (IBT) file.
1990@param[in] space_id Tablespace ID
1991@param[in] name Tablespace name
1992@param[in] path Path and filename of the datafile to create.
1993@param[in] flags Tablespace flags
1994@param[in] size Initial size of the tablespace file in pages,
1995 must be >= FIL_IBT_FILE_INITIAL_SIZE
1996@return DB_SUCCESS or error code */
1997[[nodiscard]] dberr_t fil_ibt_create(space_id_t space_id, const char *name,
1998 const char *path, uint32_t flags,
1999 page_no_t size);
2000
2001/** Create an UNDO tablespace file.
2002@param[in] space_id Tablespace ID
2003@param[in] name Tablespace name in dbname/tablename format.
2004@param[in] path Path and filename of the datafile to create.
2005@param[in] flags Tablespace flags
2006@param[in] size Initial size of the tablespace file in pages,
2007 must be >= FIL_IBD_FILE_INITIAL_SIZE
2008@param[in] is_explicit Enabled if it is an explicit UNDO tablespace
2009@return DB_SUCCESS or error code */
2010[[nodiscard]] dberr_t fil_undo_create(space_id_t space_id, const char *name,
2011 const char *path, uint32_t flags,
2012 page_no_t size, bool is_explicit);
2013/** Deletes an IBD or IBU tablespace.
2014The tablespace must be cached in the memory cache. This will delete the
2015datafile, fil_space_t & fil_node_t entries from the file_system_t cache. The
2016pages of this space that are cached in the BufferPool will remain untouched,
2017will be discarded lazily when accessed or encountered in lists like flush list
2018or LRU, as they will be visible as being stale.
2019@param[in] space_id Tablespace ID
2020@return DB_SUCCESS, DB_TABLESPCE_NOT_FOUND or DB_IO_ERROR */
2021[[nodiscard]] dberr_t fil_delete_tablespace(space_id_t space_id);
2022
2023/** Open a single-table tablespace and optionally do some validation such
2024as checking that the space id is correct. If the file is already open,
2025the validation will be done before reporting success.
2026If not successful, print an error message to the error log.
2027This function is used to open a tablespace when we start up mysqld,
2028and also in IMPORT TABLESPACE.
2029NOTE that we assume this operation is used either at the database startup
2030or under the protection of the dictionary mutex, so that two users cannot
2031race here.
2032
2033The fil_node_t::handle will not be left open.
2034
2035@param[in] validate whether we should validate the tablespace
2036 (read the first page of the file and
2037 check that the space id in it matches id)
2038@param[in] purpose FIL_TYPE_TABLESPACE or FIL_TYPE_TEMPORARY
2039@param[in] space_id Tablespace ID
2040@param[in] flags tablespace flags
2041@param[in] space_name tablespace name of the datafile
2042 If file-per-table, it is the table name in the
2043 databasename/tablename format
2044@param[in] path_in expected filepath, usually read from dictionary
2045@param[in] strict whether to report error when open ibd failed
2046@param[in] old_space whether it is a 5.7 tablespace opening
2047 by upgrade
2048@return DB_SUCCESS or error code */
2049[[nodiscard]] dberr_t fil_ibd_open(bool validate, fil_type_t purpose,
2050 space_id_t space_id, uint32_t flags,
2051 const char *space_name, const char *path_in,
2052 bool strict, bool old_space);
2053
2054/** Returns true if a matching tablespace exists in the InnoDB tablespace
2055memory cache.
2056@param[in] space_id Tablespace ID
2057@param[in] name Tablespace name used in space_create().
2058@param[in] print_err Print detailed error information to the
2059 error log if a matching tablespace is
2060 not found from memory.
2061@param[in] adjust_space Whether to adjust space id on mismatch
2062@return true if a matching tablespace exists in the memory cache */
2063[[nodiscard]] bool fil_space_exists_in_mem(space_id_t space_id,
2064 const char *name, bool print_err,
2065 bool adjust_space);
2066
2067/** Extends all tablespaces to the size stored in the space header. During the
2068mysqlbackup --apply-log phase we extended the spaces on-demand so that log
2069records could be appllied, but that may have left spaces still too small
2070compared to the size stored in the space header. */
2072
2073/** Try to extend a tablespace if it is smaller than the specified size.
2074@param[in,out] space Tablespace ID
2075@param[in] size desired size in pages
2076@return whether the tablespace is at least as big as requested */
2077[[nodiscard]] bool fil_space_extend(fil_space_t *space, page_no_t size);
2078
2079/** Tries to reserve free extents in a file space.
2080@param[in] space_id Tablespace ID
2081@param[in] n_free_now Number of free extents now
2082@param[in] n_to_reserve How many one wants to reserve
2083@return true if succeed */
2084[[nodiscard]] bool fil_space_reserve_free_extents(space_id_t space_id,
2085 ulint n_free_now,
2086 ulint n_to_reserve);
2087
2088/** Releases free extents in a file space.
2089@param[in] space_id Tablespace ID
2090@param[in] n_reserved How many were reserved */
2091void fil_space_release_free_extents(space_id_t space_id, ulint n_reserved);
2092
2093/** Gets the number of reserved extents. If the database is silent, this
2094number should be zero.
2095@param[in] space_id Tablespace ID
2096@return the number of reserved extents */
2097[[nodiscard]] ulint fil_space_get_n_reserved_extents(space_id_t space_id);
2098
2099/** Read or write data for a single page from a file.
2100@param[in] type IO type
2101@param[in] sync If true then do synchronous IO
2102@param[in] page_id Page id to read or write.
2103@param[in] page_size Structure with information on logical and
2104 physical page size in the affected tablespace.
2105@param[in] len Size of the @p buf supplied. It always has to be
2106 a multiply of OS block size (UNIV_SECTOR_SIZE). In case of write of an already
2107 compressed data, it is a length of the compressed data buffer. Otherwise it
2108 should be `page_size.physical()`. Actual number of bytes written can be
2109 smaller if the tablespace has compression enabled and data was not compressed
2110 already.
2111@param[in,out] buf A buffer where to store read data or from where
2112 to write. Data from this buffer might be copied and the copy transformed
2113 before writing it. It must be aligned in memory to OS block size
2114 (UNIV_SECTOR_SIZE). Additionally, for reads, it must be aligned to physical
2115 page size, too. The memory pointed is managed by the caller and must remain
2116 valid until the call returns if @p sync is true, or until the @p
2117 postprocess_result callback begins execution.
2118@param[in] bpage Pointer to the page descriptor in the buffer
2119 pool. This can be nullptr only if we assure the tablespace can't be deleted in
2120 meantime. If this is nullptr, the page with this page_id can't be in the
2121 buffer pool, as it risks race condition with a Buffer Pool-induced page flush.
2122@param[in] evict_after_write
2123 Evicts the page after successful write. It is
2124 ignored if @p bpage is nullptr or if it is not a
2125 write request.
2126@param[in] pre_io_complete_callback
2127 A callback to be called exactly once when the
2128 result of this IO operation is known. It may be
2129 a success if the read or write succeeded or a
2130 subset of `dberr_t` errors if the write or read
2131 could not be executed or if it failed. It can be
2132 called synchronously in this thread before
2133 returning from this method, or can be executed
2134 asynchronously from another thread, when @p sync
2135 is false, before or after this call returns. The
2136 `buf_page_io_complete()` is called after this
2137 callback returns DB_SUCCESS and @p bpage is not
2138 null.
2139@return error code
2140@retval DB_SUCCESS on success
2141@retval DB_TABLESPACE_DELETED if the tablespace does not exist
2142Note: this is not an exhaustive list of errors returned.*/
2143[[nodiscard]] dberr_t fil_io(
2144 IORequest::Type type, bool sync, const page_id_t &page_id,
2145 const page_size_t &page_size, ulint len, byte *buf, buf_page_t *bpage,
2146 bool evict_after_write,
2147 std::function<void(dberr_t err)> pre_io_complete_callback = [](dberr_t) {});
2148
2149/** Waits for an AIO operation to complete. This function is used to write the
2150handler for completed requests. The aio array of pending requests is divided
2151into segments (see os0file.cc for more info). The thread specifies which
2152segment it wants to wait for.
2153@param[in] segment The number of the segment in the AIO array
2154 to wait for */
2155void fil_aio_wait(ulint segment);
2156
2157/** Flushes to disk possible writes cached by the OS. If the space does
2158not exist or is being dropped, does not do anything.
2159@param[in] space_id Tablespace ID */
2160void fil_flush(space_id_t space_id);
2161
2162/** Flush to disk the writes in file spaces possibly cached by the OS
2163(note: spaces of type FIL_TYPE_TEMPORARY are skipped) */
2165
2166#ifdef UNIV_DEBUG
2167/** Checks the consistency of the tablespace cache.
2168@return true if ok */
2169bool fil_validate();
2170#endif /* UNIV_DEBUG */
2171
2172/** Returns true if file address is undefined.
2173@param[in] addr File address to check
2174@return true if undefined */
2175[[nodiscard]] bool fil_addr_is_null(const fil_addr_t &addr);
2176
2177/** Get the predecessor of a file page.
2178@param[in] page File page
2179@return FIL_PAGE_PREV */
2180[[nodiscard]] page_no_t fil_page_get_prev(const byte *page);
2181
2182/** Get the successor of a file page.
2183@param[in] page File page
2184@return FIL_PAGE_NEXT */
2185[[nodiscard]] page_no_t fil_page_get_next(const byte *page);
2186
2187/** Sets the file page type.
2188@param[in,out] page File page
2189@param[in] type File page type to set */
2190void fil_page_set_type(byte *page, ulint type);
2191
2192/** Reset the page type.
2193Data files created before MySQL 5.1 may contain garbage in FIL_PAGE_TYPE.
2194In MySQL 3.23.53, only undo log pages and index pages were tagged.
2195Any other pages were written with uninitialized bytes in FIL_PAGE_TYPE.
2196@param[in] page_id Page number
2197@param[in,out] page Page with invalid FIL_PAGE_TYPE
2198@param[in] type Expected page type
2199@param[in,out] mtr Mini-transaction */
2200void fil_page_reset_type(const page_id_t &page_id, byte *page, ulint type,
2201 mtr_t *mtr);
2202
2203/** Check (and if needed, reset) the page type.
2204Data files created before MySQL 5.1 may contain
2205garbage in the FIL_PAGE_TYPE field.
2206In MySQL 3.23.53, only undo log pages and index pages were tagged.
2207Any other pages were written with uninitialized bytes in FIL_PAGE_TYPE.
2208@param[in] page_id Page number
2209@param[in,out] page Page with possibly invalid FIL_PAGE_TYPE
2210@param[in] type Expected page type
2211@param[in,out] mtr Mini-transaction */
2212inline void fil_page_check_type(const page_id_t &page_id, byte *page,
2213 ulint type, mtr_t *mtr) {
2214 ulint page_type = fil_page_get_type(page);
2215
2216 if (page_type != type) {
2217 fil_page_reset_type(page_id, page, type, mtr);
2218 }
2219}
2220
2221/** Check (and if needed, reset) the page type.
2222Data files created before MySQL 5.1 may contain
2223garbage in the FIL_PAGE_TYPE field.
2224In MySQL 3.23.53, only undo log pages and index pages were tagged.
2225Any other pages were written with uninitialized bytes in FIL_PAGE_TYPE.
2226@param[in,out] block Block with possibly invalid FIL_PAGE_TYPE
2227@param[in] type Expected page type
2228@param[in,out] mtr Mini-transaction */
2229#define fil_block_check_type(block, type, mtr) \
2230 fil_page_check_type(block->page.id, block->frame, type, mtr)
2231
2232#ifdef UNIV_DEBUG
2233/** Increase redo skipped count for a tablespace.
2234@param[in] space_id Tablespace ID */
2236
2237/** Decrease redo skipped count for a tablespace.
2238@param[in] space_id Tablespace ID */
2240
2241/** Check whether a single-table tablespace is redo skipped.
2242@param[in] space_id Tablespace ID
2243@return true if redo skipped */
2244[[nodiscard]] bool fil_space_is_redo_skipped(space_id_t space_id);
2245#endif /* UNIV_DEBUG */
2246
2247/** Callback functor. */
2249 /** Default constructor */
2251
2252 virtual ~PageCallback() UNIV_NOTHROW = default;
2253
2254 /** Called for page 0 in the tablespace file at the start.
2255 @param file_size size of the file in bytes
2256 @param block contents of the first page in the tablespace file
2257 @retval DB_SUCCESS or error code. */
2258 [[nodiscard]] virtual dberr_t init(os_offset_t file_size,
2259 const buf_block_t *block) UNIV_NOTHROW = 0;
2260
2261 /** Called for every page in the tablespace. If the page was not
2262 updated then its state must be set to BUF_PAGE_NOT_USED. For
2263 compressed tables the page descriptor memory will be at offset:
2264 block->frame + UNIV_PAGE_SIZE;
2265 @param offset physical offset within the file
2266 @param block block read from file, note it is not from the buffer pool
2267 @retval DB_SUCCESS or error code. */
2268 [[nodiscard]] virtual dberr_t operator()(os_offset_t offset,
2269 buf_block_t *block) UNIV_NOTHROW = 0;
2270
2271 /** Set the name of the physical file and the file handle that is used
2272 to open it for the file that is being iterated over.
2273 @param filename then physical name of the tablespace file.
2274 @param file OS file handle */
2276 m_file = file;
2278 }
2279
2280 /** @return the space id of the tablespace */
2281 [[nodiscard]] virtual space_id_t get_space_id() const UNIV_NOTHROW = 0;
2282
2283 /**
2284 @retval the space flags of the tablespace being iterated over */
2285 [[nodiscard]] virtual ulint get_space_flags() const UNIV_NOTHROW = 0;
2286
2287 /** Set the tablespace table size.
2288 @param[in] page a page belonging to the tablespace */
2290
2291 /** The compressed page size
2292 @return the compressed page size */
2293 [[nodiscard]] const page_size_t &get_page_size() const {
2294 return (m_page_size);
2295 }
2296
2297 /** The tablespace page size. */
2299
2300 /** File handle to the tablespace */
2302
2303 /** Physical file path. */
2304 const char *m_filepath;
2305
2306 // Disable copying
2308 PageCallback(const PageCallback &) = delete;
2310};
2311
2312/** Iterate over all the pages in the tablespace.
2313@param[in] encryption_metadata the encryption metadata to use for reading
2314@param[in] table the table definition in the server
2315@param[in] n_io_buffers number of blocks to read and write together
2316@param[in] compression_type compression type if compression is enabled,
2317else Compression::Type::NONE
2318@param[in,out] callback functor that will do the page updates
2319@return DB_SUCCESS or error code */
2320[[nodiscard]] dberr_t fil_tablespace_iterate(
2321 const Encryption_metadata &encryption_metadata, dict_table_t *table,
2322 ulint n_io_buffers, Compression::Type compression_type,
2323 PageCallback &callback);
2324
2325/** Looks for a pre-existing fil_space_t with the given tablespace ID
2326and, if found, returns the name and filepath in newly allocated buffers
2327that the caller must free.
2328@param[in] space_id The tablespace ID to search for.
2329@param[out] name Name of the tablespace found.
2330@param[out] filepath The filepath of the first datafile for the
2331tablespace.
2332@return true if tablespace is found, false if not. */
2333[[nodiscard]] bool fil_space_read_name_and_filepath(space_id_t space_id,
2334 std::string &name,
2335 std::string &filepath);
2336
2337/** Convert a file path to a tablespace name, based on space ID and its flags.
2338@param[in] file_path Full path to the tablespace file.
2339@param[in] space_id space_id emitted by the redo log
2340@param[in] flags FSP flags of the tablespace. */
2341[[nodiscard]] std::string fil_path_to_space_name(const std::string &file_path,
2342 space_id_t space_id,
2343 uint32_t flags);
2344
2345/** Convert a file name to a tablespace name. Strip the file name
2346prefix and suffix, leaving only databasename/tablename.
2347@param[in] filename directory/databasename/tablename.ibd
2348@return database/tablename string */
2349[[nodiscard]] std::string fil_path_to_space_name(std::string filename);
2350
2351/** Returns the space ID based on the tablespace name.
2352The tablespace must be found in the tablespace memory cache.
2353This call is made from external to this module, so the mutex is not owned.
2354@param[in] name Tablespace name
2355@return space ID if tablespace found, SPACE_UNKNOWN if space not. */
2356[[nodiscard]] space_id_t fil_space_get_id_by_name(const char *name);
2357
2358/** Check if swapping two .ibd files can be done without failure
2359@param[in] old_table old table
2360@param[in] new_table new table
2361@param[in] tmp_name temporary table name
2362@return innodb error code */
2363[[nodiscard]] dberr_t fil_rename_precheck(const dict_table_t *old_table,
2364 const dict_table_t *new_table,
2365 const char *tmp_name);
2366
2367/** Set the compression type for the tablespace
2368@param[in] space_id Space ID of the tablespace
2369@param[in] algorithm Text representation of the algorithm
2370@return DB_SUCCESS or error code */
2371[[nodiscard]] dberr_t fil_set_compression(space_id_t space_id,
2372 const char *algorithm);
2373
2374/** Get the compression algorithm for a tablespace.
2375@param[in] space_id Space ID to check
2376@return the compression algorithm */
2377[[nodiscard]] Compression::Type fil_get_compression(space_id_t space_id);
2378
2379/** Set encryption information for IORequest.
2380@param[in,out] req_type IO request
2381@param[in] page_id page id
2382@param[in] space table space */
2383void fil_io_set_encryption(IORequest &req_type, const page_id_t &page_id,
2384 fil_space_t *space);
2385
2386/** Set the encryption type for the tablespace
2387@param[in] space_id Space ID of tablespace for which to set
2388@param[in] algorithm Encryption algorithm
2389@param[in] key Encryption key
2390@param[in] iv Encryption iv
2391@return DB_SUCCESS or error code */
2392[[nodiscard]] dberr_t fil_set_encryption(space_id_t space_id,
2393 Encryption::Type algorithm, byte *key,
2394 byte *iv);
2395
2396/** Set the autoextend_size attribute for the tablespace
2397@param[in] space_id Space ID of tablespace for which to set
2398@param[in] autoextend_size Value of autoextend_size attribute
2399@return DB_SUCCESS or error code */
2400dberr_t fil_set_autoextend_size(space_id_t space_id, uint64_t autoextend_size);
2401
2402/** Reset the encryption type for the tablespace
2403@param[in] space_id Space ID of tablespace for which to set
2404@return DB_SUCCESS or error code */
2405[[nodiscard]] dberr_t fil_reset_encryption(space_id_t space_id);
2406
2407/** Rotate the tablespace keys by new master key.
2408@return the number of tablespaces that failed to rotate. */
2409[[nodiscard]] size_t fil_encryption_rotate();
2410
2411/** Re-encrypt the tablespace keys by current master key. */
2412void fil_encryption_reencrypt(const std::vector<space_id_t> &sid_vector);
2413
2414#ifdef UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH
2415void test_make_filepath();
2416#endif /* UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH */
2417
2418/** @return the system tablespace instance */
2421}
2422
2423/** Redo a tablespace create.
2424@param[in] ptr redo log record
2425@param[in] end end of the redo log buffer
2426@param[in] space_id Tablespace Id
2427@param[in] parse_only Don't apply, parse only
2428@return pointer to next redo log record
2429@retval nullptr if this log record was truncated */
2430[[nodiscard]] const byte *fil_tablespace_redo_create(const byte *ptr,
2431 const byte *end,
2432 space_id_t space_id,
2433 bool parse_only);
2434
2435/** TODO: This is a wrapper for fil_tablespace_redo_create to be called
2436during recovery, it uses tablespace_scanning to resolve tablespace file
2437path. The reason it exists is because we want to call
2438fil_tablespace_redo_create from read replica code, and tablespace_scanning
2439is not available in this case. OTOH, we have a special tablespace interface
2440implementation for read replica, and it needs to be investigated further,
2441how to hide these details behind the tablespace interface.
2442@param[in] ptr redo log record
2443@param[in] end end of the redo log buffer
2444@param[in] space_id Tablespace Id
2445@return pointer to next redo log record
2446@retval nullptr if this log record was truncated */
2447[[nodiscard]] const byte *fil_tablespace_redo_create_wrapper(
2448 const byte *ptr, const byte *end, space_id_t space_id);
2449
2450/** Redo a tablespace delete.
2451@param[in] ptr redo log record
2452@param[in] end end of the redo log buffer
2453@param[in] space_id Tablespace Id
2454@param[in] parse_only Don't apply, parse only
2455@return pointer to next redo log record
2456@retval nullptr if this log record was truncated */
2457[[nodiscard]] const byte *fil_tablespace_redo_delete(const byte *ptr,
2458 const byte *end,
2459 space_id_t space_id,
2460 bool parse_only);
2461
2462/** TODO: This is a wrapper for fil_tablespace_redo_delete to be called
2463during recovery, it uses tablespace_scanning to resolve tablespace file
2464path. The reason it exists is because we want to call
2465fil_tablespace_redo_delete from read replica code, and tablespace_scanning
2466is not available in this case. OTOH, we have a special tablespace interface
2467implementation for read replica, and it needs to be investigated further,
2468how to hide these details behind the tablespace interface.
2469@param[in] ptr redo log record
2470@param[in] end end of the redo log buffer
2471@param[in] space_id Tablespace Id
2472@return pointer to next redo log record
2473@retval nullptr if this log record was truncated */
2474[[nodiscard]] const byte *fil_tablespace_redo_delete_wrapper(
2475 const byte *ptr, const byte *end, space_id_t space_id);
2476
2477/** Redo a tablespace rename.
2478This function doesn't do anything, simply parses the redo log record.
2479@param[in] ptr redo log record
2480@param[in] end end of the redo log buffer
2481@param[in] space_id Tablespace Id
2482@param[in] parse_only Don't apply, parse only
2483@return pointer to next redo log record
2484@retval nullptr if this log record was truncated */
2485[[nodiscard]] const byte *fil_tablespace_redo_rename(const byte *ptr,
2486 const byte *end,
2487 space_id_t space_id,
2488 bool parse_only);
2489
2490/** Redo a tablespace extend. if parse_only is false, function expects
2491tablespace to be present in fil cache.
2492@param[in] ptr redo log record
2493@param[in] end end of the redo log buffer
2494@param[in] space_id Tablespace Id
2495@param[in] parse_only Don't apply the log if true
2496@return pointer to next redo log record
2497@retval nullptr if this log record was truncated */
2498[[nodiscard]] const byte *fil_tablespace_redo_extend(const byte *ptr,
2499 const byte *end,
2500 space_id_t space_id,
2501 bool parse_only);
2502
2503/** TODO: This is a wrapper for fil_tablespace_redo_extend to be called
2504during recovery, it makes sure tablespace is loaded in fil cache. The
2505reason it exists is because we want to call fil_tablespace_redo_extend
2506from read replica code, and loading tablespace for recovery does not make
2507any sense in this case. OTOH, we have a special tablespace interface
2508implementation for read replica, and it needs to be investigated further,
2509how to hide these details behind the tablespace interface.
2510@param[in] ptr redo log record
2511@param[in] end end of the redo log buffer
2512@param[in] space_id Tablespace Id
2513@return pointer to next redo log record
2514@retval nullptr if this log record was truncated */
2515[[nodiscard]] const byte *fil_tablespace_redo_extend_wrapper(
2516 const byte *ptr, const byte *end, space_id_t space_id);
2517
2518/** Parse and process an encryption redo record.
2519@param[in] ptr redo log record
2520@param[in] end end of the redo log buffer
2521@param[in] space_id the tablespace ID
2522@param[in] lsn lsn for REDO record
2523@return true to proceed for applying the log record,
2524otherwise skip applying it the log record. Empty optional
2525indicates some error in parsing the log record */
2526[[nodiscard]] std::optional<bool> fil_tablespace_redo_encryption(
2527 const byte *ptr, const byte *end, space_id_t space_id, lsn_t lsn);
2528
2529/** Lookup the tablespace ID.
2530@param[in] space_id Tablespace ID to lookup
2531@return true if the space ID is known. */
2532[[nodiscard]] bool fil_tablespace_lookup_for_recovery(space_id_t space_id);
2533
2534/** Add tablespace to the set of tablespaces to be updated in DD.
2535@param[in] dd_object_id Server DD tablespace ID
2536@param[in] space_id Innodb tablespace ID
2537@param[in] space_name New tablespace name
2538@param[in] old_path Old Path in the data dictionary
2539@param[in] new_path New path to be update in dictionary
2540@param[in] dd_flag_missing This tablespace is outside default data
2541 directory, yet it is missing
2542 DD_TABLE_DATA_DIRECTORY flag. This could
2543 happen in versions earlier than
2544 8.0.38/8.4.1/9.0.0 */
2545void fil_add_moved_space(dd::Object_id dd_object_id, space_id_t space_id,
2546 const char *space_name, const std::string &old_path,
2547 const std::string &new_path, bool dd_flag_missing);
2548
2549/** Lookups the tablespace ID in the scanned tablespaces and return its path to
2550the file. Compares the absolute base dir (absolute path without filename) of
2551found scanned path and one supplied as the path from DD for equality. For
2552example it will return path is matching for `./test/a.ibd` and `./test/b.ibd`.
2553@param[in] space_id tablespace ID to lookup
2554@param[in] space_name tablespace name
2555@param[in] fsp_flags tablespace flags
2556@param[in] dirs_in_datadir full paths for dirs directly under datadir
2557@param[in] old_path the path found in dd:Tablespace_files
2558@param[out] new_path the scanned path for this space_id
2559@return status of the match. */
2561 const space_id_t space_id, const char *space_name, const ulint fsp_flags,
2562 const Dirs_in_datadir &dirs_in_datadir, const std::string old_path,
2563 std::string &new_path);
2564
2565/** Open the tablespace and also get the tablespace filenames, space_id must
2566already be known.
2567@param[in] space_id Tablespace ID to lookup
2568@return DB_SUCCESS if open was successful */
2570
2571/** Replay a file rename operation for ddl replay.
2572@param[in] space_id Space ID
2573@param[in] old_name old file name
2574@param[in] new_name new file name
2575@return whether the operation was successfully applied
2576(the name did not exist, or new_name did not exist and
2577name was successfully renamed to new_name) */
2578[[nodiscard]] bool fil_op_replay_rename_for_ddl(space_id_t space_id,
2579 const char *old_name,
2580 const char *new_name);
2581
2582/** Free the Tablespace_files instance.
2583@param[in] read_only_mode true if InnoDB is started in read only mode.
2584@return DB_SUCCESS if all OK */
2585[[nodiscard]] dberr_t fil_open_for_business(bool read_only_mode);
2586
2587/** Rename a tablespace. Use the space_id to find the shard.
2588@param[in] space_id tablespace ID
2589@param[in] old_name old tablespace name
2590@param[in] new_name new tablespace name
2591@return DB_SUCCESS on success */
2592[[nodiscard]] dberr_t fil_rename_tablespace_by_id(space_id_t space_id,
2593 const char *old_name,
2594 const char *new_name);
2595
2596/** Write initial pages for a new tablespace file created. Caller of this
2597function should call fsync() to make the effect of this function durable.
2598@param[in] file open file handle
2599@param[in] path path and filename of the datafile
2600@param[in] encrypt_info encryption key information
2601@param[in] space_id tablespace ID
2602@param[in,out] space_flags tablespace flags
2603@return DB_SUCCESS on success */
2605 const char *path,
2606 const byte *encrypt_info,
2607 space_id_t space_id,
2608 uint32_t space_flags);
2609
2610/** Update the tablespace name. In case, the new name
2611and old name are same, no update done.
2612@param[in,out] space tablespace object on which name
2613 will be updated
2614@param[in] name new name for tablespace */
2615void fil_space_update_name(fil_space_t *space, const char *name);
2616
2617/** Adjust file name for import for partition files in different letter case.
2618@param[in] table Innodb dict table
2619@param[in] path file path to open
2620@param[in] extn file extension */
2622 ib_file_suffix extn);
2623
2624#ifndef UNIV_HOTBACKUP
2625
2626/** Write a log record about an operation on a tablespace file.
2627@param[in] type MLOG_FILE_OPEN or MLOG_FILE_DELETE
2628 or MLOG_FILE_CREATE or MLOG_FILE_RENAME
2629@param[in] space_id Tablespace identifier
2630@param[in] path File path
2631@param[in] new_path If type is MLOG_FILE_RENAME, the new name
2632@param[in] flags If type is MLOG_FILE_CREATE, the space flags
2633@param[in,out] mtr Mini-transaction */
2634void fil_op_write_log(mlog_id_t type, space_id_t space_id, const char *path,
2635 const char *new_path, uint32_t flags, mtr_t *mtr);
2636
2637/** Allows fil system to do periodical cleanup. */
2638void fil_purge();
2639
2640/** Count how many truncated undo space IDs are still tracked in
2641the buffer pool and the file_system cache.
2642@param[in] undo_num undo tablespace number.
2643@return number of undo tablespaces that are still in memory. */
2644size_t fil_count_undo_deleted(space_id_t undo_num);
2645
2646#endif /* !UNIV_HOTBACKUP */
2647
2648/** Get the page type as a string.
2649@param[in] type page type to be converted to string.
2650@return the page type as a string. */
2651[[nodiscard]] const char *fil_get_page_type_str(page_type_t type) noexcept;
2652
2653/** Check if the given page type is valid.
2654@param[in] type the page type to be checked for validity.
2655@return true if it is valid page type, false otherwise. */
2656[[nodiscard]] bool fil_is_page_type_valid(page_type_t type) noexcept;
2657
2659 fil_node_t **node_out);
2660void fil_complete_write(space_id_t space_id, fil_node_t *node);
2661
2662#endif /* fil0fil_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
uint32_t page_no_t
Page number.
Definition: api0api.h:47
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:62
Real paths of dirs directly under the MySQL datadir (symlinks resolved)
Definition: fil0fil.h:135
std::unordered_set< std::string > Dirs
Definition: fil0fil.h:148
static Dirs_in_datadir make()
Build the set of dirs directly under the MySQL datadir.
Definition: fil0fil.cc:9108
Dirs m_dirs
Normalized paths of all dirs directly under the MySQL datadir.
Definition: fil0fil.h:151
bool contains(const std::string &discovered_dir) const
Check whether a dir path matches with one of the dirs directly under the MySQL datadir.
Definition: fil0fil.cc:9131
Type
Algorithm types supported.
Definition: os0enc.h:57
Progress
Encryption progress type.
Definition: os0enc.h:80
Iterate over the files in all the tablespaces.
Definition: fil0fil.h:1838
std::function< dberr_t(fil_node_t *)> Function
Definition: fil0fil.h:1840
static dberr_t iterate(Function &&f)
Iterate through all persistent tablespace files (FIL_TYPE_TABLESPACE) returning the nodes via callbac...
Definition: fil0fil.cc:3645
static dberr_t for_each_file(F &&f)
For each data file.
Definition: fil0fil.h:1845
Wrapper for a path to a directory that may or may not exist.
Definition: fil0fil.h:971
bool is_ancestor(const Fil_path &other) const
Check if m_path is the parent of the other path.
Definition: fil0fil.cc:8475
size_t abs_len() const
Definition: fil0fil.h:1044
static void convert_to_filename_charset(std::string &name)
Convert filename to the file system charset format.
Definition: fil0fil.cc:10118
static bool is_same_as(const std::string &first, const std::string &second)
Check if two path strings are equal.
Definition: fil0fil.h:1074
static char * make_ibd_from_table_name(const std::string &name_in)
Allocate and build a file name from a path, a table or tablespace name and a suffix.
Definition: fil0fil.h:1405
path_type
Various types of file paths.
Definition: fil0fil.h:992
@ absolute
Definition: fil0fil.h:992
@ invalid
Definition: fil0fil.h:992
@ relative
Definition: fil0fil.h:992
@ file_name_only
Definition: fil0fil.h:992
bool operator==(const Fil_path &other) const
Determine if this path is equal to the other path.
Definition: fil0fil.h:1049
static char * make(const std::string &path_in, const std::string &name_in, ib_file_suffix ext, bool trim=false)
Allocate and build a file name from a path, a table or tablespace name and a suffix.
Definition: fil0fil.cc:4573
static bool is_ancestor(const std::string &first, const std::string &second)
Check if the first path is an ancestor of the second.
Definition: fil0fil.h:1114
static char * make_cfp(const std::string &path_in)
Allocate and build a CFP file name from a path.
Definition: fil0fil.h:1385
static constexpr auto SEPARATOR
Directory separators that are supported.
Definition: fil0fil.h:980
static constexpr auto DOT_SLASH
Definition: fil0fil.h:986
std::string m_path
Path to a file or directory.
Definition: fil0fil.h:1477
const char * operator()() const
Explicit type conversion.
Definition: fil0fil.h:1022
bool is_dir_same_as(const Fil_path &other) const
Check if the directory to path is same as directory as the other path.
Definition: fil0fil.cc:8465
static bool is_relative_path(const std::string &path)
Determine if a path is a relative path or not.
Definition: fil0fil.h:1181
static bool is_absolute_path(const std::string &path)
Determine if a path is an absolute path or not.
Definition: fil0fil.h:1194
static void convert_to_lower_case(std::string &path)
Convert to lower case using the file system charset.
Definition: fil0fil.cc:10135
static std::string get_basename(const std::string &filepath)
Get the basename of the file path.
Definition: fil0fil.cc:4045
bool is_same_as(const Fil_path &other) const
Check if m_path is the same as this other path.
Definition: fil0fil.cc:8435
const std::string abs_path() const
Return the absolute path by value.
Definition: fil0fil.h:1035
bool is_valid() const
This validation is only for ':'.
Definition: fil0fil.cc:8543
static std::string make_new_path(const std::string &path_in, const std::string &name_in, ib_file_suffix extn)
Create an IBD path name after replacing the basename in an old path with a new basename.
Definition: fil0fil.cc:4685
std::string m_abs_path
A full absolute path to the same file.
Definition: fil0fil.h:1480
static bool is_separator(char c)
Check if a character is a path separator ('\' or '/')
Definition: fil0fil.h:1338
static void append_separator(std::string &path)
If the last character of a directory path is NOT a separator, append a separator to the path.
Definition: fil0fil.h:1355
static bool is_valid_location_within_db(const char *space_name, const std::string &path)
Check if the implicit filepath is immediately within a dir named for the schema.
Definition: fil0fil.cc:10055
static constexpr auto SLASH_DOT_DOT_SLASH
Definition: fil0fil.h:988
static std::pair< std::string, std::string > split(const std::string &path)
Splits the path into directory and file name parts.
Definition: fil0fil.cc:8469
size_t len() const
Definition: fil0fil.h:1028
static char * make_cfg(const std::string &path_in)
Allocate and build a CFG file name from a path.
Definition: fil0fil.h:1378
static std::string remove_quotes(const char *pathspec)
Remove quotes e.g., 'a;b' or "a;b" -> a;b.
Definition: fil0fil.h:1163
Fil_path get_abs_directory() const
Get the absolute directory of this path.
Definition: fil0fil.cc:8459
static constexpr auto OS_SEPARATOR
OS specific path separator.
Definition: fil0fil.h:977
static bool is_valid_location(const char *space_name, space_id_t space_id, uint32_t fsp_flags, const std::string &path)
Check if the filepath provided is in a valid placement.
Definition: fil0fil.cc:10011
static bool is_undo_tablespace_name(const std::string &name)
Check if the name is an undo tablespace name.
Definition: fil0fil.cc:2026
static char * make_ibd(const std::string &path_in, const std::string &name_in)
Allocate and build a file name from a path, a table or tablespace name and a suffix.
Definition: fil0fil.h:1396
const std::string & path() const
Definition: fil0fil.h:1025
bool is_circular() const
Determine if m_path contains a circular section like "/anydir/../" Fil_path::normalize() must be run ...
Definition: fil0fil.cc:8567
bool is_directory_and_exists() const
Definition: fil0fil.cc:8537
static std::string get_real_path(const std::string &path, bool force=true)
Get the real path for a directory or a file name.
Definition: fil0fil.cc:3937
static bool is_hidden(std::string path)
Determine if the file or directory is considered HIDDEN.
Definition: fil0fil.cc:8506
bool is_absolute_path() const
Definition: fil0fil.h:1186
static constexpr auto DB_SEPARATOR
schema '/' table separator
Definition: fil0fil.h:974
static void make_data_dir_path(char *data_dir_path)
This function reduces a null-terminated full remote path name into the path that is sent by MySQL for...
Definition: fil0fil.cc:4724
static void normalize(char *path)
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\'...
Definition: fil0fil.h:1255
Fil_path()
Default constructor.
Definition: fil0fil.cc:8432
static os_file_type_t get_file_type(const std::string &path)
Definition: fil0fil.cc:8532
static bool truncate_suffix(ib_file_suffix sfx, std::string &path)
Check if the file has the specified suffix and truncate.
Definition: fil0fil.h:1322
static void to_lower(std::string &path)
Convert a path string to lower case using the CHARSET my_charset_filename.
Definition: fil0fil.h:1265
static bool parse_file_path(const std::string &file_path, ib_file_suffix extn, std::string &dict_name)
Parse file-per-table file name and build Innodb dictionary table name.
Definition: fil0fil.cc:4653
static path_type type_of_path(const std::string &path)
Determine what type of path is provided.
Definition: fil0fil.h:1202
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:1244
static std::string get_existing_path(const std::string &path, std::string &ghost)
Separate the portion of a directory path that exists and the portion that does not exist.
Definition: fil0fil.cc:3907
static void trim_separator(std::string &path)
If the last character of a directory path is a separator ('\' or '/') trim it off the string.
Definition: fil0fil.h:1343
static constexpr auto DOT_DOT_SLASH
Definition: fil0fil.h:987
static bool has_prefix(const std::string &path, const std::string prefix)
Definition: fil0fil.h:1235
static bool has_suffix(ib_file_suffix sfx, const std::string &path)
Check if the file has the specified suffix.
Definition: fil0fil.h:1310
Definition: fil0fil.cc:402
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:283
Types for AIO operations.
Definition: os0file.h:262
Type
Flags that can be used to specify the IORequest mode and additional options, to be used as bitmask ty...
Definition: os0file.h:266
A RAII wrapper for os_event_t.
Definition: os0event.h:137
Definition: buf0buf.h:1156
Node of a tablespace encapsulating handle required for any IO operations on this node.
Definition: fil0fil.h:177
static dberr_t map_status_io_to_db_err(ib::fil::Tablespace_node_handle_interface::Status_IO err)
Map error code returned from read/write APIs to dberr_t code.
Definition: fil0fil.cc:1648
bool m_punch_hole
whether the file system of this node supports PUNCH HOLE
Definition: fil0fil.h:484
fil_node_t(fil_space_t *space, const char *name, uint32_t node_order, bool is_raw, page_no_t size_in_pages, page_no_t max_pages, uint32_t block_size)
Definition: fil0fil.h:179
fil_space_t *const space
tablespace containing this node
Definition: fil0fil.h:394
void pretend_is_flushed()
Sets node to flushed state without actually flushing it.
Definition: fil0fil.cc:1448
size_t get_block_size() const
Definition: fil0fil.h:386
size_t n_pending_ios
count of pending I/O's; is_open must be true if nonzero
Definition: fil0fil.h:426
void increment_modification_counter()
Increment modification counter for this node.
Definition: fil0fil.cc:1454
void wait_for_current_flush_to_finish(class Fil_shard &shard, modification_counter_t flush_upto)
Waits for the current flush (if any) to finish, unless the file is already flushed up to flush_upto.
Definition: fil0fil.cc:1485
bool is_flush_needed() const
Determine if flush is needed for the node.
Definition: fil0fil.cc:1481
~fil_node_t()
Definition: fil0fil.h:219
bool needs_flushes_for_durability() const
Definition: fil0fil.h:255
modification_counter_t m_modification_counter
number of writes to the node since the system was started
Definition: fil0fil.h:472
const size_t m_order
Number of the file in the tablespace's nodes list.
Definition: fil0fil.h:400
bool get_punch_hole() const
Check if punch_hole is supported by storage.
Definition: fil0fil.h:390
page_no_t get_cached_size_in_pages() const
Definition: fil0fil.h:406
page_no_t init_size
initial size of the node in database pages; FIL_IBD_FILE_INITIAL_SIZE by default
Definition: fil0fil.h:420
void set_punch_hole(bool value)
Definition: fil0fil.h:391
bool m_is_open
whether this node is open.
Definition: fil0fil.h:469
bool is_flushed() const
Returns true if the node is fully flushed, that is it is flushed up to the modification_counter.
Definition: fil0fil.cc:1443
fil_node_t(fil_node_t &&other)
Definition: fil0fil.h:192
size_t m_n_threads_waiting_for_flush
number of threads waiting for chance to flush
Definition: fil0fil.h:478
bool truncate(page_no_t new_size_in_pages)
Truncates the node.
Definition: fil0fil.cc:1604
modification_counter_t m_flush_counter
the m_modification_counter of the latest flush to disk
Definition: fil0fil.h:475
bool m_is_being_flushed
Set to true when the node is being flushed.
Definition: fil0fil.h:429
Os_event_t m_flush_finished_event
event that groups and serializes calls to fsync
Definition: fil0fil.h:466
void flush(class Fil_shard &shard)
Assures the node will be flushed at least to m_modification_counter.
Definition: fil0fil.cc:1518
const size_t magic_n
FIL_NODE_MAGIC_N.
Definition: fil0fil.h:438
page_no_t m_cached_size_in_pages
Size of the node in physical pages, excluding any partial last page.
Definition: fil0fil.h:502
const page_no_t m_max_size_in_pages
maximum size of the node in database pages
Definition: fil0fil.h:423
const bool is_raw_disk
whether the node actually is a raw device or disk partition
Definition: fil0fil.h:403
page_no_t flush_size
Size of the node when last flushed, used to force the flush when node grows to keep the filesystem me...
Definition: fil0fil.h:416
const size_t m_block_size
block size to use for punching holes
Definition: fil0fil.h:481
bool can_be_closed() const
Returns true if the node can be closed.
Definition: fil0fil.cc:1422
dberr_t fill_range_with_zeros(page_no_t first_page, page_no_t number_of_pages)
Makes the number_of_pages pages, starting with page number first_page contain all zeros.
Definition: fil0fil.cc:1626
dberr_t post_io_async(IORequest &type, byte *buf, size_t buffer_len, page_no_t page_no, std::function< void(dberr_t)> callback) const
Posts an asynchronous READ or WRITE IO operation on the node.
Definition: fil0fil.cc:1708
bool is_open() const
Returns true iff the node is currently opened and allows IO operations.
Definition: fil0fil.h:348
UT_LIST_NODE_T(fil_node_t) List_node
Definition: fil0fil.h:382
void set_cached_node_size(size_t new_pages_count_to_cache)
In addition to updating.
Definition: fil0fil.cc:1742
void close()
Closes the node, the IO operations will not be permitted.
Definition: fil0fil.cc:1736
void wait_for_all_flushes_to_finish(class Fil_shard &shard)
Waits for any pending flushes.
Definition: fil0fil.cc:1500
bool open()
Opens the node for incoming IO operations.
Definition: fil0fil.cc:1589
bool is_read_only() const
Must the node be opened only for read only mode? Files can be opened for read and write,...
Definition: fil0fil.cc:1585
int64_t modification_counter_t
Definition: fil0fil.h:224
dberr_t post_io_sync(IORequest &type, byte *buf, size_t buffer_len, page_no_t page_no) const
Posts a synchronous READ or WRITE IO operation on the node.
Definition: fil0fil.cc:1676
ut::unique_ptr< ib::fil::Tablespace_node_handle_interface > m_handle
file handle (not null iff is_open)
Definition: fil0fil.h:463
List_node LRU
link to the fil_system->LRU list (keeping track of open files)
Definition: fil0fil.h:435
char * name
file name; protected by Fil_shard::m_mutex and log_sys->mutex.
Definition: fil0fil.h:397
bool is_being_extended
Set to true when a node is being extended.
Definition: fil0fil.h:432
Tablespace or log data space.
Definition: fil0fil.h:506
std::ostream & print_xdes_pages(std::ostream &out) const
Print the extent descriptor pages of this tablespace into the given output stream.
Definition: fil0fil.cc:8698
ib::Timer m_last_extended
When the tablespace was extended last.
Definition: fil0fil.h:646
size_t get_reference_count() const
Definition: fil0fil.cc:10324
space_id_t id
Tablespace ID.
Definition: fil0fil.h:660
bool is_compressed() const noexcept
Check if the tablespace is compressed.
Definition: fil0fil.h:924
Encryption::Progress encryption_op_in_progress
Encryption is in progress.
Definition: fil0fil.h:911
void set_cached_fsp_size_in_header(page_no_t new_size)
Definition: fil0fil.cc:2287
std::atomic_bool m_deleted
true if the tablespace is marked for deletion.
Definition: fil0fil.h:739
void bump_version()
Bumps the space object version and cause all pages in buffer pool that reference the current space ob...
Definition: fil0fil.cc:10346
List_node unflushed_spaces
List of spaces with at least one unflushed file we have written to.
Definition: fil0fil.h:899
dberr_t validate_to_dd(bool validate, bool old_space, bool &needs_reencryption)
Checks if the space has encryption flag enabled in the tablespace flags or validate is true.
Definition: fil0fil.cc:2353
page_no_t get_max_size_in_pages() const
Definition: fil0fil.cc:10387
rw_lock_t latch
Latch protecting the file space storage allocation.
Definition: fil0fil.h:894
bool m_validated
Definition: fil0fil.h:851
ib::Throttler m_prevent_file_open_wait_message_throttler
Throttles writing to log a message about long waiting for file to perform rename.
Definition: fil0fil.h:780
uint32_t flags
Tablespace flags; see fsp_flags_is_valid() and page_size_t(ulint) (constructor).
Definition: fil0fil.h:876
uint32_t get_cached_fsp_free_len() const
Length of the FSP_FREE list.
Definition: fil0fil.cc:2293
std::atomic< uint32_t > m_version
All pages in the buffer pool that reference this fil_space_t instance with version before this versio...
Definition: fil0fil.h:695
Encryption_metadata m_encryption_metadata
Encryption metadata.
Definition: fil0fil.h:908
bool prevent_file_open
true if we want to rename the .ibd file of tablespace and want to temporarily prevent other threads f...
Definition: fil0fil.h:776
page_no_t m_undo_extend
Extend undo tablespaces by so many pages.
Definition: fil0fil.h:649
uint64_t autoextend_size_in_bytes
Autoextend size.
Definition: fil0fil.h:871
dberr_t validate_first_page()
Assures the FSP header of the tablespace is correct and fills the FSP-related data cache.
Definition: fil0fil.cc:2455
fil_space_t()
Definition: fil0fil.cc:10241
void declare_first_page_valid()
Sets the validation flag to true.
Definition: fil0fil.h:636
lsn_t m_header_page_flush_lsn
Flush lsn of header page.
Definition: fil0fil.h:914
uint64_t get_auto_extend_size() const
Definition: fil0fil.cc:10395
void dec_ref() noexcept
Decrement the page reference count.
Definition: fil0fil.h:564
std::atomic_size_t m_n_ref_count
Number of buf_page_t entries that point to this instance.
Definition: fil0fil.h:735
page_no_t m_size_in_pages
Tablespace file size in pages; 0 if not known yet.
Definition: fil0fil.h:805
std::atomic< uint64_t > m_bulk_extend_size
true if bulk operation is in progress.
Definition: fil0fil.h:745
Files files
Files attached to this tablespace.
Definition: fil0fil.h:802
bool is_fsp_cache_valid() const
Returns true if the FSP-related cache is already filled in and valid.
Definition: fil0fil.cc:2268
bool stop_new_ops
We set this true when we start deleting a single-table tablespace.
Definition: fil0fil.h:789
ulint magic_n
FIL_SPACE_MAGIC_N.
Definition: fil0fil.h:917
bool initialize_while_extending() const
Definition: fil0fil.cc:10405
uint32_t n_reserved_extents
Number of reserved free extents for ongoing operations like B-tree page split.
Definition: fil0fil.h:880
bool can_encrypt() const noexcept
Check if the encryption details, like the encryption key, type and other details, that are needed to ...
Definition: fil0fil.h:937
ut::Expected< ut::unique_ptr_aligned< byte[]> > read_page_direct(page_no_t page_no) const
Reads the specified page directly from the disk, without using fil_io or Buffer Pool caching.
Definition: fil0fil.cc:2323
uint32_t get_current_version() const
Returns current version of the space object.
Definition: fil0fil.cc:10304
bool is_encrypted() const noexcept
Check if the tablespace is encrypted.
Definition: fil0fil.h:930
static fil_space_t * s_sys_space
System tablespace.
Definition: fil0fil.h:920
void dec_cached_fsp_free_len()
Definition: fil0fil.cc:2308
uint32_t n_pending_ops
This is positive when we have pending operations against this tablespace.
Definition: fil0fil.h:890
std::atomic_bool m_is_bulk
true if bulk operation is in progress.
Definition: fil0fil.h:742
UT_LIST_NODE_T(fil_space_t) List_node
Definition: fil0fil.h:508
~fil_space_t()
Definition: fil0fil.cc:10245
void ensure_fsp_cache_valid()
Ensures the FSP-related cache is filled in and valid upon this call return.
Definition: fil0fil.cc:2272
uint32_t get_recent_version() const
Returns current version of the space object.
Definition: fil0fil.cc:10308
char * name
Tablespace name.
Definition: fil0fil.h:657
bool is_validated() const
Returns true iff the tablespace was already validated by checking the content of the first page.
Definition: fil0fil.h:640
std::vector< Observer *, ut::allocator< Observer * > > Flush_observers
Definition: fil0fil.h:643
void end_bulk_operation()
End bulk operation on the space.
Definition: fil0fil.h:756
Compression::Type compression_type
Compression algorithm.
Definition: fil0fil.h:905
uint32_t n_pending_flushes
This is positive when flushing the tablespace to disk; dropping of the tablespace is forbidden if thi...
Definition: fil0fil.h:884
fil_type_t purpose
Purpose.
Definition: fil0fil.h:798
void set_deleted()
Marks the space object for deletion.
Definition: fil0fil.cc:10332
page_no_t get_cached_fsp_size_in_header() const
Definition: fil0fil.cc:2282
struct fil_space_t::fsp_cache m_fsp_cache
page_no_t get_cached_fsp_free_limit() const
Contents of FSP_FREE_LIMIT.
Definition: fil0fil.cc:2313
void inc_cached_fsp_free_len(uint32_t delta)
Definition: fil0fil.cc:2303
bool was_not_deleted() const
Definition: fil0fil.cc:10296
bool is_in_unflushed_spaces
true if this space is currently in unflushed_spaces
Definition: fil0fil.h:902
void set_cached_fsp_free_len(uint32_t new_free_len)
Definition: fil0fil.cc:2298
bool has_no_references() const
Definition: fil0fil.cc:10314
bool is_bulk_operation_in_progress() const
Definition: fil0fil.h:759
page_no_t m_undo_initial
When an undo tablespace has been initialized with required header pages, that size is recorded here.
Definition: fil0fil.h:654
std::vector< fil_node_t, ut::allocator< fil_node_t > > Files
Definition: fil0fil.h:509
void set_cached_fsp_free_limit(page_no_t new_free_limit)
Definition: fil0fil.cc:2318
void begin_bulk_operation(uint64_t extend_size)
Begin bulk operation on the space.
Definition: fil0fil.h:750
void inc_ref() noexcept
Increment the page reference count.
Definition: fil0fil.h:553
ulint redo_skipped_count
Reference count for operations who want to skip redo log in the file space in order to make fsp_space...
Definition: fil0fil.h:794
bool is_deleted() const
Definition: fil0fil.cc:10291
fil_node_t * get_node_for_page_no(page_no_t &page_no) noexcept
Get the file node corresponding to the given page number of the tablespace.
Definition: fil0fil.cc:10269
void fill_fsp_cache(const byte *first_page)
Fills the cache of the FSP-related data that is stored in the first page of the tablespace header.
Definition: fil0fil.cc:2584
Allows to monitor an event processing times, allowing to throttle the processing to one per throttle_...
Definition: ut0ut.h:365
For measuring time elapsed.
Definition: ut0ut.h:303
Status_IO
Definition: fil0tablespace_node_handle_interface.h:79
Page identifier.
Definition: buf0types.h:191
Page size descriptor.
Definition: page0size.h:50
C++23 std::expected.
Definition: ut0expected.h:74
const char * p
Definition: ctype-mb.cc:1227
int page
Definition: ctype-mb.cc:1226
dberr_t
Definition: db0err.h:39
Data dictionary global types.
static duk_ret_t normalize_path(duk_context *ctx, duk_idx_t obj_idx)
Definition: duk_module_shim.cc:76
static constexpr char general_space_name[]
This tablespace name is used internally during file discovery to open a general tablespace before the...
Definition: fil0fil.h:92
bool fil_system_get_file_by_space_num(space_id_t space_num, space_id_t &space_id, std::string &name)
Fetch the file name opened for an undo space number from the file map.
constexpr page_type_t FIL_PAGE_TYPE_LOB_FIRST
The first page of an uncompressed LOB.
Definition: fil0fil.h:1645
void fil_purge()
Allows fil system to do periodical cleanup.
Definition: fil0fil.cc:10147
bool fil_is_page_type_valid(page_type_t type) noexcept
Check if the given page type is valid.
Definition: fil0fil.cc:10198
constexpr page_type_t FIL_PAGE_UNDO_LOG
Undo log page.
Definition: fil0fil.h:1574
fil_space_t * fil_space_create(const char *name, space_id_t space_id, uint32_t flags, fil_type_t purpose)
Create a space memory object and put it to the fil_system hash table.
Definition: fil0fil.cc:3139
std::ostream & operator<<(std::ostream &out, const fil_addr_t &obj)
Definition: fil0fil.h:1551
constexpr page_type_t FIL_PAGE_TYPE_LOB_INDEX
Index pages of uncompressed LOB.
Definition: fil0fil.h:1639
constexpr page_type_t FIL_PAGE_ENCRYPTED_RTREE
Encrypted R-tree page.
Definition: fil0fil.h:1624
bool fil_validate()
Checks the consistency of the tablespace cache.
Definition: fil0fil.cc:1837
constexpr page_type_t FIL_PAGE_TYPE_LOB_DATA
Data pages of uncompressed LOB.
Definition: fil0fil.h:1642
constexpr page_type_t FIL_PAGE_TYPE_ZBLOB
First compressed BLOB page.
Definition: fil0fil.h:1605
uint32_t fil_space_get_flags(space_id_t space_id)
Returns the flags of the space.
Definition: fil0fil.cc:3274
void fil_io_set_encryption(IORequest &req_type, const page_id_t &page_id, fil_space_t *space)
Set encryption information for IORequest.
Definition: fil0fil.cc:6910
dberr_t fil_set_compression(space_id_t space_id, const char *algorithm)
Set the compression type for the tablespace.
Definition: fil0fil.cc:8111
page_no_t fil_page_get_prev(const byte *page)
Get the predecessor of a file page.
Definition: fil0fil.cc:7493
Fil_path MySQL_undo_path
The MySQL server –innodb-undo-directory value.
Definition: fil0fil.cc:287
bool fil_page_index_page_check(const byte *page)
Check whether the page is index page (either regular Btree index or Rtree index.
Definition: fil0fil.h:1682
rw_lock_t * fil_space_get_latch(space_id_t space_id)
Returns the latch of a file space.
Definition: fil0fil.cc:2141
ulint fil_space_get_n_reserved_extents(space_id_t space_id)
Gets the number of reserved extents.
Definition: fil0fil.cc:6753
ulong srv_fast_shutdown
The value of the configuration parameter innodb_fast_shutdown, controlling the InnoDB shutdown.
Definition: srv0srv.cc:558
constexpr size_t FIL_NODE_MAGIC_N
Value of fil_node_t::magic_n.
Definition: fil0fil.h:132
constexpr size_t FIL_SCAN_MAX_TABLESPACES_PER_THREAD
Maximum number of tablespaces to be scanned by a thread while scanning for available tablespaces duri...
Definition: fil0fil.h:73
constexpr page_type_t FIL_PAGE_COMPRESSED_AND_ENCRYPTED
Compressed and Encrypted page.
Definition: fil0fil.h:1621
uint16_t page_type_t
Definition: fil0fil.h:1558
page_no_t fil_space_get_undo_initial_size(space_id_t space_id)
Returns the size of an undo space just after it was initialized.
Definition: fil0fil.cc:3238
fil_type_t fil_space_get_type(space_id_t space_id)
Gets the type of a file space.
Definition: fil0fil.cc:2158
void fil_space_inc_redo_skipped_count(space_id_t space_id)
Increase redo skipped count for a tablespace.
Definition: fil0fil.cc:4396
void fil_space_set_flags(fil_space_t *space, uint32_t flags)
Sets the flags of the tablespace.
Definition: fil0fil.cc:8601
dberr_t fil_tablespace_open_for_recovery(space_id_t space_id)
Open the tablespace and also get the tablespace filenames, space_id must already be known.
Definition: fil0fil.cc:9185
constexpr size_t FIL_IBD_FILE_INITIAL_SIZE_5_7
An empty tablespace (CREATE TABLESPACE) has minimum of 4 pages and an empty CREATE TABLE (file_per_ta...
Definition: fil0fil.h:1499
bool fil_space_extend(fil_space_t *space, page_no_t size)
Try to extend a tablespace if it is smaller than the specified size.
Definition: fil0fil.cc:6144
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_FRAG_ENTRY
Index pages of fragment pages (compressed LOB).
Definition: fil0fil.h:1661
std::string fil_path_to_space_name(const std::string &file_path, space_id_t space_id, uint32_t flags)
Convert a file path to a tablespace name, based on space ID and its flags.
Definition: fil0fil.cc:5460
dberr_t fil_close_tablespace(space_id_t space_id)
Closes a single-table tablespace.
Definition: fil0fil.cc:4057
bool fil_op_replay_rename_for_ddl(space_id_t space_id, const char *old_name, const char *new_name)
Replay a file rename operation for ddl replay.
Definition: fil0fil.cc:9009
const byte * fil_tablespace_redo_extend(const byte *ptr, const byte *end, space_id_t space_id, bool parse_only)
Redo a tablespace extend.
Definition: fil0fil.cc:9612
constexpr page_type_t FIL_PAGE_INODE
Index node.
Definition: fil0fil.h:1577
constexpr page_type_t FIL_PAGE_TYPE_UNUSED
This page type is unused.
Definition: fil0fil.h:1571
constexpr page_type_t FIL_PAGE_INDEX
File page types (values of FIL_PAGE_TYPE)
Definition: fil0fil.h:1562
std::atomic_size_t fil_n_files_open
Number of files currently open.
Definition: fil0fil.cc:300
bool MySQL_undo_path_is_unique
The undo path is different from any other known directory.
Definition: fil0fil.cc:290
void fil_space_dec_redo_skipped_count(space_id_t space_id)
Decrease redo skipped count for a tablespace.
Definition: fil0fil.cc:4412
constexpr page_type_t FIL_PAGE_RTREE
R-tree node.
Definition: fil0fil.h:1565
constexpr size_t FIL_IBD_FILE_INITIAL_SIZE
Initial size of a single-table tablespace in pages.
Definition: fil0fil.h:1493
static constexpr char undo_space_name[]
This tablespace name is used as the prefix for implicit undo tablespaces and during file discovery to...
Definition: fil0fil.h:97
dberr_t fil_write_initial_pages(pfs_os_file_t file, const char *path, const byte *encrypt_info, space_id_t space_id, uint32_t space_flags)
Write initial pages for a new tablespace file created.
Definition: fil0fil.cc:5094
bool fil_space_exists_in_mem(space_id_t space_id, const char *name, bool print_err, bool adjust_space)
Returns true if a matching tablespace exists in the InnoDB tablespace memory cache.
Definition: fil0fil.cc:5926
const byte * fil_tablespace_redo_extend_wrapper(const byte *ptr, const byte *end, space_id_t space_id)
TODO: This is a wrapper for fil_tablespace_redo_extend to be called during recovery,...
Definition: fil0fil.cc:9550
dberr_t fil_set_encryption(space_id_t space_id, Encryption::Type algorithm, byte *key, byte *iv)
Set the encryption type for the tablespace.
Definition: fil0fil.cc:8198
dberr_t fil_rename_tablespace_by_id(space_id_t space_id, const char *old_name, const char *new_name)
Rename a tablespace.
Definition: fil0fil.cc:5088
constexpr size_t FIL_IBT_FILE_INITIAL_SIZE
Definition: fil0fil.h:1494
void fil_space_update_name(fil_space_t *space, const char *name)
Update the tablespace name.
Definition: fil0fil.cc:9996
bool fil_open_files_limit_update(size_t &new_max_open_files)
Changes the maximum opened files limit.
Definition: fil0fil.cc:3392
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1502
constexpr size_t FIL_SPACE_MAGIC_N
Value of fil_space_t::magic_n.
Definition: fil0fil.h:129
void fil_node_create(const char *name, fil_space_t *space, bool is_raw, page_no_t max_pages)
Attach a node to a tablespace.
Definition: fil0fil.cc:2261
const byte * fil_tablespace_redo_delete_wrapper(const byte *ptr, const byte *end, space_id_t space_id)
TODO: This is a wrapper for fil_tablespace_redo_delete to be called during recovery,...
Definition: fil0fil.cc:9730
dberr_t fil_reset_encryption(space_id_t space_id)
Reset the encryption type for the tablespace.
Definition: fil0fil.cc:8227
size_t fil_get_scan_threads(size_t num_files)
Calculate the number of threads that can be spawned to scan the given number of files taking into the...
Definition: fil0fil.cc:140
void fil_space_close(space_id_t space_id)
Close each file of a tablespace if open.
Definition: fil0fil.cc:3329
fil_space_t * fil_space_acquire(space_id_t space_id)
Acquire a tablespace when it could be dropped concurrently.
Definition: fil0fil.cc:3755
fil_space_t * fil_space_acquire_silent(space_id_t space_id)
Acquire a tablespace that may not exist.
Definition: fil0fil.cc:3764
Fil_state
Result of comparing a path.
Definition: fil0fil.h:155
@ MATCHES
The path matches what was found during the scan.
@ MISSING
No MLOG_FILE_DELETE record and the file could not be found.
@ MOVED
Space ID matches but the paths don't match.
@ MOVED_PREV
Space ID and paths match but dd_table data dir flag is false despite the file being outside default d...
@ COMPARE_ERROR
In case of error during comparison.
void fil_add_moved_space(dd::Object_id dd_object_id, space_id_t space_id, const char *space_name, const std::string &old_path, const std::string &new_path, bool dd_flag_missing)
Add tablespace to the set of tablespaces to be updated in DD.
Definition: fil0fil.cc:9362
dberr_t fil_write_flushed_lsn(lsn_t lsn)
Write the flushed LSN to the page header of the first page in the system tablespace.
Definition: fil0fil.cc:3660
char * fil_space_get_first_path(space_id_t space_id)
Returns the path from the first fil_node_t found with this space ID.
Definition: fil0fil.cc:3206
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_FRAG
Fragment pages of compressed LOB.
Definition: fil0fil.h:1658
const byte * fil_tablespace_redo_create_wrapper(const byte *ptr, const byte *end, space_id_t space_id)
TODO: This is a wrapper for fil_tablespace_redo_create to be called during recovery,...
Definition: fil0fil.cc:9371
constexpr page_type_t FIL_PAGE_TYPE_LAST
Note the highest valid non-index page_type_t.
Definition: fil0fil.h:1664
dberr_t fil_delete_tablespace(space_id_t space_id)
Deletes an IBD or IBU tablespace.
Definition: fil0fil.cc:4316
fil_addr_t fil_addr_null
The null file address.
Definition: fil0fil.cc:334
void fil_close_all_files()
Closes all open files.
Definition: fil0fil.cc:3599
void fil_init(ulint max_n_open)
Initializes the tablespace memory cache.
Definition: fil0fil.cc:3359
size_t fil_encryption_rotate()
Rotate the tablespace keys by new master key.
Definition: fil0fil.cc:8385
bool fil_page_type_is_index(page_type_t page_type)
Check whether the page type is index (Btree or Rtree or SDI) type.
Definition: fil0fil.h:1667
ut::Expected< fil_space_t * > fil_space_open(space_id_t space_id)
Looks up the tablespace, acquires the space, opens each node of a tablespace if not already open,...
Definition: fil0fil.cc:3315
fil_space_t * fil_space_get_sys_space()
Definition: fil0fil.h:2419
const page_size_t fil_space_get_page_size(space_id_t space_id, bool *found)
Returns the page size of the space and whether it is compressed or not.
Definition: fil0fil.cc:3344
byte fil_faddr_t
'type' definition in C: an address stored in a file page is a string of bytes
Definition: fil0fil.h:1510
dberr_t fil_rename_tablespace_check(space_id_t space_id, const char *old_path, const char *new_path, bool is_discarded)
Test if a tablespace file can be renamed to a new filepath by checking if that the old filepath exist...
Definition: fil0fil.cc:4748
void fil_space_release(fil_space_t *space)
Release a tablespace acquired with fil_space_acquire().
Definition: fil0fil.cc:3770
bool fil_truncate_tablespace(space_id_t space_id, page_no_t size_in_pages)
Basically recreates the tablespace`s only node and set it to the needed size in place.
Definition: fil0fil.cc:4387
void fil_close()
Initializes the tablespace memory cache.
Definition: fil0fil.cc:7527
const char * fil_get_page_type_str(page_type_t type) noexcept
Get the page type as a string.
Definition: fil0fil.cc:10159
void fil_flush_file_spaces()
Flush to disk the writes in file spaces possibly cached by the OS (note: spaces of type FIL_TYPE_TEMP...
Definition: fil0fil.cc:7481
std::vector< std::string, ut::allocator< std::string > > Filenames
Definition: fil0fil.h:125
bool fil_space_reserve_free_extents(space_id_t space_id, ulint n_free_now, ulint n_to_reserve)
Tries to reserve free extents in a file space.
Definition: fil0fil.cc:6701
dberr_t fil_ibd_open(bool validate, fil_type_t purpose, space_id_t space_id, uint32_t flags, const char *space_name, const char *path_in, bool strict, bool old_space)
Open a single-table tablespace and optionally do some validation such as checking that the space id i...
Definition: fil0fil.cc:5343
page_no_t fil_page_get_next(const byte *page)
Get the successor of a file page.
Definition: fil0fil.cc:7500
const byte * fil_tablespace_redo_rename(const byte *ptr, const byte *end, space_id_t space_id, bool parse_only)
Redo a tablespace rename.
Definition: fil0fil.cc:9501
constexpr size_t FIL_SCAN_THREADS_PER_CORE
Number of threads per core.
Definition: fil0fil.h:81
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_DATA
Data pages of compressed LOB.
Definition: fil0fil.h:1651
constexpr page_type_t FIL_PAGE_TYPE_XDES
Extent descriptor page.
Definition: fil0fil.h:1599
void fil_space_set_undo_size(space_id_t space_id, bool use_current)
This is called for an undo tablespace after it has been initialized or opened.
Definition: fil0fil.cc:3253
constexpr page_type_t FIL_PAGE_COMPRESSED
Compressed page.
Definition: fil0fil.h:1615
std::vector< space_id_t, ut::allocator< space_id_t > > Space_ids
Definition: fil0fil.h:126
std::atomic< std::uint64_t > fil_n_pending_tablespace_flushes
Number of pending tablespace flushes.
Definition: fil0fil.cc:297
constexpr page_type_t FIL_PAGE_SDI
Tablespace SDI Index page.
Definition: fil0fil.h:1568
bool fil_tablespace_lookup_for_recovery(space_id_t space_id)
Lookup the tablespace ID.
Definition: fil0fil.cc:9137
dberr_t fil_rename_tablespace(space_id_t space_id, const char *old_path, const char *new_name, const char *new_path_in)
Rename a single-table tablespace.
Definition: fil0fil.cc:5023
dberr_t fil_tablespace_iterate(const Encryption_metadata &encryption_metadata, dict_table_t *table, ulint n_io_buffers, Compression::Type compression_type, PageCallback &callback)
Iterate over all the pages in the tablespace.
Definition: fil0fil.cc:7828
void fil_space_set_imported(space_id_t space_id)
Note that a tablespace has been imported.
Definition: fil0fil.cc:2172
void fil_op_write_log(mlog_id_t type, space_id_t space_id, const char *path, const char *new_path, uint32_t flags, mtr_t *mtr)
Write a log record about an operation on a tablespace file.
Definition: fil0fil.cc:4115
constexpr size_t FIL_SCAN_MAX_THREADS
Maximum number of threads that will be used for scanning the tablespace files.
Definition: fil0fil.h:78
constexpr uint32_t UNDO_INITIAL_SIZE
Initial size of an UNDO tablespace when it is created new or truncated under low load.
Definition: fil0fil.h:110
void fil_extend_tablespaces_to_stored_len()
Extends all tablespaces to the size stored in the space header.
void fil_space_release_free_extents(space_id_t space_id, ulint n_reserved)
Releases free extents in a file space.
Definition: fil0fil.cc:6727
constexpr page_type_t FIL_PAGE_TYPE_ZBLOB2
Subsequent compressed BLOB page.
Definition: fil0fil.h:1608
constexpr page_type_t FIL_PAGE_TYPE_UNKNOWN
In old tablespaces, garbage in FIL_PAGE_TYPE is replaced with this value when flushing pages.
Definition: fil0fil.h:1612
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_FIRST
The first page of a compressed LOB.
Definition: fil0fil.h:1648
dberr_t fil_io(IORequest::Type type, bool sync, const page_id_t &page_id, const page_size_t &page_size, ulint len, byte *buf, buf_page_t *bpage, bool evict_after_write, std::function< void(dberr_t err)> pre_io_complete_callback=[](dberr_t) {})
Read or write data for a single page from a file.
Definition: fil0fil.cc:7277
fil_space_t * fil_space_get(space_id_t space_id)
Look up a tablespace.
Definition: fil0fil.cc:2124
constexpr page_type_t FIL_PAGE_TYPE_ALLOCATED
Freshly allocated page.
Definition: fil0fil.h:1584
constexpr page_type_t FIL_PAGE_TYPE_LEGACY_DBLWR
Legacy doublewrite buffer page.
Definition: fil0fil.h:1633
constexpr page_type_t FIL_PAGE_IBUF_FREE_LIST
Insert buffer free list.
Definition: fil0fil.h:1580
void fil_set_max_space_id_if_bigger(space_id_t max_id)
Sets the max tablespace id counter if the given number is bigger than the previous value.
Definition: fil0fil.cc:3650
volatile bool recv_recovery_on
true when applying redo log records during crash recovery; false otherwise.
Definition: log0recv.cc:108
constexpr page_type_t FIL_PAGE_SDI_ZBLOB
Compressed SDI BLOB page.
Definition: fil0fil.h:1630
constexpr page_type_t FIL_PAGE_TYPE_TRX_SYS
Transaction system data.
Definition: fil0fil.h:1593
Fil_state fil_tablespace_dir_equals(const space_id_t space_id, const char *space_name, const ulint fsp_flags, const Dirs_in_datadir &dirs_in_datadir, const std::string old_path, std::string &new_path)
Lookups the tablespace ID in the scanned tablespaces and return its path to the file.
Definition: fil0fil.cc:9189
std::optional< bool > fil_tablespace_redo_encryption(const byte *ptr, const byte *end, space_id_t space_id, lsn_t lsn)
Parse and process an encryption redo record.
Definition: fil0fil.cc:9798
page_type_t fil_page_get_type(const byte *page)
Get the file page type.
Definition: fil0fil.h:1675
constexpr page_type_t FIL_PAGE_ENCRYPTED
Encrypted page.
Definition: fil0fil.h:1618
dberr_t fil_set_autoextend_size(space_id_t space_id, uint64_t autoextend_size)
Set the autoextend_size attribute for the tablespace.
Definition: fil0fil.cc:8178
page_no_t fil_space_get_size(space_id_t space_id)
Returns the size of the space in pages.
Definition: fil0fil.cc:3225
dberr_t fil_ibt_create(space_id_t space_id, const char *name, const char *path, uint32_t flags, page_no_t size)
Create a session temporary tablespace (IBT) file.
Definition: fil0fil.cc:5324
Compression::Type fil_get_compression(space_id_t space_id)
Get the compression algorithm for a tablespace.
Definition: fil0fil.cc:8168
space_id_t fil_space_get_id_by_name(const char *name)
Returns the space ID based on the tablespace name.
Definition: fil0fil.cc:5939
bool fil_assign_new_space_id(space_id_t *space_id)
Assigns a new space id for a new single-table tablespace.
Definition: fil0fil.cc:3202
void fil_aio_wait(ulint segment)
Waits for an AIO operation to complete.
Definition: fil0fil.cc:7254
Fil_path MySQL_datadir_path
The MySQL server –datadir value.
Definition: fil0fil.cc:284
void fil_encryption_reencrypt(const std::vector< space_id_t > &sid_vector)
Re-encrypt the tablespace keys by current master key.
Definition: fil0fil.cc:8387
constexpr page_type_t FIL_PAGE_TYPE_SYS
System page.
Definition: fil0fil.h:1590
bool fil_space_is_redo_skipped(space_id_t space_id)
Check whether a single-table tablespace is redo skipped.
Definition: fil0fil.cc:4430
const byte * fil_tablespace_redo_create(const byte *ptr, const byte *end, space_id_t space_id, bool parse_only)
Redo a tablespace create.
Definition: fil0fil.cc:9460
void fil_page_reset_type(const page_id_t &page_id, byte *page, ulint type, mtr_t *mtr)
Reset the page type.
Definition: fil0fil.cc:7519
bool fil_space_read_name_and_filepath(space_id_t space_id, std::string &name, std::string &filepath)
Looks for a pre-existing fil_space_t with the given tablespace ID and, if found, returns the name and...
Definition: fil0fil.cc:5441
constexpr page_type_t FIL_PAGE_SDI_BLOB
Uncompressed SDI BLOB page.
Definition: fil0fil.h:1627
dberr_t fil_rename_precheck(const dict_table_t *old_table, const dict_table_t *new_table, const char *tmp_name)
Check if swapping two .ibd files can be done without failure.
Definition: fil0fil.cc:8021
constexpr page_type_t FIL_PAGE_TYPE_BLOB
Uncompressed BLOB page.
Definition: fil0fil.h:1602
bool fil_addr_is_null(const fil_addr_t &addr)
Returns true if file address is undefined.
Definition: fil0fil.cc:7486
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_INDEX
Index pages of compressed LOB.
Definition: fil0fil.h:1655
void fil_page_set_type(byte *page, ulint type)
Sets the file page type.
Definition: fil0fil.cc:7507
dberr_t fil_discard_tablespace(space_id_t space_id)
Discards a single-table tablespace.
Definition: fil0fil.cc:4463
const byte * fil_tablespace_redo_delete(const byte *ptr, const byte *end, space_id_t space_id, bool parse_only)
Redo a tablespace delete.
Definition: fil0fil.cc:9763
size_t fil_count_undo_deleted(space_id_t undo_num)
Count how many truncated undo space IDs are still tracked in the buffer pool and the file_system cach...
Definition: fil0fil.cc:10149
ib_file_suffix
Common InnoDB file extensions.
Definition: fil0fil.h:943
@ DWR
Definition: fil0fil.h:950
@ BWR
Definition: fil0fil.h:951
@ IBT
Definition: fil0fil.h:948
@ IBD
Definition: fil0fil.h:945
@ CFP
Definition: fil0fil.h:947
@ CFG
Definition: fil0fil.h:946
@ NO_EXT
Definition: fil0fil.h:944
@ IBU
Definition: fil0fil.h:949
const char * dot_ext[]
Common InnoDB file extensions.
Definition: fil0fil.cc:293
dberr_t fil_ibd_create(space_id_t space_id, const char *name, const char *path, uint32_t flags, page_no_t size)
Create an IBD tablespace file.
Definition: fil0fil.cc:5315
constexpr page_type_t FIL_PAGE_TYPE_RSEG_ARRAY
Rollback Segment Array page.
Definition: fil0fil.h:1636
void fil_adjust_name_import(dict_table_t *table, const char *path, ib_file_suffix extn)
Adjust file name for import for partition files in different letter case.
Definition: fil0fil.cc:7747
dberr_t fil_open_for_business(bool read_only_mode)
Free the Tablespace_files instance.
Definition: fil0fil.cc:9005
void fil_flush(space_id_t space_id)
Flushes to disk possible writes cached by the OS.
Definition: fil0fil.cc:7439
void fil_complete_write(space_id_t space_id, fil_node_t *node)
Definition: fil0fil.cc:10380
dberr_t fil_undo_create(space_id_t space_id, const char *name, const char *path, uint32_t flags, page_no_t size, bool is_explicit)
Create an UNDO tablespace file.
Definition: fil0fil.cc:5332
constexpr page_type_t FIL_PAGE_TYPE_FSP_HDR
File space header.
Definition: fil0fil.h:1596
dberr_t fil_prepare_file_for_io(space_id_t space_id, page_no_t &page_no, fil_node_t **node_out)
Definition: fil0fil.cc:10360
void fil_page_check_type(const page_id_t &page_id, byte *page, ulint type, mtr_t *mtr)
Check (and if needed, reset) the page type.
Definition: fil0fil.h:2212
constexpr page_type_t FIL_PAGE_IBUF_BITMAP
Insert buffer bitmap.
Definition: fil0fil.h:1587
The low-level file system page header & trailer offsets.
constexpr uint32_t FIL_PAGE_TYPE
file page type: FIL_PAGE_INDEX,..., 2 bytes.
Definition: fil0types.h:76
fil_type_t
File types.
Definition: fil0types.h:180
static bool equal(const Item *i1, const Item *i2, const Field *f2)
Definition: sql_select.cc:3935
constexpr uint32_t FSP_FLAGS_GET_ENCRYPTION(uint32_t flags)
Return the contents of the ENCRYPTION field.
Definition: fsp0types.h:368
static int flags[50]
Definition: hp_test1.cc:40
Insert buffer global types.
#define F
Definition: jit_executor_value.cc:374
unsigned char byte
Blob class.
Definition: common.h:151
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
#define OS_PATH_SEPARATOR
Definition: log_sink_syseventlog.cc:94
A better implementation of the UNIX ctype(3) library.
char my_tolower(const CHARSET_INFO *cs, char ch)
Definition: m_ctype.h:561
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_filename
Definition: ctype-utf8.cc:7047
static uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
The memory management.
static char * mem_strdup(const char *str)
Duplicates a NUL-terminated string.
mlog_id_t
Definition: mtr0types.h:63
static const char * filepath
Definition: myisamlog.cc:97
static size_t file_size
Definition: mysql_config_editor.cc:72
static char * path
Definition: mysqldump.cc:151
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
unsigned long long Object_id
Definition: object_id.h:31
Innodb data dictionary name.
Definition: dict0dd.cc:7192
Definition: os0file.h:89
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:943
Json_data_extension ext
Definition: backend.cc:50
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
ValueType max(X &&first)
Definition: gtid.h:103
@ NONE
Definition: base.h:45
bool isalpha(const char &ch)
Definition: parsing_helpers.h:37
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
HARNESS_EXPORT void trim(std::string &str)
Removes both leading and trailing whitespaces from the string.
Definition: string_utils.cc:71
size_t size(const char *const c)
Definition: base64.h:46
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
Define std::hash<Gtid>.
Definition: gtid.h:355
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2284
void free(void *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::malloc*(),...
Definition: ut0new.h:559
os_file_type_t
Definition: os0file.h:678
uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:87
A class describing a page size.
const char * filename
Definition: pfs_example_component_population.cc:67
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required string type
Definition: replication_group_member_actions.proto:34
The server main program.
Starts the Innobase database server.
case opt name
Definition: sslopt-case.h:29
Type
Algorithm types supported.
Definition: file.h:53
@ NONE
No compression.
Definition: file.h:59
Encryption metadata.
Definition: os0enc.h:445
Encryption::Type m_type
Encrypt type.
Definition: os0enc.h:447
Callback functor.
Definition: fil0fil.h:2248
virtual ulint get_space_flags() const 1=0
virtual dberr_t init(os_offset_t file_size, const buf_block_t *block) 1=0
Called for page 0 in the tablespace file at the start.
pfs_os_file_t m_file
File handle to the tablespace.
Definition: fil0fil.h:2301
virtual dberr_t operator()(os_offset_t offset, buf_block_t *block) 1=0
Called for every page in the tablespace.
page_size_t m_page_size
The tablespace page size.
Definition: fil0fil.h:2298
PageCallback()
Default constructor.
Definition: fil0fil.h:2250
void set_file(const char *filename, pfs_os_file_t file) 1
Set the name of the physical file and the file handle that is used to open it for the file that is be...
Definition: fil0fil.h:2275
void set_page_size(const buf_frame_t *page) 1
Set the tablespace table size.
Definition: fil0fil.cc:8016
PageCallback(PageCallback &&)=delete
const char * m_filepath
Physical file path.
Definition: fil0fil.h:2304
const page_size_t & get_page_size() const
The compressed page size.
Definition: fil0fil.h:2293
PageCallback(const PageCallback &)=delete
virtual space_id_t get_space_id() const 1=0
PageCallback & operator=(const PageCallback &)=delete
The buffer control block structure.
Definition: buf0buf.h:1756
Data structure for a database table.
Definition: dict0mem.h:1927
File space address.
Definition: fil0fil.h:1513
fil_addr_t()
Definition: fil0fil.h:1515
std::ostream & print(std::ostream &out) const
Print a string representation.
Definition: fil0fil.h:1535
uint32_t boffset
Byte offset within the page.
Definition: fil0fil.h:1545
fil_addr_t(page_no_t p, uint32_t boff)
Constructor.
Definition: fil0fil.h:1520
page_no_t page
Page number within a space.
Definition: fil0fil.h:1542
bool is_equal(const fil_addr_t &rhs) const
Compare to instances.
Definition: fil0fil.h:1525
bool is_null() const
Check if the file address is null.
Definition: fil0fil.h:1531
Structure to hold cached data for the FSP subsystem.
Definition: fil0fil.h:854
uint32_t m_free_len
Length of the FSP_FREE list.
Definition: fil0fil.h:859
page_no_t m_size_in_header
FSP_SIZE in the tablespace header;.
Definition: fil0fil.h:856
bool m_cache_valid
Definition: fil0fil.h:866
page_no_t m_free_limit
Contents of FSP_FREE_LIMIT.
Definition: fil0fil.h:862
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:174
Common file descriptor for file IO instrumentation with PFS on windows and other platforms.
Definition: os0file.h:172
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:362
Definition: trx0trx.h:670
Version control for database, common definitions, and include files.
#define UNIV_NOTHROW
Definition: univ.i:459
#define OS_PATH_SEPARATOR_ALT
Definition: univ.i:542
unsigned long int ulint
Definition: univ.i:403
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97
Minimal implementation of C++23 std::expected.
#define UT_LIST_NODE_T(t)
Macro used for legacy reasons.
Definition: ut0lst.h:64
Dynamic memory allocation routines and custom allocators specifically crafted to support memory instr...
static uint64_t lsn
Definition: xcom_base.cc:446