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