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