MySQL 9.1.0
Source Code Documentation
mf_iocache.cc File Reference

Cashing of files with only does (sequential) read or writes of fixed- length records. More...

#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <algorithm>
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_sys.h"
#include "my_systime.h"
#include "my_thread_local.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/int2str.h"
#include "mysys/mysys_priv.h"
#include "thr_mutex.h"

Macros

#define lock_append_buffer(info)   mysql_mutex_lock(&(info)->append_buffer_lock)
 
#define unlock_append_buffer(info)    mysql_mutex_unlock(&(info)->append_buffer_lock)
 
#define IO_ROUND_UP(X)   (((X) + IO_SIZE - 1) & ~(IO_SIZE - 1))
 
#define IO_ROUND_DN(X)   ((X) & ~(IO_SIZE - 1))
 
#define LOCK_APPEND_BUFFER    if (need_append_buffer_lock) lock_append_buffer(info);
 
#define UNLOCK_APPEND_BUFFER    if (need_append_buffer_lock) unlock_append_buffer(info);
 

Functions

void setup_io_cache (IO_CACHE *info)
 
static void init_functions (IO_CACHE *info)
 
int init_io_cache_ext (IO_CACHE *info, File file, size_t cachesize, enum cache_type type, my_off_t seek_offset, bool use_async_io, myf cache_myflags, PSI_file_key file_key)
 
int init_io_cache (IO_CACHE *info, File file, size_t cachesize, enum cache_type type, my_off_t seek_offset, bool use_async_io, myf cache_myflags)
 
bool reinit_io_cache (IO_CACHE *info, enum cache_type type, my_off_t seek_offset, bool use_async_io, bool clear_cache)
 
int _my_b_read (IO_CACHE *info, uchar *Buffer, size_t Count)
 
void init_io_cache_share (IO_CACHE *read_cache, IO_CACHE_SHARE *cshare, IO_CACHE *write_cache, uint num_threads)
 
void remove_io_thread (IO_CACHE *cache)
 
static int lock_io_cache (IO_CACHE *cache, my_off_t pos)
 
static void unlock_io_cache (IO_CACHE *cache)
 
int _my_b_read_r (IO_CACHE *cache, uchar *Buffer, size_t Count)
 
static void copy_to_read_buffer (IO_CACHE *write_cache, const uchar *write_buffer, size_t write_length)
 
int _my_b_seq_read (IO_CACHE *info, uchar *Buffer, size_t Count)
 
int _my_b_get (IO_CACHE *info)
 
int _my_b_write (IO_CACHE *info, const uchar *Buffer, size_t Count)
 
int my_b_append (IO_CACHE *info, const uchar *Buffer, size_t Count)
 
int my_b_safe_write (IO_CACHE *info, const uchar *Buffer, size_t Count)
 
int my_block_write (IO_CACHE *info, const uchar *Buffer, size_t Count, my_off_t pos)
 
int my_b_flush_io_cache (IO_CACHE *info, int need_append_buffer_lock)
 
int end_io_cache (IO_CACHE *info)
 
my_off_t mysql_encryption_file_seek (IO_CACHE *cache, my_off_t pos, int whence, myf flags)
 This is a wrapper around mysql_file_seek. More...
 
size_t mysql_encryption_file_read (IO_CACHE *cache, uchar *buffer, size_t count, myf flags)
 This is a wrapper around mysql_file_read. More...
 
size_t mysql_encryption_file_write (IO_CACHE *cache, const uchar *buffer, size_t count, myf flags)
 This is a wrapper around mysql_file_write. More...
 

Variables

PSI_file_key key_file_io_cache
 
bool binlog_cache_temporary_file_is_encrypted = false
 (end of group MYSYS) More...
 

Detailed Description

Cashing of files with only does (sequential) read or writes of fixed- length records.

A read isn't allowed to go over file-length. A read is ok if it ends at file-length and next read can try to read after file-length (and get a EOF-error). Possibly use of asyncronic io. macros for read and writes for faster io. Used instead of FILE when reading or writing whole files. This code makes mf_rec_cache obsolete (currently only used by ISAM). One can change info->pos_in_file to a higher value to skip bytes in the file if also info->read_pos is set to info->read_end. If called through open_cached_file(), then the temporary file will only be created if a write exceeds the file buffer or if one calls my_b_flush_io_cache().

If one uses SEQ_READ_APPEND, then two buffers are allocated, one for reading and another for writing. Reads are first done from disk and then done from the write buffer. This is an efficient way to read from a log file when one is writing to it at the same time. For this to work, the file has to be opened in append mode! Note that when one uses SEQ_READ_APPEND, one MUST write using my_b_append ! This is needed because we need to lock the mutex every time we access the write buffer.

TODO: When one SEQ_READ_APPEND and we are reading and writing at the same time, each time the write buffer gets full and it's written to disk, we will always do a disk read to read a part of the buffer from disk to the read buffer. This should be fixed so that when we do a my_b_flush_io_cache() and we have been reading the write buffer, we should transfer the rest of the write buffer to the read buffer before we start to reuse it.

Macro Definition Documentation

◆ IO_ROUND_DN

#define IO_ROUND_DN (   X)    ((X) & ~(IO_SIZE - 1))

◆ IO_ROUND_UP

#define IO_ROUND_UP (   X)    (((X) + IO_SIZE - 1) & ~(IO_SIZE - 1))

◆ lock_append_buffer

#define lock_append_buffer (   info)    mysql_mutex_lock(&(info)->append_buffer_lock)

◆ LOCK_APPEND_BUFFER

#define LOCK_APPEND_BUFFER    if (need_append_buffer_lock) lock_append_buffer(info);

◆ unlock_append_buffer

#define unlock_append_buffer (   info)     mysql_mutex_unlock(&(info)->append_buffer_lock)

◆ UNLOCK_APPEND_BUFFER

#define UNLOCK_APPEND_BUFFER    if (need_append_buffer_lock) unlock_append_buffer(info);

Function Documentation

◆ copy_to_read_buffer()

static void copy_to_read_buffer ( IO_CACHE write_cache,
const uchar write_buffer,
size_t  write_length 
)
static

◆ init_functions()

static void init_functions ( IO_CACHE info)
static

◆ lock_io_cache()

static int lock_io_cache ( IO_CACHE cache,
my_off_t  pos 
)
static

◆ mysql_encryption_file_read()

size_t mysql_encryption_file_read ( IO_CACHE cache,
uchar buffer,
size_t  count,
myf  flags 
)

This is a wrapper around mysql_file_read.

Read data from the temporary file of a binlog cache, and take care of decrypting the data if binlog_encryption is on.

Parameters
cacheThe handler of a binlog cache to read.
[out]bufferThe memory buffer to write to.
countThe length of data in the temporary file to be read in bytes.
flagsThe bitmap of different flags MY_WME | MY_FAE | MY_NABP | MY_FNABP | MY_DONT_CHECK_FILESIZE and so on.
Return values
Thelength of bytes to be read, or MY_FILE_ERROR on error.

◆ mysql_encryption_file_seek()

my_off_t mysql_encryption_file_seek ( IO_CACHE cache,
my_off_t  pos,
int  whence,
myf  flags 
)

This is a wrapper around mysql_file_seek.

Seek to a position in the temporary file of a binlog cache, and set the encryption/decryption stream offset if binlog_encryption is on.

Parameters
cacheThe handler of a binlog cache to seek.
posThe expected position (absolute or relative)
whenceA direction parameter and one of {SEEK_SET, SEEK_CUR, SEEK_END}
flagsThe bitmap of different flags MY_WME | MY_FAE | MY_NABP | MY_FNABP | MY_DONT_CHECK_FILESIZE and so on.
Return values
Thenew position in the file, or MY_FILEPOS_ERROR on error.

◆ mysql_encryption_file_write()

size_t mysql_encryption_file_write ( IO_CACHE cache,
const uchar buffer,
size_t  count,
myf  flags 
)

This is a wrapper around mysql_file_write.

Write data in buffer to the temporary file of a binlog cache, and take care of encrypting the data if binlog_encryption is on.

Parameters
cacheThe handler of a binlog cache to write.
bufferThe memory buffer to write from.
countThe length of data in buffer to be written in bytes.
flagsThe bitmap of different flags MY_WME | MY_FAE | MY_NABP | MY_FNABP | MY_DONT_CHECK_FILESIZE and so on
Returns
The number of bytes written

◆ unlock_io_cache()

static void unlock_io_cache ( IO_CACHE cache)
static

Variable Documentation

◆ binlog_cache_temporary_file_is_encrypted

bool binlog_cache_temporary_file_is_encrypted = false

(end of group MYSYS)