Understanding of InnoDB Redo Buffer

Source: Internet
Author: User

A discussion on the structure of InnoDB redo (1@ tomorrow will be better (Group No.: 196380905)1. Redo log: The structure of the Redo log is physical to the page, logical to the record, and the physical logical log is used. InnoDB redo logs are based on mini-implemented by transaction. Each redo log block is 512 bytes, which means that the log buffer is also organized as a 512-byte block. Each mini-transaction will have a structure of MTR, the structure of this MTR encapsulates a log not written to the log buffer, the MTR structure has a log member, the member is the structure of the log.            Log_t is the structure that represents the log buffer, and only one Sys_log instance (lot_t sys_log) is maintained in the mysqld running instance. Sys_log maintained the size of the innodb_log_buffer_size developed by US redo buffer. The memory area in the Sys_log-BUF maintains this area of memory. Redo Buffer has the following three structures:|----------------|  |                Block Header |                |----------------|  |                Records Logs |                |----------------|  |                         Block Trialer | |----------------|(log block structure)|----------|----------|----------|----------|         |log Block |log Block |log block |log block | |----------|----------|----------|----------|(log buffer organization) the header and tail in the log buffer are defined in the source code:/*offsets of a log block header*/        #defineLog_block_hdr_no 0/* BLOCK number which must be > 0 and isallowed to wrap around at 2G; the highest bit is SetTo1 if  This  isThe first log blockincha log flush write segment*/#defineLog_block_flush_bit_mask 0x80000000ul/*mask used to get the highest bit in the preceding field*/        #defineLog_block_hdr_data_len 4/* Number of bytes of log written to ThisBlock */#defineLog_block_first_rec_group 6/* Offset of the first start of anMTR Log Record Groupinch  Thislog block,0 ifNoneifThe value isThe same asLog_block_hdr_data_len, it means that the first REC group have not yet been Cate Nated to Thislog block, butifIt'll, it'll start at Thisoffset; An archive recovery can start parsing the log records starting  from  ThisOffsetinch  Thislog block,ifValue not0*/#defineLog_block_checkpoint_no 8/* 4 Lower bytes of the value ofLog_sys-Next_checkpoint_no when the log block is last written to:ifThe block has no yet been written full, ThisValue isOnly updated before a log buffer flush*/#defineLog_block_hdr_size/* SIZE of the log BLOCK header inbytes*//*offsets of a log block trailer from the end of the block*/        #defineLog_block_checksum 4/* 4 byte CHECKSUM of the log BLOCKcontents;inchInnoDB versions<3.23. the  ThisDid not contain the checksum but the same value as                    .. _hdr_no*/#defineLog_block_trl_size 4/* Trailer SIZE in bytes */Mini-transactions is the abbreviation for MTR, which centralizes a set of log record and writes it to log buffer. /*mini-transaction handle and buffer*/            structmtr_t{#ifdef univ_debug ulint State; /*!< mtr_active, mtr_committing, mtr_committed*/            #endifdyn_array_t Memo; /*!< Memo stack for locks etc.*/dyn_array_t log; /*!< mini-transaction Log*/unsigned inside_ibuf:1; /*!< TRUE If inside ibuf changes*/unsigned modifications:1; /*!< TRUE If the mini-transaction modified buffer pool pages*/unsigned made_dirty:1; /*!< TRUE If MTR have made at least one buffer pool page dirty*/Ulint n_log_recs; /*count of how many page initial log records has been written to the MTR log*/Ulint n_freed_pages; /*Number of pages that has been freed in this mini-transaction*/Ulint Log_mode;/*specifies which operations should be logged; default value Mtr_log_all*/lsn_t start_lsn;/*start LSN of the possible log entry for this MTR*/lsn_t end_lsn;/*end LSN of the possible log entry for this MTR*/#ifdef univ_debug ulint magic_n; #endif/* Univ_debug */            }; Definition of dyn_block_t:/** A block in a dynamically allocated array*/            structdyn_block_t; /** Dynamically allocated array*/typedef dyn_block_t dyn_array_t; /** This is the initial ' payload ' size of a dynamic array; This must is > Mlog_buf_margin + 30! */            #defineDyn_array_data_size 512/*#################################################################*/            /** @brief a block in a dynamically allocated array. note! Do not access the fields of the struct directly:the definition appears this compiler to know its size! */            structdyn_block_t{mem_heap_t* HEAP;/*!< in the first block this is! = NULL If dynamic allocation has been needed*/Ulint used; /*!< number of data bytes used in this block; Dyn_block_full_flag is set when the BLOCK becomes*/                byteData[dyn_array_data_size];//real-World log data                            /*!< storage for array elements*/ut_list_base_node_t (dyn_block_t)Base; /*!< Linear list of dyn blocks:this node is used only in the first block*/ut_list_node_t (dyn_block_t) LIST; /*!< Linear list node:used in all blocks*/#ifdef univ_debug ulint buf_end;/*!< only in the debug version:if dyn array are opened, this is the buffer End offset, else this is 0*/Ulint magic_n;/*!< Magic Number (Dyn_block_magic_n)*/            #endif            };2. mini-logic for calling methods of transaction log: Mtr_commit-Mtr_log_reserve_and_write->log_write_low//the function is to write the Mtr->log to the free log buffer.        /************************************************************//** Writes the contents of a mini-transaction log, if any, to the database log.*/        Static voidMtr_log_reserve_and_write (mtr_t* mtr)/*!< in/out:mtr*/--->/************************************************************//** Writes to the log the string given. It is assumed that the caller holds the log mutex. */Univ_internvoidLog_write_low (byte* STR/*!< in:string*/, Ulint Str_len/*!< in:string Length*/)

Understanding of InnoDB Redo Buffer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.