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