MySQL 8.0.40
Source Code Documentation
|
The interface to the operating system file i/o primitives. More...
#include "os0file.h"
#include "fil0fil.h"
#include "ha_prototypes.h"
#include "log0write.h"
#include "my_dbug.h"
#include "my_io.h"
#include "sql_const.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "os0event.h"
#include "os0thread.h"
#include <errno.h>
#include <lz4.h>
#include "my_aes.h"
#include "my_rnd.h"
#include "mysql/service_mysql_keyring.h"
#include "mysqld.h"
#include <sys/types.h>
#include <zlib.h>
#include <ctime>
#include <functional>
#include <new>
#include <ostream>
#include <vector>
Classes | |
struct | Slot |
The asynchronous I/O context. More... | |
class | AIO |
The asynchronous i/o array structure. More... | |
class | AIOHandler |
Generic AIO Handler methods. More... | |
class | SyncFileIO |
Helper class for doing synchronous file IO. More... | |
class | SimulatedAIOHandler |
Simulated AIO handler for reaping IO requests. More... | |
Macros | |
#define | BUFFER_BLOCK_SIZE ((ulint)(UNIV_PAGE_SIZE * 1.3)) |
Block buffer size. More... | |
#define | USE_FILE_LOCK |
Typedefs | |
using | Blocks = std::vector< file::Block > |
For storing the allocated blocks. More... | |
Functions | |
bool | os_is_o_direct_supported () |
Determine if O_DIRECT is supported. More... | |
bool | buf_flush_page_cleaner_is_active () |
Checks if the page_cleaner is in active state. More... | |
std::ostream & | operator<< (std::ostream &out, const Slot &obj) noexcept |
static bool | os_aio_validate () |
Validates the consistency of the aio system. More... | |
static bool | os_file_handle_error (const char *name, const char *operation) |
Does error handling when a file operation fails. More... | |
dberr_t | os_file_punch_hole (os_file_t fh, os_offset_t off, os_offset_t len) |
Free storage space associated with a section of the file. More... | |
static bool | os_file_handle_error_no_exit (const char *name, const char *operation, bool on_error_silent) |
Does error handling when a file operation fails. More... | |
static dberr_t | os_file_io_complete (const IORequest &type, os_file_t fh, byte *buf, ulint src_len, os_offset_t offset, ulint len) |
Decompress after a read and punch a hole in the file if it was a write. More... | |
static dberr_t | os_aio_simulated_handler (ulint global_segment, fil_node_t **m1, void **m2, IORequest *type) |
Does simulated AIO. More... | |
static bool | os_file_can_delete (const char *name) |
Check the file type and determine if it can be deleted. More... | |
byte * | os_block_get_frame (const file::Block *block) noexcept |
Get the sector aligned frame pointer. More... | |
file::Block * | os_alloc_block () noexcept |
Allocate a page for sync IO. More... | |
void | os_free_block (file::Block *block) noexcept |
Free a page after sync IO. More... | |
ulint | os_file_compressed_page_size (const byte *buf) |
If it is a compressed page return the compressed page data + footer size. More... | |
ulint | os_file_original_page_size (const byte *buf) |
If it is a compressed page return the original page data + footer size. More... | |
byte * | os_file_compress_page (Compression compression, ulint block_size, byte *src, ulint src_len, byte *dst, ulint *dst_len) |
Compress a data page. More... | |
static bool | os_aio_validate_skip () |
Validates the consistency the aio system some of the time. More... | |
static int | os_file_lock (int fd, const char *name) |
Obtain an exclusive lock on a file. More... | |
FILE * | os_file_create_tmpfile () |
Create a temporary file. More... | |
void | os_file_read_string (FILE *file, char *str, ulint size) |
Rewind file to its start, read at most size - 1 bytes from it to str, and NUL-terminate str. More... | |
static bool | os_file_is_root (const char *path, const char *last_slash) |
Check if the path refers to the root of a drive using a pointer to the last directory separator that the caller has fixed. More... | |
static char * | os_file_get_parent_dir (const char *path) |
Return the parent directory component of a null-terminated path. More... | |
dberr_t | os_file_create_subdirs_if_needed (const char *path) |
Creates all missing subdirectories along the given path. More... | |
file::Block * | os_file_compress_page (IORequest &type, void *&buf, ulint *n) |
Allocate the buffer for IO on a transparently compressed table. More... | |
file::Block * | os_file_encrypt_page (const IORequest &type, void *&buf, ulint n) |
Encrypt a page content when write it to disk. More... | |
static file::Block * | os_file_encrypt_log (const IORequest &type, void *&buf, byte *&scratch, ulint n) |
Encrypt log blocks provided in first n bytes of buf. More... | |
static dberr_t | os_file_punch_hole_posix (os_file_t fh, os_offset_t off, os_offset_t len) |
Free storage space associated with a section of the file. More... | |
static ulint | os_file_get_last_error_low (bool report_all_errors, bool on_error_silent) |
Retrieves the last error number if an error occurs in a file io function. More... | |
static int | os_file_fsync_posix (os_file_t file) |
Wrapper to fsync(2)/fdatasync(2) that retries the call on some errors. More... | |
static void | os_parent_dir_fsync_posix (const char *path) |
fsync the parent directory of a path. More... | |
static bool | os_file_status_posix (const char *path, bool *exists, os_file_type_t *type) |
Check the existence and type of the given file. More... | |
static bool | os_file_exists_posix (const char *path) |
Check the existence and usefulness of a given path. More... | |
bool | os_file_flush_func (os_file_t file) |
NOTE! Use the corresponding macro os_file_flush(), not directly this function! Flushes the write buffers of a given file to the disk. More... | |
bool | os_file_create_directory (const char *pathname, bool fail_if_exists) |
This function attempts to create a directory named pathname. More... | |
bool | os_file_scan_directory (const char *path, os_dir_cbk_t scan_cbk, bool is_drop) |
This function scans the contents of a directory and invokes the callback for each entry. More... | |
pfs_os_file_t | os_file_create_func (const char *name, ulint create_mode, ulint purpose, bool read_only, bool *success) |
NOTE! Use the corresponding macro os_file_create(), not directly this function! Opens an existing file or creates a new. More... | |
pfs_os_file_t | os_file_create_simple_no_error_handling_func (const char *name, ulint create_mode, ulint access_type, bool read_only, mode_t umask, bool *success) |
NOTE! Use the corresponding macro os_file_create_simple_no_error_handling(), not directly this function! A simple function to open or create a file. More... | |
bool | os_file_delete_if_exists_func (const char *name, bool *exist) |
Deletes a file if it exists. More... | |
bool | os_file_delete_func (const char *name) |
Deletes a file. More... | |
bool | os_file_rename_func (const char *oldpath, const char *newpath) |
NOTE! Use the corresponding macro os_file_rename(), not directly this function! Renames a file (can also move it to another directory). More... | |
bool | os_file_close_func (os_file_t file) |
NOTE! Use the corresponding macro os_file_close(), not directly this function! Closes a file handle. More... | |
os_offset_t | os_file_get_size (pfs_os_file_t file) |
Gets a file size. More... | |
os_file_size_t | os_file_get_size (const char *filename) |
Gets a file size. More... | |
static dberr_t | os_get_free_space_posix (const char *path, uint64_t &free_space) |
Get available free space on disk. More... | |
static dberr_t | os_file_get_status_posix (const char *path, os_file_stat_t *stat_info, struct stat *statinfo, bool check_rw_perm, bool read_only) |
This function returns information about the specified file. More... | |
static bool | os_file_truncate_posix (const char *pathname, pfs_os_file_t file, os_offset_t size) |
Truncates a file to a specified size in bytes. More... | |
bool | os_file_set_eof (FILE *file) |
Truncates a file at its current position. More... | |
void | os_aio_simulated_put_read_threads_to_sleep () |
This function can be called if one wants to post a batch of reads and prefers an i/o-handler thread to handle them all at once later. More... | |
static ssize_t | os_file_io (const IORequest &in_type, os_file_t file, void *buf, ulint n, os_offset_t offset, dberr_t *err, const file::Block *e_block) |
Does a synchronous read or write depending upon the type specified In case of partial reads/writes the function tries NUM_RETRIES_ON_PARTIAL_IO times to read/write the complete data. More... | |
static ssize_t | os_file_pwrite (IORequest &type, os_file_t file, const byte *buf, ulint n, os_offset_t offset, dberr_t *err, const file::Block *e_block) |
Does a synchronous write operation in Posix. More... | |
static dberr_t | os_file_write_page (IORequest &type, const char *name, os_file_t file, const byte *buf, os_offset_t offset, ulint n, const file::Block *e_block) |
Requests a synchronous write operation. More... | |
static ssize_t | os_file_pread (IORequest &type, os_file_t file, void *buf, ulint n, os_offset_t offset, dberr_t *err) |
Does a synchronous read operation in Posix. More... | |
static dberr_t | os_file_read_page (IORequest &type, const char *file_name, os_file_t file, void *buf, os_offset_t offset, ulint n, ulint *o, bool exit_on_err) |
Requests a synchronous positioned read operation. More... | |
ulint | os_file_get_last_error (bool report_all_errors) |
Retrieves the last error number if an error occurs in a file io function. More... | |
static bool | os_file_handle_error_cond_exit (const char *name, const char *operation, bool should_exit, bool on_error_silent) |
Does error handling when a file operation fails. More... | |
void | os_file_set_nocache (int fd, const char *file_name, const char *operation_name) |
Tries to disable OS caching on an opened file descriptor. More... | |
bool | os_file_set_size_fast (const char *name, pfs_os_file_t pfs_file, os_offset_t offset, os_offset_t size, bool flush) |
Allocate a block to file using fallocate from the given offset if fallocate is supported. More... | |
bool | os_file_set_size (const char *name, pfs_os_file_t file, os_offset_t offset, os_offset_t size, bool flush) |
Write the specified number of zeros to a file from specific offset. More... | |
bool | os_file_truncate (const char *pathname, pfs_os_file_t file, os_offset_t size) |
Truncates a file to a specified size in bytes. More... | |
bool | os_file_seek (const char *pathname, os_file_t file, os_offset_t offset) |
Set read/write position of a file handle to specific offset. More... | |
dberr_t | os_file_read_func (IORequest &type, const char *file_name, os_file_t file, void *buf, os_offset_t offset, ulint n) |
NOTE! Use the corresponding macro os_file_read_first_page(), not directly this function! Requests a synchronous read operation of page 0 of IBD file. More... | |
dberr_t | os_file_read_first_page_func (IORequest &type, const char *file_name, os_file_t file, void *buf, ulint n) |
NOTE! Use the corresponding macro os_file_read_first_page(), not directly this function! Requests a synchronous read operation of page 0 of IBD file. More... | |
static dberr_t | os_file_copy_read_write (os_file_t src_file, os_offset_t src_offset, os_file_t dest_file, os_offset_t dest_offset, uint size) |
copy data from one file to another file using read, write. More... | |
dberr_t | os_file_copy_func (os_file_t src_file, os_offset_t src_offset, os_file_t dest_file, os_offset_t dest_offset, uint size) |
Copy data from one file to another file. More... | |
dberr_t | os_file_read_no_error_handling_func (IORequest &type, const char *file_name, os_file_t file, void *buf, os_offset_t offset, ulint n, ulint *o) |
NOTE! Use the corresponding macro os_file_read_no_error_handling(), not directly this function! Requests a synchronous positioned read operation. More... | |
dberr_t | os_file_write_func (IORequest &type, const char *name, os_file_t file, const void *buf, os_offset_t offset, ulint n) |
NOTE! Use the corresponding macro os_file_write(), not directly this function! Requests a synchronous write operation. More... | |
bool | os_file_status (const char *path, bool *exists, os_file_type_t *type) |
Check the existence and type of a given path. More... | |
bool | os_file_exists (const char *path) |
Check the existence and usefulness of a given path. More... | |
bool | os_is_sparse_file_supported (pfs_os_file_t fh) |
Check if the file system supports sparse files. More... | |
dberr_t | os_get_free_space (const char *path, uint64_t &free_space) |
Get available free space on disk. More... | |
dberr_t | os_file_get_status (const char *path, os_file_stat_t *stat_info, bool check_rw_perm, bool read_only) |
This function returns information about the specified file. More... | |
dberr_t | os_file_write_zeros (pfs_os_file_t file, const char *name, ulint page_size, os_offset_t start, ulint len) |
Fill the pages with NULs. More... | |
bool | os_file_check_mode (const char *name, bool read_only) |
Check if a file can be opened in read-write mode. More... | |
dberr_t | os_aio_handler (ulint segment, fil_node_t **m1, void **m2, IORequest *request) |
Waits for an AIO operation to complete. More... | |
static void | io_handler_thread (ulint segment) |
I/o-handler thread function. More... | |
void | os_create_block_cache () |
Creates and initializes block_cache. More... | |
bool | os_aio_init (ulint n_readers, ulint n_writers) |
Initializes the asynchronous io system. More... | |
void | os_aio_start_threads () |
Starts one thread for each segment created in os_aio_init. More... | |
void | os_aio_free () |
Frees the asynchronous io system. More... | |
void | os_aio_wake_all_threads_at_shutdown () |
Wakes up all async i/o threads so that they know to exit themselves in shutdown. More... | |
void | os_aio_wait_until_no_pending_writes () |
Waits until there are no pending writes in AIO::s_writes. More... | |
void | os_aio_simulated_wake_handler_threads () |
Wakes up simulated aio i/o-handler threads if they have something to do. More... | |
dberr_t | os_aio_func (IORequest &type, AIO_mode aio_mode, const char *name, pfs_os_file_t file, void *buf, os_offset_t offset, ulint n, bool read_only, fil_node_t *m1, void *m2) |
NOTE! Use the corresponding macro os_aio(), not directly this function! Requests an asynchronous i/o operation. More... | |
void | os_aio_print (FILE *file) |
Prints info of the aio arrays. More... | |
void | os_aio_refresh_stats () |
Refreshes the statistics used to print per-second averages. More... | |
bool | os_aio_all_slots_free () |
Checks that all slots in the system have been freed, that is, there are no pending io operations. More... | |
void | os_aio_print_pending_io (FILE *file) |
Prints all pending IO. More... | |
void | os_file_set_umask (mode_t umask) |
Set the global file create umask. More... | |
dberr_t | os_file_write_retry (IORequest &type, const char *name, pfs_os_file_t file, const void *buf, os_offset_t offset, ulint n) |
This is a wrapper function for the os_file_write() function call. More... | |
Variables | |
unsigned long long | os_fsync_threshold = 0 |
static const ulint | IO_IBUF_SEGMENT = 0 |
Insert buffer segment id. More... | |
static const ulint | NUM_RETRIES_ON_PARTIAL_IO = 10 |
Number of retries for partial I/O's. More... | |
static Blocks * | block_cache |
Block collection. More... | |
static const size_t | MAX_BLOCKS = 128 |
Number of blocks to allocate for sync read/writes. More... | |
static ulint | os_io_ptr_align = UNIV_SECTOR_SIZE |
Disk sector size of aligning write buffer for DIRECT_IO. More... | |
static mode_t | os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
This specifies the file permissions InnoDB uses when it creates files in Unix; the value of os_innodb_umask is initialized in ha_innodb.cc to my_umask. More... | |
static const ulint | OS_AIO_MERGE_N_CONSECUTIVE = 64 |
In simulated aio, merge at most this many consecutive i/os. More... | |
static os_event_t * | os_aio_segment_wait_events = nullptr |
Array of events used in simulated AIO. More... | |
static ulint | os_aio_n_segments = ULINT_UNDEFINED |
Number of asynchronous I/O segments. More... | |
static bool | os_aio_recommend_sleep_for_read_threads = false |
If the following is true, read i/o handler threads try to wait until a batch of new read requests have been posted. More... | |
ulint | os_n_file_reads = 0 |
static ulint | os_bytes_read_since_printout = 0 |
ulint | os_n_file_writes = 0 |
ulint | os_n_fsyncs = 0 |
static ulint | os_n_file_reads_old = 0 |
static ulint | os_n_file_writes_old = 0 |
static ulint | os_n_fsyncs_old = 0 |
std::atomic< ulint > | os_n_pending_writes {0} |
Number of pending write operations. More... | |
std::atomic< ulint > | os_n_pending_reads {0} |
Number of pending read operations. More... | |
static std::chrono::steady_clock::time_point | os_last_printout |
bool | os_has_said_disk_full = false |
uint | page_zip_level |
Default Zip compression level. More... | |
The interface to the operating system file i/o primitives.
Created 10/21/1995 Heikki Tuuri
#define BUFFER_BLOCK_SIZE ((ulint)(UNIV_PAGE_SIZE * 1.3)) |
Block buffer size.
#define USE_FILE_LOCK |
using Blocks = std::vector<file::Block> |
For storing the allocated blocks.
bool buf_flush_page_cleaner_is_active | ( | ) |
Checks if the page_cleaner is in active state.
Checks if the page_cleaner is in active state.
|
static |
I/o-handler thread function.
[in] | segment | The AIO segment the thread will work on |
|
inlinenoexcept |
bool os_aio_all_slots_free | ( | ) |
Checks that all slots in the system have been freed, that is, there are no pending io operations.
void os_aio_free | ( | ) |
Frees the asynchronous io system.
dberr_t os_aio_func | ( | IORequest & | type, |
AIO_mode | aio_mode, | ||
const char * | name, | ||
pfs_os_file_t | file, | ||
void * | buf, | ||
os_offset_t | offset, | ||
ulint | n, | ||
bool | read_only, | ||
fil_node_t * | m1, | ||
void * | m2 | ||
) |
NOTE! Use the corresponding macro os_aio(), not directly this function! Requests an asynchronous i/o operation.
[in] | type | IO request context |
[in] | aio_mode | IO mode |
[in] | name | Name of the file or path as NUL terminated string |
[in] | file | Open file handle |
[out] | buf | buffer where to read |
[in] | offset | file offset where to read |
[in] | n | how many bytes to read or write; this must not cross a file boundary; in AIO this must be a block size multiple |
[in] | read_only | if true read only mode checks are enforced |
[in,out] | m1 | Message for the AIO handler, (can be used to identify a completed AIO operation); ignored if mode is OS_AIO_SYNC |
[in,out] | m2 | message for the AIO handler (can be used to identify a completed AIO operation); ignored if mode is OS_AIO_SYNC |
dberr_t os_aio_handler | ( | ulint | segment, |
fil_node_t ** | m1, | ||
void ** | m2, | ||
IORequest * | request | ||
) |
Waits for an AIO operation to complete.
This function is used to wait the for completed requests. The AIO array of pending requests is divided into segments. The thread specifies which segment or slot it wants to wait for. NOTE: this function will also take care of freeing the AIO slot, therefore no other thread is allowed to do the freeing!
[in] | segment | The number of the segment in the AIO arrays to wait for; segment 0 is the ibuf I/O thread, then follow the non-ibuf read threads, and as the last are the non-ibuf write threads |
[out] | m1 | the messages passed with the AIO request; note that also in the case where the AIO operation failed, these output parameters are valid and can be used to restart the operation, for example |
[out] | m2 | callback message |
[out] | request | OS_FILE_WRITE or ..._READ |
Initializes the asynchronous io system.
Creates an array for ibuf i/o (if not in read-only mode). Also creates one array each for read and write where each array is divided logically into n_readers and n_writers respectively. The caller must create an i/o handler thread for each segment in these arrays by calling os_aio_start_threads().
[in] | n_readers | number of reader threads |
[in] | n_writers | number of writer threads |
void os_aio_print | ( | FILE * | file | ) |
Prints info of the aio arrays.
[in,out] | file | file where to print |
void os_aio_print_pending_io | ( | FILE * | file | ) |
Prints all pending IO.
[in] | file | File where to print |
void os_aio_refresh_stats | ( | ) |
Refreshes the statistics used to print per-second averages.
|
static |
Does simulated AIO.
This function should be called by an i/o-handler thread.
[in] | global_segment | The number of the segment in the aio arrays to await for; segment 0 is the ibuf i/o thread, then follow the non-ibuf read threads, and as the last are the non-ibuf write threads |
[out] | m1 | the messages passed with the AIO request; note that also in the case where the AIO operation failed, these output parameters are valid and can be used to restart the operation, for example |
[out] | m2 | Callback argument |
[in] | type | IO context |
Found a slot that has already completed its IO
void os_aio_simulated_put_read_threads_to_sleep | ( | ) |
This function can be called if one wants to post a batch of reads and prefers an i/o-handler thread to handle them all at once later.
You must call os_aio_simulated_wake_handler_threads later to ensure the threads are not left sleeping!
void os_aio_simulated_wake_handler_threads | ( | ) |
Wakes up simulated aio i/o-handler threads if they have something to do.
void os_aio_start_threads | ( | ) |
Starts one thread for each segment created in os_aio_init.
|
static |
Validates the consistency of the aio system.
Validates the consistency the aio system.
|
static |
Validates the consistency the aio system some of the time.
Try os_aio_validate() every this many times
The os_aio_validate() call skip counter. Use a signed type because of the race condition below.
void os_aio_wait_until_no_pending_writes | ( | ) |
Waits until there are no pending writes in AIO::s_writes.
Waits until there are no pending writes in os_aio_write_array.
There can be other, synchronous, pending writes.
void os_aio_wake_all_threads_at_shutdown | ( | ) |
Wakes up all async i/o threads so that they know to exit themselves in shutdown.
|
noexcept |
Allocate a page for sync IO.
|
noexcept |
Get the sector aligned frame pointer.
[in] | block | the memory block containing the page frame. |
void os_create_block_cache | ( | ) |
Creates and initializes block_cache.
Creates array of MAX_BLOCKS and allocates the memory in each block to hold BUFFER_BLOCK_SIZE of data.
This function is called by InnoDB during srv_start(). It is also called by MEB while applying the redo logs on TDE tablespaces, the "Blocks" allocated in this block_cache are used to hold the decrypted page data.
|
static |
Check the file type and determine if it can be deleted.
[in] | name | Filename/Path to check |
bool os_file_check_mode | ( | const char * | name, |
bool | read_only | ||
) |
Check if a file can be opened in read-write mode.
[in] | name | filename to check |
[in] | read_only | true if check for read-only mode only |
true | if file can be opened in the specified mode (rw or ro); or file does not exist |
false | if file exists and can't be opened in the specified mode |
bool os_file_close_func | ( | os_file_t | file | ) |
NOTE! Use the corresponding macro os_file_close(), not directly this function! Closes a file handle.
In case of error, error number can be retrieved with os_file_get_last_error.
[in] | file | Handle to a file |
byte * os_file_compress_page | ( | Compression | compression, |
ulint | block_size, | ||
byte * | src, | ||
ulint | src_len, | ||
byte * | dst, | ||
ulint * | dst_len | ||
) |
Compress a data page.
[in] | compression | Compression algorithm |
[in] | block_size | File system block size |
[in] | src | Source contents to compress |
[in] | src_len | Length in bytes of the source |
[out] | dst | Compressed page contents |
[out] | dst_len | Length in bytes of dst contents |
file::Block * os_file_compress_page | ( | IORequest & | type, |
void *& | buf, | ||
ulint * | n | ||
) |
Allocate the buffer for IO on a transparently compressed table.
[in] | type | IO flags |
[out] | buf | buffer to read or write |
[in,out] | n | number of bytes to read/write, starting from offset |
If it is a compressed page return the compressed page data + footer size.
[in] | buf | Buffer to check, must include header + 10 bytes |
dberr_t os_file_copy_func | ( | os_file_t | src_file, |
os_offset_t | src_offset, | ||
os_file_t | dest_file, | ||
os_offset_t | dest_offset, | ||
uint | size | ||
) |
Copy data from one file to another file.
Data is read/written at current file offset.
[in] | src_file | file handle to copy from |
[in] | src_offset | offset to copy from |
[in] | dest_file | file handle to copy to |
[in] | dest_offset | offset to copy to |
[in] | size | number of bytes to copy |
|
static |
copy data from one file to another file using read, write.
[in] | src_file | file handle to copy from |
[in] | src_offset | offset to copy from |
[in] | dest_file | file handle to copy to |
[in] | dest_offset | offset to copy to |
[in] | size | number of bytes to copy |
bool os_file_create_directory | ( | const char * | pathname, |
bool | fail_if_exists | ||
) |
This function attempts to create a directory named pathname.
The new directory gets default permissions. On Unix the permissions are (0770 & ~umask). If the directory exists already, nothing is done and the call succeeds, unless the fail_if_exists arguments is true. If another error occurs, such as a permission error, this does not crash, but reports the error and returns false.
[in] | pathname | directory name as null-terminated string |
[in] | fail_if_exists | if true, pre-existing directory is treated as an error. |
pfs_os_file_t os_file_create_func | ( | const char * | name, |
ulint | create_mode, | ||
ulint | purpose, | ||
bool | read_only, | ||
bool * | success | ||
) |
NOTE! Use the corresponding macro os_file_create(), not directly this function! Opens an existing file or creates a new.
[in] | name | name of the file or path as a null-terminated string |
[in] | create_mode | create mode |
[in] | purpose | OS_DATA_FILE, OS_LOG_FILE etc. |
[in] | read_only | if true read only mode checks are enforced |
[out] | success | true if succeeded |
pfs_os_file_t os_file_create_simple_no_error_handling_func | ( | const char * | name, |
ulint | create_mode, | ||
ulint | access_type, | ||
bool | read_only, | ||
mode_t | umask, | ||
bool * | success | ||
) |
NOTE! Use the corresponding macro os_file_create_simple_no_error_handling(), not directly this function! A simple function to open or create a file.
[in] | name | name of the file or path as a null-terminated string |
[in] | create_mode | create mode |
[in] | access_type | OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or OS_FILE_READ_ALLOW_DELETE; the last option is used by a backup program reading the file |
[in] | read_only | if true read only mode checks are enforced |
[in] | umask | UNIX access permission to be set when creating a file. Use os_umask_default to use global default umask. |
[out] | success | true if succeeded |
dberr_t os_file_create_subdirs_if_needed | ( | const char * | path | ) |
Creates all missing subdirectories along the given path.
Create all missing subdirectories along the given path.
[in] | path | Path name |
FILE * os_file_create_tmpfile | ( | ) |
Create a temporary file.
This function is like tmpfile(3). It will create the file in the MySQL server configuration parameter (–tmpdir).
bool os_file_delete_func | ( | const char * | name | ) |
Deletes a file.
The file has to be closed before calling this.
[in] | name | file path as a null-terminated string |
bool os_file_delete_if_exists_func | ( | const char * | name, |
bool * | exist | ||
) |
Deletes a file if it exists.
The file has to be closed before calling this.
[in] | name | file path as a null-terminated string |
[out] | exist | indicate if file pre-exist |
|
static |
Encrypt log blocks provided in first n bytes of buf.
If encryption is successful then buf will be repointed to the encrypted redo log of length n. If encryption fails then buf is not modified. The encrypted redo log will be stored in a newly allocated block returned from the function or in a newly allocated memory pointed by scratch. The caller takes ownership of the returned block and memory pointed by scratch, and when the buf is no longer needed, it should free the block using os_free_block(block) and scratch memory by using ut::aligned_free(scratch).
[in] | type | IO flags |
[in,out] | buf | before the call should contain unencrypted data, after the call will point to encrypted data, or to the original unencrypted data on failure |
[in,out] | scratch | if not null contains the buf, and should be freed using ut::aligned_free |
[in] | n | number of bytes in buf (encryption does not change the length) |
file::Block * os_file_encrypt_page | ( | const IORequest & | type, |
void *& | buf, | ||
ulint | n | ||
) |
Encrypt a page content when write it to disk.
[in] | type | IO flags |
[out] | buf | buffer to read or write |
[in] | n | number of bytes to read/write, starting from offset |
bool os_file_exists | ( | const char * | path | ) |
Check the existence and usefulness of a given path.
[in] | path | path name |
true | if the path exists and can be used |
false | if the path does not exist or if the path is unusable to get to a possibly existing file or directory. |
|
static |
Check the existence and usefulness of a given path.
[in] | path | path name |
true | if the path exists and can be used |
false | if the path does not exist or if the path is unusable to get to a possibly existing file or directory. |
bool os_file_flush_func | ( | os_file_t | file | ) |
NOTE! Use the corresponding macro os_file_flush(), not directly this function! Flushes the write buffers of a given file to the disk.
[in] | file | handle to a file |
|
static |
Wrapper to fsync(2)/fdatasync(2) that retries the call on some errors.
Returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. srv_use_fdatasync determines whether fsync or fdatasync will be used. (true -> fdatasync)
[in] | file | open file handle |
ulint os_file_get_last_error | ( | bool | report_all_errors | ) |
Retrieves the last error number if an error occurs in a file io function.
The number should be retrieved before any other OS calls (because they may overwrite the error number). If the number is not known to this program, the OS error number + 100 is returned.
[in] | report_all_errors | true if we want an error message printed for all errors |
|
static |
Retrieves the last error number if an error occurs in a file io function.
The number should be retrieved before any other OS calls (because they may overwrite the error number). If the number is not known to this program, the OS error number + 100 is returned.
[in] | report_all_errors | true if we want an error message printed of all errors |
[in] | on_error_silent | true then don't print any diagnostic to the log |
|
static |
Return the parent directory component of a null-terminated path.
Return a new buffer containing the string up to, but not including, the final component of the path. The path returned will not contain a trailing separator. Do not return a root path, return NULL instead. The final component trimmed off may be a filename or a directory name. If the final component is the only component of the path, return NULL. It is the caller's responsibility to free the returned string after it is no longer needed.
[in] | path | Path name |
os_file_size_t os_file_get_size | ( | const char * | filename | ) |
Gets a file size.
[in] | filename | Full path to the filename to check |
os_offset_t os_file_get_size | ( | pfs_os_file_t | file | ) |
Gets a file size.
[in] | file | Handle to a file |
dberr_t os_file_get_status | ( | const char * | path, |
os_file_stat_t * | stat_info, | ||
bool | check_rw_perm, | ||
bool | read_only | ||
) |
This function returns information about the specified file.
[in] | path | pathname of the file |
[out] | stat_info | information of a file in a directory |
[in] | check_rw_perm | for testing whether the file can be opened in RW mode |
[in] | read_only | true if file is opened in read-only mode |
|
static |
This function returns information about the specified file.
[in] | path | pathname of the file |
[out] | stat_info | information of a file in a directory |
[in,out] | statinfo | information of a file in a directory |
[in] | check_rw_perm | for testing whether the file can be opened in RW mode |
[in] | read_only | if true read only mode checks are enforced |
|
static |
Does error handling when a file operation fails.
[in] | name | File name or NULL |
[in] | operation | Name of operation e.g., "read", "write" |
|
static |
Does error handling when a file operation fails.
Conditionally exits (calling srv_fatal_error()) based on should_exit value and the error type, if should_exit is true then on_error_silent is ignored.
[in] | name | name of a file or NULL |
[in] | operation | operation |
[in] | should_exit | call srv_fatal_error() on an unknown error, if this parameter is true |
[in] | on_error_silent | if true then don't print any message to the log iff it is an unknown non-fatal error |
|
static |
Does error handling when a file operation fails.
[in] | name | File name or NULL |
[in] | operation | Name of operation e.g., "read", "write" |
[in] | on_error_silent | if true then don't print any message to the log. |
|
static |
Does a synchronous read or write depending upon the type specified In case of partial reads/writes the function tries NUM_RETRIES_ON_PARTIAL_IO times to read/write the complete data.
[in] | in_type | IO flags |
[in] | file | handle to an open file |
[out] | buf | buffer where to read |
[in] | offset | file offset from the start where to read |
[in] | n | number of bytes to read, starting from offset |
[out] | err | DB_SUCCESS or error code |
[in] | e_block | encrypted block or nullptr. |
|
static |
Decompress after a read and punch a hole in the file if it was a write.
[in] | type | IO context |
[in] | fh | Open file handle |
[in,out] | buf | Buffer to transform |
[in] | src_len | Length of the buffer before compression |
[in] | offset | file offset from the start where to read |
[in] | len | Compressed buffer length for write and size of buf len for read |
|
inlinestatic |
Check if the path refers to the root of a drive using a pointer to the last directory separator that the caller has fixed.
[in] | path | path name |
[in] | last_slash | last directory separator in the path |
|
static |
Obtain an exclusive lock on a file.
[in] | fd | file descriptor |
[in] | name | file name |
If it is a compressed page return the original page data + footer size.
[in] | buf | Buffer to check, must include header + 10 bytes |
|
static |
Does a synchronous read operation in Posix.
[in] | type | IO flags |
[in] | file | handle to an open file |
[out] | buf | buffer where to read |
[in] | offset | file offset from the start where to read |
[in] | n | number of bytes to read, starting from offset |
[out] | err | DB_SUCCESS or error code |
dberr_t os_file_punch_hole | ( | os_file_t | fh, |
os_offset_t | off, | ||
os_offset_t | len | ||
) |
Free storage space associated with a section of the file.
[in] | fh | Open file handle |
[in] | off | Starting offset (SEEK_SET) |
[in] | len | Size of the hole |
|
static |
Free storage space associated with a section of the file.
[in] | fh | Open file handle |
[in] | off | Starting offset (SEEK_SET) |
[in] | len | Size of the hole |
|
static |
Does a synchronous write operation in Posix.
[in] | type | IO context |
[in] | file | handle to an open file |
[out] | buf | buffer from which to write |
[in] | n | number of bytes to read, starting from offset |
[in] | offset | file offset from the start where to read |
[out] | err | DB_SUCCESS or error code |
[in] | e_block | encrypted block or nullptr. |
dberr_t os_file_read_first_page_func | ( | IORequest & | type, |
const char * | file_name, | ||
os_file_t | file, | ||
void * | buf, | ||
ulint | n | ||
) |
NOTE! Use the corresponding macro os_file_read_first_page(), not directly this function! Requests a synchronous read operation of page 0 of IBD file.
[in] | type | IO request context |
[in] | file_name | file name |
[in] | file | Open file handle |
[out] | buf | buffer where to read |
[in] | n | number of bytes to read |
dberr_t os_file_read_func | ( | IORequest & | type, |
const char * | file_name, | ||
os_file_t | file, | ||
void * | buf, | ||
os_offset_t | offset, | ||
ulint | n | ||
) |
NOTE! Use the corresponding macro os_file_read_first_page(), not directly this function! Requests a synchronous read operation of page 0 of IBD file.
[in] | type | IO request context |
[in] | file_name | file name |
[in] | file | Open file handle |
[out] | buf | buffer where to read |
[in] | offset | file offset where to read |
[in] | n | number of bytes to read |
dberr_t os_file_read_no_error_handling_func | ( | IORequest & | type, |
const char * | file_name, | ||
os_file_t | file, | ||
void * | buf, | ||
os_offset_t | offset, | ||
ulint | n, | ||
ulint * | o | ||
) |
NOTE! Use the corresponding macro os_file_read_no_error_handling(), not directly this function! Requests a synchronous positioned read operation.
This function does not do any error handling. In case of error it returns false.
[in] | type | IO request context |
[in] | file_name | file name |
[in] | file | Open file handle |
[out] | buf | buffer where to read |
[in] | offset | file offset where to read |
[in] | n | number of bytes to read |
[out] | o | number of bytes actually read |
|
static |
Requests a synchronous positioned read operation.
[in] | type | IO flags |
[in] | file_name | file name |
[in] | file | handle to an open file |
[out] | buf | buffer where to read |
[in] | offset | file offset from the start where to read |
[in] | n | number of bytes to read, starting from offset |
[out] | o | number of bytes actually read |
[in] | exit_on_err | if true then exit on error |
The read will succeed but decompress can fail for various reasons.
void os_file_read_string | ( | FILE * | file, |
char * | str, | ||
ulint | size | ||
) |
Rewind file to its start, read at most size - 1 bytes from it to str, and NUL-terminate str.
All errors are silently ignored. This function is mostly meant to be used with temporary files.
[in,out] | file | File to read from |
[in,out] | str | Buffer where to read |
[in] | size | Size of buffer |
bool os_file_rename_func | ( | const char * | oldpath, |
const char * | newpath | ||
) |
NOTE! Use the corresponding macro os_file_rename(), not directly this function! Renames a file (can also move it to another directory).
It is safest that the file is closed before calling this function.
[in] | oldpath | old file path as a null-terminated string |
[in] | newpath | new file path |
bool os_file_scan_directory | ( | const char * | path, |
os_dir_cbk_t | scan_cbk, | ||
bool | is_drop | ||
) |
This function scans the contents of a directory and invokes the callback for each entry.
[in] | path | directory name as null-terminated string |
[in] | scan_cbk | use callback to be called for each entry |
[in] | is_drop | attempt to drop the directory after scan |
bool os_file_seek | ( | const char * | pathname, |
os_file_t | file, | ||
os_offset_t | offset | ||
) |
Set read/write position of a file handle to specific offset.
[in] | pathname | file path |
[in] | file | file handle |
[in] | offset | read/write offset |
bool os_file_set_eof | ( | FILE * | file | ) |
Truncates a file at its current position.
file | in: file to be truncated |
void os_file_set_nocache | ( | int | fd, |
const char * | file_name, | ||
const char * | operation_name | ||
) |
Tries to disable OS caching on an opened file descriptor.
[in] | fd | file descriptor to alter |
[in] | file_name | file name, used in the diagnostic message |
[in] | operation_name | "open" or "create"; used in the diagnostic message |
bool os_file_set_size | ( | const char * | name, |
pfs_os_file_t | file, | ||
os_offset_t | offset, | ||
os_offset_t | size, | ||
bool | flush | ||
) |
Write the specified number of zeros to a file from specific offset.
[in] | name | name of the file or path as a null-terminated string |
[in] | file | handle to a file |
[in] | offset | file offset |
[in] | size | file size |
[in] | flush | flush file content to disk |
bool os_file_set_size_fast | ( | const char * | name, |
pfs_os_file_t | file, | ||
os_offset_t | offset, | ||
os_offset_t | size, | ||
bool | flush | ||
) |
Allocate a block to file using fallocate from the given offset if fallocate is supported.
Falls back to the old slower method of writing zeros otherwise.
[in] | name | name of the file |
[in] | file | handle to the file |
[in] | offset | file offset |
[in] | size | file size |
[in] | flush | flush file content to disk |
void os_file_set_umask | ( | mode_t | umask | ) |
Set the global file create umask.
This value is to be set once, at startup and never modified.
[in] | umask | The umask to use for all InnoDB file creation. |
bool os_file_status | ( | const char * | path, |
bool * | exists, | ||
os_file_type_t * | type | ||
) |
Check the existence and type of a given path.
[in] | path | pathname of the file |
[out] | exists | true if file exists |
[out] | type | type of the file (if it exists) |
|
static |
Check the existence and type of the given file.
[in] | path | path name of file |
[out] | exists | true if the file exists |
[out] | type | Type of the file, if it exists |
bool os_file_truncate | ( | const char * | pathname, |
pfs_os_file_t | file, | ||
os_offset_t | size | ||
) |
Truncates a file to a specified size in bytes.
Do nothing if the size to preserve is greater or equal to the current size of the file.
[in] | pathname | file path |
[in] | file | file to be truncated |
[in] | size | size to preserve in bytes |
|
static |
Truncates a file to a specified size in bytes.
Do nothing if the size to preserve is greater or equal to the current size of the file.
[in] | pathname | file path |
[in] | file | file to be truncated |
[in] | size | size to preserve in bytes |
dberr_t os_file_write_func | ( | IORequest & | type, |
const char * | name, | ||
os_file_t | file, | ||
const void * | buf, | ||
os_offset_t | offset, | ||
ulint | n | ||
) |
NOTE! Use the corresponding macro os_file_write(), not directly this function! Requests a synchronous write operation.
[in,out] | type | IO request context |
[in] | name | name of the file or path as a null-terminated string |
[in] | file | Open file handle |
[out] | buf | buffer where to read |
[in] | offset | file offset where to read |
[in] | n | number of bytes to read |
|
static |
Requests a synchronous write operation.
[in] | type | IO flags |
[in] | name | name of the file or path as a null-terminated string |
[in] | file | handle to an open file |
[out] | buf | buffer from which to write |
[in] | offset | file offset from the start where to read |
[in] | n | number of bytes to read, starting from offset |
[in] | e_block | encrypted block or nullptr. |
dberr_t os_file_write_retry | ( | IORequest & | type, |
const char * | name, | ||
pfs_os_file_t | file, | ||
const void * | buf, | ||
os_offset_t | offset, | ||
ulint | n | ||
) |
This is a wrapper function for the os_file_write() function call.
The purpose of this wrapper function is to retry on i/o error. On I/O error (perhaps because of disk full situation) keep retrying the write operation till it succeeds.
[in] | type | IO flags |
[in] | name | name of the file or path as a null-terminated string |
[in] | file | handle to an open file |
[out] | buf | buffer from which to write |
[in] | offset | file offset from the start where to read |
[in] | n | number of bytes to read, starting from offset |
dberr_t os_file_write_zeros | ( | pfs_os_file_t | file, |
const char * | name, | ||
ulint | page_size, | ||
os_offset_t | start, | ||
ulint | len | ||
) |
Fill the pages with NULs.
[in] | file | File handle |
[in] | name | File name |
[in] | page_size | physical page size |
[in] | start | Offset from the start of the file in bytes |
[in] | len | Length in bytes |
|
noexcept |
Free a page after sync IO.
[in,out] | block | The block to free/release |
dberr_t os_get_free_space | ( | const char * | path, |
uint64_t & | free_space | ||
) |
Get available free space on disk.
[in] | path | pathname of a directory or file in disk |
[out] | free_space | free space available in bytes |
|
static |
Get available free space on disk.
[in] | path | pathname of a directory or file in disk |
[out] | free_space | free space available in bytes |
bool os_is_o_direct_supported | ( | ) |
Determine if O_DIRECT is supported.
true | if O_DIRECT is supported. |
false | if O_DIRECT is not supported. |
bool os_is_sparse_file_supported | ( | pfs_os_file_t | fh | ) |
Check if the file system supports sparse files.
Warning: On POSIX systems we try and punch a hole from offset 0 to the system configured page size. This should only be called on an empty file.
Note: On Windows we use the name and on Unices we use the file handle.
[in] | fh | File handle for the file - if opened |
|
static |
fsync the parent directory of a path.
Useful following rename, unlink, etc..
[in] | path | path of file |
if there is no parent dir in the path, then the real parent is either the current directory, or the root directory
Using fsync even when –innodb_use_fdatasync=ON since this operation is not very frequent, but WSL1 does not support fdatasync on directories.
|
static |
Block collection.
|
static |
Insert buffer segment id.
|
static |
Number of blocks to allocate for sync read/writes.
|
static |
Number of retries for partial I/O's.
|
static |
In simulated aio, merge at most this many consecutive i/os.
|
static |
Number of asynchronous I/O segments.
Set by os_aio_init().
|
static |
If the following is true, read i/o handler threads try to wait until a batch of new read requests have been posted.
|
static |
Array of events used in simulated AIO.
|
static |
unsigned long long os_fsync_threshold = 0 |
bool os_has_said_disk_full = false |
|
static |
This specifies the file permissions InnoDB uses when it creates files in Unix; the value of os_innodb_umask is initialized in ha_innodb.cc to my_umask.
It is a global value and can't be modified once it is set.
|
static |
Disk sector size of aligning write buffer for DIRECT_IO.
|
static |
ulint os_n_file_reads = 0 |
|
static |
ulint os_n_file_writes = 0 |
|
static |
ulint os_n_fsyncs = 0 |
|
static |
std::atomic<ulint> os_n_pending_reads {0} |
Number of pending read operations.
std::atomic<ulint> os_n_pending_writes {0} |
Number of pending write operations.
|
extern |
Default Zip compression level.