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