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