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