MySQL 8.0.40
Source Code Documentation
Batch_segment Class Reference

Segment for batched writes. More...

Inheritance diagram for Batch_segment:
[legend]

Public Member Functions

 Batch_segment (uint16_t id, dblwr::File &file, page_no_t start, uint32_t n_pages)
 Constructor. More...
 
 Batch_segment (uint16_t id, dblwr::File &file, uint32_t phy_size, page_no_t start, uint32_t n_pages)
 Constructor. More...
 
 ~Batch_segment () noexcept override
 Destructor. More...
 
uint16_t id () const noexcept
 
void write (const Buffer &buffer) noexcept
 Write a batch to the segment. More...
 
void write (const byte *buf, uint32_t len) noexcept
 Write a batch to the segment. More...
 
bool write_complete () noexcept
 Called on page write completion. More...
 
void reset () noexcept
 Reset the state. More...
 
void set_batch_size (uint32_t size) noexcept
 Set the batch size. More...
 
uint32_t batch_size () const noexcept
 
void start (Double_write *dblwr) noexcept
 Note that the batch has started for the double write instance. More...
 
void completed () noexcept
 Note that the batch has completed. More...
 
- Public Member Functions inherited from Segment
 Segment (dblwr::File &file, page_no_t start, uint32_t n_pages)
 Constructor. More...
 
 Segment (dblwr::File &file, uint32_t phy_size, page_no_t start, uint32_t n_pages)
 Constructor. More...
 
virtual ~Segment ()=default
 Destructor. More...
 
void write (const void *ptr, uint32_t len) noexcept
 Write to the segment. More...
 
void flush () noexcept
 Flush the segment to disk. More...
 
 Segment (Segment &&)=delete
 
 Segment (const Segment &)=delete
 
Segmentoperator= (Segment &&)=delete
 
Segmentoperator= (const Segment &)=delete
 

Public Attributes

uint16_t m_id {}
 Batch segment ID. More...
 
Double_writem_dblwr {}
 The instance that is being written to disk. More...
 
byte m_pad1 [ut::INNODB_CACHE_LINE_SIZE]
 
uint32_t m_batch_size {}
 Size of the batch. More...
 
byte m_pad2 [ut::INNODB_CACHE_LINE_SIZE]
 
std::atomic_int m_uncompleted {}
 Number of page writes in the batch which are still not completed. More...
 
- Public Attributes inherited from Segment
dblwr::Filem_file
 File that owns the segment. More...
 
uint32_t m_phy_size {}
 Physical page size of each entry/Segment. More...
 
os_offset_t m_start {}
 Physical offset in the file for the segment. More...
 
os_offset_t m_end {}
 Physical offset up to which this segment is responsible for. More...
 

Detailed Description

Segment for batched writes.

Constructor & Destructor Documentation

◆ Batch_segment() [1/2]

Batch_segment::Batch_segment ( uint16_t  id,
dblwr::File file,
page_no_t  start,
uint32_t  n_pages 
)
inline

Constructor.

Parameters
[in]idSegment ID.
[in]fileFile that owns the segment.
[in]startOffset (page number) of segment in the file.
[in]n_pagesNumber of pages in the segment.

◆ Batch_segment() [2/2]

Batch_segment::Batch_segment ( uint16_t  id,
dblwr::File file,
uint32_t  phy_size,
page_no_t  start,
uint32_t  n_pages 
)
inline

Constructor.

Parameters
[in]idSegment ID.
[in]fileFile that owns the segment.
[in]phy_sizephysical size of each segment entry
[in]startOffset (page number) of segment in the file.
[in]n_pagesNumber of pages in the segment.

◆ ~Batch_segment()

Batch_segment::~Batch_segment ( )
inlineoverridenoexcept

Destructor.

Member Function Documentation

◆ batch_size()

uint32_t Batch_segment::batch_size ( ) const
inlinenoexcept
Returns
the batch size.

◆ completed()

void Batch_segment::completed ( )
inlinenoexcept

Note that the batch has completed.

◆ id()

uint16_t Batch_segment::id ( ) const
inlinenoexcept
Returns
the batch segment ID.

◆ reset()

void Batch_segment::reset ( void  )
inlinenoexcept

Reset the state.

◆ set_batch_size()

void Batch_segment::set_batch_size ( uint32_t  size)
inlinenoexcept

Set the batch size.

Parameters
[in]sizeNumber of pages to write to disk.

◆ start()

void Batch_segment::start ( Double_write dblwr)
inlinenoexcept

Note that the batch has started for the double write instance.

Parameters
[in]dblwrInstance for which batch has started.

◆ write() [1/2]

void Batch_segment::write ( const Buffer buffer)
noexcept

Write a batch to the segment.

Parameters
[in]bufferBuffer to write.

◆ write() [2/2]

void Batch_segment::write ( const byte buf,
uint32_t  len 
)
noexcept

Write a batch to the segment.

Parameters
[in]bufBuffer to write
[in]lenamount of data to write

◆ write_complete()

bool Batch_segment::write_complete ( )
inlinenoexcept

Called on page write completion.

Returns
if batch ended.

Member Data Documentation

◆ m_batch_size

uint32_t Batch_segment::m_batch_size {}

Size of the batch.

Set to number of pages to be written with set_batch_size() before scheduling writes to data pages. Reset to zero with reset() after all IOs are completed. Read only by the thread which has observed the last IO completion, the one which will reset it back to zero and enqueue the segment for future reuse. Accesses to this field are ordered by happens-before relation: set_batch_size() sequenced-before fil_io() happens-before dblwr::write_complete() entry sequenced-before batch_size() sequenced-before reset() sequenced-before enqueue() synchronizes-with dequeue() sequenced-before set_batch_size() ...

◆ m_dblwr

Double_write* Batch_segment::m_dblwr {}

The instance that is being written to disk.

◆ m_id

uint16_t Batch_segment::m_id {}

Batch segment ID.

◆ m_pad1

byte Batch_segment::m_pad1[ut::INNODB_CACHE_LINE_SIZE]

◆ m_pad2

byte Batch_segment::m_pad2[ut::INNODB_CACHE_LINE_SIZE]

◆ m_uncompleted

std::atomic_int Batch_segment::m_uncompleted {}

Number of page writes in the batch which are still not completed.

Set to equal m_batch_size by set_batch_size(), and decremented when a page write is finished (either by failing/not attempting or in IO completion). It serves a role of a reference counter: when it drops to zero, the segment can be enqueued back to the pool of available segments. Accessing a segment which has m_uncompleted == 0 is safe only from the thread which knows it can not be recycled - for example because it's the thread which has caused the m_uncompleted drop to 0 and will enqueue it, or it's the thread which has just dequeued it, or it is handling shutdown.


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