InnoDB Plugin  1.0
Data Structures | Macros | Functions
trx0undo.h File Reference
#include "univ.i"
#include "trx0types.h"
#include "mtr0mtr.h"
#include "trx0sys.h"
#include "page0types.h"
#include "trx0xa.h"
#include "trx0undo.ic"
Include dependency graph for trx0undo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  trx_undo_t

Macros

#define trx_undo_free_last_page(trx, undo, mtr)   trx_undo_free_last_page_func(trx,undo,mtr)
#define trx_undo_truncate_end(trx, undo, limit)   trx_undo_truncate_end_func(trx,undo,limit)
#define TRX_UNDO_INSERT   1 /* contains undo entries for inserts */
#define TRX_UNDO_UPDATE
#define TRX_UNDO_ACTIVE
#define TRX_UNDO_CACHED   2 /* cached for quick reuse */
#define TRX_UNDO_TO_FREE   3 /* insert undo segment can be freed */
#define TRX_UNDO_TO_PURGE
#define TRX_UNDO_PREPARED
#define TRX_UNDO_PAGE_HDR   FSEG_PAGE_DATA
#define TRX_UNDO_PAGE_REUSE_LIMIT   (3 * UNIV_PAGE_SIZE / 4)
#define TRX_UNDO_SEG_HDR   (TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE)
#define TRX_UNDO_PAGE_TYPE   0
#define TRX_UNDO_PAGE_START   2
#define TRX_UNDO_PAGE_FREE   4
#define TRX_UNDO_PAGE_NODE   6
#define TRX_UNDO_PAGE_HDR_SIZE   (6 + FLST_NODE_SIZE)
#define TRX_UNDO_STATE   0
#define TRX_UNDO_LAST_LOG   2
#define TRX_UNDO_FSEG_HEADER   4
#define TRX_UNDO_PAGE_LIST   (4 + FSEG_HEADER_SIZE)
#define TRX_UNDO_SEG_HDR_SIZE   (4 + FSEG_HEADER_SIZE + FLST_BASE_NODE_SIZE)
#define TRX_UNDO_TRX_ID   0
#define TRX_UNDO_TRX_NO   8
#define TRX_UNDO_DEL_MARKS   16
#define TRX_UNDO_LOG_START   18
#define TRX_UNDO_XID_EXISTS   20
#define TRX_UNDO_DICT_TRANS   21
#define TRX_UNDO_TABLE_ID   22
#define TRX_UNDO_NEXT_LOG   30
#define TRX_UNDO_PREV_LOG   32
#define TRX_UNDO_HISTORY_NODE   34
#define TRX_UNDO_LOG_OLD_HDR_SIZE   (34 + FLST_NODE_SIZE)
#define TRX_UNDO_XA_FORMAT   (TRX_UNDO_LOG_OLD_HDR_SIZE)
#define TRX_UNDO_XA_TRID_LEN   (TRX_UNDO_XA_FORMAT + 4)
#define TRX_UNDO_XA_BQUAL_LEN   (TRX_UNDO_XA_TRID_LEN + 4)
#define TRX_UNDO_XA_XID   (TRX_UNDO_XA_BQUAL_LEN + 4)
#define TRX_UNDO_LOG_XA_HDR_SIZE   (TRX_UNDO_XA_XID + XIDDATASIZE)

Functions

UNIV_INLINE roll_ptr_t trx_undo_build_roll_ptr (ibool is_insert, ulint rseg_id, ulint page_no, ulint offset)
UNIV_INLINE void trx_undo_decode_roll_ptr (roll_ptr_t roll_ptr, ibool *is_insert, ulint *rseg_id, ulint *page_no, ulint *offset)
UNIV_INLINE ibool trx_undo_roll_ptr_is_insert (roll_ptr_t roll_ptr)
UNIV_INLINE bool trx_undo_trx_id_is_insert (const byte *trx_id))
UNIV_INLINE void trx_write_roll_ptr (byte *ptr, roll_ptr_t roll_ptr)
UNIV_INLINE roll_ptr_t trx_read_roll_ptr (const byte *ptr)
UNIV_INLINE page_ttrx_undo_page_get (ulint space, ulint zip_size, ulint page_no, mtr_t *mtr)
UNIV_INLINE page_ttrx_undo_page_get_s_latched (ulint space, ulint zip_size, ulint page_no, mtr_t *mtr)
UNIV_INLINE trx_undo_rec_ttrx_undo_page_get_prev_rec (trx_undo_rec_t *rec, ulint page_no, ulint offset)
UNIV_INLINE trx_undo_rec_ttrx_undo_page_get_next_rec (trx_undo_rec_t *rec, ulint page_no, ulint offset)
UNIV_INLINE trx_undo_rec_ttrx_undo_page_get_last_rec (page_t *undo_page, ulint page_no, ulint offset)
UNIV_INLINE trx_undo_rec_ttrx_undo_page_get_first_rec (page_t *undo_page, ulint page_no, ulint offset)
UNIV_INTERN trx_undo_rec_ttrx_undo_get_prev_rec (trx_undo_rec_t *rec, ulint page_no, ulint offset, bool shared, mtr_t *mtr)
UNIV_INTERN trx_undo_rec_ttrx_undo_get_next_rec (trx_undo_rec_t *rec, ulint page_no, ulint offset, mtr_t *mtr)
UNIV_INTERN trx_undo_rec_ttrx_undo_get_first_rec (ulint space, ulint zip_size, ulint page_no, ulint offset, ulint mode, mtr_t *mtr)
UNIV_INTERN buf_block_ttrx_undo_add_page (trx_t *trx, trx_undo_t *undo, mtr_t *mtr))
UNIV_INTERN void trx_undo_free_last_page_func (const trx_t *trx, trx_undo_t *undo, mtr_t *mtr))
UNIV_INTERN void trx_undo_truncate_end_func (const trx_t *trx, trx_undo_t *undo, undo_no_t limit))
UNIV_INTERN void trx_undo_truncate_start (trx_rseg_t *rseg, ulint space, ulint hdr_page_no, ulint hdr_offset, undo_no_t limit)
UNIV_INTERN ulint trx_undo_lists_init (trx_rseg_t *rseg)
UNIV_INTERN dberr_t trx_undo_assign_undo (trx_t *trx, ulint type))
UNIV_INTERN page_ttrx_undo_set_state_at_finish (trx_undo_t *undo, mtr_t *mtr)
UNIV_INTERN page_ttrx_undo_set_state_at_prepare (trx_t *trx, trx_undo_t *undo, mtr_t *mtr)
UNIV_INTERN void trx_undo_update_cleanup (trx_t *trx, page_t *undo_page, mtr_t *mtr)
UNIV_INTERN void trx_undo_insert_cleanup (trx_t *trx)
UNIV_INTERN void trx_undo_free_prepared (trx_t *trx) UNIV_COLD)
UNIV_INTERN byte * trx_undo_parse_page_init (byte *ptr, byte *end_ptr, page_t *page, mtr_t *mtr)
UNIV_INTERN byte * trx_undo_parse_page_header (ulint type, byte *ptr, byte *end_ptr, page_t *page, mtr_t *mtr)
UNIV_INTERN byte * trx_undo_parse_discard_latest (byte *ptr, byte *end_ptr, page_t *page, mtr_t *mtr)
UNIV_INTERN void trx_undo_mem_free (trx_undo_t *undo)

Detailed Description

Transaction undo log

Created 3/26/1996 Heikki Tuuri

Macro Definition Documentation

#define TRX_UNDO_ACTIVE
Value:
1 /* contains an undo log of an active
transaction */
#define TRX_UNDO_DEL_MARKS   16

Defined only in an update undo log: TRUE if the transaction may have done delete markings of records, and thus purge is necessary

#define TRX_UNDO_DICT_TRANS   21

TRUE if the transaction is a table create, index create, or drop transaction: in recovery the transaction cannot be rolled back in the usual way: a 'rollback' rather means dropping the created or dropped table, if it still exists

#define TRX_UNDO_FSEG_HEADER   4

Header for the file segment which the undo log segment occupies

#define TRX_UNDO_HISTORY_NODE   34

If the log is put to the history list, the file list node is here

#define TRX_UNDO_LAST_LOG   2

Offset of the last undo log header on the segment header page, 0 if none

#define TRX_UNDO_LOG_OLD_HDR_SIZE   (34 + FLST_NODE_SIZE)

Size of the undo log header without XID information

#define TRX_UNDO_LOG_START   18

Offset of the first undo log record of this log on the header page; purge may remove undo log record from the log start, and therefore this is not necessarily the same as this log header end offset

#define TRX_UNDO_LOG_XA_HDR_SIZE   (TRX_UNDO_XA_XID + XIDDATASIZE)

Total size of the undo log header with the XA XID

#define TRX_UNDO_NEXT_LOG   30

Offset of the next undo log header on this page, 0 if none

#define TRX_UNDO_PAGE_FREE   4

On each page of the undo log this field contains the byte offset of the first free byte on the page

#define TRX_UNDO_PAGE_HDR   FSEG_PAGE_DATA

The offset of the undo log page header on pages of the undo log

#define TRX_UNDO_PAGE_HDR_SIZE   (6 + FLST_NODE_SIZE)

Size of the transaction undo log page header, in bytes

#define TRX_UNDO_PAGE_LIST   (4 + FSEG_HEADER_SIZE)

Base node for the list of pages in the undo log segment; defined only on the undo log segment's first page

#define TRX_UNDO_PAGE_NODE   6

The file list node in the chain of undo log pages

#define TRX_UNDO_PAGE_REUSE_LIMIT   (3 * UNIV_PAGE_SIZE / 4)
An update undo segment with just one page can be reused if it has

at most this many bytes used; we must leave space at least for one new undo log header on the page

#define TRX_UNDO_PAGE_START   2

Byte offset where the undo log records for the LATEST transaction start on this page (remember that in an update undo log, the first page can contain several undo logs)

#define TRX_UNDO_PAGE_TYPE   0

Transaction undo log page header offsets TRX_UNDO_INSERT or TRX_UNDO_UPDATE

#define TRX_UNDO_PREPARED
Value:
5 /* contains an undo log of an
prepared transaction */
#define TRX_UNDO_PREV_LOG   32

Offset of the previous undo log header on this page, 0 if none

#define TRX_UNDO_SEG_HDR   (TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE)
The offset of the undo log segment header on the first page of the undo

log segment

#define TRX_UNDO_SEG_HDR_SIZE   (4 + FSEG_HEADER_SIZE + FLST_BASE_NODE_SIZE)

Size of the undo log segment header

#define TRX_UNDO_STATE   0

Undo log segment header TRX_UNDO_ACTIVE, ...

#define TRX_UNDO_TABLE_ID   22

Id of the table if the preceding field is TRUE

#define TRX_UNDO_TO_PURGE
Value:
4 /* update undo segment will not be
reused: it can be freed in purge when
all undo data in it is removed */
#define TRX_UNDO_TRX_ID   0
The undo log header. There can be several undo log headers on the first

page of an update undo log segment. Transaction id

#define TRX_UNDO_TRX_NO   8

Transaction number of the transaction; defined only if the log is in a history list

#define TRX_UNDO_UPDATE
Value:
2 /* contains undo entries for updates
and delete markings: in short,
modifys (the name 'UPDATE' is a
historical relic) */
#define TRX_UNDO_XA_BQUAL_LEN   (TRX_UNDO_XA_TRID_LEN + 4)
#define TRX_UNDO_XA_FORMAT   (TRX_UNDO_LOG_OLD_HDR_SIZE)

X/Open XA Transaction Identification (XID) xid_t::formatID

#define TRX_UNDO_XA_TRID_LEN   (TRX_UNDO_XA_FORMAT + 4)
#define TRX_UNDO_XA_XID   (TRX_UNDO_XA_BQUAL_LEN + 4)

Distributed transaction identifier data

#define TRX_UNDO_XID_EXISTS   20

TRUE if undo log header includes X/Open XA transaction identification XID

Function Documentation

UNIV_INLINE roll_ptr_t trx_read_roll_ptr ( const byte *  ptr)

Reads a roll ptr from an index page. In case that the roll ptr size changes in some future version, this function should be used instead of mach_read_...

Returns
roll ptr in: pointer to memory from where to read

Reads a roll ptr from an index page. In case that the roll ptr size changes in some future version, this function should be used instead of mach_read_...

Returns
roll ptr
Parameters
ptrin: pointer to memory from where to read
UNIV_INTERN buf_block_t* trx_undo_add_page ( trx_t trx,
trx_undo_t undo,
mtr_t mtr 
)

Tries to add a page to the undo log segment where the undo log is placed.

Returns
X-latched block if success, else NULL
Parameters
trxin: transaction
undoin: undo log memory object
mtrin: mtr which does not have a latch to any undo log page; the caller must have reserved the rollback segment mutex
UNIV_INTERN dberr_t trx_undo_assign_undo ( trx_t trx,
ulint  type 
)

Assigns an undo log for a transaction. A new undo log is created or a cached undo log reused.

Returns
DB_SUCCESS if undo log assign successful, possible error codes are: DB_TOO_MANY_CONCURRENT_TRXS DB_OUT_OF_FILE_SPACE DB_READ_ONLY DB_OUT_OF_MEMORY
Parameters
trxin: transaction
typein: TRX_UNDO_INSERT or TRX_UNDO_UPDATE
UNIV_INLINE roll_ptr_t trx_undo_build_roll_ptr ( ibool  is_insert,
ulint  rseg_id,
ulint  page_no,
ulint  offset 
)

Builds a roll pointer.

Returns
roll pointer in: offset of the undo entry within page

Builds a roll pointer.

Returns
roll pointer
Parameters
is_insertin: TRUE if insert undo log
rseg_idin: rollback segment id
page_noin: page number
offsetin: offset of the undo entry within page
UNIV_INLINE void trx_undo_decode_roll_ptr ( roll_ptr_t  roll_ptr,
ibool is_insert,
ulint *  rseg_id,
ulint *  page_no,
ulint *  offset 
)

Decodes a roll pointer. out: offset of the undo entry within page

Decodes a roll pointer.

Parameters
roll_ptrin: roll pointer
is_insertout: TRUE if insert undo log
rseg_idout: rollback segment id
page_noout: page number
offsetout: offset of the undo entry within page
UNIV_INTERN void trx_undo_free_last_page_func ( const trx_t trx,
trx_undo_t undo,
mtr_t mtr 
)

Frees the last undo log page. The caller must hold the rollback segment mutex.

Parameters
trxin: transaction
undoin/out: undo log memory copy
mtrin/out: mini-transaction which does not have a latch to any undo log page or which has allocated the undo log page
UNIV_INTERN void trx_undo_free_prepared ( trx_t trx)

At shutdown, frees the undo logs of a PREPARED transaction.

Parameters
trxin/out: PREPARED transaction
UNIV_INTERN trx_undo_rec_t* trx_undo_get_first_rec ( ulint  space,
ulint  zip_size,
ulint  page_no,
ulint  offset,
ulint  mode,
mtr_t mtr 
)

Gets the first record in an undo log.

Returns
undo log record, the page latched, NULL if none in: mtr
Parameters
spacein: undo log header space
zip_sizein: compressed page size in bytes or 0 for uncompressed pages
page_noin: undo log header page number
offsetin: undo log header offset on page
modein: latching mode: RW_S_LATCH or RW_X_LATCH
UNIV_INTERN trx_undo_rec_t* trx_undo_get_next_rec ( trx_undo_rec_t rec,
ulint  page_no,
ulint  offset,
mtr_t mtr 
)

Gets the next record in an undo log.

Returns
undo log record, the page s-latched, NULL if none in: mtr
Parameters
recin: undo record
page_noin: undo log header page number
offsetin: undo log header offset on page
UNIV_INTERN trx_undo_rec_t* trx_undo_get_prev_rec ( trx_undo_rec_t rec,
ulint  page_no,
ulint  offset,
bool  shared,
mtr_t mtr 
)

Gets the previous record in an undo log.

Returns
undo log record, the page s-latched, NULL if none in: mtr
Parameters
recin: undo record
page_noin: undo log header page number
offsetin: undo log header offset on page
sharedin: true=S-latch, false=X-latch
UNIV_INTERN void trx_undo_insert_cleanup ( trx_t trx)

Frees or caches an insert undo log after a transaction commit or rollback. Knowledge of inserts is not needed after a commit or rollback, therefore the data can be discarded. in: transaction handle

UNIV_INTERN ulint trx_undo_lists_init ( trx_rseg_t rseg)

Initializes the undo log lists for a rollback segment memory copy. This function is only called when the database is started or a new rollback segment created.

Returns
the combined size of undo log segments in pages in: rollback segment memory object
UNIV_INLINE page_t* trx_undo_page_get ( ulint  space,
ulint  zip_size,
ulint  page_no,
mtr_t mtr 
)

Gets an undo log page and x-latches it.

Returns
pointer to page x-latched in: mtr

Gets an undo log page and x-latches it.

Returns
pointer to page x-latched
Parameters
spacein: space where placed
zip_sizein: compressed page size in bytes or 0 for uncompressed pages
page_noin: page number
mtrin: mtr
UNIV_INLINE trx_undo_rec_t* trx_undo_page_get_first_rec ( page_t undo_page,
ulint  page_no,
ulint  offset 
)

Returns the first undo record on the page in the specified undo log, or NULL if none exists.

Returns
pointer to record, NULL if none in: undo log header offset on page

Returns the first undo record on the page in the specified undo log, or NULL if none exists.

Returns
pointer to record, NULL if none
Parameters
undo_pagein: undo log page
page_noin: undo log header page number
offsetin: undo log header offset on page
UNIV_INLINE trx_undo_rec_t* trx_undo_page_get_last_rec ( page_t undo_page,
ulint  page_no,
ulint  offset 
)

Returns the last undo record on the page in the specified undo log, or NULL if none exists.

Returns
pointer to record, NULL if none in: undo log header offset on page

Returns the last undo record on the page in the specified undo log, or NULL if none exists.

Returns
pointer to record, NULL if none
Parameters
undo_pagein: undo log page
page_noin: undo log header page number
offsetin: undo log header offset on page
UNIV_INLINE trx_undo_rec_t* trx_undo_page_get_next_rec ( trx_undo_rec_t rec,
ulint  page_no,
ulint  offset 
)

Returns the next undo log record on the page in the specified log, or NULL if none exists.

Returns
pointer to record, NULL if none in: undo log header offset on page

Returns the next undo log record on the page in the specified log, or NULL if none exists.

Returns
pointer to record, NULL if none
Parameters
recin: undo log record
page_noin: undo log header page number
offsetin: undo log header offset on page
UNIV_INLINE trx_undo_rec_t* trx_undo_page_get_prev_rec ( trx_undo_rec_t rec,
ulint  page_no,
ulint  offset 
)

Returns the previous undo record on the page in the specified log, or NULL if none exists.

Returns
pointer to record, NULL if none in: undo log header offset on page

Returns the previous undo record on the page in the specified log, or NULL if none exists.

Returns
pointer to record, NULL if none
Parameters
recin: undo log record
page_noin: undo log header page number
offsetin: undo log header offset on page
UNIV_INLINE page_t* trx_undo_page_get_s_latched ( ulint  space,
ulint  zip_size,
ulint  page_no,
mtr_t mtr 
)

Gets an undo log page and s-latches it.

Returns
pointer to page s-latched in: mtr

Gets an undo log page and s-latches it.

Returns
pointer to page s-latched
Parameters
spacein: space where placed
zip_sizein: compressed page size in bytes or 0 for uncompressed pages
page_noin: page number
mtrin: mtr
UNIV_INTERN byte* trx_undo_parse_discard_latest ( byte *  ptr,
byte *  end_ptr,
page_t page,
mtr_t mtr 
)

Parses the redo log entry of an undo log page header discard.

Returns
end of log record or NULL in: mtr or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
pagein: page or NULL
UNIV_INTERN byte* trx_undo_parse_page_header ( ulint  type,
byte *  ptr,
byte *  end_ptr,
page_t page,
mtr_t mtr 
)

Parses the redo log entry of an undo log page header create or reuse.

Returns
end of log record or NULL in: mtr or NULL
Parameters
typein: MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE
ptrin: buffer
end_ptrin: buffer end
pagein: page or NULL
UNIV_INTERN byte* trx_undo_parse_page_init ( byte *  ptr,
byte *  end_ptr,
page_t page,
mtr_t mtr 
)

Parses the redo log entry of an undo log page initialization.

Returns
end of log record or NULL in: mtr or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
pagein: page or NULL
UNIV_INLINE ibool trx_undo_roll_ptr_is_insert ( roll_ptr_t  roll_ptr)

Returns TRUE if the roll pointer is of the insert type.

Returns
TRUE if insert undo log in: roll pointer

Returns TRUE if the roll pointer is of the insert type.

Returns
TRUE if insert undo log
Parameters
roll_ptrin: roll pointer
UNIV_INTERN page_t* trx_undo_set_state_at_finish ( trx_undo_t undo,
mtr_t mtr 
)

Sets the state of the undo log segment at a transaction finish.

Returns
undo log segment header page, x-latched in: mtr
Parameters
undoin: undo log memory copy
UNIV_INTERN page_t* trx_undo_set_state_at_prepare ( trx_t trx,
trx_undo_t undo,
mtr_t mtr 
)

Sets the state of the undo log segment at a transaction prepare.

Returns
undo log segment header page, x-latched in: mtr
Parameters
trxin: transaction
undoin: undo log memory copy
UNIV_INTERN void trx_undo_truncate_end_func ( const trx_t trx,
trx_undo_t undo,
undo_no_t  limit 
)

Truncates an undo log from the end. This function is used during a rollback to free space from an undo log.

Parameters
trxin: transaction whose undo log it is
undoin/out: undo log
limitin: all undo records with undo number >= this value should be truncated
UNIV_INTERN void trx_undo_truncate_start ( trx_rseg_t rseg,
ulint  space,
ulint  hdr_page_no,
ulint  hdr_offset,
undo_no_t  limit 
)

Truncates an undo log from the start. This function is used during a purge operation. in: all undo pages with undo numbers < this value should be truncated; NOTE that the function only frees whole pages; the header page is not freed, but emptied, if all the records there are < limit

Parameters
rsegin: rollback segment
spacein: space id of the log
hdr_page_noin: header page number
hdr_offsetin: header offset on the page
UNIV_INLINE bool trx_undo_trx_id_is_insert ( const byte *  trx_id)

Returns true if the record is of the insert type.

Returns
true if the record was freshly inserted (not updated).
Parameters
trx_idin: DB_TRX_ID, followed by DB_ROLL_PTR
UNIV_INTERN void trx_undo_update_cleanup ( trx_t trx,
page_t undo_page,
mtr_t mtr 
)

Adds the update undo log header as the first in the history list, and frees the memory object, or puts it to the list of cached update undo log segments. in: mtr

Parameters
trxin: trx owning the update undo log
undo_pagein: update undo log header page, x-latched
UNIV_INLINE void trx_write_roll_ptr ( byte *  ptr,
roll_ptr_t  roll_ptr 
)

Writes a roll ptr to an index page. In case that the size changes in some future version, this function should be used instead of mach_write_... in: roll ptr

Writes a roll ptr to an index page. In case that the size changes in some future version, this function should be used instead of mach_write_...

Parameters
ptrin: pointer to memory where written
roll_ptrin: roll ptr