MySQL 8.4.2
Source Code Documentation
PFS_ringbuffer_index Class Reference

Index in the error-log ring-buffer. More...

#include <cursor_by_error_log.h>

Public Member Functions

void reset ()
 Reset index. More...
 
 PFS_ringbuffer_index ()
 Constructor. More...
 
void set_at (const PFS_ringbuffer_index *other)
 Set this index to a given position. More...
 
void set_after (const PFS_ringbuffer_index *other)
 Set our index to the element after the given one (if that is valid; otherwise, we cannot determine a next element). More...
 
log_sink_pfs_eventget_event ()
 Get event if it's still valid. More...
 
log_sink_pfs_eventscan_next ()
 Return current record (if valid), then set index to the next record. More...
 

Private Attributes

int m_index
 Numeric row index. More...
 
log_sink_pfs_eventm_event
 Pointer to an event in the ring-buffer. More...
 
ulonglong m_timestamp
 Time-stamp we copied from the event we point to when setting this index. More...
 

Detailed Description

Index in the error-log ring-buffer.

Has a numeric index, a pointer to an event in the buffer, and the timestamp for that event. This lets us easily check whether this index is still valid: its timestamp must be greater than or equal to that of the ring-buffer's oldest entry (the tail or "read-position"). If our timestamp is older than that value, it points to an event that has since expired.

Constructor & Destructor Documentation

◆ PFS_ringbuffer_index()

PFS_ringbuffer_index::PFS_ringbuffer_index ( )
inline

Constructor.

Member Function Documentation

◆ get_event()

log_sink_pfs_event * PFS_ringbuffer_index::get_event ( )
inline

Get event if it's still valid.

Caller should hold read-lock on ring-buffer.

If m_index is 0, the index was reset, and we re-obtain the ring-buffer's read-pointer / tail. This updates m_event and m_timestamp.

If m_index is -1 (EOF), we return nullptr.

Otherwise, we try to obtain the event in the ring-buffer pointed to by m_event. If that event is still valid, we return it; otherwise, we return nullptr (but leave the stale pointer on the object for debugging). It is therefore vital to to determine success/failure by checking the retval rather than calling this method and then checking m_event directly!

Return values
nullptrno event (EOF, empty buffer, or stale index)
!=nullptrthe event this index is referring to

◆ reset()

void PFS_ringbuffer_index::reset ( void  )
inline

Reset index.

◆ scan_next()

log_sink_pfs_event * PFS_ringbuffer_index::scan_next ( )
inline

Return current record (if valid), then set index to the next record.

Caller should hold read-lock on ring-buffer. Returned value is only valid as long as the lock is held.

Note that three states are possible: a) an event-pointer is returned, and the index points to a valid succeeding event (i.e. is not EOF): there are more elements b) an event-pointer is returned, but the index now flags EOF: this was the last element c) NULL is returned, and the index flags EOF: no event could be obtained (the buffer is empty, or we're at EOF)

Updates m_event, m_timestamp, and m_index.

Return values
nullptrno valid record could be obtained (end of buffer etc.)
!=nullptrpointer to an entry in the ring-buffer

◆ set_after()

void PFS_ringbuffer_index::set_after ( const PFS_ringbuffer_index other)
inline

Set our index to the element after the given one (if that is valid; otherwise, we cannot determine a next element).

Caller should hold read-lock on ring-buffer.

Parameters
otherset our index to the position after the given one

◆ set_at()

void PFS_ringbuffer_index::set_at ( const PFS_ringbuffer_index other)
inline

Set this index to a given position.

This copies other without validating it.

Parameters
otherset our index from the given one

Member Data Documentation

◆ m_event

log_sink_pfs_event* PFS_ringbuffer_index::m_event
private

Pointer to an event in the ring-buffer.

Before dereferencing this pointer, use

See also
log_sink_pfs_event_valid() to make sure it has not become stale.

◆ m_index

int PFS_ringbuffer_index::m_index
private

Numeric row index.

valid range [0;num_events[. -1 == EOF

◆ m_timestamp

ulonglong PFS_ringbuffer_index::m_timestamp
private

Time-stamp we copied from the event we point to when setting this index.

The ring-buffer keeps track of what the oldest item in it is. If our timestamp is older than that item's timestamp, the event we're pointing too has been purged from the ring-buffer, and our pointer is stale. 0 for undefined.


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