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