MySQL 9.0.0
Source Code Documentation
Double_write Class Reference

Doublewrite implementation. More...

Inheritance diagram for Double_write:
[legend]

Classes

struct  Buf_pages
 For collecting pages to write. More...
 

Public Member Functions

 Double_write (uint16_t id, uint32_t n_pages) noexcept
 Constructor. More...
 
virtual ~Double_write () noexcept
 Destructor. More...
 
uint16_t id () const noexcept
 
void write (buf_flush_t flush_type) noexcept
 Process the requests in the flush queue, write the blocks to the double write file, sync the file if required and then write to the data files. More...
 
bool wait_for_pending_batch () noexcept
 Wait for any pending batch to complete. More...
 
bool flush_to_disk (buf_flush_t flush_type) noexcept
 Flush buffered pages to disk, clear the buffers. More...
 
void write_pages (buf_flush_t flush_type) noexcept
 Process the requests in the flush queue, write the blocks to the double write file, sync the file if required and then write to the data files. More...
 
virtual uint16_t write_dblwr_pages (buf_flush_t flush_type) noexcept
 
void write_data_pages (buf_flush_t flush_type, uint16_t batch_id) noexcept
 
void force_flush (buf_flush_t flush_type) noexcept
 Force a flush of the page queue. More...
 
void enqueue (buf_flush_t flush_type, buf_page_t *bpage, const file::Block *e_block) noexcept
 Add a page to the flush batch. More...
 
void batch_started () noexcept
 Note that the IO batch has started. More...
 
void batch_completed () noexcept
 Wake up all the threads that were waiting for the batch to complete. More...
 
 Double_write (const Double_write &)=delete
 
 Double_write (const Double_write &&)=delete
 
Double_writeoperator= (Double_write &&)=delete
 
Double_writeoperator= (const Double_write &)=delete
 

Static Public Member Functions

static Double_writeinstance (buf_flush_t flush_type, uint32_t buf_pool_index, bool is_reduced) noexcept
 
static dberr_t create_batch_segments (uint32_t segments_per_file) noexcept
 Create the batch write segments. More...
 
static dberr_t create_reduced_batch_segments () noexcept
 Create the Reduced batch write segments. More...
 
static dberr_t create_single_segments () noexcept
 Create the single page flush segments. More...
 
static void submit (buf_flush_t flush_type, buf_page_t *bpage, const file::Block *e_block) noexcept
 Get the instance that handles a particular page's IO. More...
 
static dberr_t sync_page_flush (buf_page_t *bpage, file::Block *e_block) noexcept
 Writes a single page to the doublewrite buffer on disk, syncs it, then writes the page to the datafile. More...
 
static Double_writeinstance (buf_flush_t flush_type, const buf_page_t *bpage) noexcept
 
static void write_complete (buf_page_t *bpage, buf_flush_t flush_type) noexcept
 Updates the double write buffer when a write request is completed. More...
 
static bool init_v1 (page_no_t &block1, page_no_t &block2) noexcept
 REad the V1 doublewrite buffer extents boundaries. More...
 
static bool create_v1 (page_no_t &block1, page_no_t &block2) noexcept
 Creates the V1 doublewrite buffer extents. More...
 
static dberr_t write_to_datafile (const buf_page_t *in_bpage, bool sync, const file::Block *e_block) noexcept
 Writes a page that has already been written to the doublewrite buffer to the data file. More...
 
static void force_flush (buf_flush_t flush_type, uint32_t buf_pool_index) noexcept
 Force a flush of the page queue. More...
 
static dberr_t load (dblwr::File &file, recv::Pages *pages) noexcept
 Load the doublewrite buffer pages from an external file. More...
 
static dberr_t load_reduced_batch (dblwr::File &file, recv::Pages *pages) noexcept
 Load the reduced doublewrite buffer page entries from an reduced batch double write buffer file (.bdblwr) More...
 
static dberr_t init_file (dblwr::File &file, uint32_t n_pages, uint32_t phy_size=univ_page_size.physical()) noexcept
 Write zeros to the file if it is "empty". More...
 
static void reset_file (dblwr::File &file, bool truncate) noexcept
 Reset the size in bytes to the configured size. More...
 
static void reduced_reset_file (dblwr::File &file, uint32_t pages_per_file, uint32_t phy_size) noexcept
 Reset the size in bytes to the configured size. More...
 
static void reset_files () noexcept
 Reset the size in bytes to the configured size of all files. More...
 
static dberr_t create_v2 () noexcept
 Create the v2 data structures. More...
 
static dberr_t create_reduced () noexcept
 Create the data structures for reduced doublewrite buffer. More...
 
static bool is_fsync_required () noexcept
 
static void prepare (const buf_page_t *bpage, void **ptr, uint32_t *len) noexcept
 Extract the data and length to write to the doublewrite file. More...
 
static void shutdown () noexcept
 Free the data structures. More...
 
static void toggle (ulong value) noexcept
 Toggle the doublewrite buffer dynamically. More...
 
static void single_write (Segment *segment, const buf_page_t *bpage, file::Block *e_block) noexcept
 Write the data to disk synchronously. More...
 

Public Attributes

unsigned long long m_bytes_written {}
 Number of bytes written to disk by this instance. More...
 

Static Public Attributes

static uint32_t s_n_instances {}
 Number of instances. More...
 
static std::vector< dblwr::Files_files
 Files to use for atomic writes. More...
 
static std::vector< dblwr::Files_r_files
 Reduced batch doublewrite files to use for atomic writes. More...
 
static Instancess_instances {}
 The global instances. More...
 
static Instancess_r_instances {}
 The global Reduced Doublewrite instances. More...
 

Protected Types

using Segments = mpmc_bq< Segment * >
 
using Instances = std::vector< Double_write * >
 
using Batch_segments = mpmc_bq< Batch_segment * >
 

Static Protected Member Functions

static void free_segments (Batch_segments *&segments) noexcept
 Utility function to free batch segments. More...
 
static bool is_reduced_batch_id (uint32_t batch_id)
 

Protected Attributes

uint16_t m_id {}
 Instance ID. More...
 
ib_mutex_t m_mutex
 Protects m_buf_pages. More...
 
os_event_t m_event
 Wait for IO batch to complete. More...
 
std::atomic_bool m_batch_running {false}
 true if the the batch hasn't completed yet. More...
 
Buffer m_buffer
 The copy of the page frame, the page must be in in m_buf_pages. More...
 
Buf_pages m_buf_pages
 Pages that should be written to the data files. More...
 

Static Protected Attributes

static Batch_segmentss_LRU_batch_segments {}
 File segments to use for LRU batched writes. More...
 
static Batch_segmentss_flush_list_batch_segments {}
 File segments to use for flush list batched writes. More...
 
static Segmentss_single_segments {}
 File segments to use for single page writes. More...
 
static Batch_segmentss_r_LRU_batch_segments {}
 File segments to use for LRU batched writes in reduced dblwr mode. More...
 
static Batch_segmentss_r_flush_list_batch_segments {}
 File segments to use for flush list batched writes (reduced mode) More...
 
static std::vector< Batch_segment * > s_segments {}
 For indexing batch segments by ID. More...
 
static uint32_t s_regular_last_batch_id {}
 Last used batch_id for regular batch segments. More...
 

Static Private Member Functions

static dberr_t start () noexcept
 Create the singleton instance, start the flush thread. More...
 
static void croak (const buf_block_t *block) noexcept
 Asserts when a corrupt block is found during writing out data to the disk. More...
 
static void check_block (const buf_block_t *block) noexcept
 Check the LSN values on the page with which this block is associated. More...
 
static void check_page_lsn (const page_t *page) noexcept
 Check the LSN values on the page. More...
 
static byteget (mtr_t *mtr) noexcept
 Calls buf_page_get() on the TRX_SYS_PAGE and returns a pointer to the doublewrite buffer within it. More...
 

Detailed Description

Doublewrite implementation.

Assumes it can use DBLWR_PAGES.

Member Typedef Documentation

◆ Batch_segments

◆ Instances

using Double_write::Instances = std::vector<Double_write *>
protected

◆ Segments

using Double_write::Segments = mpmc_bq<Segment *>
protected

Constructor & Destructor Documentation

◆ Double_write() [1/3]

Double_write::Double_write ( uint16_t  id,
uint32_t  n_pages 
)
noexcept

Constructor.

Parameters
[in]idInstance ID
[in]n_pagesNumber of pages handled by this instance.

◆ ~Double_write()

Double_write::~Double_write ( )
virtualnoexcept

Destructor.

◆ Double_write() [2/3]

Double_write::Double_write ( const Double_write )
delete

◆ Double_write() [3/3]

Double_write::Double_write ( const Double_write &&  )
delete

Member Function Documentation

◆ batch_completed()

void Double_write::batch_completed ( )
inlinenoexcept

Wake up all the threads that were waiting for the batch to complete.

◆ batch_started()

void Double_write::batch_started ( )
inlinenoexcept

Note that the IO batch has started.

◆ check_block()

void Double_write::check_block ( const buf_block_t block)
staticprivatenoexcept

Check the LSN values on the page with which this block is associated.

Also validate the page if the option is set.

Parameters
[in]blockBlock to check

◆ check_page_lsn()

void Double_write::check_page_lsn ( const page_t page)
staticprivatenoexcept

Check the LSN values on the page.

Parameters
[in]pagePage to check

◆ create_batch_segments()

dberr_t Double_write::create_batch_segments ( uint32_t  segments_per_file)
staticnoexcept

Create the batch write segments.

Parameters
[in]segments_per_fileNumber of configured segments per file.
Returns
DB_SUCCESS or error code.

◆ create_reduced()

dberr_t Double_write::create_reduced ( )
staticnoexcept

Create the data structures for reduced doublewrite buffer.

Returns
DB_SUCCESS or error code

◆ create_reduced_batch_segments()

dberr_t Double_write::create_reduced_batch_segments ( )
staticnoexcept

Create the Reduced batch write segments.

These segments are mapped to separate file which has extension .bdblwr

Returns
DB_SUCCESS or error code.

◆ create_single_segments()

dberr_t Double_write::create_single_segments ( )
staticnoexcept

Create the single page flush segments.

Returns
DB_SUCCESS or error code.

◆ create_v1()

bool Double_write::create_v1 ( page_no_t block1,
page_no_t block2 
)
staticnoexcept

Creates the V1 doublewrite buffer extents.

The header of the doublewrite buffer is placed on the trx system header page.

Parameters
[in,out]block1Starting block number for the first extent.
[in,out]block2Starting block number for the second extent.
Returns
true if successful, false if not.

◆ create_v2()

dberr_t Double_write::create_v2 ( )
staticnoexcept

Create the v2 data structures.

Returns
DB_SUCCESS or error code

◆ croak()

void Double_write::croak ( const buf_block_t block)
staticprivatenoexcept

Asserts when a corrupt block is found during writing out data to the disk.

Parameters
[in]blockBlock that was corrupt

◆ enqueue()

void Double_write::enqueue ( buf_flush_t  flush_type,
buf_page_t bpage,
const file::Block e_block 
)
inlinenoexcept

Add a page to the flush batch.

If the flush batch is full then write the batch to disk.

Parameters
[in]flush_typeFlush type.
[in]bpagePage to flush to disk.
[in]e_blockEncrypted block frame or nullptr.

◆ flush_to_disk()

bool Double_write::flush_to_disk ( buf_flush_t  flush_type)
inlinenoexcept

Flush buffered pages to disk, clear the buffers.

Parameters
[in]flush_typeFLUSH LIST or LRU LIST flush.
Returns
false if there was a write batch already in progress.

◆ force_flush() [1/2]

void Double_write::force_flush ( buf_flush_t  flush_type)
inlinenoexcept

Force a flush of the page queue.

Parameters
[in]flush_typeFLUSH LIST or LRU LIST flush.

◆ force_flush() [2/2]

static void Double_write::force_flush ( buf_flush_t  flush_type,
uint32_t  buf_pool_index 
)
inlinestaticnoexcept

Force a flush of the page queue.

Parameters
[in]flush_typeFLUSH LIST or LRU LIST flush.
[in]buf_pool_indexBuffer pool instance for which called.

◆ free_segments()

void Double_write::free_segments ( Batch_segments *&  segments)
staticprotectednoexcept

Utility function to free batch segments.

Parameters
[in]segmentsbatch segment to free

◆ get()

byte * Double_write::get ( mtr_t mtr)
staticprivatenoexcept

Calls buf_page_get() on the TRX_SYS_PAGE and returns a pointer to the doublewrite buffer within it.

Parameters
[in,out]mtrTo manage the page latches
Returns
pointer to the doublewrite buffer within the filespace header page.

◆ id()

uint16_t Double_write::id ( ) const
inlinenoexcept
Returns
instance ID

◆ init_file()

dberr_t Double_write::init_file ( dblwr::File file,
uint32_t  n_pages,
uint32_t  phy_size = univ_page_size.physical() 
)
staticnoexcept

Write zeros to the file if it is "empty".

Parameters
[in]fileFile instance.
[in]n_pagesSize in physical pages.
[in]phy_sizePhysical page size in DBLWR file (For reduced DBLW file, it is not UNIV_PAGE_SIZE, it is hardcoded to 8K page size)
Returns
DB_SUCCESS or error code

◆ init_v1()

bool Double_write::init_v1 ( page_no_t block1,
page_no_t block2 
)
staticnoexcept

REad the V1 doublewrite buffer extents boundaries.

Parameters
[in,out]block1Starting block number for the first extent.
[in,out]block2Starting block number for the second extent.
Returns
true if successful, false if not.

◆ instance() [1/2]

static Double_write * Double_write::instance ( buf_flush_t  flush_type,
const buf_page_t bpage 
)
inlinestaticnoexcept
Returns
the double write instance to use for flushing.
Parameters
[in]flush_typeLRU or Flush list write.
[in]bpagePage to write to disk.
Returns
instance that will handle the flush to disk.

◆ instance() [2/2]

static Double_write * Double_write::instance ( buf_flush_t  flush_type,
uint32_t  buf_pool_index,
bool  is_reduced 
)
inlinestaticnoexcept
Returns
the double write instance to use for flushing.
Parameters
[in]buf_pool_indexBuffer pool instance number.
[in]flush_typeLRU or Flush list write.
[in]is_reducedtrue if reduced mode of dblwr is being used.
Returns
instance that will handle the flush to disk.

◆ is_fsync_required()

static bool Double_write::is_fsync_required ( )
inlinestaticnoexcept
Returns
true if we need to fsync to disk

◆ is_reduced_batch_id()

bool Double_write::is_reduced_batch_id ( uint32_t  batch_id)
staticprotected
Returns
true if batch belonged to reduced dblwr. When returning a batch segment to lock-free queue, we should know which lock-free queue(Batch_segments) to return to
Parameters
[in]batch_idBatch segment id

◆ load()

dberr_t Double_write::load ( dblwr::File file,
recv::Pages pages 
)
staticnoexcept

Load the doublewrite buffer pages from an external file.

Parameters
[in,out]fileFile handle
[in,out]pagesFor storing the doublewrite pages read from the file
Returns
DB_SUCCESS or error code

◆ load_reduced_batch()

dberr_t Double_write::load_reduced_batch ( dblwr::File file,
recv::Pages pages 
)
staticnoexcept

Load the reduced doublewrite buffer page entries from an reduced batch double write buffer file (.bdblwr)

Parameters
[in,out]fileFile handle
[in,out]pagesFor storing the doublewrite pages read from the file
Returns
DB_SUCCESS or error code

◆ operator=() [1/2]

Double_write & Double_write::operator= ( const Double_write )
delete

◆ operator=() [2/2]

Double_write & Double_write::operator= ( Double_write &&  )
delete

◆ prepare()

void Double_write::prepare ( const buf_page_t bpage,
void **  ptr,
uint32_t *  len 
)
staticnoexcept

Extract the data and length to write to the doublewrite file.

Parameters
[in]bpagePage to write
[out]ptrStart of buffer to write
[out]lenLength of the data to write

◆ reduced_reset_file()

void Double_write::reduced_reset_file ( dblwr::File file,
uint32_t  pages_per_file,
uint32_t  phy_size 
)
staticnoexcept

Reset the size in bytes to the configured size.

Parameters
[in,out]fileFile to reset
[in]pages_per_fileNumber of pages to be created in doublewrite file
[in]phy_sizephysical page size

◆ reset_file()

void Double_write::reset_file ( dblwr::File file,
bool  truncate 
)
staticnoexcept

Reset the size in bytes to the configured size.

Parameters
[in,out]fileFile to reset.
[in]truncateTruncate the file to configured size if true.

◆ reset_files()

static void Double_write::reset_files ( )
inlinestaticnoexcept

Reset the size in bytes to the configured size of all files.

◆ shutdown()

void Double_write::shutdown ( )
staticnoexcept

Free the data structures.

◆ single_write()

void Double_write::single_write ( Segment segment,
const buf_page_t bpage,
file::Block e_block 
)
staticnoexcept

Write the data to disk synchronously.

Parameters
[in]segmentSegment to write to.
[in]bpagePage to write.
[in]e_blockEncrypted block. Can be nullptr.

◆ start()

static dberr_t Double_write::start ( )
staticprivatenoexcept

Create the singleton instance, start the flush thread.

Returns
DB_SUCCESS or error code

◆ submit()

static void Double_write::submit ( buf_flush_t  flush_type,
buf_page_t bpage,
const file::Block e_block 
)
inlinestaticnoexcept

Get the instance that handles a particular page's IO.

Submit the write request to the a double write queue that is empty.

Parameters
[in]flush_typeFlush type.
[in]bpagePage from the buffer pool.
[in]e_blockcompressed + encrypted frame contents or nullptr.

◆ sync_page_flush()

dberr_t Double_write::sync_page_flush ( buf_page_t bpage,
file::Block e_block 
)
staticnoexcept

Writes a single page to the doublewrite buffer on disk, syncs it, then writes the page to the datafile.

Parameters
[in]bpageData page to write to disk.
[in]e_blockEncrypted data block.
Returns
DB_SUCCESS or error code

◆ toggle()

static void Double_write::toggle ( ulong  value)
inlinestaticnoexcept

Toggle the doublewrite buffer dynamically.

Parameters
[in]valueCurrent value

◆ wait_for_pending_batch()

bool Double_write::wait_for_pending_batch ( )
inlinenoexcept

Wait for any pending batch to complete.

Returns
true if the thread had to wait for another batch.

◆ write()

void Double_write::write ( buf_flush_t  flush_type)
noexcept

Process the requests in the flush queue, write the blocks to the double write file, sync the file if required and then write to the data files.

◆ write_complete()

void Double_write::write_complete ( buf_page_t bpage,
buf_flush_t  flush_type 
)
staticnoexcept

Updates the double write buffer when a write request is completed.

Parameters
[in,out]bpageBlock that has just been written to disk.
[in]flush_typeFlush type that triggered the write.

◆ write_data_pages()

void Double_write::write_data_pages ( buf_flush_t  flush_type,
uint16_t  batch_id 
)
noexcept

◆ write_dblwr_pages()

uint16_t Double_write::write_dblwr_pages ( buf_flush_t  flush_type)
virtualnoexcept

Reimplemented in Reduced_double_write.

◆ write_pages()

void Double_write::write_pages ( buf_flush_t  flush_type)
noexcept

Process the requests in the flush queue, write the blocks to the double write file, sync the file if required and then write to the data files.

Parameters
[in]flush_typeLRU or FLUSH request.

◆ write_to_datafile()

dberr_t Double_write::write_to_datafile ( const buf_page_t in_bpage,
bool  sync,
const file::Block e_block 
)
staticnoexcept

Writes a page that has already been written to the doublewrite buffer to the data file.

It is the job of the caller to sync the datafile.

Parameters
[in]in_bpagePage to write.
[in]synctrue if it's a synchronous write.
[in]e_blockblock containing encrypted data frame.
Returns
DB_SUCCESS or error code

Member Data Documentation

◆ m_batch_running

std::atomic_bool Double_write::m_batch_running {false}
protected

true if the the batch hasn't completed yet.

◆ m_buf_pages

Buf_pages Double_write::m_buf_pages
protected

Pages that should be written to the data files.

◆ m_buffer

Buffer Double_write::m_buffer
protected

The copy of the page frame, the page must be in in m_buf_pages.

◆ m_bytes_written

unsigned long long Double_write::m_bytes_written {}

Number of bytes written to disk by this instance.

It is never reset. It is printed to server log during shutdown.

◆ m_event

os_event_t Double_write::m_event
protected

Wait for IO batch to complete.

◆ m_id

uint16_t Double_write::m_id {}
protected

Instance ID.

◆ m_mutex

ib_mutex_t Double_write::m_mutex
protected

Protects m_buf_pages.

◆ s_files

std::vector< dblwr::File > Double_write::s_files
static

Files to use for atomic writes.

◆ s_flush_list_batch_segments

Double_write::Batch_segments * Double_write::s_flush_list_batch_segments {}
staticprotected

File segments to use for flush list batched writes.

◆ s_instances

Double_write::Instances * Double_write::s_instances {}
static

The global instances.

◆ s_LRU_batch_segments

Double_write::Batch_segments * Double_write::s_LRU_batch_segments {}
staticprotected

File segments to use for LRU batched writes.

◆ s_n_instances

uint32_t Double_write::s_n_instances {}
static

Number of instances.

◆ s_r_files

std::vector< dblwr::File > Double_write::s_r_files
static

Reduced batch doublewrite files to use for atomic writes.

◆ s_r_flush_list_batch_segments

Double_write::Batch_segments * Double_write::s_r_flush_list_batch_segments {}
staticprotected

File segments to use for flush list batched writes (reduced mode)

◆ s_r_instances

Double_write::Instances * Double_write::s_r_instances {}
static

The global Reduced Doublewrite instances.

◆ s_r_LRU_batch_segments

Double_write::Batch_segments * Double_write::s_r_LRU_batch_segments {}
staticprotected

File segments to use for LRU batched writes in reduced dblwr mode.

◆ s_regular_last_batch_id

uint32_t Double_write::s_regular_last_batch_id {}
staticprotected

Last used batch_id for regular batch segments.

Any id greater than this belongs to reduced double write

◆ s_segments

std::vector< Batch_segment * > Double_write::s_segments {}
staticprotected

For indexing batch segments by ID.

◆ s_single_segments

Double_write::Segments * Double_write::s_single_segments {}
staticprotected

File segments to use for single page writes.


The documentation for this class was generated from the following file: