MySQL 9.1.0
Source Code Documentation
os0file.cc File Reference

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 "my_macros.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  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
 
#define io_ibuf_thread_key   PFS_NOT_INSTRUMENTED
 
#define io_read_thread_key   PFS_NOT_INSTRUMENTED
 
#define io_write_thread_key   PFS_NOT_INSTRUMENTED
 

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...
 
byteos_block_get_frame (const file::Block *block) noexcept
 Get the sector aligned frame pointer. More...
 
file::Blockos_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...
 
byteos_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::Blockos_file_compress_page (IORequest &type, void *&buf, ulint *n)
 Allocate the buffer for IO on a transparently compressed table. More...
 
file::Blockos_file_encrypt_page (const IORequest &type, void *&buf, ulint n)
 Encrypt a page content when write it to disk. More...
 
static file::Blockos_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)
 Clang on Windows warns about umask not found. 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 Blocksblock_cache
 Block collection. More...
 
static const size_t MAX_BLOCKS = 128
 Number of blocks to allocate for sync read/writes. 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_tos_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< ulintos_n_pending_writes {0}
 Number of pending write operations. More...
 
std::atomic< ulintos_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...
 

Detailed Description

The interface to the operating system file i/o primitives.

Created 10/21/1995 Heikki Tuuri

Macro Definition Documentation

◆ BUFFER_BLOCK_SIZE

#define BUFFER_BLOCK_SIZE   ((ulint)(UNIV_PAGE_SIZE * 1.3))

Block buffer size.

◆ io_ibuf_thread_key

#define io_ibuf_thread_key   PFS_NOT_INSTRUMENTED

◆ io_read_thread_key

#define io_read_thread_key   PFS_NOT_INSTRUMENTED

◆ io_write_thread_key

#define io_write_thread_key   PFS_NOT_INSTRUMENTED

◆ USE_FILE_LOCK

#define USE_FILE_LOCK

Typedef Documentation

◆ Blocks

using Blocks = std::vector<file::Block>

For storing the allocated blocks.

Function Documentation

◆ buf_flush_page_cleaner_is_active()

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.

◆ io_handler_thread()

static void io_handler_thread ( ulint  segment)
static

I/o-handler thread function.

Parameters
[in]segmentThe AIO segment the thread will work on

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
const Slot obj 
)
inlinenoexcept

◆ os_aio_all_slots_free()

bool os_aio_all_slots_free ( )

Checks that all slots in the system have been freed, that is, there are no pending io operations.

Returns
true if all free

◆ os_aio_free()

void os_aio_free ( )

Frees the asynchronous io system.

◆ os_aio_func()

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.

Parameters
[in]typeIO request context
[in]aio_modeIO mode
[in]nameName of the file or path as NUL terminated string
[in]fileOpen file handle
[out]bufbuffer where to read
[in]offsetfile offset where to read
[in]nhow many bytes to read or write; this must not cross a file boundary; in AIO this must be a block size multiple
[in]read_onlyif true read only mode checks are enforced
[in,out]m1Message for the AIO handler, (can be used to identify a completed AIO operation); ignored if mode is OS_AIO_SYNC
[in,out]m2message for the AIO handler (can be used to identify a completed AIO operation); ignored if mode is OS_AIO_SYNC
Returns
DB_SUCCESS or error code

◆ os_aio_handler()

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!

Parameters
[in]segmentThe 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]m1the 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]m2callback message
[out]requestOS_FILE_WRITE or ..._READ
Returns
DB_SUCCESS or error code

◆ os_aio_init()

bool os_aio_init ( ulint  n_readers,
ulint  n_writers 
)

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().

Parameters
[in]n_readersnumber of reader threads
[in]n_writersnumber of writer threads

◆ os_aio_print()

void os_aio_print ( FILE *  file)

Prints info of the aio arrays.

Parameters
[in,out]filefile where to print

◆ os_aio_print_pending_io()

void os_aio_print_pending_io ( FILE *  file)

Prints all pending IO.

Parameters
[in]fileFile where to print

◆ os_aio_refresh_stats()

void os_aio_refresh_stats ( )

Refreshes the statistics used to print per-second averages.

◆ os_aio_simulated_handler()

static dberr_t os_aio_simulated_handler ( ulint  global_segment,
fil_node_t **  m1,
void **  m2,
IORequest type 
)
static

Does simulated AIO.

This function should be called by an i/o-handler thread.

Parameters
[in]global_segmentThe 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]m1the 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]m2Callback argument
[in]typeIO context
Returns
DB_SUCCESS or error code

Found a slot that has already completed its IO

◆ os_aio_simulated_put_read_threads_to_sleep()

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!

◆ os_aio_simulated_wake_handler_threads()

void os_aio_simulated_wake_handler_threads ( )

Wakes up simulated aio i/o-handler threads if they have something to do.

◆ os_aio_start_threads()

void os_aio_start_threads ( )

Starts one thread for each segment created in os_aio_init.

◆ os_aio_validate()

static bool os_aio_validate ( )
static

Validates the consistency of the aio system.

Validates the consistency the aio system.

Returns
true if ok

◆ os_aio_validate_skip()

static bool os_aio_validate_skip ( )
static

Validates the consistency the aio system some of the time.

Returns
true if ok or the check was skipped

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.

◆ os_aio_wait_until_no_pending_writes()

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.

◆ os_aio_wake_all_threads_at_shutdown()

void os_aio_wake_all_threads_at_shutdown ( )

Wakes up all async i/o threads so that they know to exit themselves in shutdown.

◆ os_alloc_block()

file::Block * os_alloc_block ( )
noexcept

Allocate a page for sync IO.

Returns
pointer to page

◆ os_block_get_frame()

byte * os_block_get_frame ( const file::Block block)
noexcept

Get the sector aligned frame pointer.

Parameters
[in]blockthe memory block containing the page frame.
Returns
the sector aligned frame pointer.

◆ os_create_block_cache()

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.

◆ os_file_can_delete()

static bool os_file_can_delete ( const char *  name)
static

Check the file type and determine if it can be deleted.

Parameters
[in]nameFilename/Path to check
Returns
true if it's a file or a symlink and can be deleted

◆ os_file_check_mode()

bool os_file_check_mode ( const char *  name,
bool  read_only 
)

Check if a file can be opened in read-write mode.

Parameters
[in]namefilename to check
[in]read_onlytrue if check for read-only mode only
Return values
trueif file can be opened in the specified mode (rw or ro); or file does not exist
falseif file exists and can't be opened in the specified mode

◆ os_file_close_func()

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.

Parameters
[in]fileHandle to a file
Returns
true if success

◆ os_file_compress_page() [1/2]

byte * os_file_compress_page ( Compression  compression,
ulint  block_size,
byte src,
ulint  src_len,
byte dst,
ulint dst_len 
)

Compress a data page.

Parameters
[in]compressionCompression algorithm
[in]block_sizeFile system block size
[in]srcSource contents to compress
[in]src_lenLength in bytes of the source
[out]dstCompressed page contents
[out]dst_lenLength in bytes of dst contents
Returns
buffer data, dst_len will have the length of the data

◆ os_file_compress_page() [2/2]

file::Block * os_file_compress_page ( IORequest type,
void *&  buf,
ulint n 
)

Allocate the buffer for IO on a transparently compressed table.

Parameters
[in]typeIO flags
[out]bufbuffer to read or write
[in,out]nnumber of bytes to read/write, starting from offset
Returns
pointer to allocated page, compressed data is written to the offset that is aligned on the disk sector size

◆ os_file_compressed_page_size()

ulint os_file_compressed_page_size ( const byte buf)

If it is a compressed page return the compressed page data + footer size.

Parameters
[in]bufBuffer to check, must include header + 10 bytes
Returns
ULINT_UNDEFINED if the page is not a compressed page or length of the compressed data (including footer) if it is a compressed page

◆ os_file_copy_func()

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.

Parameters
[in]src_filefile handle to copy from
[in]src_offsetoffset to copy from
[in]dest_filefile handle to copy to
[in]dest_offsetoffset to copy to
[in]sizenumber of bytes to copy
Returns
DB_SUCCESS if successful

◆ os_file_copy_read_write()

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 
)
static

copy data from one file to another file using read, write.

Parameters
[in]src_filefile handle to copy from
[in]src_offsetoffset to copy from
[in]dest_filefile handle to copy to
[in]dest_offsetoffset to copy to
[in]sizenumber of bytes to copy
Returns
DB_SUCCESS if successful

◆ os_file_create_directory()

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.

Parameters
[in]pathnamedirectory name as null-terminated string
[in]fail_if_existsif true, pre-existing directory is treated as an error.
Returns
true if call succeeds, false on error

◆ os_file_create_func()

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.

Parameters
[in]namename of the file or path as a null-terminated string
[in]create_modecreate mode
[in]purposeOS_DATA_FILE, OS_LOG_FILE etc.
[in]read_onlyif true read only mode checks are enforced
[out]successtrue if succeeded
Returns
own: handle to the file, not defined if error, error number can be retrieved with os_file_get_last_error

◆ os_file_create_simple_no_error_handling_func()

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 
)

Clang on Windows warns about umask not found.

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.

Parameters
[in]namename of the file or path as a null-terminated string
[in]create_modecreate mode
[in]access_typeOS_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_onlyif true read only mode checks are enforced
[in]umaskUNIX access permission to be set when creating a file. Use os_umask_default to use global default umask.
[out]successtrue if succeeded
Returns
own: handle to the file, not defined if error, error number can be retrieved with os_file_get_last_error

◆ os_file_create_subdirs_if_needed()

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.

Parameters
[in]pathPath name
Returns
DB_SUCCESS if OK, otherwise error code.

◆ os_file_create_tmpfile()

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).

Returns
temporary file handle, or NULL on error

◆ os_file_delete_func()

bool os_file_delete_func ( const char *  name)

Deletes a file.

The file has to be closed before calling this.

Parameters
[in]namefile path as a null-terminated string
Returns
true if success

◆ os_file_delete_if_exists_func()

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.

Parameters
[in]namefile path as a null-terminated string
[out]existindicate if file pre-exist
Returns
true if success

◆ os_file_encrypt_log()

static file::Block * os_file_encrypt_log ( const IORequest type,
void *&  buf,
byte *&  scratch,
ulint  n 
)
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).

Parameters
[in]typeIO flags
[in,out]bufbefore the call should contain unencrypted data, after the call will point to encrypted data, or to the original unencrypted data on failure
[in,out]scratchif not null contains the buf, and should be freed using ut::aligned_free
[in]nnumber of bytes in buf (encryption does not change the length)
Returns
if not null, then it's the block which contain the buf, and should be freed using os_free_block(block).

◆ os_file_encrypt_page()

file::Block * os_file_encrypt_page ( const IORequest type,
void *&  buf,
ulint  n 
)

Encrypt a page content when write it to disk.

Parameters
[in]typeIO flags
[out]bufbuffer to read or write
[in]nnumber of bytes to read/write, starting from offset
Returns
pointer to the encrypted page

◆ os_file_exists()

bool os_file_exists ( const char *  path)

Check the existence and usefulness of a given path.

Parameters
[in]pathpath name
Return values
trueif the path exists and can be used
falseif the path does not exist or if the path is unusable to get to a possibly existing file or directory.

◆ os_file_exists_posix()

static bool os_file_exists_posix ( const char *  path)
static

Check the existence and usefulness of a given path.

Parameters
[in]pathpath name
Return values
trueif the path exists and can be used
falseif the path does not exist or if the path is unusable to get to a possibly existing file or directory.

◆ os_file_flush_func()

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.

Parameters
[in]filehandle to a file
Returns
true if success

◆ os_file_fsync_posix()

static int os_file_fsync_posix ( os_file_t  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)

Parameters
[in]fileopen file handle
Returns
0 if success, -1 otherwise

◆ os_file_get_last_error()

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.

Parameters
[in]report_all_errorstrue if we want an error message printed for all errors
Returns
error number, or OS error number + 100

◆ os_file_get_last_error_low()

static ulint os_file_get_last_error_low ( bool  report_all_errors,
bool  on_error_silent 
)
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.

Parameters
[in]report_all_errorstrue if we want an error message printed of all errors
[in]on_error_silenttrue then don't print any diagnostic to the log
Returns
error number, or OS error number + 100

◆ os_file_get_parent_dir()

static char * os_file_get_parent_dir ( const char *  path)
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.

Parameters
[in]pathPath name
Returns
own: parent directory of the path

◆ os_file_get_size() [1/2]

os_file_size_t os_file_get_size ( const char *  filename)

Gets a file size.

Parameters
[in]filenameFull path to the filename to check
Returns
file size if OK, else set m_total_size to ~0 and m_alloc_size to errno.

◆ os_file_get_size() [2/2]

os_offset_t os_file_get_size ( pfs_os_file_t  file)

Gets a file size.

Parameters
[in]fileHandle to a file
Returns
file size, or (os_offset_t) -1 on failure

◆ os_file_get_status()

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.

Parameters
[in]pathpathname of the file
[out]stat_infoinformation of a file in a directory
[in]check_rw_permfor testing whether the file can be opened in RW mode
[in]read_onlytrue if file is opened in read-only mode
Returns
DB_SUCCESS if all OK

◆ os_file_get_status_posix()

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 
)
static

This function returns information about the specified file.

Parameters
[in]pathpathname of the file
[out]stat_infoinformation of a file in a directory
[in,out]statinfoinformation of a file in a directory
[in]check_rw_permfor testing whether the file can be opened in RW mode
[in]read_onlyif true read only mode checks are enforced
Returns
DB_SUCCESS if all OK

◆ os_file_handle_error()

static bool os_file_handle_error ( const char *  name,
const char *  operation 
)
static

Does error handling when a file operation fails.

Parameters
[in]nameFile name or NULL
[in]operationName of operation e.g., "read", "write"
Returns
true if we should retry the operation

◆ os_file_handle_error_cond_exit()

static bool os_file_handle_error_cond_exit ( const char *  name,
const char *  operation,
bool  should_exit,
bool  on_error_silent 
)
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.

Parameters
[in]namename of a file or NULL
[in]operationoperation
[in]should_exitcall srv_fatal_error() on an unknown error, if this parameter is true
[in]on_error_silentif true then don't print any message to the log iff it is an unknown non-fatal error
Returns
true if we should retry the operation

◆ os_file_handle_error_no_exit()

static bool os_file_handle_error_no_exit ( const char *  name,
const char *  operation,
bool  on_error_silent 
)
static

Does error handling when a file operation fails.

Parameters
[in]nameFile name or NULL
[in]operationName of operation e.g., "read", "write"
[in]on_error_silentif true then don't print any message to the log.
Returns
true if we should retry the operation

◆ os_file_io()

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 
)
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.

Parameters
[in]in_typeIO flags
[in]filehandle to an open file
[out]bufbuffer where to read
[in]offsetfile offset from the start where to read
[in]nnumber of bytes to read, starting from offset
[out]errDB_SUCCESS or error code
[in]e_blockencrypted block or nullptr.
Returns
number of bytes read/written, -1 if error

◆ os_file_io_complete()

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 
)
static

Decompress after a read and punch a hole in the file if it was a write.

Parameters
[in]typeIO context
[in]fhOpen file handle
[in,out]bufBuffer to transform
[in]src_lenLength of the buffer before compression
[in]offsetfile offset from the start where to read
[in]lenCompressed buffer length for write and size of buf len for read
Returns
DB_SUCCESS or error code

◆ os_file_is_root()

static bool os_file_is_root ( const char *  path,
const char *  last_slash 
)
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.

Parameters
[in]pathpath name
[in]last_slashlast directory separator in the path
Returns
true if this path is a drive root, false if not

◆ os_file_lock()

static int os_file_lock ( int  fd,
const char *  name 
)
static

Obtain an exclusive lock on a file.

Parameters
[in]fdfile descriptor
[in]namefile name
Returns
0 on success

◆ os_file_original_page_size()

ulint os_file_original_page_size ( const byte buf)

If it is a compressed page return the original page data + footer size.

Parameters
[in]bufBuffer to check, must include header + 10 bytes
Returns
ULINT_UNDEFINED if the page is not a compressed page or length of the original data + footer if it is a compressed page

◆ os_file_pread()

static ssize_t os_file_pread ( IORequest type,
os_file_t  file,
void *  buf,
ulint  n,
os_offset_t  offset,
dberr_t err 
)
static

Does a synchronous read operation in Posix.

Parameters
[in]typeIO flags
[in]filehandle to an open file
[out]bufbuffer where to read
[in]offsetfile offset from the start where to read
[in]nnumber of bytes to read, starting from offset
[out]errDB_SUCCESS or error code
Returns
number of bytes read, -1 if error

◆ os_file_punch_hole()

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.

Parameters
[in]fhOpen file handle
[in]offStarting offset (SEEK_SET)
[in]lenSize of the hole
Returns
DB_SUCCESS or error code

◆ os_file_punch_hole_posix()

static dberr_t os_file_punch_hole_posix ( os_file_t  fh,
os_offset_t  off,
os_offset_t  len 
)
static

Free storage space associated with a section of the file.

Parameters
[in]fhOpen file handle
[in]offStarting offset (SEEK_SET)
[in]lenSize of the hole
Returns
DB_SUCCESS or error code

◆ os_file_pwrite()

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 
)
static

Does a synchronous write operation in Posix.

Parameters
[in]typeIO context
[in]filehandle to an open file
[out]bufbuffer from which to write
[in]nnumber of bytes to read, starting from offset
[in]offsetfile offset from the start where to read
[out]errDB_SUCCESS or error code
[in]e_blockencrypted block or nullptr.
Returns
number of bytes written, -1 if error

◆ os_file_read_first_page_func()

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.

Parameters
[in]typeIO request context
[in]file_namefile name
[in]fileOpen file handle
[out]bufbuffer where to read
[in]nnumber of bytes to read
Returns
DB_SUCCESS if request was successful, DB_IO_ERROR on failure

◆ os_file_read_func()

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.

Parameters
[in]typeIO request context
[in]file_namefile name
[in]fileOpen file handle
[out]bufbuffer where to read
[in]offsetfile offset where to read
[in]nnumber of bytes to read
Returns
DB_SUCCESS if request was successful, DB_IO_ERROR on failure

◆ os_file_read_no_error_handling_func()

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.

Parameters
[in]typeIO request context
[in]file_namefile name
[in]fileOpen file handle
[out]bufbuffer where to read
[in]offsetfile offset where to read
[in]nnumber of bytes to read
[out]onumber of bytes actually read
Returns
DB_SUCCESS or error code

◆ os_file_read_page()

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 
)
static

Requests a synchronous positioned read operation.

Returns
DB_SUCCESS if request was successful, false if fail
Parameters
[in]typeIO flags
[in]file_namefile name
[in]filehandle to an open file
[out]bufbuffer where to read
[in]offsetfile offset from the start where to read
[in]nnumber of bytes to read, starting from offset
[out]onumber of bytes actually read
[in]exit_on_errif true then exit on error
Returns
DB_SUCCESS or error code

The read will succeed but decompress can fail for various reasons.

◆ os_file_read_string()

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.

Parameters
[in,out]fileFile to read from
[in,out]strBuffer where to read
[in]sizeSize of buffer

◆ os_file_rename_func()

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.

Parameters
[in]oldpathold file path as a null-terminated string
[in]newpathnew file path
Returns
true if success

◆ os_file_scan_directory()

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.

Parameters
[in]pathdirectory name as null-terminated string
[in]scan_cbkuse callback to be called for each entry
[in]is_dropattempt to drop the directory after scan
Returns
true if call succeeds, false on error

◆ os_file_seek()

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.

Parameters
[in]pathnamefile path
[in]filefile handle
[in]offsetread/write offset
Returns
true if success

◆ os_file_set_eof()

bool os_file_set_eof ( FILE *  file)

Truncates a file at its current position.

Returns
true if success
Parameters
filein: file to be truncated

◆ os_file_set_nocache()

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.

Parameters
[in]fdfile descriptor to alter
[in]file_namefile name, used in the diagnostic message
[in]operation_name"open" or "create"; used in the diagnostic message

◆ os_file_set_size()

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.

Parameters
[in]namename of the file or path as a null-terminated string
[in]filehandle to a file
[in]offsetfile offset
[in]sizefile size
[in]flushflush file content to disk
Returns
true if success

◆ os_file_set_size_fast()

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.

Parameters
[in]namename of the file
[in]filehandle to the file
[in]offsetfile offset
[in]sizefile size
[in]flushflush file content to disk
Returns
true if success

◆ os_file_set_umask()

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.

Parameters
[in]umaskThe umask to use for all InnoDB file creation.

◆ os_file_status()

bool os_file_status ( const char *  path,
bool *  exists,
os_file_type_t type 
)

Check the existence and type of a given path.

Parameters
[in]pathpathname of the file
[out]existstrue if file exists
[out]typetype of the file (if it exists)
Returns
true if call succeeded

◆ os_file_status_posix()

static bool os_file_status_posix ( const char *  path,
bool *  exists,
os_file_type_t type 
)
static

Check the existence and type of the given file.

Parameters
[in]pathpath name of file
[out]existstrue if the file exists
[out]typeType of the file, if it exists
Returns
true if call succeeded

◆ os_file_truncate()

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.

Parameters
[in]pathnamefile path
[in]filefile to be truncated
[in]sizesize to preserve in bytes
Returns
true if success

◆ os_file_truncate_posix()

static bool os_file_truncate_posix ( const char *  pathname,
pfs_os_file_t  file,
os_offset_t  size 
)
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.

Parameters
[in]pathnamefile path
[in]filefile to be truncated
[in]sizesize to preserve in bytes
Returns
true if success

◆ os_file_write_func()

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.

Parameters
[in,out]typeIO request context
[in]namename of the file or path as a null-terminated string
[in]fileOpen file handle
[out]bufbuffer where to read
[in]offsetfile offset where to read
[in]nnumber of bytes to read
Returns
DB_SUCCESS if request was successful

◆ os_file_write_page()

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 
)
static

Requests a synchronous write operation.

Parameters
[in]typeIO flags
[in]namename of the file or path as a null-terminated string
[in]filehandle to an open file
[out]bufbuffer from which to write
[in]offsetfile offset from the start where to read
[in]nnumber of bytes to read, starting from offset
[in]e_blockencrypted block or nullptr.
Returns
DB_SUCCESS if request was successful, false if fail

◆ os_file_write_retry()

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.

Parameters
[in]typeIO flags
[in]namename of the file or path as a null-terminated string
[in]filehandle to an open file
[out]bufbuffer from which to write
[in]offsetfile offset from the start where to read
[in]nnumber of bytes to read, starting from offset
Returns
DB_SUCCESS if request was successful, false if fail

◆ os_file_write_zeros()

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.

Parameters
[in]fileFile handle
[in]nameFile name
[in]page_sizephysical page size
[in]startOffset from the start of the file in bytes
[in]lenLength in bytes
Returns
DB_SUCCESS or error code

◆ os_free_block()

void os_free_block ( file::Block block)
noexcept

Free a page after sync IO.

Parameters
[in,out]blockThe block to free/release

◆ os_get_free_space()

dberr_t os_get_free_space ( const char *  path,
uint64_t &  free_space 
)

Get available free space on disk.

Parameters
[in]pathpathname of a directory or file in disk
[out]free_spacefree space available in bytes
Returns
DB_SUCCESS if all OK

◆ os_get_free_space_posix()

static dberr_t os_get_free_space_posix ( const char *  path,
uint64_t &  free_space 
)
static

Get available free space on disk.

Parameters
[in]pathpathname of a directory or file in disk
[out]free_spacefree space available in bytes
Returns
DB_SUCCESS if all OK

◆ os_is_o_direct_supported()

bool os_is_o_direct_supported ( )

Determine if O_DIRECT is supported.

Return values
trueif O_DIRECT is supported.
falseif O_DIRECT is not supported.

◆ os_is_sparse_file_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.

Parameters
[in]fhFile handle for the file - if opened
Returns
true if the file system supports sparse files

◆ os_parent_dir_fsync_posix()

static void os_parent_dir_fsync_posix ( const char *  path)
static

fsync the parent directory of a path.

Useful following rename, unlink, etc..

Parameters
[in]pathpath 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.

Variable Documentation

◆ block_cache

Blocks* block_cache
static

Block collection.

◆ IO_IBUF_SEGMENT

const ulint IO_IBUF_SEGMENT = 0
static

Insert buffer segment id.

◆ MAX_BLOCKS

const size_t MAX_BLOCKS = 128
static

Number of blocks to allocate for sync read/writes.

◆ OS_AIO_MERGE_N_CONSECUTIVE

const ulint OS_AIO_MERGE_N_CONSECUTIVE = 64
static

In simulated aio, merge at most this many consecutive i/os.

◆ os_aio_n_segments

ulint os_aio_n_segments = ULINT_UNDEFINED
static

Number of asynchronous I/O segments.

Set by os_aio_init().

◆ os_aio_recommend_sleep_for_read_threads

bool os_aio_recommend_sleep_for_read_threads = false
static

If the following is true, read i/o handler threads try to wait until a batch of new read requests have been posted.

◆ os_aio_segment_wait_events

os_event_t* os_aio_segment_wait_events = nullptr
static

Array of events used in simulated AIO.

◆ os_bytes_read_since_printout

ulint os_bytes_read_since_printout = 0
static

◆ os_fsync_threshold

unsigned long long os_fsync_threshold = 0

◆ os_has_said_disk_full

bool os_has_said_disk_full = false

◆ os_innodb_umask

mode_t os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
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.

◆ os_last_printout

std::chrono::steady_clock::time_point os_last_printout
static

◆ os_n_file_reads

ulint os_n_file_reads = 0

◆ os_n_file_reads_old

ulint os_n_file_reads_old = 0
static

◆ os_n_file_writes

ulint os_n_file_writes = 0

◆ os_n_file_writes_old

ulint os_n_file_writes_old = 0
static

◆ os_n_fsyncs

ulint os_n_fsyncs = 0

◆ os_n_fsyncs_old

ulint os_n_fsyncs_old = 0
static

◆ os_n_pending_reads

std::atomic<ulint> os_n_pending_reads {0}

Number of pending read operations.

◆ os_n_pending_writes

std::atomic<ulint> os_n_pending_writes {0}

Number of pending write operations.

◆ page_zip_level

uint page_zip_level
extern

Default Zip compression level.