MySQL 8.0.39
Source Code Documentation
fil0fil.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2024, 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"
40#include "fil0types.h"
41#include "log0recv.h"
42#include "page0size.h"
43#ifndef UNIV_HOTBACKUP
44#include "ibuf0types.h"
45#endif /* !UNIV_HOTBACKUP */
46#include "ut0new.h"
47
48#include "m_ctype.h"
49#include "sql/dd/object_id.h"
50
51#include <atomic>
52#include <cstdint>
53#include <list>
54#include <vector>
55
56extern ulong srv_fast_shutdown;
57
58/** Maximum number of tablespaces to be scanned by a thread while scanning
59for available tablespaces during server startup. This is a hard maximum.
60If the number of files to be scanned is more than
61FIL_SCAN_MAX_TABLESPACES_PER_THREAD,
62then additional threads will be spawned to scan the additional files in
63parallel. */
65
66/** Maximum number of threads that will be used for scanning the tablespace
67files. This can be further adjusted depending on the number of available
68cores. */
69constexpr size_t FIL_SCAN_MAX_THREADS = 16;
70
71/** Number of threads per core. */
72constexpr size_t FIL_SCAN_THREADS_PER_CORE = 2;
73
74/** Calculate the number of threads that can be spawned to scan the given
75number of files taking into the consideration, number of cores available
76on the machine.
77@param[in] num_files Number of files to be scanned
78@return number of threads to be spawned for scanning the files */
79size_t fil_get_scan_threads(size_t num_files);
80
81/** This tablespace name is used internally during file discovery to open a
82general tablespace before the data dictionary is recovered and available. */
83static constexpr char general_space_name[] = "innodb_general";
84
85/** This tablespace name is used as the prefix for implicit undo tablespaces
86and during file discovery to open an undo tablespace before the DD is
87recovered and available. */
88static constexpr char undo_space_name[] = "innodb_undo";
89
90extern volatile bool recv_recovery_on;
91
92/** Initial size of an UNDO tablespace when it is created new
93or truncated under low load.
94page size | FSP_EXTENT_SIZE | Initial Size | Pages
95----------+------------------+--------------+-------
96 4 KB | 256 pages = 1 MB | 16 MB | 4096
97 8 KB | 128 pages = 1 MB | 16 MB | 2048
98 16 KB | 64 pages = 1 MB | 16 MB | 1024
99 32 KB | 64 pages = 2 MB | 16 MB | 512
100 64 KB | 64 pages = 4 MB | 16 MB | 256 */
101constexpr uint32_t UNDO_INITIAL_SIZE = 16 * 1024 * 1024;
102#define UNDO_INITIAL_SIZE_IN_PAGES \
103 os_offset_t { UNDO_INITIAL_SIZE / srv_page_size }
104
105#ifdef UNIV_HOTBACKUP
106#include <unordered_set>
107using Dir_set = std::unordered_set<std::string>;
108extern Dir_set rem_gen_ts_dirs;
109extern bool replay_in_datadir;
110#endif /* UNIV_HOTBACKUP */
111
112// Forward declaration
113struct trx_t;
114class page_id_t;
115
116using Filenames = std::vector<std::string, ut::allocator<std::string>>;
117using Space_ids = std::vector<space_id_t, ut::allocator<space_id_t>>;
118
119/** File types */
120enum fil_type_t : uint8_t {
121 /** temporary tablespace (temporary undo log or tables) */
123 /** a tablespace that is being imported (no logging until finished) */
125 /** persistent tablespace (for system, undo log or tables) */
127};
128
129/** Result of comparing a path. */
130enum class Fil_state {
131 /** The path matches what was found during the scan. */
132 MATCHES,
133
134 /** No MLOG_FILE_DELETE record and the file could not be found. */
135 MISSING,
136
137 /** A MLOG_FILE_DELETE was found, file was deleted. */
138 DELETED,
139
140 /** Space ID matches but the paths don't match. */
141 MOVED,
142
143 /** Space ID and paths match but dd_table data dir flag doesn't
144 exist or tablespace is created outside default data dir */
146
147 /** Tablespace and/or filename was renamed. The DDL log will handle
148 this case. */
149 RENAMED
150};
151
152struct fil_space_t;
153
154/** File node of a tablespace or the log data space */
156 /** Returns true if the file can be closed. */
157 bool can_be_closed() const;
158 /** Returns true if the file is flushed. */
159 bool is_flushed() const {
162 }
163 /** Sets file to flushed state. */
165
167
168 /** tablespace containing this file */
170
171 /** file name; protected by Fil_shard::m_mutex and log_sys->mutex. */
172 char *name;
173
174 /** whether this file is open. Note: We set the is_open flag after
175 we increase the write the MLOG_FILE_OPEN record to redo log. Therefore
176 we increment the in_use reference count before setting the OPEN flag. */
178
179 /** file handle (valid if is_open) */
181
182 /** event that groups and serializes calls to fsync */
184
185 /** whether the file actually is a raw device or disk partition */
187
188 /** size of the file in database pages (0 if not known yet);
189 the possible last incomplete megabyte may be ignored
190 if space->id == 0 */
192
193 /** Size of the file when last flushed, used to force the flush when file
194 grows to keep the filesystem metadata synced when using O_DIRECT_NO_FSYNC */
196
197 /** initial size of the file in database pages;
198 FIL_IBD_FILE_INITIAL_SIZE by default */
200
201 /** maximum size of the file in database pages */
203
204 /** count of pending I/O's; is_open must be true if nonzero */
206
207 /** count of pending flushes; is_open must be true if nonzero */
209
210 /** Set to true when a file is being extended. */
212
213 /** number of writes to the file since the system was started */
215
216 /** the modification_counter of the latest flush to disk */
218
219 /** link to the fil_system->LRU list (keeping track of open files) */
221
222 /** whether the file system of this file supports PUNCH HOLE */
224
225 /** block size to use for punching holes */
227
228 /** whether atomic write is enabled for this file */
230
231 /** FIL_NODE_MAGIC_N */
232 size_t magic_n;
233};
234
235/** Tablespace or log data space */
238 using Files = std::vector<fil_node_t, ut::allocator<fil_node_t>>;
239
240 /** Release the reserved free extents.
241 @param[in] n_reserved number of reserved extents */
242 void release_free_extents(ulint n_reserved);
243
244 /** @return true if the instance is queued for deletion. Guarantees the space
245 is not deleted as long as the fil_shard mutex is not released. */
246 bool is_deleted() const;
247
248 /** @return true if the instance was not queued for deletion. It does not
249 guarantee it is not queued for deletion at the moment. */
250 bool was_not_deleted() const;
251
252 /** Marks the space object for deletion. It will bump the space object version
253 and cause all pages in buffer pool that reference to the current space
254 object version to be stale and be freed on first encounter. */
255 void set_deleted();
256
257#ifndef UNIV_HOTBACKUP
258 /** Returns current version of the space object. It is being bumped when the
259 space is truncated or deleted. Guarantees the version returned is up to date
260 as long as fil_shard mutex is not released.*/
261 uint32_t get_current_version() const;
262
263 /** Returns current version of the space object. It is being bumped when the
264 space is truncated or deleted. It does not guarantee the version is current
265 one.*/
266 uint32_t get_recent_version() const;
267
268 /** Bumps the space object version and cause all pages in buffer pool that
269 reference the current space object version to be stale and be freed on
270 first encounter. */
271 void bump_version();
272
273 /** @return true if this space does not have any more references. Guarantees
274 the result only if true was returned. */
275 bool has_no_references() const;
276
277 /** @return Current number of references to the space. This method
278 should be called only while shutting down the server. Only when there is no
279 background nor user session activity the returned value will be valid. */
280 size_t get_reference_count() const;
281
282 /** Increment the page reference count. */
283 void inc_ref() noexcept {
284 /* We assume space is protected from being removed either through
285 n_pending_ops or m_n_ref_count already bumped, OR MDL latch is
286 protecting it, OR it is a private space. Bumping the n_pending_ops
287 can be done only under fil shard mutex and stopping new bumps is also
288 done under this mutex */
289 const auto o = m_n_ref_count.fetch_add(1);
290 ut_a(o != std::numeric_limits<size_t>::max());
291 }
292
293 /** Decrement the page reference count. */
294 void dec_ref() noexcept {
295 const auto o = m_n_ref_count.fetch_sub(1);
296 ut_a(o >= 1);
297 }
298#endif /* !UNIV_HOTBACKUP */
299
300#ifdef UNIV_DEBUG
301 /** Print the extent descriptor pages of this tablespace into
302 the given output stream.
303 @param[in] out the output stream.
304 @return the output stream. */
305 std::ostream &print_xdes_pages(std::ostream &out) const;
306
307 /** Print the extent descriptor pages of this tablespace into
308 the given file.
309 @param[in] filename the output file name. */
310 void print_xdes_pages(const char *filename) const;
311#endif /* UNIV_DEBUG */
312
313 public:
315 using Flush_observers = std::vector<Observer *, ut::allocator<Observer *>>;
316
317 /** When the tablespace was extended last. */
319
320 /** Extend undo tablespaces by so many pages. */
322
323 /** When an undo tablespace has been initialized with required header pages,
324 that size is recorded here. Auto-truncation happens when the file size
325 becomes bigger than both this and srv_max_undo_log_size. */
327
328 /** Tablespace name */
329 char *name{};
330
331 /** Tablespace ID */
333
334 /** Initializes fields. This could be replaced by a constructor if SunPro is
335 compiling it correctly. */
336 void initialize() noexcept {
338 new (&files) fil_space_t::Files();
339
340#ifndef UNIV_HOTBACKUP
341 new (&m_version) std::atomic<uint32_t>;
342 new (&m_n_ref_count) std::atomic_size_t;
343 new (&m_deleted) std::atomic<bool>;
344#endif /* !UNIV_HOTBACKUP */
345 }
346
347 private:
348#ifndef UNIV_HOTBACKUP
349 /** All pages in the buffer pool that reference this fil_space_t instance with
350 version before this version can be lazily freed or reused as free pages.
351 They should be rejected if there is an attempt to write them to disk.
352
353 Writes to m_version are guarded by the exclusive MDL/table lock latches
354 acquired by the caller, as stated in docs. Note that the Fil_shard mutex seems
355 to be latched in 2 of 3 usages only, so is not really an alternative.
356
357 Existence of the space object during reads is assured during these operations:
358 1. when read by the buf_page_init_low on page read/creation - the caller must
359 have acquired shared MDL/table lock latches.
360 2. when read on buf_page_t::is_stale() on page access for a query or for purge
361 operation. The caller must have acquired shared MDL/table lock latches.
362 3. when read on buf_page_t::is_stale() on page access from LRU list, flush
363 list or whatever else. Here, the fact that the page has latched the space
364 using the reference counting system is what guards the space existence.
365
366 When reading the value for the page being created with buf_page_init_low we
367 have the MDL latches on table that is in tablespace or the tablespace alone,
368 so we won't be able to bump m_version until they are released, so we will
369 read the current value of the version. When reading the value for the page
370 validation with buf_page_t::is_stale(), we will either:
371 a) have the MDL latches required in at least S mode in case we need to be
372 certain if the page is stale, to use it in a query or in purge operation, or
373 b) in case we don't not have the MDL latches, we may read an outdated value.
374 This happens for pages that are seen during for example LRU or flush page
375 scans. These pages are not needed for the query itself. The read is to decide
376 if the page can be safely discarded. Reading incorrect value can lead to no
377 action being executed. Reading incorrect value can't lead to page being
378 incorrectly evicted.
379 */
380 std::atomic<uint32_t> m_version{};
381
382 /** Number of buf_page_t entries that point to this instance.
383
384 This field is guarded by the Fil_shard mutex and the "reference
385 count system". The reference count system here is allowing to take a "latch"
386 on the space by incrementing the reference count, and release it by
387 decrementing it.
388
389 The increments are possible from two places:
390 1. buf_page_init_low is covered by the existing MDL/table lock latches only
391 and the fact that the space it is using is a current version of the space
392 (the version itself is also guarded by these MDL/table lock latches). It
393 implicitly acquires the "reference count system" latch after this operation.
394 2. buf_page_t::buf_page_t(const buf_page_t&) copy constructor - increases the
395 value, but it assumes the page being copied from has "reference count system"
396 latch so the reference count is greater than 0 during this constructor call.
397
398 For decrementing the reference count is itself a latch allowing for the safe
399 decrement.
400
401 The value is checked for being 0 in Fil_shard::checkpoint under the Fil_shard
402 mutex, and only if the space is deleted.
403 Observing m_n_ref_count==0 might trigger freeing the object. No other thread
404 can be during the process of incrementing m_n_ref_count from 0 to 1 in
405 parallel to this check. This is impossible for following reasons. Recall the
406 only two places where we do increments listed above:
407 1. If the space is deleted, then MDL/table lock latches guarantee there are
408 no users that would be able to see it as the current version of space and thus
409 will not attempt to increase the reference value from 0.
410 2. The buf_page_t copy constructor can increase it, but it assumes the page
411 being copied from has "reference count system" latch so the reference count is
412 greater than 0 during this constructor call.
413
414 There is also an opposite race possible: while we check for ref count being
415 zero, another thread may be decrementing it in parallel, and we might miss
416 that if we check too soon. This is benign, as it will result in us not
417 reclaiming the memory we could (but not have to) free, and will return to the
418 check on next checkpoint.
419 */
420 std::atomic_size_t m_n_ref_count{};
421#endif /* !UNIV_HOTBACKUP */
422
423 /** true if the tablespace is marked for deletion. */
424 std::atomic_bool m_deleted{};
425
426 public:
427 /** true if we want to rename the .ibd file of tablespace and
428 want to temporarily prevent other threads from opening the file that is being
429 renamed. */
431
432 /** Throttles writing to log a message about long waiting for file to perform
433 rename. */
435
436 /** We set this true when we start deleting a single-table
437 tablespace. When this is set following new ops are not allowed:
438 * read IO request
439 * ibuf merge
440 * file flush
441 Note that we can still possibly have new write operations because we
442 don't check this flag when doing flush batches. */
444
445#ifdef UNIV_DEBUG
446 /** Reference count for operations who want to skip redo log in
447 the file space in order to make fsp_space_modify_check pass. */
449#endif /* UNIV_DEBUG */
450
451 /** Purpose */
453
454 /** Files attached to this tablespace. Note: Only the system tablespace
455 can have multiple files, this is a legacy issue. */
457
458 /** Tablespace file size in pages; 0 if not known yet */
460
461 /** FSP_SIZE in the tablespace header; 0 if not known yet */
463
464 /** Autoextend size */
466
467 /** Length of the FSP_FREE list */
468 uint32_t free_len{};
469
470 /** Contents of FSP_FREE_LIMIT */
472
473 /** Tablespace flags; see fsp_flags_is_valid() and
474 page_size_t(ulint) (constructor).
475 This is protected by space->latch and tablespace MDL */
476 uint32_t flags{};
477
478 /** Number of reserved free extents for ongoing operations like
479 B-tree page split */
481
482 /** This is positive when flushing the tablespace to disk;
483 dropping of the tablespace is forbidden if this is positive */
485
486 /** This is positive when we have pending operations against this
487 tablespace. The pending operations can be ibuf merges or lock
488 validation code trying to read a block. Dropping of the tablespace
489 is forbidden if this is positive. Protected by Fil_shard::m_mutex. */
490 uint32_t n_pending_ops{};
491
492#ifndef UNIV_HOTBACKUP
493 /** Latch protecting the file space storage allocation */
495#endif /* !UNIV_HOTBACKUP */
496
497 /** List of spaces with at least one unflushed file we have
498 written to */
500
501 /** true if this space is currently in unflushed_spaces */
503
504 /** Compression algorithm */
506
507 /** Encryption metadata */
509
510 /** Encryption is in progress */
512
513 /** Flush lsn of header page. It is used only during recovery */
515
516 /** FIL_SPACE_MAGIC_N */
518
519 /** System tablespace */
521
522 /** Check if the tablespace is compressed.
523 @return true if compressed, false otherwise. */
524 [[nodiscard]] bool is_compressed() const noexcept {
526 }
527
528 /** Check if the tablespace is encrypted.
529 @return true if encrypted, false otherwise. */
530 [[nodiscard]] bool is_encrypted() const noexcept {
532 }
533
534 /** Check if the encryption details, like the encryption key, type and
535 other details, that are needed to carry out encryption are available.
536 @return true if encryption can be done, false otherwise. */
537 [[nodiscard]] bool can_encrypt() const noexcept {
539 }
540
541 public:
542 /** Get the file node corresponding to the given page number of the
543 tablespace.
544 @param[in,out] page_no Caller passes the page number within a tablespace.
545 After return, it contains the page number within
546 the returned file node. For tablespaces containing
547 only one file, the given page_no will not change.
548 @return the file node object. */
549 [[nodiscard]] fil_node_t *get_file_node(page_no_t *page_no) noexcept;
550};
551
552/** Value of fil_space_t::magic_n */
553constexpr size_t FIL_SPACE_MAGIC_N = 89472;
554
555/** Value of fil_node_t::magic_n */
556constexpr size_t FIL_NODE_MAGIC_N = 89389;
557
558/** Common InnoDB file extensions */
561 IBD = 1,
562 CFG = 2,
563 CFP = 3,
564 IBT = 4,
565 IBU = 5,
566 DWR = 6,
567 BWR = 7
569
570extern const char *dot_ext[];
571
572#define DOT_IBD dot_ext[IBD]
573#define DOT_CFG dot_ext[CFG]
574#define DOT_CFP dot_ext[CFP]
575#define DOT_IBT dot_ext[IBT]
576#define DOT_IBU dot_ext[IBU]
577#define DOT_DWR dot_ext[DWR]
578
579#ifdef _WIN32
580/* Initialization of m_abs_path() produces warning C4351:
581"new behavior: elements of array '...' will be default initialized."
582See https://msdn.microsoft.com/en-us/library/1ywe7hcy.aspx */
583#pragma warning(disable : 4351)
584#endif /* _WIN32 */
585
586/** Wrapper for a path to a directory that may or may not exist. */
587class Fil_path {
588 public:
589 /** schema '/' table separator */
590 static constexpr auto DB_SEPARATOR = '/';
591
592 /** OS specific path separator. */
593 static constexpr auto OS_SEPARATOR = OS_PATH_SEPARATOR;
594
595 /** Directory separators that are supported. */
596 static constexpr auto SEPARATOR = "\\/";
597#ifdef _WIN32
598 static constexpr auto DOT_SLASH = ".\\";
599 static constexpr auto DOT_DOT_SLASH = "..\\";
600 static constexpr auto SLASH_DOT_DOT_SLASH = "\\..\\";
601#else
602 static constexpr auto DOT_SLASH = "./";
603 static constexpr auto DOT_DOT_SLASH = "../";
604 static constexpr auto SLASH_DOT_DOT_SLASH = "/../";
605#endif /* _WIN32 */
606
607 /** Various types of file paths. */
609
610 /** Default constructor. Defaults to MySQL_datadir_path. */
611 Fil_path();
612
613 /** Constructor
614 @param[in] path Path, not necessarily NUL terminated
615 @param[in] len Length of path
616 @param[in] normalize_path If false, it's the callers responsibility to
617 ensure that the path is normalized. */
618 explicit Fil_path(const char *path, size_t len, bool normalize_path = false);
619
620 /** Constructor
621 @param[in] path Path, not necessarily NUL terminated
622 @param[in] normalize_path If false, it's the callers responsibility to
623 ensure that the path is normalized. */
624 explicit Fil_path(const char *path, bool normalize_path = false);
625
626 /** Constructor
627 @param[in] path pathname (may also include the file basename)
628 @param[in] normalize_path If false, it's the callers responsibility to
629 ensure that the path is normalized. */
630 explicit Fil_path(const std::string &path, bool normalize_path = false);
631
632 /** Implicit type conversion
633 @return pointer to m_path.c_str() */
634 [[nodiscard]] operator const char *() const { return m_path.c_str(); }
635
636 /** Explicit type conversion
637 @return pointer to m_path.c_str() */
638 [[nodiscard]] const char *operator()() const { return m_path.c_str(); }
639
640 /** @return the value of m_path */
641 [[nodiscard]] const std::string &path() const { return (m_path); }
642
643 /** @return the length of m_path */
644 [[nodiscard]] size_t len() const { return (m_path.length()); }
645
646 /** Return the absolute path by value. If m_abs_path is null, calculate
647 it and return it by value without trying to reset this const object.
648 m_abs_path can be empty if the path did not exist when this object
649 was constructed.
650 @return the absolute path by value. */
651 [[nodiscard]] const std::string abs_path() const {
652 if (m_abs_path.empty()) {
653 return (get_real_path(m_path));
654 }
655
656 return (m_abs_path);
657 }
658
659 /** @return the length of m_abs_path */
660 [[nodiscard]] size_t abs_len() const { return (m_abs_path.length()); }
661
662 /** Determine if this path is equal to the other path.
663 @param[in] other path to compare to
664 @return true if the paths are the same */
665 bool operator==(const Fil_path &other) const { return (is_same_as(other)); }
666
667 /** Check if m_path is the same as this other path.
668 @param[in] other directory path to compare to
669 @return true if m_path is the same as path */
670 [[nodiscard]] bool is_same_as(const Fil_path &other) const;
671
672 /** Check if this path is the same as the other path.
673 @param[in] other directory path to compare to
674 @return true if this path is the same as the other path */
675 [[nodiscard]] bool is_same_as(const std::string &other) const;
676
677 /** Get the absolute directory of this path */
678 [[nodiscard]] Fil_path get_abs_directory() const;
679
680 /** Check if the directory to path is same as directory as the other path.
681 @param[in] other directory path to compare to
682 @return true if this path directory is the same as the other path directory */
683 [[nodiscard]] bool is_dir_same_as(const Fil_path &other) const;
684
685 /** Check if two path strings are equal. Put them into Fil_path objects
686 so that they can be compared correctly.
687 @param[in] first first path to check
688 @param[in] second socond path to check
689 @return true if these two paths are the same */
690 [[nodiscard]] static bool is_same_as(const std::string &first,
691 const std::string &second) {
692 if (first.empty() || second.empty()) {
693 return (false);
694 }
695
696 Fil_path first_path(first);
697 std::string first_abs = first_path.abs_path();
698 trim_separator(first_abs);
699
700 Fil_path second_path(second);
701 std::string second_abs = second_path.abs_path();
702 trim_separator(second_abs);
703
704 return (first_abs == second_abs);
705 }
706
707 /** Splits the path into directory and file name parts.
708 @param[in] path path to split
709 @return [directory, file] for the path */
710 [[nodiscard]] static std::pair<std::string, std::string> split(
711 const std::string &path);
712
713 /** Check if m_path is the parent of the other path.
714 @param[in] other path to compare to
715 @return true if m_path is an ancestor of name */
716 [[nodiscard]] bool is_ancestor(const Fil_path &other) const;
717
718 /** Check if this Fil_path is an ancestor of the other path.
719 @param[in] other path to compare to
720 @return true if this Fil_path is an ancestor of the other path */
721 [[nodiscard]] bool is_ancestor(const std::string &other) const;
722
723 /** Check if the first path is an ancestor of the second.
724 Do not assume that these paths have been converted to real paths
725 and are ready to compare. If the two paths are the same
726 we will return false.
727 @param[in] first Parent path to check
728 @param[in] second Descendent path to check
729 @return true if the first path is an ancestor of the second */
730 [[nodiscard]] static bool is_ancestor(const std::string &first,
731 const std::string &second) {
732 if (first.empty() || second.empty()) {
733 return (false);
734 }
735
736 Fil_path ancestor(first);
737 Fil_path descendant(second);
738
739 return (ancestor.is_ancestor(descendant));
740 }
741
742 /** @return true if m_path exists and is a file. */
743 [[nodiscard]] bool is_file_and_exists() const;
744
745 /** @return true if m_path exists and is a directory. */
746 [[nodiscard]] bool is_directory_and_exists() const;
747
748 /** This validation is only for ':'.
749 @return true if the path is valid. */
750 [[nodiscard]] bool is_valid() const;
751
752 /** Determine if m_path contains a circular section like "/anydir/../"
753 Fil_path::normalize() must be run before this.
754 @return true if a circular section if found, false if not */
755 [[nodiscard]] bool is_circular() const;
756
757 /** Determine if the file or directory is considered HIDDEN.
758 Most file systems identify the HIDDEN attribute by a '.' preceding the
759 basename. On Windows, a HIDDEN path is identified by a file attribute.
760 We will use the preceding '.' to indicate a HIDDEN attribute on ALL
761 file systems so that InnoDB tablespaces and their directory structure
762 remain portable.
763 @param[in] path The full or relative path of a file or directory.
764 @return true if the directory or path is HIDDEN. */
765 static bool is_hidden(std::string path);
766
767#ifdef _WIN32
768 /** Use the WIN32_FIND_DATA struncture to determine if the file or
769 directory is HIDDEN. Consider a SYSTEM attribute also as an indicator
770 that it is HIDDEN to InnoDB.
771 @param[in] dirent A directory entry obtained from a call to FindFirstFile()
772 or FindNextFile()
773 @return true if the directory or path is HIDDEN. */
774 static bool is_hidden(WIN32_FIND_DATA &dirent);
775#endif /* WIN32 */
776
777 /** Remove quotes e.g., 'a;b' or "a;b" -> a;b.
778 This will only remove the quotes if they are matching on the whole string.
779 This will not work if each delimited string is quoted since this is called
780 before the string is parsed.
781 @return pathspec with the quotes stripped */
782 static std::string remove_quotes(const char *pathspec) {
783 std::string path(pathspec);
784
785 ut_ad(!path.empty());
786
787 if (path.size() >= 2 && ((path.front() == '\'' && path.back() == '\'') ||
788 (path.front() == '"' && path.back() == '"'))) {
789 path.erase(0, 1);
790 path.erase(path.size() - 1);
791 }
792
793 return (path);
794 }
795
796 /** Determine if a path is a relative path or not.
797 @param[in] path OS directory or file path to evaluate
798 @retval true if the path is relative
799 @retval false if the path is absolute or file_name_only */
800 [[nodiscard]] static bool is_relative_path(const std::string &path) {
801 return (type_of_path(path) == relative);
802 }
803
804 /** @return true if the path is an absolute path. */
805 [[nodiscard]] bool is_absolute_path() const {
806 return (type_of_path(m_path) == absolute);
807 }
808
809 /** Determine if a path is an absolute path or not.
810 @param[in] path OS directory or file path to evaluate
811 @retval true if the path is absolute
812 @retval false if the path is relative or file_name_only */
813 [[nodiscard]] static bool is_absolute_path(const std::string &path) {
814 return (type_of_path(path) == absolute);
815 }
816
817 /** Determine what type of path is provided.
818 @param[in] path OS directory or file path to evaluate
819 @return the type of filepath; 'absolute', 'relative',
820 'file_name_only', or 'invalid' if the path is empty. */
821 [[nodiscard]] static path_type type_of_path(const std::string &path) {
822 if (path.empty()) {
823 return (invalid);
824 }
825
826 /* The most likely type is a file name only with no separators. */
827 auto first_separator = path.find_first_of(SEPARATOR);
828 if (first_separator == std::string::npos) {
829 return (file_name_only);
830 }
831
832 /* Any string that starts with an OS_SEPARATOR is
833 an absolute path. This includes any OS and even
834 paths like "\\Host\share" on Windows. */
835 if (first_separator == 0) {
836 return (absolute);
837 }
838
839#ifdef _WIN32
840 /* Windows may have an absolute path like 'A:\' */
841 if (path.length() >= 3 && isalpha(path.at(0)) && path.at(1) == ':' &&
842 (path.at(2) == '\\' || path.at(2) == '/')) {
843 return (absolute);
844 }
845#endif /* _WIN32 */
846
847 /* Since it contains separators and is not an absolute path,
848 it must be a relative path. */
849 return (relative);
850 }
851
852 /* Check if the path is prefixed with pattern.
853 @return true if prefix matches */
854 [[nodiscard]] static bool has_prefix(const std::string &path,
855 const std::string prefix) {
856 return (path.size() >= prefix.size() &&
857 std::equal(prefix.begin(), prefix.end(), path.begin()));
858 }
859
860 /** Normalize a directory path for the current OS:
861 On Windows, we convert '/' to '\', else we convert '\' to '/'.
862 @param[in,out] path Directory and file path */
863 static void normalize(std::string &path) {
864 for (auto &c : path) {
865 if (c == OS_PATH_SEPARATOR_ALT) {
866 c = OS_SEPARATOR;
867 }
868 }
869 }
870
871 /** Normalize a directory path for the current OS:
872 On Windows, we convert '/' to '\', else we convert '\' to '/'.
873 @param[in,out] path A NUL terminated path */
874 static void normalize(char *path) {
875 for (auto ptr = path; *ptr; ++ptr) {
876 if (*ptr == OS_PATH_SEPARATOR_ALT) {
877 *ptr = OS_SEPARATOR;
878 }
879 }
880 }
881
882 /** Convert a path string to lower case using the CHARSET my_charset_filename.
883 @param[in,out] path Directory and file path */
884 static void to_lower(std::string &path) {
885 for (auto &c : path) {
887 }
888 }
889
890 /** @return true if the path exists and is a file . */
891 [[nodiscard]] static os_file_type_t get_file_type(const std::string &path);
892
893 /** Return a string to display the file type of a path.
894 @param[in] path path name
895 @return true if the path exists and is a file . */
896 static const char *get_file_type_string(const std::string &path);
897
898 /** Return a string to display the file type of a path.
899 @param[in] type OS file type
900 @return true if the path exists and is a file . */
901 static const char *get_file_type_string(os_file_type_t type);
902
903 /** Get the real path for a directory or a file name. This path can be
904 used to compare with another absolute path. It will be converted to
905 lower case on case insensitive file systems and if it is a directory,
906 it will end with a directory separator. The call to my_realpath() may
907 fail on non-Windows platforms if the path does not exist. If so, the
908 parameter 'force' determines what to return.
909 @param[in] path directory or filename to convert to a real path
910 @param[in] force if true and my_realpath() fails, use the path provided.
911 if false and my_realpath() fails, return a null string.
912 @return the absolute path prepared for making comparisons with other real
913 paths. */
914 [[nodiscard]] static std::string get_real_path(const std::string &path,
915 bool force = true);
916
917 /** Get the basename of the file path. This is the file name without any
918 directory separators. In other words, the file name after the last separator.
919 @param[in] filepath The name of a file, optionally with a path. */
920 [[nodiscard]] static std::string get_basename(const std::string &filepath);
921
922 /** Separate the portion of a directory path that exists and the portion that
923 does not exist.
924 @param[in] path Path to evaluate
925 @param[in,out] ghost The portion of the path that does not exist.
926 @return the existing portion of a path. */
927 [[nodiscard]] static std::string get_existing_path(const std::string &path,
928 std::string &ghost);
929
930 /** Check if the name is an undo tablespace name.
931 @param[in] name Tablespace name
932 @return true if it is an undo tablespace name */
933 [[nodiscard]] static bool is_undo_tablespace_name(const std::string &name);
934
935 /** Check if the file has the the specified suffix
936 @param[in] sfx suffix to look for
937 @param[in] path Filename to check
938 @return true if it has the the ".ibd" suffix. */
939 static bool has_suffix(ib_file_suffix sfx, const std::string &path) {
940 const auto suffix = dot_ext[sfx];
941 size_t len = strlen(suffix);
942
943 return (path.size() >= len &&
944 path.compare(path.size() - len, len, suffix) == 0);
945 }
946
947 /** Check if the file has the the specified suffix and truncate
948 @param[in] sfx suffix to look for
949 @param[in,out] path Filename to check
950 @return true if the suffix is found and truncated. */
951 static bool truncate_suffix(ib_file_suffix sfx, std::string &path) {
952 const auto suffix = dot_ext[sfx];
953 size_t len = strlen(suffix);
954
955 if (path.size() < len ||
956 path.compare(path.size() - len, len, suffix) != 0) {
957 return (false);
958 }
959
960 path.resize(path.size() - len);
961 return (true);
962 }
963
964 /** Check if a character is a path separator ('\' or '/')
965 @param[in] c Character to check
966 @return true if it is a separator */
967 static bool is_separator(char c) { return (c == '\\' || c == '/'); }
968
969 /** If the last character of a directory path is a separator ('\' or '/')
970 trim it off the string.
971 @param[in] path file system path */
972 static void trim_separator(std::string &path) {
973 if (!path.empty() && is_separator(path.back())) {
974 path.resize(path.size() - 1);
975 }
976 }
977
978 /** If the last character of a directory path is NOT a separator,
979 append a separator to the path.
980 NOTE: We leave it up to the caller to assure that the path is a directory
981 and not a file since if that directory does not yet exist, this function
982 cannot tell the difference.
983 @param[in] path file system path */
984 static void append_separator(std::string &path) {
985 if (!path.empty() && !is_separator(path.back())) {
986 path.push_back(OS_SEPARATOR);
987 }
988 }
989
990 /** Allocate and build a file name from a path, a table or
991 tablespace name and a suffix.
992 @param[in] path_in nullptr or the directory path or
993 the full path and filename
994 @param[in] name_in nullptr if path is full, or
995 Table/Tablespace name
996 @param[in] ext the file extension to use
997 @param[in] trim whether last name on the path should
998 be trimmed
999 @return own: file name; must be freed by ut::free() */
1000 [[nodiscard]] static char *make(const std::string &path_in,
1001 const std::string &name_in,
1002 ib_file_suffix ext, bool trim = false);
1003
1004 /** Allocate and build a CFG file name from a path.
1005 @param[in] path_in Full path to the filename
1006 @return own: file name; must be freed by ut::free() */
1007 [[nodiscard]] static char *make_cfg(const std::string &path_in) {
1008 return (make(path_in, "", CFG));
1009 }
1010
1011 /** Allocate and build a CFP file name from a path.
1012 @param[in] path_in Full path to the filename
1013 @return own: file name; must be freed by ut::free() */
1014 [[nodiscard]] static char *make_cfp(const std::string &path_in) {
1015 return (make(path_in, "", CFP));
1016 }
1017
1018 /** Allocate and build a file name from a path, a table or
1019 tablespace name and a suffix.
1020 @param[in] path_in nullptr or the directory path or
1021 the full path and filename
1022 @param[in] name_in nullptr if path is full, or
1023 Table/Tablespace name
1024 @return own: file name; must be freed by ut::free() */
1025 [[nodiscard]] static char *make_ibd(const std::string &path_in,
1026 const std::string &name_in) {
1027 return (make(path_in, name_in, IBD));
1028 }
1029
1030 /** Allocate and build a file name from a path, a table or
1031 tablespace name and a suffix.
1032 @param[in] name_in Table/Tablespace name
1033 @return own: file name; must be freed by ut::free() */
1034 [[nodiscard]] static char *make_ibd_from_table_name(
1035 const std::string &name_in) {
1036 return (make("", name_in, IBD));
1037 }
1038
1039 /** Create an IBD path name after replacing the basename in an old path
1040 with a new basename. The old_path is a full path name including the
1041 extension. The tablename is in the normal form "schema/tablename".
1042 @param[in] path_in Pathname
1043 @param[in] name_in Contains new base name
1044 @param[in] extn File extension
1045 @return new full pathname */
1046 [[nodiscard]] static std::string make_new_path(const std::string &path_in,
1047 const std::string &name_in,
1048 ib_file_suffix extn);
1049
1050 /** Parse file-per-table file name and build Innodb dictionary table name.
1051 @param[in] file_path File name with complete path
1052 @param[in] extn File extension
1053 @param[out] dict_name Innodb dictionary table name
1054 @return true, if successful. */
1055 static bool parse_file_path(const std::string &file_path, ib_file_suffix extn,
1056 std::string &dict_name);
1057
1058 /** This function reduces a null-terminated full remote path name
1059 into the path that is sent by MySQL for DATA DIRECTORY clause.
1060 It replaces the 'databasename/tablename.ibd' found at the end of the
1061 path with just 'tablename'.
1062
1063 Since the result is always smaller than the path sent in, no new
1064 memory is allocated. The caller should allocate memory for the path
1065 sent in. This function manipulates that path in place. If the path
1066 format is not as expected, set data_dir_path to "" and return.
1067
1068 The result is used to inform a SHOW CREATE TABLE command.
1069 @param[in,out] data_dir_path Full path/data_dir_path */
1070 static void make_data_dir_path(char *data_dir_path);
1071
1072#ifndef UNIV_HOTBACKUP
1073 /** Check if the filepath provided is in a valid placement.
1074 This routine is run during file discovery at startup.
1075 1) File-per-table must be in a dir named for the schema.
1076 2) File-per-table must not be in the datadir.
1077 3) General tablespace must not be under the datadir.
1078 @param[in] space_name tablespace name
1079 @param[in] space_id tablespace ID
1080 @param[in] fsp_flags tablespace flags
1081 @param[in] path scanned realpath to an existing file to validate
1082 @retval true if the filepath is a valid datafile location */
1083 static bool is_valid_location(const char *space_name, space_id_t space_id,
1084 uint32_t fsp_flags, const std::string &path);
1085
1086 /** Check if the implicit filepath is immediately within a dir named for
1087 the schema.
1088 @param[in] space_name tablespace name
1089 @param[in] path scanned realpath to an existing file to validate
1090 @retval true if the filepath is valid */
1091 static bool is_valid_location_within_db(const char *space_name,
1092 const std::string &path);
1093
1094 /** Convert filename to the file system charset format.
1095 @param[in,out] name Filename to convert */
1096 static void convert_to_filename_charset(std::string &name);
1097
1098 /** Convert to lower case using the file system charset.
1099 @param[in,out] path Filepath to convert */
1100 static void convert_to_lower_case(std::string &path);
1101
1102#endif /* !UNIV_HOTBACKUP */
1103
1104 protected:
1105 /** Path to a file or directory. */
1106 std::string m_path;
1107
1108 /** A full absolute path to the same file. */
1109 std::string m_abs_path;
1110};
1111
1112/** The MySQL server --datadir value */
1114
1115/** The MySQL server --innodb-undo-directory value */
1117
1118/** The undo path is different from any other known directory. */
1119extern bool MySQL_undo_path_is_unique;
1120
1121/** Initial size of a single-table tablespace in pages */
1122constexpr size_t FIL_IBD_FILE_INITIAL_SIZE = 7;
1123constexpr size_t FIL_IBT_FILE_INITIAL_SIZE = 5;
1124
1125/** An empty tablespace (CREATE TABLESPACE) has minimum
1126of 4 pages and an empty CREATE TABLE (file_per_table) has 6 pages.
1127Minimum of these two is 4 */
1129
1130/** 'null' (undefined) page offset in the context of file spaces */
1131constexpr page_no_t FIL_NULL = std::numeric_limits<page_no_t>::max();
1132
1133/** Maximum Page Number, one less than FIL_NULL */
1134constexpr page_no_t PAGE_NO_MAX = std::numeric_limits<page_no_t>::max() - 1;
1135
1136/** Unknown space id */
1137constexpr space_id_t SPACE_UNKNOWN = std::numeric_limits<space_id_t>::max();
1138
1139/* Space address data type; this is intended to be used when
1140addresses accurate to a byte are stored in file pages. If the page part
1141of the address is FIL_NULL, the address is considered undefined. */
1142
1143/** 'type' definition in C: an address stored in a file page is a
1144string of bytes */
1146
1147/** File space address */
1149 /* Default constructor */
1151
1152 /** Constructor
1153 @param[in] p Logical page number
1154 @param[in] boff Offset within the page */
1155 fil_addr_t(page_no_t p, uint32_t boff) : page(p), boffset(boff) {}
1156
1157 /** Compare to instances
1158 @param[in] rhs Instance to compare with
1159 @return true if the page number and page offset are equal */
1160 bool is_equal(const fil_addr_t &rhs) const {
1161 return (page == rhs.page && boffset == rhs.boffset);
1162 }
1163
1164 /** Check if the file address is null.
1165 @return true if null */
1166 bool is_null() const { return (page == FIL_NULL && boffset == 0); }
1167
1168 /** Print a string representation.
1169 @param[in,out] out Stream to write to */
1170 std::ostream &print(std::ostream &out) const {
1171 out << "[fil_addr_t: page=" << page << ", boffset=" << boffset << "]";
1172
1173 return (out);
1174 }
1175
1176 /** Page number within a space */
1178
1179 /** Byte offset within the page */
1180 uint32_t boffset;
1181};
1182
1183/* For printing fil_addr_t to a stream.
1184@param[in,out] out Stream to write to
1185@param[in] obj fil_addr_t instance to write */
1186inline std::ostream &operator<<(std::ostream &out, const fil_addr_t &obj) {
1187 return (obj.print(out));
1188}
1189
1190/** The null file address */
1192
1193using page_type_t = uint16_t;
1194
1195/** File page types (values of FIL_PAGE_TYPE) @{ */
1196/** B-tree node */
1197constexpr page_type_t FIL_PAGE_INDEX = 17855;
1198
1199/** R-tree node */
1200constexpr page_type_t FIL_PAGE_RTREE = 17854;
1201
1202/** Tablespace SDI Index page */
1203constexpr page_type_t FIL_PAGE_SDI = 17853;
1204
1205/** This page type is unused. */
1207
1208/** Undo log page */
1210
1211/** Index node */
1213
1214/** Insert buffer free list */
1216
1217/* File page types introduced in MySQL/InnoDB 5.1.7 */
1218/** Freshly allocated page */
1220
1221/** Insert buffer bitmap */
1223
1224/** System page */
1226
1227/** Transaction system data */
1229
1230/** File space header */
1232
1233/** Extent descriptor page */
1235
1236/** Uncompressed BLOB page */
1238
1239/** First compressed BLOB page */
1241
1242/** Subsequent compressed BLOB page */
1244
1245/** In old tablespaces, garbage in FIL_PAGE_TYPE is replaced with
1246this value when flushing pages. */
1248
1249/** Compressed page */
1251
1252/** Encrypted page */
1254
1255/** Compressed and Encrypted page */
1257
1258/** Encrypted R-tree page */
1260
1261/** Uncompressed SDI BLOB page */
1263
1264/** Compressed SDI BLOB page */
1266
1267/** Legacy doublewrite buffer page. */
1269
1270/** Rollback Segment Array page */
1272
1273/** Index pages of uncompressed LOB */
1275
1276/** Data pages of uncompressed LOB */
1278
1279/** The first page of an uncompressed LOB */
1281
1282/** The first page of a compressed LOB */
1284
1285/** Data pages of compressed LOB */
1287
1288/** Index pages of compressed LOB. This page contains an array of
1289z_index_entry_t objects.*/
1291
1292/** Fragment pages of compressed LOB. */
1294
1295/** Index pages of fragment pages (compressed LOB). */
1297
1298/** Note the highest valid non-index page_type_t. */
1300
1301/** Check whether the page type is index (Btree or Rtree or SDI) type */
1302inline bool fil_page_type_is_index(page_type_t page_type) {
1303 return page_type == FIL_PAGE_INDEX || page_type == FIL_PAGE_SDI ||
1304 page_type == FIL_PAGE_RTREE;
1305}
1306
1308
1309/** Check whether the page is index page (either regular Btree index or Rtree
1310index */
1311inline bool fil_page_index_page_check(const byte *page) {
1313}
1314
1315/** @} */
1316
1317/** Number of pending tablespace flushes */
1318extern std::atomic<std::uint64_t> fil_n_pending_tablespace_flushes;
1319
1320/** Number of files currently open */
1321extern std::atomic_size_t fil_n_files_open;
1322
1323/** Look up a tablespace.
1324The caller should hold an InnoDB table lock or a MDL that prevents
1325the tablespace from being dropped during the operation,
1326or the caller should be in single-threaded crash recovery mode
1327(no user connections that could drop tablespaces).
1328If this is not the case, fil_space_acquire() and fil_space_release()
1329should be used instead.
1330@param[in] space_id Tablespace ID
1331@return tablespace, or nullptr if not found */
1332[[nodiscard]] fil_space_t *fil_space_get(space_id_t space_id);
1333
1334#ifndef UNIV_HOTBACKUP
1335/** Returns the latch of a file space.
1336@param[in] space_id Tablespace ID
1337@return latch protecting storage allocation */
1338[[nodiscard]] rw_lock_t *fil_space_get_latch(space_id_t space_id);
1339
1340#ifdef UNIV_DEBUG
1341/** Gets the type of a file space.
1342@param[in] space_id Tablespace ID
1343@return file type */
1344[[nodiscard]] fil_type_t fil_space_get_type(space_id_t space_id);
1345#endif /* UNIV_DEBUG */
1346
1347/** Note that a tablespace has been imported.
1348It is initially marked as FIL_TYPE_IMPORT so that no logging is
1349done during the import process when the space ID is stamped to each page.
1350Now we change it to FIL_TYPE_TABLESPACE to start redo and undo logging.
1351NOTE: temporary tablespaces are never imported.
1352@param[in] space_id Tablespace ID */
1353void fil_space_set_imported(space_id_t space_id);
1354#endif /* !UNIV_HOTBACKUP */
1355
1356/** Attach a file to a tablespace. File must be closed.
1357@param[in] name file name (file must be closed)
1358@param[in] size file size in database blocks, rounded
1359 downwards to an integer
1360@param[in,out] space space where to append
1361@param[in] is_raw true if a raw device or a raw disk partition
1362@param[in] atomic_write true if the file has atomic write enabled
1363@param[in] max_pages maximum number of pages in file
1364@return pointer to the file name
1365@retval nullptr if error */
1366[[nodiscard]] char *fil_node_create(const char *name, page_no_t size,
1367 fil_space_t *space, bool is_raw,
1368 bool atomic_write,
1369 page_no_t max_pages = PAGE_NO_MAX);
1370
1371/** Create a space memory object and put it to the fil_system hash table.
1372The tablespace name is independent from the tablespace file-name.
1373Error messages are issued to the server log.
1374@param[in] name Tablespace name
1375@param[in] space_id Tablespace ID
1376@param[in] flags Tablespace flags
1377@param[in] purpose Tablespace purpose
1378@return pointer to created tablespace, to be filled in with fil_node_create()
1379@retval nullptr on failure (such as when the same tablespace exists) */
1380[[nodiscard]] fil_space_t *fil_space_create(const char *name,
1381 space_id_t space_id, uint32_t flags,
1382 fil_type_t purpose);
1383
1384/** Assigns a new space id for a new single-table tablespace. This works
1385simply by incrementing the global counter. If 4 billion id's is not enough,
1386we may need to recycle id's.
1387@param[out] space_id Set this to the new tablespace ID
1388@return true if assigned, false if not */
1389[[nodiscard]] bool fil_assign_new_space_id(space_id_t *space_id);
1390
1391/** Returns the path from the first fil_node_t found with this space ID.
1392The caller is responsible for freeing the memory allocated here for the
1393value returned.
1394@param[in] space_id Tablespace ID
1395@return own: A copy of fil_node_t::path, nullptr if space ID is zero
1396 or not found. */
1397[[nodiscard]] char *fil_space_get_first_path(space_id_t space_id);
1398
1399/** Returns the size of the space in pages. The tablespace must be cached
1400in the memory cache.
1401@param[in] space_id Tablespace ID
1402@return space size, 0 if space not found */
1403[[nodiscard]] page_no_t fil_space_get_size(space_id_t space_id);
1404
1405/** Returns the size of an undo space just after it was initialized.
1406@param[in] space_id Tablespace ID
1407@return initial space size, 0 if space not found */
1409
1410/** This is called for an undo tablespace after it has been initialized
1411or opened. It sets the minimum size in pages at which it should be truncated
1412and the number of pages that it should be extended. An undo tablespace is
1413extended by larger amounts than normal tablespaces. It starts at 16Mb and
1414is increased during aggressive growth and decreased when the growth is slower.
1415@param[in] space_id Tablespace ID
1416@param[in] use_current If true, use the current size in pages as the initial
1417 size. If false, use UNDO_INITIAL_SIZE_IN_PAGES. */
1418void fil_space_set_undo_size(space_id_t space_id, bool use_current);
1419
1420/** Returns the flags of the space. The tablespace must be cached
1421in the memory cache.
1422@param[in] space_id Tablespace ID for which to get the flags
1423@return flags, ULINT_UNDEFINED if space not found */
1424[[nodiscard]] uint32_t fil_space_get_flags(space_id_t space_id);
1425
1426/** Sets the flags of the tablespace. The tablespace must be locked
1427in MDL_EXCLUSIVE MODE.
1428@param[in] space tablespace in-memory struct
1429@param[in] flags tablespace flags */
1430void fil_space_set_flags(fil_space_t *space, uint32_t flags);
1431
1432/** Open each file of a tablespace if not already open.
1433@param[in] space_id Tablespace ID
1434@retval true if all file nodes were opened
1435@retval false on failure */
1436[[nodiscard]] bool fil_space_open(space_id_t space_id);
1437
1438/** Close each file of a tablespace if open.
1439@param[in] space_id Tablespace ID */
1440void fil_space_close(space_id_t space_id);
1441
1442/** Returns the page size of the space and whether it is compressed or not.
1443The tablespace must be cached in the memory cache.
1444@param[in] space_id Tablespace ID
1445@param[out] found true if tablespace was found
1446@return page size */
1447[[nodiscard]] const page_size_t fil_space_get_page_size(space_id_t space_id,
1448 bool *found);
1449
1450/** Initializes the tablespace memory cache.
1451@param[in] max_n_open Maximum number of open files */
1452void fil_init(ulint max_n_open);
1453
1454/** Changes the maximum opened files limit.
1455@param[in, out] new_max_open_files New value for the open files limit. If the
1456limit cannot be changed, the value is changed to a minimum value recommended.
1457@return true if the new limit was set. */
1458bool fil_open_files_limit_update(size_t &new_max_open_files);
1459
1460/** Initializes the tablespace memory cache. */
1461void fil_close();
1462
1463/** Opens all log files and system tablespace data files.
1464They stay open until the database server shutdown. This should be called
1465at a server startup after the space objects for the log and the system
1466tablespace have been created. The purpose of this operation is to make
1467sure we never run out of file descriptors if we need to read from the
1468insert buffer or to write to the log. */
1470
1471/** Closes all open files. There must not be any pending i/o's or not flushed
1472modifications in the files. */
1473void fil_close_all_files();
1474
1475/** Iterate over the files in all the tablespaces. */
1477 public:
1478 using Function = std::function<dberr_t(fil_node_t *)>;
1479
1480 /** For each data file.
1481 @param[in] f Callback */
1482 template <typename F>
1483 static dberr_t for_each_file(F &&f) {
1484 return iterate([=](fil_node_t *file) { return (f(file)); });
1485 }
1486
1487 /** Iterate through all persistent tablespace files (FIL_TYPE_TABLESPACE)
1488 returning the nodes via callback function f.
1489 @param[in] f Callback
1490 @return any error returned by the callback function. */
1491 static dberr_t iterate(Function &&f);
1492};
1493
1494/** Sets the max tablespace id counter if the given number is bigger than the
1495previous value.
1496@param[in] max_id Maximum known tablespace ID */
1498
1499#ifndef UNIV_HOTBACKUP
1500
1501/** Write the flushed LSN to the page header of the first page in the
1502system tablespace.
1503@param[in] lsn Flushed LSN
1504@return DB_SUCCESS or error number */
1505[[nodiscard]] dberr_t fil_write_flushed_lsn(lsn_t lsn);
1506
1507#else /* !UNIV_HOTBACKUP */
1508/** Frees a space object from the tablespace memory cache.
1509Closes a tablespaces' files but does not delete them.
1510There must not be any pending i/o's or flushes on the files.
1511@param[in] space_id Tablespace ID
1512@return true if success */
1513bool meb_fil_space_free(space_id_t space_id);
1514
1515/** Extends all tablespaces to the size stored in the space header. During the
1516mysqlbackup --apply-log phase we extended the spaces on-demand so that log
1517records could be applied, but that may have left spaces still too small
1518compared to the size stored in the space header. */
1519void meb_extend_tablespaces_to_stored_len();
1520
1521/** Process a file name passed as an input
1522@param[in] name absolute path of tablespace file
1523@param[in] space_id the tablespace ID */
1524void meb_fil_name_process(const char *name, space_id_t space_id);
1525
1526#endif /* !UNIV_HOTBACKUP */
1527
1528/** Acquire a tablespace when it could be dropped concurrently.
1529Used by background threads that do not necessarily hold proper locks
1530for concurrency control.
1531@param[in] space_id Tablespace ID
1532@return the tablespace, or nullptr if missing or being deleted */
1533[[nodiscard]] fil_space_t *fil_space_acquire(space_id_t space_id);
1534
1535/** Acquire a tablespace that may not exist.
1536Used by background threads that do not necessarily hold proper locks
1537for concurrency control.
1538@param[in] space_id Tablespace ID
1539@return the tablespace, or nullptr if missing or being deleted */
1540[[nodiscard]] fil_space_t *fil_space_acquire_silent(space_id_t space_id);
1541
1542/** Release a tablespace acquired with fil_space_acquire().
1543@param[in,out] space Tablespace to release */
1544void fil_space_release(fil_space_t *space);
1545
1546/** Fetch the file name opened for a space_id from the file map.
1547@param[in] space_id tablespace ID
1548@param[out] name the scanned filename
1549@return true if the space_id is found. The name is set to an
1550empty string if the space_id is not found. */
1551bool fil_system_get_file_by_space_id(space_id_t space_id, std::string &name);
1552
1553/** Fetch the file name opened for an undo space number from the file map.
1554@param[in] space_num Undo tablespace Number
1555@param[out] space_id Undo tablespace ID
1556@param[out] name the scanned filename
1557@return true if the space_num was found. The name is set to an
1558empty string if the space_num is not found. */
1560 space_id_t &space_id, std::string &name);
1561
1562/** Truncate the tablespace to needed size.
1563@param[in] space_id Tablespace ID to truncate
1564@param[in] size_in_pages Truncate size.
1565@return true if truncate was successful. */
1566[[nodiscard]] bool fil_truncate_tablespace(space_id_t space_id,
1567 page_no_t size_in_pages);
1568
1569/** Closes a single-table tablespace. The tablespace must be cached in the
1570memory cache. Free all pages used by the tablespace.
1571@param[in] space_id Tablespace ID
1572@return DB_SUCCESS or error */
1573[[nodiscard]] dberr_t fil_close_tablespace(space_id_t space_id);
1574
1575/** Discards a single-table tablespace. The tablespace must be cached in the
1576memory cache. Discarding is like deleting a tablespace, but
1577
1578 1. We do not drop the table from the data dictionary;
1579
1580 2. We remove all insert buffer entries for the tablespace immediately;
1581 in DROP TABLE they are only removed gradually in the background;
1582
1583 3. When the user does IMPORT TABLESPACE, the tablespace will have the
1584 same id as it originally had.
1585
1586 4. Free all the pages in use by the tablespace if rename=true.
1587@param[in] space_id Tablespace ID
1588@return DB_SUCCESS or error */
1589[[nodiscard]] dberr_t fil_discard_tablespace(space_id_t space_id);
1590
1591/** Test if a tablespace file can be renamed to a new filepath by checking
1592if that the old filepath exists and the new filepath does not exist.
1593@param[in] space_id Tablespace ID
1594@param[in] old_path Old filepath
1595@param[in] new_path New filepath
1596@param[in] is_discarded Whether the tablespace is discarded
1597@return innodb error code */
1598[[nodiscard]] dberr_t fil_rename_tablespace_check(space_id_t space_id,
1599 const char *old_path,
1600 const char *new_path,
1601 bool is_discarded);
1602
1603/** Rename a single-table tablespace.
1604The tablespace must exist in the memory cache.
1605@param[in] space_id Tablespace ID
1606@param[in] old_path Old file name
1607@param[in] new_name New tablespace name in the schema/name format
1608@param[in] new_path_in New file name, or nullptr if it is located in
1609the normal data directory
1610@return InnoDB error code */
1611[[nodiscard]] dberr_t fil_rename_tablespace(space_id_t space_id,
1612 const char *old_path,
1613 const char *new_name,
1614 const char *new_path_in);
1615
1616/** Create an IBD tablespace file.
1617@param[in] space_id Tablespace ID
1618@param[in] name Tablespace name in dbname/tablename format.
1619 For general tablespaces, the 'dbname/' part
1620 may be missing.
1621@param[in] path Path and filename of the datafile to create.
1622@param[in] flags Tablespace flags
1623@param[in] size Initial size of the tablespace file in pages,
1624 must be >= FIL_IBD_FILE_INITIAL_SIZE
1625@return DB_SUCCESS or error code */
1626[[nodiscard]] dberr_t fil_ibd_create(space_id_t space_id, const char *name,
1627 const char *path, uint32_t flags,
1628 page_no_t size);
1629
1630/** Create a session temporary tablespace (IBT) file.
1631@param[in] space_id Tablespace ID
1632@param[in] name Tablespace name
1633@param[in] path Path and filename of the datafile to create.
1634@param[in] flags Tablespace flags
1635@param[in] size Initial size of the tablespace file in pages,
1636 must be >= FIL_IBT_FILE_INITIAL_SIZE
1637@return DB_SUCCESS or error code */
1638[[nodiscard]] dberr_t fil_ibt_create(space_id_t space_id, const char *name,
1639 const char *path, uint32_t flags,
1640 page_no_t size);
1641
1642/** Deletes an IBD or IBU tablespace.
1643The tablespace must be cached in the memory cache. This will delete the
1644datafile, fil_space_t & fil_node_t entries from the file_system_t cache.
1645@param[in] space_id Tablespace ID
1646@param[in] buf_remove Specify the action to take on the pages
1647for this table in the buffer pool.
1648@return DB_SUCCESS, DB_TABLESPCE_NOT_FOUND or DB_IO_ERROR */
1649[[nodiscard]] dberr_t fil_delete_tablespace(space_id_t space_id,
1650 buf_remove_t buf_remove);
1651
1652/** Open a single-table tablespace and optionally do some validation such
1653as checking that the space id is correct. If the file is already open,
1654the validation will be done before reporting success.
1655If not successful, print an error message to the error log.
1656This function is used to open a tablespace when we start up mysqld,
1657and also in IMPORT TABLESPACE.
1658NOTE that we assume this operation is used either at the database startup
1659or under the protection of the dictionary mutex, so that two users cannot
1660race here.
1661
1662The fil_node_t::handle will not be left open.
1663
1664@param[in] validate whether we should validate the tablespace
1665 (read the first page of the file and
1666 check that the space id in it matches id)
1667@param[in] purpose FIL_TYPE_TABLESPACE or FIL_TYPE_TEMPORARY
1668@param[in] space_id Tablespace ID
1669@param[in] flags tablespace flags
1670@param[in] space_name tablespace name of the datafile
1671 If file-per-table, it is the table name in the
1672 databasename/tablename format
1673@param[in] path_in expected filepath, usually read from dictionary
1674@param[in] strict whether to report error when open ibd failed
1675@param[in] old_space whether it is a 5.7 tablespace opening
1676 by upgrade
1677@return DB_SUCCESS or error code */
1678[[nodiscard]] dberr_t fil_ibd_open(bool validate, fil_type_t purpose,
1679 space_id_t space_id, uint32_t flags,
1680 const char *space_name, const char *path_in,
1681 bool strict, bool old_space);
1682
1683/** Returns true if a matching tablespace exists in the InnoDB tablespace
1684memory cache.
1685@param[in] space_id Tablespace ID
1686@param[in] name Tablespace name used in space_create().
1687@param[in] print_err Print detailed error information to the
1688 error log if a matching tablespace is
1689 not found from memory.
1690@param[in] adjust_space Whether to adjust space id on mismatch
1691@return true if a matching tablespace exists in the memory cache */
1692[[nodiscard]] bool fil_space_exists_in_mem(space_id_t space_id,
1693 const char *name, bool print_err,
1694 bool adjust_space);
1695
1696/** Extends all tablespaces to the size stored in the space header. During the
1697mysqlbackup --apply-log phase we extended the spaces on-demand so that log
1698records could be appllied, but that may have left spaces still too small
1699compared to the size stored in the space header. */
1701
1702/** Try to extend a tablespace if it is smaller than the specified size.
1703@param[in,out] space Tablespace ID
1704@param[in] size desired size in pages
1705@return whether the tablespace is at least as big as requested */
1706[[nodiscard]] bool fil_space_extend(fil_space_t *space, page_no_t size);
1707
1708/** Tries to reserve free extents in a file space.
1709@param[in] space_id Tablespace ID
1710@param[in] n_free_now Number of free extents now
1711@param[in] n_to_reserve How many one wants to reserve
1712@return true if succeed */
1713[[nodiscard]] bool fil_space_reserve_free_extents(space_id_t space_id,
1714 ulint n_free_now,
1715 ulint n_to_reserve);
1716
1717/** Releases free extents in a file space.
1718@param[in] space_id Tablespace ID
1719@param[in] n_reserved How many were reserved */
1720void fil_space_release_free_extents(space_id_t space_id, ulint n_reserved);
1721
1722/** Gets the number of reserved extents. If the database is silent, this
1723number should be zero.
1724@param[in] space_id Tablespace ID
1725@return the number of reserved extents */
1726[[nodiscard]] ulint fil_space_get_n_reserved_extents(space_id_t space_id);
1727
1728/** Read or write data from a file.
1729@param[in] type IO context
1730@param[in] sync If true then do synchronous IO
1731@param[in] page_id page id
1732@param[in] page_size page size
1733@param[in] byte_offset remainder of offset in bytes; in aio this
1734 must be divisible by the OS block size
1735@param[in] len how many bytes to read or write; this must
1736 not cross a file boundary; in AIO this must
1737 be a block size multiple
1738@param[in,out] buf buffer where to store read data or from where
1739 to write; in AIO this must be appropriately
1740 aligned
1741@param[in] message message for AIO handler if !sync, else ignored
1742@return error code
1743@retval DB_SUCCESS on success
1744@retval DB_TABLESPACE_DELETED if the tablespace does not exist */
1745[[nodiscard]] dberr_t fil_io(const IORequest &type, bool sync,
1746 const page_id_t &page_id,
1747 const page_size_t &page_size, ulint byte_offset,
1748 ulint len, void *buf, void *message);
1749
1750/** Waits for an AIO operation to complete. This function is used to write the
1751handler for completed requests. The aio array of pending requests is divided
1752into segments (see os0file.cc for more info). The thread specifies which
1753segment it wants to wait for.
1754@param[in] segment The number of the segment in the AIO array
1755 to wait for */
1756void fil_aio_wait(ulint segment);
1757
1758/** Flushes to disk possible writes cached by the OS. If the space does
1759not exist or is being dropped, does not do anything.
1760@param[in] space_id Tablespace ID */
1761void fil_flush(space_id_t space_id);
1762
1763/** Flush to disk the writes in file spaces possibly cached by the OS
1764(note: spaces of type FIL_TYPE_TEMPORARY are skipped) */
1766
1767#ifdef UNIV_DEBUG
1768/** Checks the consistency of the tablespace cache.
1769@return true if ok */
1770bool fil_validate();
1771#endif /* UNIV_DEBUG */
1772
1773/** Returns true if file address is undefined.
1774@param[in] addr File address to check
1775@return true if undefined */
1776[[nodiscard]] bool fil_addr_is_null(const fil_addr_t &addr);
1777
1778/** Get the predecessor of a file page.
1779@param[in] page File page
1780@return FIL_PAGE_PREV */
1781[[nodiscard]] page_no_t fil_page_get_prev(const byte *page);
1782
1783/** Get the successor of a file page.
1784@param[in] page File page
1785@return FIL_PAGE_NEXT */
1786[[nodiscard]] page_no_t fil_page_get_next(const byte *page);
1787
1788/** Sets the file page type.
1789@param[in,out] page File page
1790@param[in] type File page type to set */
1791void fil_page_set_type(byte *page, ulint type);
1792
1793/** Reset the page type.
1794Data files created before MySQL 5.1 may contain garbage in FIL_PAGE_TYPE.
1795In MySQL 3.23.53, only undo log pages and index pages were tagged.
1796Any other pages were written with uninitialized bytes in FIL_PAGE_TYPE.
1797@param[in] page_id Page number
1798@param[in,out] page Page with invalid FIL_PAGE_TYPE
1799@param[in] type Expected page type
1800@param[in,out] mtr Mini-transaction */
1801void fil_page_reset_type(const page_id_t &page_id, byte *page, ulint type,
1802 mtr_t *mtr);
1803
1804/** Get the file page type.
1805@param[in] page File page
1806@return page type */
1808 return (static_cast<page_type_t>(mach_read_from_2(page + FIL_PAGE_TYPE)));
1809}
1810
1811#ifdef UNIV_DEBUG
1812/** Increase redo skipped count for a tablespace.
1813@param[in] space_id Tablespace ID */
1815
1816/** Decrease redo skipped count for a tablespace.
1817@param[in] space_id Tablespace ID */
1819
1820/** Check whether a single-table tablespace is redo skipped.
1821@param[in] space_id Tablespace ID
1822@return true if redo skipped */
1823[[nodiscard]] bool fil_space_is_redo_skipped(space_id_t space_id);
1824#endif /* UNIV_DEBUG */
1825
1826/** Delete the tablespace file and any related files like .cfg.
1827This should not be called for temporary tables.
1828@param[in] path File path of the IBD tablespace
1829@return true on success */
1830[[nodiscard]] bool fil_delete_file(const char *path);
1831
1832/** Callback functor. */
1834 /** Default constructor */
1836
1837 virtual ~PageCallback() UNIV_NOTHROW = default;
1838
1839 /** Called for page 0 in the tablespace file at the start.
1840 @param file_size size of the file in bytes
1841 @param block contents of the first page in the tablespace file
1842 @retval DB_SUCCESS or error code. */
1843 [[nodiscard]] virtual dberr_t init(os_offset_t file_size,
1844 const buf_block_t *block) UNIV_NOTHROW = 0;
1845
1846 /** Called for every page in the tablespace. If the page was not
1847 updated then its state must be set to BUF_PAGE_NOT_USED. For
1848 compressed tables the page descriptor memory will be at offset:
1849 block->frame + UNIV_PAGE_SIZE;
1850 @param offset physical offset within the file
1851 @param block block read from file, note it is not from the buffer pool
1852 @retval DB_SUCCESS or error code. */
1853 [[nodiscard]] virtual dberr_t operator()(os_offset_t offset,
1854 buf_block_t *block) UNIV_NOTHROW = 0;
1855
1856 /** Set the name of the physical file and the file handle that is used
1857 to open it for the file that is being iterated over.
1858 @param filename then physical name of the tablespace file.
1859 @param file OS file handle */
1861 m_file = file;
1863 }
1864
1865 /** @return the space id of the tablespace */
1866 [[nodiscard]] virtual space_id_t get_space_id() const UNIV_NOTHROW = 0;
1867
1868 /**
1869 @retval the space flags of the tablespace being iterated over */
1870 [[nodiscard]] virtual ulint get_space_flags() const UNIV_NOTHROW = 0;
1871
1872 /** Set the tablespace table size.
1873 @param[in] page a page belonging to the tablespace */
1875
1876 /** The compressed page size
1877 @return the compressed page size */
1878 [[nodiscard]] const page_size_t &get_page_size() const {
1879 return (m_page_size);
1880 }
1881
1882 /** The tablespace page size. */
1884
1885 /** File handle to the tablespace */
1887
1888 /** Physical file path. */
1889 const char *m_filepath;
1890
1891 // Disable copying
1893 PageCallback(const PageCallback &) = delete;
1895};
1896
1897/** Iterate over all the pages in the tablespace.
1898@param[in] encryption_metadata the encryption metadata to use for reading
1899@param[in] table the table definition in the server
1900@param[in] n_io_buffers number of blocks to read and write together
1901@param[in] compression_type compression type if compression is enabled,
1902else Compression::Type::NONE
1903@param[in,out] callback functor that will do the page updates
1904@return DB_SUCCESS or error code */
1905[[nodiscard]] dberr_t fil_tablespace_iterate(
1906 const Encryption_metadata &encryption_metadata, dict_table_t *table,
1907 ulint n_io_buffers, Compression::Type compression_type,
1908 PageCallback &callback);
1909
1910/** Looks for a pre-existing fil_space_t with the given tablespace ID
1911and, if found, returns the name and filepath in newly allocated buffers
1912that the caller must free.
1913@param[in] space_id The tablespace ID to search for.
1914@param[out] name Name of the tablespace found.
1915@param[out] filepath The filepath of the first datafile for the
1916tablespace.
1917@return true if tablespace is found, false if not. */
1918[[nodiscard]] bool fil_space_read_name_and_filepath(space_id_t space_id,
1919 char **name,
1920 char **filepath);
1921
1922/** Convert a file name to a tablespace name. Strip the file name
1923prefix and suffix, leaving only databasename/tablename.
1924@param[in] filename directory/databasename/tablename.ibd
1925@return database/tablename string, to be freed with ut::free() */
1926[[nodiscard]] char *fil_path_to_space_name(const char *filename);
1927
1928/** Returns the space ID based on the tablespace name.
1929The tablespace must be found in the tablespace memory cache.
1930This call is made from external to this module, so the mutex is not owned.
1931@param[in] name Tablespace name
1932@return space ID if tablespace found, SPACE_UNKNOWN if space not. */
1933[[nodiscard]] space_id_t fil_space_get_id_by_name(const char *name);
1934
1935/** Check if swapping two .ibd files can be done without failure
1936@param[in] old_table old table
1937@param[in] new_table new table
1938@param[in] tmp_name temporary table name
1939@return innodb error code */
1940[[nodiscard]] dberr_t fil_rename_precheck(const dict_table_t *old_table,
1941 const dict_table_t *new_table,
1942 const char *tmp_name);
1943
1944/** Set the compression type for the tablespace
1945@param[in] space_id Space ID of the tablespace
1946@param[in] algorithm Text representation of the algorithm
1947@return DB_SUCCESS or error code */
1948[[nodiscard]] dberr_t fil_set_compression(space_id_t space_id,
1949 const char *algorithm);
1950
1951/** Get the compression algorithm for a tablespace.
1952@param[in] space_id Space ID to check
1953@return the compression algorithm */
1954[[nodiscard]] Compression::Type fil_get_compression(space_id_t space_id);
1955
1956/** Set encryption information for IORequest.
1957@param[in,out] req_type IO request
1958@param[in] page_id page id
1959@param[in] space table space */
1960void fil_io_set_encryption(IORequest &req_type, const page_id_t &page_id,
1961 fil_space_t *space);
1962
1963/** Set the encryption type for the tablespace
1964@param[in] space_id Space ID of tablespace for which to set
1965@param[in] algorithm Encryption algorithm
1966@param[in] key Encryption key
1967@param[in] iv Encryption iv
1968@return DB_SUCCESS or error code */
1969[[nodiscard]] dberr_t fil_set_encryption(space_id_t space_id,
1970 Encryption::Type algorithm, byte *key,
1971 byte *iv);
1972
1973/** Set the autoextend_size attribute for the tablespace
1974@param[in] space_id Space ID of tablespace for which to set
1975@param[in] autoextend_size Value of autoextend_size attribute
1976@return DB_SUCCESS or error code */
1977dberr_t fil_set_autoextend_size(space_id_t space_id, uint64_t autoextend_size);
1978
1979/** Reset the encryption type for the tablespace
1980@param[in] space_id Space ID of tablespace for which to set
1981@return DB_SUCCESS or error code */
1982[[nodiscard]] dberr_t fil_reset_encryption(space_id_t space_id);
1983
1984/** Rotate the tablespace keys by new master key.
1985@return the number of tablespaces that failed to rotate. */
1986[[nodiscard]] size_t fil_encryption_rotate();
1987
1988/** Roencrypt the tablespace keys by current master key. */
1989void fil_encryption_reencrypt(std::vector<space_id_t> &sid_vector);
1990
1991/** During crash recovery, open a tablespace if it had not been opened
1992yet, to get valid size and flags.
1993@param[in,out] space Tablespace instance */
1995 if (space->size == 0) {
1996 /* Initially, size and flags will be set to 0,
1997 until the files are opened for the first time.
1998 fil_space_get_size() will open the file
1999 and adjust the size and flags. */
2000 page_no_t size = fil_space_get_size(space->id);
2001
2002 ut_a(size == space->size);
2003 }
2004}
2005
2006#if !defined(NO_FALLOCATE) && defined(UNIV_LINUX)
2007/**
2008Try and enable FusionIO atomic writes.
2009@param[in] file OS file handle
2010@return true if successful */
2011[[nodiscard]] bool fil_fusionio_enable_atomic_write(pfs_os_file_t file);
2012#endif /* !NO_FALLOCATE && UNIV_LINUX */
2013
2014/** Note that the file system where the file resides doesn't support PUNCH HOLE.
2015Called from AIO handlers when IO returns DB_IO_NO_PUNCH_HOLE
2016@param[in,out] file file to set */
2018
2019#ifdef UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH
2020void test_make_filepath();
2021#endif /* UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH */
2022
2023/** @return the system tablespace instance */
2026}
2027
2028/** Redo a tablespace create.
2029@param[in] ptr redo log record
2030@param[in] end end of the redo log buffer
2031@param[in] page_id Tablespace Id and first page in file
2032@param[in] parsed_bytes Number of bytes parsed so far
2033@param[in] parse_only Don't apply, parse only
2034@return pointer to next redo log record
2035@retval nullptr if this log record was truncated */
2036[[nodiscard]] byte *fil_tablespace_redo_create(byte *ptr, const byte *end,
2037 const page_id_t &page_id,
2038 ulint parsed_bytes,
2039 bool parse_only);
2040
2041/** Redo a tablespace delete.
2042@param[in] ptr redo log record
2043@param[in] end end of the redo log buffer
2044@param[in] page_id Tablespace Id and first page in file
2045@param[in] parsed_bytes Number of bytes parsed so far
2046@param[in] parse_only Don't apply, parse only
2047@return pointer to next redo log record
2048@retval nullptr if this log record was truncated */
2049[[nodiscard]] byte *fil_tablespace_redo_delete(byte *ptr, const byte *end,
2050 const page_id_t &page_id,
2051 ulint parsed_bytes,
2052 bool parse_only);
2053
2054/** Redo a tablespace rename.
2055This function doesn't do anything, simply parses the redo log record.
2056@param[in] ptr redo log record
2057@param[in] end end of the redo log buffer
2058@param[in] page_id Tablespace Id and first page in file
2059@param[in] parsed_bytes Number of bytes parsed so far
2060@param[in] parse_only Don't apply, parse only
2061@return pointer to next redo log record
2062@retval nullptr if this log record was truncated */
2063[[nodiscard]] byte *fil_tablespace_redo_rename(byte *ptr, const byte *end,
2064 const page_id_t &page_id,
2065 ulint parsed_bytes,
2066 bool parse_only);
2067
2068/** Redo a tablespace extend
2069@param[in] ptr redo log record
2070@param[in] end end of the redo log buffer
2071@param[in] page_id Tablespace Id and first page in file
2072@param[in] parsed_bytes Number of bytes parsed so far
2073@param[in] parse_only Don't apply the log if true
2074@return pointer to next redo log record
2075@retval nullptr if this log record was truncated */
2076[[nodiscard]] byte *fil_tablespace_redo_extend(byte *ptr, const byte *end,
2077 const page_id_t &page_id,
2078 ulint parsed_bytes,
2079 bool parse_only);
2080
2081/** Parse and process an encryption redo record.
2082@param[in] ptr redo log record
2083@param[in] end end of the redo log buffer
2084@param[in] space_id the tablespace ID
2085@param[in] lsn lsn for REDO record
2086@return log record end, nullptr if not a complete record */
2087[[nodiscard]] byte *fil_tablespace_redo_encryption(byte *ptr, const byte *end,
2088 space_id_t space_id,
2089 lsn_t lsn);
2090
2091/** Read the tablespace id to path mapping from the file
2092@param[in] recovery true if called from crash recovery */
2094
2095/** Lookup the tablespace ID.
2096@param[in] space_id Tablespace ID to lookup
2097@return true if the space ID is known. */
2098[[nodiscard]] bool fil_tablespace_lookup_for_recovery(space_id_t space_id);
2099
2100/** Compare and update space name and dd path for partitioned table. Uniformly
2101converts partition separators and names to lower case.
2102@param[in] space_id tablespace ID
2103@param[in] fsp_flags tablespace flags
2104@param[in] update_space update space name
2105@param[in,out] space_name tablespace name
2106@param[in,out] dd_path file name with complete path
2107@return true, if names are updated. */
2108bool fil_update_partition_name(space_id_t space_id, uint32_t fsp_flags,
2109 bool update_space, std::string &space_name,
2110 std::string &dd_path);
2111
2112/** Add tablespace to the set of tablespaces to be updated in DD.
2113@param[in] dd_object_id Server DD tablespace ID
2114@param[in] space_id InnoDB tablespace ID
2115@param[in] space_name Tablespace name
2116@param[in] old_path Old Path in the data dictionary
2117@param[in] new_path New path to be update in dictionary
2118@param[in] moved_prev_or_has_datadir The move has happened before
2119 8.0.38/8.4.1/9.0.0 or table is
2120 created with data dir clause.*/
2121void fil_add_moved_space(dd::Object_id dd_object_id, space_id_t space_id,
2122 const char *space_name, const std::string &old_path,
2123 const std::string &new_path,
2124 bool moved_prev_or_has_datadir);
2125/** Lookup the tablespace ID and return the path to the file. The filename
2126is ignored when testing for equality. Only the path up to the file name is
2127considered for matching: e.g. ./test/a.ibd == ./test/b.ibd.
2128@param[in] space_id tablespace ID to lookup
2129@param[in] space_name tablespace name
2130@param[in] fsp_flags tablespace flags
2131@param[in] old_path the path found in dd:Tablespace_files
2132@param[out] new_path the scanned path for this space_id
2133@return status of the match. */
2134[[nodiscard]] Fil_state fil_tablespace_path_equals(space_id_t space_id,
2135 const char *space_name,
2136 ulint fsp_flags,
2137 std::string old_path,
2138 std::string *new_path);
2139
2140/** This function should be called after recovery has completed.
2141Check for tablespace files for which we did not see any MLOG_FILE_DELETE
2142or MLOG_FILE_RENAME record. These could not be recovered
2143@return true if there were some filenames missing for which we had to
2144ignore redo log records during the apply phase */
2145[[nodiscard]] bool fil_check_missing_tablespaces();
2146
2147/** Normalize and save a directory to scan for datafiles.
2148@param[in] directory directory to scan for ibd and ibu files
2149@param[in] is_undo_dir true for an undo directory */
2150void fil_set_scan_dir(const std::string &directory, bool is_undo_dir = false);
2151
2152/** Normalize and save a list of directories to scan for datafiles.
2153@param[in] directories Directories to scan for ibd and ibu files
2154 in the form: "dir1;dir2; ... dirN" */
2155void fil_set_scan_dirs(const std::string &directories);
2156
2157/** Discover tablespaces by reading the header from .ibd files.
2158@return DB_SUCCESS if all goes well */
2160
2161/** Open the tablespace and also get the tablespace filenames, space_id must
2162already be known.
2163@param[in] space_id Tablespace ID to lookup
2164@return DB_SUCCESS if open was successful */
2166
2167/** Replay a file rename operation for ddl replay.
2168@param[in] page_id Space ID and first page number in the file
2169@param[in] old_name old file name
2170@param[in] new_name new file name
2171@return whether the operation was successfully applied
2172(the name did not exist, or new_name did not exist and
2173name was successfully renamed to new_name) */
2174bool fil_op_replay_rename_for_ddl(const page_id_t &page_id,
2175 const char *old_name, const char *new_name);
2176
2177/** Free the Tablespace_files instance.
2178@param[in] read_only_mode true if InnoDB is started in read only mode.
2179@return DB_SUCCESS if all OK */
2180[[nodiscard]] dberr_t fil_open_for_business(bool read_only_mode);
2181
2182/** Check if a path is known to InnoDB meaning that it is in or under
2183one of the four path settings scanned at startup for file discovery.
2184@param[in] path Path to check
2185@return true if path is known to InnoDB */
2186[[nodiscard]] bool fil_path_is_known(const std::string &path);
2187
2188/** Get the list of directories that datafiles can reside in.
2189@return the list of directories 'dir1;dir2;....;dirN' */
2190[[nodiscard]] std::string fil_get_dirs();
2191
2192/** Rename a tablespace. Use the space_id to find the shard.
2193@param[in] space_id tablespace ID
2194@param[in] old_name old tablespace name
2195@param[in] new_name new tablespace name
2196@return DB_SUCCESS on success */
2197[[nodiscard]] dberr_t fil_rename_tablespace_by_id(space_id_t space_id,
2198 const char *old_name,
2199 const char *new_name);
2200
2201/** Write initial pages for a new tablespace file created.
2202@param[in] file open file handle
2203@param[in] path path and filename of the datafile
2204@param[in] type file type
2205@param[in] size Initial size of the tablespace file in pages
2206@param[in] encrypt_info encryption key information
2207@param[in] space_id tablespace ID
2208@param[in,out] space_flags tablespace flags
2209@param[out] atomic_write if atomic write is used
2210@param[out] punch_hole if punch hole is used
2211@return DB_SUCCESS on success */
2212[[nodiscard]] dberr_t fil_write_initial_pages(
2213 pfs_os_file_t file, const char *path, fil_type_t type, page_no_t size,
2214 const byte *encrypt_info, space_id_t space_id, uint32_t &space_flags,
2215 bool &atomic_write, bool &punch_hole);
2216
2217/** Free the data structures required for recovery. */
2219
2220/** Update the tablespace name. In case, the new name
2221and old name are same, no update done.
2222@param[in,out] space tablespace object on which name
2223 will be updated
2224@param[in] name new name for tablespace */
2225void fil_space_update_name(fil_space_t *space, const char *name);
2226
2227/** Adjust file name for import for partition files in different letter case.
2228@param[in] table Innodb dict table
2229@param[in] path file path to open
2230@param[in] extn file extension */
2231void fil_adjust_name_import(dict_table_t *table, const char *path,
2232 ib_file_suffix extn);
2233
2234#ifndef UNIV_HOTBACKUP
2235
2236/** Allows fil system to do periodical cleanup. */
2237void fil_purge();
2238
2239/** Count how many truncated undo space IDs are still tracked in
2240the buffer pool and the file_system cache.
2241@param[in] undo_num undo tablespace number.
2242@return number of undo tablespaces that are still in memory. */
2243size_t fil_count_undo_deleted(space_id_t undo_num);
2244
2245#endif /* !UNIV_HOTBACKUP */
2246
2247/** Get the page type as a string.
2248@param[in] type page type to be converted to string.
2249@return the page type as a string. */
2250[[nodiscard]] const char *fil_get_page_type_str(page_type_t type) noexcept;
2251
2252/** Check if the given page type is valid.
2253@param[in] type the page type to be checked for validity.
2254@return true if it is valid page type, false otherwise. */
2255[[nodiscard]] bool fil_is_page_type_valid(page_type_t type) noexcept;
2256#endif /* fil0fil_h */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:51
uint32_t page_no_t
Page number.
Definition: api0api.h:49
byte buf_frame_t
A buffer frame.
Definition: buf0types.h:62
buf_remove_t
Algorithm to remove the pages for a tablespace from the buffer pool.
Definition: buf0types.h:84
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:1476
std::function< dberr_t(fil_node_t *)> Function
Definition: fil0fil.h:1478
static dberr_t iterate(Function &&f)
Iterate through all persistent tablespace files (FIL_TYPE_TABLESPACE) returning the nodes via callbac...
Definition: fil0fil.cc:3941
static dberr_t for_each_file(F &&f)
For each data file.
Definition: fil0fil.h:1483
Wrapper for a path to a directory that may or may not exist.
Definition: fil0fil.h:587
bool is_ancestor(const Fil_path &other) const
Check if m_path is the parent of the other path.
Definition: fil0fil.cc:9212
size_t abs_len() const
Definition: fil0fil.h:660
static void convert_to_filename_charset(std::string &name)
Convert filename to the file system charset format.
Definition: fil0fil.cc:11652
static bool is_same_as(const std::string &first, const std::string &second)
Check if two path strings are equal.
Definition: fil0fil.h:690
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:1034
static const char * get_file_type_string(const std::string &path)
Return a string to display the file type of a path.
Definition: fil0fil.cc:9280
path_type
Various types of file paths.
Definition: fil0fil.h:608
@ absolute
Definition: fil0fil.h:608
@ invalid
Definition: fil0fil.h:608
@ relative
Definition: fil0fil.h:608
@ file_name_only
Definition: fil0fil.h:608
bool operator==(const Fil_path &other) const
Determine if this path is equal to the other path.
Definition: fil0fil.h:665
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:4899
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:730
static char * make_cfp(const std::string &path_in)
Allocate and build a CFP file name from a path.
Definition: fil0fil.h:1014
static constexpr auto SEPARATOR
Directory separators that are supported.
Definition: fil0fil.h:596
static constexpr auto DOT_SLASH
Definition: fil0fil.h:602
std::string m_path
Path to a file or directory.
Definition: fil0fil.h:1106
const char * operator()() const
Explicit type conversion.
Definition: fil0fil.h:638
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:9202
static bool is_relative_path(const std::string &path)
Determine if a path is a relative path or not.
Definition: fil0fil.h:800
static bool is_absolute_path(const std::string &path)
Determine if a path is an absolute path or not.
Definition: fil0fil.h:813
static void convert_to_lower_case(std::string &path)
Convert to lower case using the file system charset.
Definition: fil0fil.cc:11669
static std::string get_basename(const std::string &filepath)
Get the basename of the file path.
Definition: fil0fil.cc:4317
bool is_same_as(const Fil_path &other) const
Check if m_path is the same as this other path.
Definition: fil0fil.cc:9172
const std::string abs_path() const
Return the absolute path by value.
Definition: fil0fil.h:651
bool is_valid() const
This validation is only for ':'.
Definition: fil0fil.cc:9322
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:5011
std::string m_abs_path
A full absolute path to the same file.
Definition: fil0fil.h:1109
static bool is_separator(char c)
Check if a character is a path separator ('\' or '/')
Definition: fil0fil.h:967
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:984
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:11589
static constexpr auto SLASH_DOT_DOT_SLASH
Definition: fil0fil.h:604
static std::pair< std::string, std::string > split(const std::string &path)
Splits the path into directory and file name parts.
Definition: fil0fil.cc:9206
size_t len() const
Definition: fil0fil.h:644
static char * make_cfg(const std::string &path_in)
Allocate and build a CFG file name from a path.
Definition: fil0fil.h:1007
static std::string remove_quotes(const char *pathspec)
Remove quotes e.g., 'a;b' or "a;b" -> a;b.
Definition: fil0fil.h:782
Fil_path get_abs_directory() const
Get the absolute directory of this path.
Definition: fil0fil.cc:9196
static constexpr auto OS_SEPARATOR
OS specific path separator.
Definition: fil0fil.h:593
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:11545
static bool is_undo_tablespace_name(const std::string &name)
Check if the name is an undo tablespace name.
Definition: fil0fil.cc:2101
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:1025
const std::string & path() const
Definition: fil0fil.h:641
bool is_circular() const
Determine if m_path contains a circular section like "/anydir/../" Fil_path::normalize() must be run ...
Definition: fil0fil.cc:9346
bool is_directory_and_exists() const
Definition: fil0fil.cc:9316
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:4207
bool is_file_and_exists() const
Definition: fil0fil.cc:9311
static bool is_hidden(std::string path)
Determine if the file or directory is considered HIDDEN.
Definition: fil0fil.cc:9243
bool is_absolute_path() const
Definition: fil0fil.h:805
static constexpr auto DB_SEPARATOR
schema '/' table separator
Definition: fil0fil.h:590
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:5050
static void normalize(char *path)
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\'...
Definition: fil0fil.h:874
Fil_path()
Default constructor.
Definition: fil0fil.cc:9169
static os_file_type_t get_file_type(const std::string &path)
Definition: fil0fil.cc:9269
static bool truncate_suffix(ib_file_suffix sfx, std::string &path)
Check if the file has the the specified suffix and truncate.
Definition: fil0fil.h:951
static void to_lower(std::string &path)
Convert a path string to lower case using the CHARSET my_charset_filename.
Definition: fil0fil.h:884
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:4979
static path_type type_of_path(const std::string &path)
Determine what type of path is provided.
Definition: fil0fil.h:821
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:863
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:4177
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:972
static constexpr auto DOT_DOT_SLASH
Definition: fil0fil.h:603
static bool has_prefix(const std::string &path, const std::string prefix)
Definition: fil0fil.h:854
static bool has_suffix(ib_file_suffix sfx, const std::string &path)
Check if the file has the the specified suffix.
Definition: fil0fil.h:939
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:269
The IO Context that is passed down to the low level IO code.
Definition: os0file.h:275
Allows to monitor an event processing times, allowing to throttle the processing to one per THROTTLE_...
Definition: ut0ut.h:362
For measuring time elapsed.
Definition: ut0ut.h:300
Page identifier.
Definition: buf0types.h:207
Page size descriptor.
Definition: page0size.h:50
const char * p
Definition: ctype-mb.cc:1237
int page
Definition: ctype-mb.cc:1236
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:77
byte * fil_tablespace_redo_delete(byte *ptr, const byte *end, const page_id_t &page_id, ulint parsed_bytes, bool parse_only)
Redo a tablespace delete.
Definition: fil0fil.cc:10565
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:83
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.
Definition: fil0fil.cc:4465
constexpr page_type_t FIL_PAGE_TYPE_LOB_FIRST
The first page of an uncompressed LOB.
Definition: fil0fil.h:1280
bool fil_system_get_file_by_space_id(space_id_t space_id, std::string &name)
Fetch the file name opened for a space_id from the file map.
Definition: fil0fil.cc:4459
void fil_purge()
Allows fil system to do periodical cleanup.
Definition: fil0fil.cc:11681
bool fil_is_page_type_valid(page_type_t type) noexcept
Check if the given page type is valid.
Definition: fil0fil.cc:11732
bool fil_check_missing_tablespaces()
This function should be called after recovery has completed.
Definition: fil0fil.cc:10176
constexpr page_type_t FIL_PAGE_UNDO_LOG
Undo log page.
Definition: fil0fil.h:1209
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:3308
std::ostream & operator<<(std::ostream &out, const fil_addr_t &obj)
Definition: fil0fil.h:1186
constexpr page_type_t FIL_PAGE_TYPE_LOB_INDEX
Index pages of uncompressed LOB.
Definition: fil0fil.h:1274
constexpr page_type_t FIL_PAGE_ENCRYPTED_RTREE
Encrypted R-tree page.
Definition: fil0fil.h:1259
bool fil_path_is_known(const std::string &path)
Check if a path is known to InnoDB meaning that it is in or under one of the four path settings scann...
Definition: fil0fil.cc:11514
bool fil_validate()
Checks the consistency of the tablespace cache.
Definition: fil0fil.cc:1952
constexpr page_no_t PAGE_NO_MAX
Maximum Page Number, one less than FIL_NULL.
Definition: fil0fil.h:1134
constexpr page_type_t FIL_PAGE_TYPE_LOB_DATA
Data pages of uncompressed LOB.
Definition: fil0fil.h:1277
constexpr page_type_t FIL_PAGE_TYPE_ZBLOB
First compressed BLOB page.
Definition: fil0fil.h:1240
uint32_t fil_space_get_flags(space_id_t space_id)
Returns the flags of the space.
Definition: fil0fil.cc:3528
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:7540
dberr_t fil_set_compression(space_id_t space_id, const char *algorithm)
Set the compression type for the tablespace.
Definition: fil0fil.cc:8835
page_no_t fil_page_get_prev(const byte *page)
Get the predecessor of a file page.
Definition: fil0fil.cc:8200
Fil_path MySQL_undo_path
The MySQL server –innodb-undo-directory value.
Definition: fil0fil.cc:279
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:1311
rw_lock_t * fil_space_get_latch(space_id_t space_id)
Returns the latch of a file space.
Definition: fil0fil.cc:2239
bool fil_delete_file(const char *path)
Delete the tablespace file and any related files like .cfg.
Definition: fil0fil.cc:8714
ulint fil_space_get_n_reserved_extents(space_id_t space_id)
Gets the number of reserved extents.
Definition: fil0fil.cc:7392
ulong srv_fast_shutdown
The value of the configuration parameter innodb_fast_shutdown, controlling the InnoDB shutdown.
Definition: srv0srv.cc:566
constexpr size_t FIL_NODE_MAGIC_N
Value of fil_node_t::magic_n.
Definition: fil0fil.h:556
void fil_open_system_tablespace_files()
Opens all log files and system tablespace data files.
Definition: fil0fil.cc:3750
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:64
constexpr page_type_t FIL_PAGE_COMPRESSED_AND_ENCRYPTED
Compressed and Encrypted page.
Definition: fil0fil.h:1256
char * fil_path_to_space_name(const char *filename)
Convert a file name to a tablespace name.
Definition: fil0fil.cc:5982
uint16_t page_type_t
Definition: fil0fil.h:1193
byte * fil_tablespace_redo_create(byte *ptr, const byte *end, const page_id_t &page_id, ulint parsed_bytes, bool parse_only)
Redo a tablespace create.
Definition: fil0fil.cc:10188
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:3492
void fil_encryption_reencrypt(std::vector< space_id_t > &sid_vector)
Roencrypt the tablespace keys by current master key.
Definition: fil0fil.cc:9124
byte * fil_tablespace_redo_rename(byte *ptr, const byte *end, const page_id_t &page_id, ulint parsed_bytes, bool parse_only)
Redo a tablespace rename.
Definition: fil0fil.cc:10288
fil_type_t fil_space_get_type(space_id_t space_id)
Gets the type of a file space.
Definition: fil0fil.cc:2256
void fil_space_inc_redo_skipped_count(space_id_t space_id)
Increase redo skipped count for a tablespace.
Definition: fil0fil.cc:4726
void fil_space_set_flags(fil_space_t *space, uint32_t flags)
Sets the flags of the tablespace.
Definition: fil0fil.cc:9379
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:9926
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:1128
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:6779
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_FRAG_ENTRY
Index pages of fragment pages (compressed LOB).
Definition: fil0fil.h:1296
dberr_t fil_close_tablespace(space_id_t space_id)
Closes a single-table tablespace.
Definition: fil0fil.cc:4336
constexpr page_type_t FIL_PAGE_INODE
Index node.
Definition: fil0fil.h:1212
bool fil_update_partition_name(space_id_t space_id, uint32_t fsp_flags, bool update_space, std::string &space_name, std::string &dd_path)
Compare and update space name and dd path for partitioned table.
Definition: fil0fil.cc:10063
void fil_free_scanned_files()
Free the data structures required for recovery.
Definition: fil0fil.cc:11523
constexpr page_type_t FIL_PAGE_TYPE_UNUSED
This page type is unused.
Definition: fil0fil.h:1206
constexpr page_type_t FIL_PAGE_INDEX
File page types (values of FIL_PAGE_TYPE)
Definition: fil0fil.h:1197
std::atomic_size_t fil_n_files_open
Number of files currently open.
Definition: fil0fil.cc:292
bool MySQL_undo_path_is_unique
The undo path is different from any other known directory.
Definition: fil0fil.cc:282
void fil_space_dec_redo_skipped_count(space_id_t space_id)
Decrease redo skipped count for a tablespace.
Definition: fil0fil.cc:4742
constexpr page_type_t FIL_PAGE_RTREE
R-tree node.
Definition: fil0fil.h:1200
void fil_space_open_if_needed(fil_space_t *space)
During crash recovery, open a tablespace if it had not been opened yet, to get valid size and flags.
Definition: fil0fil.h:1994
constexpr size_t FIL_IBD_FILE_INITIAL_SIZE
Initial size of a single-table tablespace in pages.
Definition: fil0fil.h:1122
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:88
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:6432
bool fil_space_read_name_and_filepath(space_id_t space_id, char **name, char **filepath)
Looks for a pre-existing fil_space_t with the given tablespace ID and, if found, returns the name and...
Definition: fil0fil.cc:5951
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:8928
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:5459
constexpr size_t FIL_IBT_FILE_INITIAL_SIZE
Definition: fil0fil.h:1123
void fil_space_update_name(fil_space_t *space, const char *name)
Update the tablespace name.
Definition: fil0fil.cc:11530
bool fil_open_files_limit_update(size_t &new_max_open_files)
Changes the maximum opened files limit.
Definition: fil0fil.cc:3625
constexpr page_no_t FIL_NULL
'null' (undefined) page offset in the context of file spaces
Definition: fil0fil.h:1131
constexpr size_t FIL_SPACE_MAGIC_N
Value of fil_space_t::magic_n.
Definition: fil0fil.h:553
dberr_t fil_reset_encryption(space_id_t space_id)
Reset the encryption type for the tablespace.
Definition: fil0fil.cc:8957
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:130
void fil_space_close(space_id_t space_id)
Close each file of a tablespace if open.
Definition: fil0fil.cc:3580
fil_space_t * fil_space_acquire(space_id_t space_id)
Acquire a tablespace when it could be dropped concurrently.
Definition: fil0fil.cc:4025
fil_space_t * fil_space_acquire_silent(space_id_t space_id)
Acquire a tablespace that may not exist.
Definition: fil0fil.cc:4034
Fil_state
Result of comparing a path.
Definition: fil0fil.h:130
@ MOVED_PREV_OR_HAS_DATADIR
Space ID and paths match but dd_table data dir flag doesn't exist or tablespace is created outside de...
@ MATCHES
The path matches what was found during the scan.
@ MISSING
No MLOG_FILE_DELETE record and the file could not be found.
@ DELETED
A MLOG_FILE_DELETE was found, file was deleted.
@ MOVED
Space ID matches but the paths don't match.
@ RENAMED
Tablespace and/or filename was renamed.
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:3958
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:3454
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_FRAG
Fragment pages of compressed LOB.
Definition: fil0fil.h:1293
char * fil_node_create(const char *name, page_no_t size, fil_space_t *space, bool is_raw, bool atomic_write, page_no_t max_pages=PAGE_NO_MAX)
Attach a file to a tablespace.
Definition: fil0fil.cc:2427
constexpr page_type_t FIL_PAGE_TYPE_LAST
Note the highest valid non-index page_type_t.
Definition: fil0fil.h:1299
void fil_tablespace_open_init_for_recovery(bool recovery)
Read the tablespace id to path mapping from the file.
fil_addr_t fil_addr_null
The null file address.
Definition: fil0fil.cc:326
void fil_close_all_files()
Closes all open files.
Definition: fil0fil.cc:3895
byte * fil_tablespace_redo_encryption(byte *ptr, const byte *end, space_id_t space_id, lsn_t lsn)
Parse and process an encryption redo record.
Definition: fil0fil.cc:10653
void fil_init(ulint max_n_open)
Initializes the tablespace memory cache.
Definition: fil0fil.cc:3610
size_t fil_encryption_rotate()
Rotate the tablespace keys by new master key.
Definition: fil0fil.cc:9122
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:1302
void fil_set_scan_dirs(const std::string &directories)
Normalize and save a list of directories to scan for datafiles.
Definition: fil0fil.cc:11502
fil_space_t * fil_space_get_sys_space()
Definition: fil0fil.h:2024
void fil_no_punch_hole(fil_node_t *file)
Note that the file system where the file resides doesn't support PUNCH HOLE.
Definition: fil0fil.cc:8833
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:3595
dberr_t fil_scan_for_tablespaces()
Discover tablespaces by reading the header from .ibd files.
Definition: fil0fil.cc:11508
byte fil_faddr_t
'type' definition in C: an address stored in a file page is a string of bytes
Definition: fil0fil.h:1145
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:5081
void fil_space_release(fil_space_t *space)
Release a tablespace acquired with fil_space_acquire().
Definition: fil0fil.cc:4040
bool fil_truncate_tablespace(space_id_t space_id, page_no_t size_in_pages)
Truncate the tablespace to needed size.
Definition: fil0fil.cc:4717
byte * fil_tablespace_redo_extend(byte *ptr, const byte *end, const page_id_t &page_id, ulint parsed_bytes, bool parse_only)
Redo a tablespace extend.
Definition: fil0fil.cc:10398
void fil_close()
Initializes the tablespace memory cache.
Definition: fil0fil.cc:8234
const char * fil_get_page_type_str(page_type_t type) noexcept
Get the page type as a string.
Definition: fil0fil.cc:11693
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:8188
std::vector< std::string, ut::allocator< std::string > > Filenames
Definition: fil0fil.h:116
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:7347
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:5766
page_no_t fil_page_get_next(const byte *page)
Get the successor of a file page.
Definition: fil0fil.cc:8207
constexpr size_t FIL_SCAN_THREADS_PER_CORE
Number of threads per core.
Definition: fil0fil.h:72
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_DATA
Data pages of compressed LOB.
Definition: fil0fil.h:1286
constexpr page_type_t FIL_PAGE_TYPE_XDES
Extent descriptor page.
Definition: fil0fil.h:1234
fil_type_t
File types.
Definition: fil0fil.h:120
@ FIL_TYPE_TEMPORARY
temporary tablespace (temporary undo log or tables)
Definition: fil0fil.h:122
@ FIL_TYPE_IMPORT
a tablespace that is being imported (no logging until finished)
Definition: fil0fil.h:124
@ FIL_TYPE_TABLESPACE
persistent tablespace (for system, undo log or tables)
Definition: fil0fil.h:126
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:3506
constexpr page_type_t FIL_PAGE_COMPRESSED
Compressed page.
Definition: fil0fil.h:1250
std::vector< space_id_t, ut::allocator< space_id_t > > Space_ids
Definition: fil0fil.h:117
std::atomic< std::uint64_t > fil_n_pending_tablespace_flushes
Number of pending tablespace flushes.
Definition: fil0fil.cc:289
constexpr page_type_t FIL_PAGE_SDI
Tablespace SDI Index page.
Definition: fil0fil.h:1203
bool fil_tablespace_lookup_for_recovery(space_id_t space_id)
Lookup the tablespace ID.
Definition: fil0fil.cc:9873
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:5383
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:8524
void fil_space_set_imported(space_id_t space_id)
Note that a tablespace has been imported.
Definition: fil0fil.cc:2270
constexpr size_t FIL_SCAN_MAX_THREADS
Maximum number of threads that will be used for scanning the tablespace files.
Definition: fil0fil.h:69
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:101
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:7373
constexpr page_type_t FIL_PAGE_TYPE_ZBLOB2
Subsequent compressed BLOB page.
Definition: fil0fil.h:1243
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:1247
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_FIRST
The first page of a compressed LOB.
Definition: fil0fil.h:1283
fil_space_t * fil_space_get(space_id_t space_id)
Look up a tablespace.
Definition: fil0fil.cc:2222
constexpr page_type_t FIL_PAGE_TYPE_ALLOCATED
Freshly allocated page.
Definition: fil0fil.h:1219
constexpr page_type_t FIL_PAGE_TYPE_LEGACY_DBLWR
Legacy doublewrite buffer page.
Definition: fil0fil.h:1268
constexpr page_type_t FIL_PAGE_IBUF_FREE_LIST
Insert buffer free list.
Definition: fil0fil.h:1215
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:3946
volatile bool recv_recovery_on
true when applying redo log records during crash recovery; false otherwise.
Definition: log0recv.cc:100
constexpr page_type_t FIL_PAGE_SDI_ZBLOB
Compressed SDI BLOB page.
Definition: fil0fil.h:1265
constexpr page_type_t FIL_PAGE_TYPE_TRX_SYS
Transaction system data.
Definition: fil0fil.h:1228
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 moved_prev_or_has_datadir)
Add tablespace to the set of tablespaces to be updated in DD.
Definition: fil0fil.cc:10054
Fil_state fil_tablespace_path_equals(space_id_t space_id, const char *space_name, ulint fsp_flags, std::string old_path, std::string *new_path)
Lookup the tablespace ID and return the path to the file.
Definition: fil0fil.cc:9930
page_type_t fil_page_get_type(const byte *page)
Get the file page type.
Definition: fil0fil.h:1807
constexpr page_type_t FIL_PAGE_ENCRYPTED
Encrypted page.
Definition: fil0fil.h:1253
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:8902
page_no_t fil_space_get_size(space_id_t space_id)
Returns the size of the space in pages.
Definition: fil0fil.cc:3478
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:5758
Compression::Type fil_get_compression(space_id_t space_id)
Get the compression algorithm for a tablespace.
Definition: fil0fil.cc:8892
space_id_t fil_space_get_id_by_name(const char *name)
Returns the space ID based on the tablespace name.
Definition: fil0fil.cc:6445
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:3395
constexpr space_id_t SPACE_UNKNOWN
Unknown space id.
Definition: fil0fil.h:1137
void fil_aio_wait(ulint segment)
Waits for an AIO operation to complete.
Definition: fil0fil.cc:7907
Fil_path MySQL_datadir_path
The MySQL server –datadir value.
Definition: fil0fil.cc:276
bool fil_op_replay_rename_for_ddl(const page_id_t &page_id, const char *old_name, const char *new_name)
Replay a file rename operation for ddl replay.
Definition: fil0fil.cc:9816
constexpr page_type_t FIL_PAGE_TYPE_SYS
System page.
Definition: fil0fil.h:1225
bool fil_space_is_redo_skipped(space_id_t space_id)
Check whether a single-table tablespace is redo skipped.
Definition: fil0fil.cc:4760
dberr_t fil_io(const IORequest &type, bool sync, const page_id_t &page_id, const page_size_t &page_size, ulint byte_offset, ulint len, void *buf, void *message)
Read or write data from a file.
Definition: fil0fil.cc:7964
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:8226
constexpr page_type_t FIL_PAGE_SDI_BLOB
Uncompressed SDI BLOB page.
Definition: fil0fil.h:1262
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:8740
constexpr page_type_t FIL_PAGE_TYPE_BLOB
Uncompressed BLOB page.
Definition: fil0fil.h:1237
bool fil_addr_is_null(const fil_addr_t &addr)
Returns true if file address is undefined.
Definition: fil0fil.cc:8193
constexpr page_type_t FIL_PAGE_TYPE_ZLOB_INDEX
Index pages of compressed LOB.
Definition: fil0fil.h:1290
void fil_page_set_type(byte *page, ulint type)
Sets the file page type.
Definition: fil0fil.cc:8214
dberr_t fil_discard_tablespace(space_id_t space_id)
Discards a single-table tablespace.
Definition: fil0fil.cc:4793
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:11683
ib_file_suffix
Common InnoDB file extensions.
Definition: fil0fil.h:559
@ DWR
Definition: fil0fil.h:566
@ BWR
Definition: fil0fil.h:567
@ IBT
Definition: fil0fil.h:564
@ IBD
Definition: fil0fil.h:561
@ CFP
Definition: fil0fil.h:563
@ CFG
Definition: fil0fil.h:562
@ NO_EXT
Definition: fil0fil.h:560
@ IBU
Definition: fil0fil.h:565
const char * dot_ext[]
Common InnoDB file extensions.
Definition: fil0fil.cc:285
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:5750
constexpr page_type_t FIL_PAGE_TYPE_RSEG_ARRAY
Rollback Segment Array page.
Definition: fil0fil.h:1271
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:8445
dberr_t fil_open_for_business(bool read_only_mode)
Free the Tablespace_files instance.
Definition: fil0fil.cc:9805
dberr_t fil_write_initial_pages(pfs_os_file_t file, const char *path, fil_type_t type, page_no_t size, const byte *encrypt_info, space_id_t space_id, uint32_t &space_flags, bool &atomic_write, bool &punch_hole)
Write initial pages for a new tablespace file created.
Definition: fil0fil.cc:5464
bool fil_space_open(space_id_t space_id)
Open each file of a tablespace if not already open.
Definition: fil0fil.cc:3566
dberr_t fil_delete_tablespace(space_id_t space_id, buf_remove_t buf_remove)
Deletes an IBD or IBU tablespace.
Definition: fil0fil.cc:4637
void fil_flush(space_id_t space_id)
Flushes to disk possible writes cached by the OS.
Definition: fil0fil.cc:8146
constexpr page_type_t FIL_PAGE_TYPE_FSP_HDR
File space header.
Definition: fil0fil.h:1231
std::string fil_get_dirs()
Get the list of directories that datafiles can reside in.
Definition: fil0fil.cc:11520
void fil_set_scan_dir(const std::string &directory, bool is_undo_dir=false)
Normalize and save a directory to scan for datafiles.
Definition: fil0fil.cc:11498
constexpr page_type_t FIL_PAGE_IBUF_BITMAP
Insert buffer bitmap.
Definition: fil0fil.h:1222
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
static bool equal(const Item *i1, const Item *i2, const Field *f2)
Definition: sql_select.cc:3820
constexpr uint32_t FSP_FLAGS_GET_ENCRYPTION(uint32_t flags)
Return the contents of the ENCRYPTION field.
Definition: fsp0types.h:351
static int flags[50]
Definition: hp_test1.cc:40
Insert buffer global types.
unsigned char byte
Blob class.
Definition: common.h:151
Recovery.
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
A better implementation of the UNIX ctype(3) library.
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename
Definition: ctype-utf8.cc:7040
#define my_tolower(s, c)
Definition: m_ctype.h:688
static uint16_t mach_read_from_2(const byte *b)
The following function is used to fetch data from 2 consecutive bytes.
static const char * filepath
Definition: myisamlog.cc:94
static size_t file_size
Definition: mysql_config_editor.cc:71
static char * path
Definition: mysqldump.cc:137
Definition: buf0block_hint.cc:30
unsigned long long Object_id
Definition: object_id.h:31
Innodb data dictionary name.
Definition: dict0dd.cc:7319
Definition: os0file.h:86
Json_data_extension ext
Definition: backend.cc:51
HARNESS_EXPORT void trim(std::string &str)
Removes both leading and trailing whitespaces from the string.
Definition: string_utils.cc:70
static mysql_service_status_t validate(reference_caching_channel channel) noexcept
Definition: component.cc:67
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
os_file_type_t
Definition: os0file.h:661
uint64_t os_offset_t
File offset in bytes.
Definition: os0file.h:84
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
case opt name
Definition: sslopt-case.h:33
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:1833
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:1886
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:1883
PageCallback()
Default constructor.
Definition: fil0fil.h:1835
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:1860
void set_page_size(const buf_frame_t *page) 1
Set the tablespace table size.
Definition: fil0fil.cc:8706
PageCallback(PageCallback &&)=delete
const char * m_filepath
Physical file path.
Definition: fil0fil.h:1889
const page_size_t & get_page_size() const
The compressed page size.
Definition: fil0fil.h:1878
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:1690
Data structure for a database table.
Definition: dict0mem.h:1909
File space address.
Definition: fil0fil.h:1148
fil_addr_t()
Definition: fil0fil.h:1150
std::ostream & print(std::ostream &out) const
Print a string representation.
Definition: fil0fil.h:1170
uint32_t boffset
Byte offset within the page.
Definition: fil0fil.h:1180
fil_addr_t(page_no_t p, uint32_t boff)
Constructor.
Definition: fil0fil.h:1155
page_no_t page
Page number within a space.
Definition: fil0fil.h:1177
bool is_equal(const fil_addr_t &rhs) const
Compare to instances.
Definition: fil0fil.h:1160
bool is_null() const
Check if the file address is null.
Definition: fil0fil.h:1166
File node of a tablespace or the log data space.
Definition: fil0fil.h:155
page_no_t max_size
maximum size of the file in database pages
Definition: fil0fil.h:202
void set_flushed()
Sets file to flushed state.
Definition: fil0fil.h:164
size_t n_pending_ios
count of pending I/O's; is_open must be true if nonzero
Definition: fil0fil.h:205
fil_space_t * space
tablespace containing this file
Definition: fil0fil.h:169
size_t block_size
block size to use for punching holes
Definition: fil0fil.h:226
bool is_open
whether this file is open.
Definition: fil0fil.h:177
bool atomic_write
whether atomic write is enabled for this file
Definition: fil0fil.h:229
pfs_os_file_t handle
file handle (valid if is_open)
Definition: fil0fil.h:180
page_no_t init_size
initial size of the file in database pages; FIL_IBD_FILE_INITIAL_SIZE by default
Definition: fil0fil.h:199
page_no_t size
size of the file in database pages (0 if not known yet); the possible last incomplete megabyte may be...
Definition: fil0fil.h:191
size_t magic_n
FIL_NODE_MAGIC_N.
Definition: fil0fil.h:232
size_t n_pending_flushes
count of pending flushes; is_open must be true if nonzero
Definition: fil0fil.h:208
bool is_flushed() const
Returns true if the file is flushed.
Definition: fil0fil.h:159
os_event_t sync_event
event that groups and serializes calls to fsync
Definition: fil0fil.h:183
int64_t flush_counter
the modification_counter of the latest flush to disk
Definition: fil0fil.h:217
page_no_t flush_size
Size of the file when last flushed, used to force the flush when file grows to keep the filesystem me...
Definition: fil0fil.h:195
bool can_be_closed() const
Returns true if the file can be closed.
Definition: fil0fil.cc:1827
UT_LIST_NODE_T(fil_node_t) List_node
Definition: fil0fil.h:166
bool punch_hole
whether the file system of this file supports PUNCH HOLE
Definition: fil0fil.h:223
int64_t modification_counter
number of writes to the file since the system was started
Definition: fil0fil.h:214
List_node LRU
link to the fil_system->LRU list (keeping track of open files)
Definition: fil0fil.h:220
char * name
file name; protected by Fil_shard::m_mutex and log_sys->mutex.
Definition: fil0fil.h:172
bool is_being_extended
Set to true when a file is being extended.
Definition: fil0fil.h:211
bool is_raw_disk
whether the file actually is a raw device or disk partition
Definition: fil0fil.h:186
Tablespace or log data space.
Definition: fil0fil.h:236
void initialize() noexcept
Initializes fields.
Definition: fil0fil.h:336
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:9489
fil_node_t * get_file_node(page_no_t *page_no) noexcept
Get the file node corresponding to the given page number of the tablespace.
Definition: fil0fil.cc:11765
ib::Timer m_last_extended
When the tablespace was extended last.
Definition: fil0fil.h:318
size_t get_reference_count() const
Definition: fil0fil.cc:11827
space_id_t id
Tablespace ID.
Definition: fil0fil.h:332
bool is_compressed() const noexcept
Check if the tablespace is compressed.
Definition: fil0fil.h:524
Encryption::Progress encryption_op_in_progress
Encryption is in progress.
Definition: fil0fil.h:511
std::atomic_bool m_deleted
true if the tablespace is marked for deletion.
Definition: fil0fil.h:424
void bump_version()
Bumps the space object version and cause all pages in buffer pool that reference the current space ob...
Definition: fil0fil.cc:11849
List_node unflushed_spaces
List of spaces with at least one unflushed file we have written to.
Definition: fil0fil.h:499
page_no_t size
Tablespace file size in pages; 0 if not known yet.
Definition: fil0fil.h:459
rw_lock_t latch
Latch protecting the file space storage allocation.
Definition: fil0fil.h:494
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:434
uint32_t flags
Tablespace flags; see fsp_flags_is_valid() and page_size_t(ulint) (constructor).
Definition: fil0fil.h:476
void release_free_extents(ulint n_reserved)
Release the reserved free extents.
Definition: fil0fil.cc:9462
page_no_t size_in_header
FSP_SIZE in the tablespace header; 0 if not known yet.
Definition: fil0fil.h:462
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:380
Encryption_metadata m_encryption_metadata
Encryption metadata.
Definition: fil0fil.h:508
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:430
page_no_t m_undo_extend
Extend undo tablespaces by so many pages.
Definition: fil0fil.h:321
uint64_t autoextend_size_in_bytes
Autoextend size.
Definition: fil0fil.h:465
uint32_t free_len
Length of the FSP_FREE list.
Definition: fil0fil.h:468
lsn_t m_header_page_flush_lsn
Flush lsn of header page.
Definition: fil0fil.h:514
void dec_ref() noexcept
Decrement the page reference count.
Definition: fil0fil.h:294
std::atomic_size_t m_n_ref_count
Number of buf_page_t entries that point to this instance.
Definition: fil0fil.h:420
Files files
Files attached to this tablespace.
Definition: fil0fil.h:456
bool stop_new_ops
We set this true when we start deleting a single-table tablespace.
Definition: fil0fil.h:443
ulint magic_n
FIL_SPACE_MAGIC_N.
Definition: fil0fil.h:517
uint32_t n_reserved_extents
Number of reserved free extents for ongoing operations like B-tree page split.
Definition: fil0fil.h:480
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:537
uint32_t get_current_version() const
Returns current version of the space object.
Definition: fil0fil.cc:11807
bool is_encrypted() const noexcept
Check if the tablespace is encrypted.
Definition: fil0fil.h:530
static fil_space_t * s_sys_space
System tablespace.
Definition: fil0fil.h:520
uint32_t n_pending_ops
This is positive when we have pending operations against this tablespace.
Definition: fil0fil.h:490
page_no_t free_limit
Contents of FSP_FREE_LIMIT.
Definition: fil0fil.h:471
UT_LIST_NODE_T(fil_space_t) List_node
Definition: fil0fil.h:237
uint32_t get_recent_version() const
Returns current version of the space object.
Definition: fil0fil.cc:11811
char * name
Tablespace name.
Definition: fil0fil.h:329
std::vector< Observer *, ut::allocator< Observer * > > Flush_observers
Definition: fil0fil.h:315
Compression::Type compression_type
Compression algorithm.
Definition: fil0fil.h:505
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:484
fil_type_t purpose
Purpose.
Definition: fil0fil.h:452
void set_deleted()
Marks the space object for deletion.
Definition: fil0fil.cc:11835
bool was_not_deleted() const
Definition: fil0fil.cc:11799
bool is_in_unflushed_spaces
true if this space is currently in unflushed_spaces
Definition: fil0fil.h:502
bool has_no_references() const
Definition: fil0fil.cc:11817
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:326
std::vector< fil_node_t, ut::allocator< fil_node_t > > Files
Definition: fil0fil.h:238
void inc_ref() noexcept
Increment the page reference count.
Definition: fil0fil.h:283
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:448
bool is_deleted() const
Definition: fil0fil.cc:11794
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:177
InnoDB condition variable.
Definition: os0event.cc:63
Common file descriptor for file IO instrumentation with PFS on windows and other platforms.
Definition: os0file.h:173
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:360
Definition: trx0trx.h:684
Version control for database, common definitions, and include files.
#define OS_PATH_SEPARATOR
Definition: univ.i:538
#define UNIV_NOTHROW
Definition: univ.i:456
#define OS_PATH_SEPARATOR_ALT
Definition: univ.i:539
unsigned long int ulint
Definition: univ.i:406
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:69
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:57
#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