/** Options for os_file_create_func @{ */ enum os_file_create_t { /** create a new file */
OS_FILE_CREATE= 0, /** open an existing file */
OS_FILE_OPEN, /** retry opening an existing file */
OS_FILE_OPEN_RETRY, /** open a raw block device */
OS_FILE_OPEN_RAW,
/** do not display diagnostic messages */
OS_FILE_ON_ERROR_SILENT= 4,
/**
The I/O context that is passed down to the low level IO code */ class IORequest
{ public: enum Type
{ /** Synchronous read */
READ_SYNC= 2, /** Asynchronous read; some errors will be ignored */
READ_ASYNC= READ_SYNC | 1, /** Possibly partial read; only used with
os_file_read_no_error_handling() */
READ_MAYBE_PARTIAL= READ_SYNC | 4, /** Read for doublewrite buffer recovery */
DBLWR_RECOVER= READ_SYNC | 8, /** Synchronous write */
WRITE_SYNC= 16, /** Asynchronous write */
WRITE_ASYNC= WRITE_SYNC | 1, /** Asynchronous doublewritten page */
WRITE_DBL= WRITE_ASYNC | 4, /** A doublewrite batch */
DBLWR_BATCH= WRITE_ASYNC | 8, /** Write data and punch hole for the rest */
PUNCH= WRITE_ASYNC | 16, /** Write doublewritten data and punch hole for the rest */
PUNCH_DBL= PUNCH | 4, /** Zero out a range of bytes in fil_space_t::io() */
PUNCH_RANGE= WRITE_SYNC | 32,
};
/** If requested, free storage space associated with a section of the file. @paramoffbyteoffsetfromthestart(SEEK_SET) @paramlensizeoftheholeinbytes
@return DB_SUCCESS or error code */
dberr_t maybe_punch_hole(os_offset_t off, ulint len) noexcept
{ return off && len && node && (type & (PUNCH ^ WRITE_ASYNC))
? punch_hole(off, len)
: DB_SUCCESS;
}
private: /** Free storage space associated with a section of the file. @paramoffbyteoffsetfromthestart(SEEK_SET) @paramlensizeoftheholeinbytes
@return DB_SUCCESS or error code */
dberr_t punch_hole(os_offset_t off, ulint len) const noexcept;
public: /** Page to be written on write operation */
buf_page_t *const bpage= nullptr;
/** Memory to be used for encrypted or page_compressed pages */
buf_tmp_buffer_t *const slot= nullptr;
/* Maximum path string length in bytes when referring to tables with in the './databasename/tablename.ibd'pathformat;wecanallocateatleast2buffers ofthissizefromthethreadstack;thatiswhythisshouldnotbemademuch biggerthan4000bytes.Themaximumpathlengthusedbyanystorageengine
in the server must be at least this big. */
/** Struct used in fetching information of a file in a directory */ struct os_file_stat_t { char name[OS_FILE_MAX_PATH]; /*!< path to a file */
os_file_type_t type; /*!< file type */
os_offset_t size; /*!< file size in bytes */
os_offset_t alloc_size; /*!< Allocated size for
sparse files in bytes */
size_t block_size; /*!< Block size to use for IO
in bytes*/
time_t ctime; /*!< creation time */
time_t mtime; /*!< modification time */
time_t atime; /*!< access time */ bool rw_perm; /*!< true if can be opened inread-writemode.Onlyvalid
if type == OS_FILE_TYPE_FILE */
};
/** Create a temporary file. This function is like tmpfile(3), but thetemporaryfileiscreatedintheinthemysqlserverconfiguration parameter(--tmpdir).
@return temporary file handle, or NULL on error */
FILE *os_file_create_tmpfile() noexcept;
@param[in]pathnamedirectorynameasnull-terminatedstring @param[in]fail_if_existsiftrue,pre-existingdirectoryistreated asanerror.
@return true if call succeeds, false on error */ bool os_file_create_directory(constchar *pathname, bool fail_if_exists)
noexcept;
/** NOTE! Use the corresponding macro os_file_create_simple(), not directly thisfunction! Asimplefunctiontoopenorcreateafile. @param[in]namenameofthefileorpathasanull-terminated string @param[in]create_modecreatemode @param[in]access_typeOS_FILE_READ_ONLYorOS_FILE_READ_WRITE @param[in]read_onlyiftruereadonlymodechecksareenforced @param[out]successtrueifsucceed,falseiferror @returnown:handletothefile,notdefinediferror,errornumber
can be retrieved with os_file_get_last_error */
pfs_os_file_t
os_file_create_simple_func( constchar* name,
os_file_create_t create_mode,
ulint access_type, bool read_only, bool* success) noexcept;
/** NOTE! Use the corresponding macro os_file_create_simple_no_error_handling(),notdirectlythisfunction! Asimplefunctiontoopenorcreateafile. @param[in]namenameofthefileorpathasanull-terminatedstring @param[in]create_modeOS_FILE_CREATEorOS_FILE_OPEN @param[in]access_typeOS_FILE_READ_ONLY,OS_FILE_READ_WRITE,or OS_FILE_READ_ALLOW_DELETE;thelastoption isusedbyabackupprogramreadingthefile @param[in]read_onlyiftruereadonlymodechecksareenforced @param[out]successtrueifsucceeded @returnown:handletothefile,notdefinediferror,errornumber
can be retrieved with os_file_get_last_error */
pfs_os_file_t
os_file_create_simple_no_error_handling_func( constchar* name,
os_file_create_t create_mode,
ulint access_type, bool read_only, bool* success) noexcept
MY_ATTRIBUTE((warn_unused_result));
#ifndef _WIN32 /* On Microsoft Windows, mandatory locking is used */ /** Obtain an exclusive lock on a file. @paramfdfiledescriptor @paramnamefilename
@return 0 on success */ int os_file_lock(int fd, constchar *name) noexcept; #endif
/** NOTE! Use the corresponding macro os_file_create(), not directly thisfunction! Opensanexistingfileorcreatesanew. @param[in]namenameofthefileorpathasanull-terminated string @param[in]create_modecreatemode @param[in]typeOS_DATA_FILEorOS_LOG_FILE @param[in]read_onlyiftruereadonlymodechecksareenforced @param[in]successtrueifsucceeded @returnown:handletothefile,notdefinediferror,errornumber
can be retrieved with os_file_get_last_error */
pfs_os_file_t
os_file_create_func( constchar* name,
os_file_create_t create_mode,
ulint type, bool read_only, bool* success) noexcept
MY_ATTRIBUTE((warn_unused_result));
/** Deletes a file. The file has to be closed before calling this. @param[in]namefilepathasanull-terminatedstring
@return true if success */ bool
os_file_delete_func(constchar* name);
/** Deletes a file if it exists. The file has to be closed before calling this. @param[in]namefilepathasanull-terminatedstring @param[out]existindicateiffilepre-exist
@return true if success */ bool
os_file_delete_if_exists_func(constchar* name, bool* exist);
/** NOTE! Use the corresponding macro os_file_rename(), not directly thisfunction! Renamesafile(canalsomoveittoanotherdirectory).Itissafestthatthe fileisclosedbeforecallingthisfunction. @param[in]oldpatholdfilepathasanull-terminatedstring @param[in]newpathnewfilepath
@return true if success */ bool
os_file_rename_func(constchar* oldpath, constchar* newpath);
/** NOTE! Use the corresponding macro os_file_close(), not directly this function! Closesafilehandle.Incaseoferror,errornumbercanberetrievedwith os_file_get_last_error. @param[in]fileown:handletoafile
@return true if success */ bool os_file_close_func(os_file_t file);
#ifdef UNIV_PFS_IO
/* Keys to register InnoDB I/O with performance schema */ extern mysql_pfs_key_t innodb_data_file_key; extern mysql_pfs_key_t innodb_temp_file_key;
/* Following four macros are instumentations to register variousfileI/Ooperationswithperformanceschema. 1)register_pfs_file_open_begin()andregister_pfs_file_open_end()are usedtoregisterfilecreation,opening,closingandrenaming. 2)register_pfs_file_rename_begin()andregister_pfs_file_rename_end() areusedtoregisterfilerenaming 2)register_pfs_file_io_begin()andregister_pfs_file_io_end()are usedtoregisteractualfileread,writeandflush 3)register_pfs_file_close_begin()andregister_pfs_file_close_end()
are used to register file deletion operations*/ # define register_pfs_file_open_begin(state, locker, key, op, name, \
src_file, src_line) \ do { \
locker = PSI_FILE_CALL(get_thread_file_name_locker)( \
state, key, op, name, nullptr); \ if (locker != NULL) { \
PSI_FILE_CALL(start_file_open_wait)( \
locker, src_file, src_line); \
} \
} while (0)
# define register_pfs_file_open_end(locker, file, result) \ do { \ if (locker != NULL) { \
file.m_psi = PSI_FILE_CALL(end_file_open_wait)( \
locker, result); \
} \
} while (0)
# define register_pfs_file_io_end(locker, count) \ do { \ if (locker != NULL) { \
PSI_FILE_CALL(end_file_wait)(locker, count); \
} \
} while (0)
/* Following macros/functions are file I/O APIs that would be performance schemainstrumentedif"UNIV_PFS_IO"isdefined.Theywouldpointto wrapperfunctionswithperformanceschemainstrumentationinsuchcase.
/* If UNIV_PFS_IO is not defined, these I/O APIs point
to original un-instrumented file I/O APIs */ # define os_file_create(key, name, create, type, read_only, \
success) \
os_file_create_func(name, create, type, read_only, \
success)
/** Gets a file size. @param[in]filehandletoafile @returnfilesizeifOK,elsesetm_total_sizeto~0andm_alloc_size
to errno */
os_file_size_t os_file_get_size(constchar *filename) noexcept
MY_ATTRIBUTE((warn_unused_result));
/** Determine the logical size of a file. Thismaychangethecurrentwritepositionofthefiletotheendofthefile. (Notcurrentlyaproblem;InnoDBtypicallyusespositionedI/O.) @paramfilehandletoanopenfile @returnfilesize,inoctets
@retval -1 on failure */
os_offset_t os_file_get_size(os_file_t file) noexcept
MY_ATTRIBUTE((warn_unused_result));
/** Truncates a file at its current position. @param[in/out]filefiletobetruncated
@return true if success */ bool os_file_set_eof(FILE *file) noexcept;
/** Truncate a file to a specified size in bytes. @param[in]pathnamefilepath @param[in]filefiletobetruncated @param[in]sizesizepreservedinbytes @param[in]allow_shrinkwhethertoallowthefiletobecomesmaller
@return true if success */ bool
os_file_truncate( constchar* pathname,
os_file_t file,
os_offset_t size, bool allow_shrink = false) noexcept;
/** NOTE! Use the corresponding macro os_file_flush(), not directly this function! Flushesthewritebuffersofagivenfiletothedisk. @param[in]filehandletoafile
@return true if success */ bool os_file_flush_func(os_file_t file) noexcept;
/** Retrieves the last error number if an error occurs in a file io function. ThenumbershouldberetrievedbeforeanyotherOScalls(becausetheymay overwritetheerrornumber).Ifthenumberisnotknowntothisprogram, theOSerrornumber+OS_FILE_ERROR_MAXisreturned. @param[in]report_all_errorstrueifwewantanerrormessage printedofallerrors @param[in]on_error_silenttruethendon'tprintanydiagnostic tothelog
@return error number, or OS error number + OS_FILE_ERROR_MAX */
ulint os_file_get_last_error(bool report_all_errors, bool on_error_silent= false) noexcept;
/** NOTE! Use the corresponding macro os_file_read(), not directly this function! Requestsasynchronousreadoperation. @param[in]typeIOrequestcontext @param[in]fileOpenfilehandle @param[out]bufbufferwheretoread @param[in]offsetfileoffsetwheretoread @param[in]nnumberofbytestoread @param[out]onumberofbytesactuallyread
@return DB_SUCCESS if request was successful */
dberr_t
os_file_read_func( const IORequest& type,
os_file_t file, void* buf,
os_offset_t offset,
ulint n,
ulint* o) noexcept
MY_ATTRIBUTE((warn_unused_result));
/** Rewind file to its start, read at most size - 1 bytes from it to str, and NUL-terminatestr.Allerrorsaresilentlyignored.Thisfunctionis mostlymeanttobeusedwithtemporaryfiles. @param[in,out]filefiletoreadfrom @param[in,out]strbufferwheretoread
@param[in] size size of buffer */ void
os_file_read_string(
FILE* file, char* str,
ulint size) noexcept;
/** NOTE! Use the corresponding macro os_file_write(), not directly this function! Requestsasynchronouswriteoperation. @param[in]typeIOrequestcontext @param[in]fileOpenfilehandle @param[out]bufbufferwheretoread @param[in]offsetfileoffsetwheretoread @param[in]nnumberofbytestoread
@return DB_SUCCESS if request was successful */
dberr_t
os_file_write_func( const IORequest& type, constchar* name,
os_file_t file, constvoid* buf,
os_offset_t offset,
ulint n)
MY_ATTRIBUTE((warn_unused_result));
/** Check the existence and type of the given file. @param[in]pathpathnameofthefile @param[out]existstrueiffileexists @param[out]typetypeofthefile(ifitexists)
@return true if call succeeded */ bool
os_file_status( constchar* path, bool* exists,
os_file_type_t* type) noexcept;
/** This function reduces a null-terminated full remote path name into thepaththatissentbyMySQLforDATADIRECTORYclause.Itreplaces the'databasename/tablename.ibd'foundattheendofthepathwithjust 'tablename'.
/** Create all missing subdirectories along the given path.
@return DB_SUCCESS if OK, otherwise error code. */
dberr_t os_file_create_subdirs_if_needed(constchar* path) noexcept;
#ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR /* Test the function os_file_get_parent_dir. */ void
unit_test_os_file_get_parent_dir() noexcept; #endif/* UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR */
/**
Initializes the asynchronous io system. */ int os_aio_init() noexcept;
/**
Frees the asynchronous io system. */ void os_aio_free() noexcept;
/** Request a read or write. @paramtypeI/Orequest @parambufbuffer @paramoffsetfileoffset @paramnnumberofbytes @retvalDB_SUCCESSifrequestwasqueuedsuccessfully
@retval DB_IO_ERROR on I/O error */
dberr_t os_aio(const IORequest &type, void *buf, os_offset_t offset, size_t n)
noexcept;
/** @return number of pending reads */
size_t os_aio_pending_reads() noexcept; /** @return approximate number of pending reads */
size_t os_aio_pending_reads_approx() noexcept; /** @return number of pending writes */
size_t os_aio_pending_writes() noexcept; /** @return approximate number of pending writes */
size_t os_aio_pending_writes_approx() noexcept;
/** Wait until there are no pending asynchronous writes.
@param declare whether the wait will be declared in tpool */ void os_aio_wait_until_no_pending_writes(bool declare) noexcept;
/** Wait until all pending asynchronous reads have completed.
@param declare whether the wait will be declared in tpool */ void os_aio_wait_until_no_pending_reads(bool declare) noexcept;
/** Prints info of the aio arrays.
@param[in/out] file file where to print */ void os_aio_print(FILE *file) noexcept;
/** Refreshes the statistics used to print per-second averages. */ void os_aio_refresh_stats() noexcept;
/** Checks that all slots in the system have been freed, that is, there are
no pending io operations. */ bool os_aio_all_slots_free() noexcept;
/** This function returns information about the specified file @param[in]pathpathnameofthefile @param[in]stat_infoinformationofafileinadirectory @param[in]check_rw_permfortestingwhetherthefilecanbeopened inRWmode @param[in]read_onlyiftruereadonlymodechecksareenforced
@return DB_SUCCESS if all OK */
dberr_t
os_file_get_status( constchar* path,
os_file_stat_t* stat_info, bool check_rw_perm, bool read_only) noexcept;
#ifdef _WIN32
/** Makefilesparse,onWindows.
@param[in]filefilehandle @param[in]is_sparseiftrue,makefilesparse, otherwise"unsparse"thefile
@return true on success, false on error */ bool os_file_set_sparse_win32(os_file_t file, bool is_sparse = true) noexcept;
/** Free storage space associated with a section of the file. @param[in]fhOpenfilehandle @param[in]offStartingoffset(SEEK_SET) @param[in]lenSizeofthehole
@return DB_SUCCESS or error code */
dberr_t
os_file_punch_hole(
os_file_t fh,
os_offset_t off,
os_offset_t len) noexcept
MY_ATTRIBUTE((warn_unused_result));
/* Determine if a path is an absolute path or not. @param[in]OSdirectoryorfilepathtoevaluate @retvaltrueifanabsolutepath
@retval false if a relative path */ inlinebool is_absolute_path(constchar *path) noexcept
{ switch (path[0]) { #ifdef _WIN32 case'\0': returnfalse; case'\\': #endif case'/': returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.