trx0undo.h, trx0undo.c, trx0trx.c, trx0roll.c:

  Make InnoDB-5.0.3 to process log records of 4.1 undo log header create and reuse just like in 4.1; storing XID to the start of the undo log is a separately logged operation; this conforms to Rule 3 of InnoDB redo logging
parent 2af86eaf
...@@ -307,23 +307,6 @@ trx_undo_parse_discard_latest( ...@@ -307,23 +307,6 @@ trx_undo_parse_discard_latest(
byte* end_ptr,/* in: buffer end */ byte* end_ptr,/* in: buffer end */
page_t* page, /* in: page or NULL */ page_t* page, /* in: page or NULL */
mtr_t* mtr); /* in: mtr or NULL */ mtr_t* mtr); /* in: mtr or NULL */
/************************************************************************
Write X/Open XA Transaction Identification (XID) to undo log header */
void
trx_undo_write_xid(
/*===============*/
trx_ulogf_t* log_hdr,/* in: undo log header */
XID* xid); /* in: X/Open XA Transaction Identification */
/************************************************************************
Read X/Open XA Transaction Identification (XID) from undo log header */
void
trx_undo_read_xid(
/*==============*/
trx_ulogf_t* log_hdr,/* in: undo log header */
XID* xid); /* out: X/Open XA Transaction Identification */
/* Types of an undo log segment */ /* Types of an undo log segment */
#define TRX_UNDO_INSERT 1 /* contains undo entries for inserts */ #define TRX_UNDO_INSERT 1 /* contains undo entries for inserts */
...@@ -419,7 +402,8 @@ struct trx_undo_struct{ ...@@ -419,7 +402,8 @@ struct trx_undo_struct{
#define TRX_UNDO_PAGE_HDR_SIZE (6 + FLST_NODE_SIZE) #define TRX_UNDO_PAGE_HDR_SIZE (6 + FLST_NODE_SIZE)
/* An update undo segment with just one page can be reused if it has /* An update undo segment with just one page can be reused if it has
< this number bytes used */ < this number bytes used; we must leave space at least for one new undo
log header on the page */
#define TRX_UNDO_PAGE_REUSE_LIMIT (3 * UNIV_PAGE_SIZE / 4) #define TRX_UNDO_PAGE_REUSE_LIMIT (3 * UNIV_PAGE_SIZE / 4)
...@@ -488,17 +472,25 @@ page of an update undo log segment. */ ...@@ -488,17 +472,25 @@ page of an update undo log segment. */
#define TRX_UNDO_HISTORY_NODE 34 /* If the log is put to the history #define TRX_UNDO_HISTORY_NODE 34 /* If the log is put to the history
list, the file list node is here */ list, the file list node is here */
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
#define TRX_UNDO_LOG_OLD_HDR_SIZE (34 + FLST_NODE_SIZE)
/* Note: the writing of the undo log old header is coded by a log record
MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE. The appending of an XID to the
header is logged separately. In this sense, the XID is not really a member
of the undo log header. TODO: do not append the XID to the log header if XA
is not needed by the user. The XID wastes about 150 bytes of space in every
undo log. In the history list we may have millions of undo logs, which means
quite a large overhead. */
/* X/Open XA Transaction Identification (XID) */ /* X/Open XA Transaction Identification (XID) */
#define TRX_UNDO_XA_FORMAT (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_TRID_LEN (TRX_UNDO_XA_FORMAT + 4)
#define TRX_UNDO_XA_BQUAL_LEN (TRX_UNDO_XA_TRID_LEN + 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_XA_XID (TRX_UNDO_XA_BQUAL_LEN + 4)
#define TRX_UNDO_XA_LEN (TRX_UNDO_XA_XID + XIDDATASIZE) /*--------------------------------------------------------------*/
#define TRX_UNDO_LOG_XA_HDR_SIZE (TRX_UNDO_XA_XID + XIDDATASIZE)
/*-------------------------------------------------------------*/ /* Total size of the header with the XA XID */
#define TRX_UNDO_LOG_HDR_SIZE (TRX_UNDO_XA_LEN)
/*-------------------------------------------------------------*/
#ifndef UNIV_NONINL #ifndef UNIV_NONINL
#include "trx0undo.ic" #include "trx0undo.ic"
......
...@@ -950,7 +950,7 @@ try_again: ...@@ -950,7 +950,7 @@ try_again:
if (progress_pct != trx_roll_progress_printed_pct) { if (progress_pct != trx_roll_progress_printed_pct) {
if (trx_roll_progress_printed_pct == 0) { if (trx_roll_progress_printed_pct == 0) {
fprintf(stderr, fprintf(stderr,
"\nInnoDB: Progress in percents: %lu\n", (ulong) progress_pct); "\nInnoDB: Progress in percents: %lu", (ulong) progress_pct);
} else { } else {
fprintf(stderr, fprintf(stderr,
" %lu", (ulong) progress_pct); " %lu", (ulong) progress_pct);
......
...@@ -162,7 +162,7 @@ trx_create( ...@@ -162,7 +162,7 @@ trx_create(
trx->read_view = NULL; trx->read_view = NULL;
/* Set X/Open XA transaction identification to NULL */ /* Set X/Open XA transaction identification to NULL */
memset(&trx->xid,0,sizeof(trx->xid)); memset(&trx->xid, 0, sizeof(trx->xid));
trx->xid.formatID = -1; trx->xid.formatID = -1;
return(trx); return(trx);
...@@ -436,12 +436,8 @@ trx_lists_init_at_db_start(void) ...@@ -436,12 +436,8 @@ trx_lists_init_at_db_start(void)
if (undo->state == TRX_UNDO_PREPARED) { if (undo->state == TRX_UNDO_PREPARED) {
fprintf(stderr, fprintf(stderr,
"InnoDB: Transaction %lu %lu was in the XA prepared state. We change it to\n" "InnoDB: Transaction %lu %lu was in the XA prepared state.\n",
"InnoDB: the 'active' state, so that InnoDB's true-and-tested crash\n" ut_dulint_get_high(trx->id),
"InnoDB: recovery will roll it back. If mysqld refuses to start after\n"
"InnoDB: this, you may be able to resolve the problem by moving the binlog\n"
"InnoDB: files to a safe place, and deleting all binlog files and the binlog\n"
"InnoDB: .index file from the datadir.\n", ut_dulint_get_high(trx->id),
ut_dulint_get_low(trx->id)); ut_dulint_get_low(trx->id));
/* trx->conc_state = TRX_PREPARED; */ /* trx->conc_state = TRX_PREPARED; */
...@@ -504,12 +500,8 @@ trx_lists_init_at_db_start(void) ...@@ -504,12 +500,8 @@ trx_lists_init_at_db_start(void)
if (undo->state == TRX_UNDO_PREPARED) { if (undo->state == TRX_UNDO_PREPARED) {
fprintf(stderr, fprintf(stderr,
"InnoDB: Transaction %lu %lu was in the XA prepared state. We change it to\n" "InnoDB: Transaction %lu %lu was in the XA prepared state.\n",
"InnoDB: the 'active' state, so that InnoDB's true-and-tested crash\n" ut_dulint_get_high(trx->id),
"InnoDB: recovery will roll it back. If mysqld refuses to start after\n"
"InnoDB: this, you may be able to resolve the problem by moving the binlog\n"
"InnoDB: files to a safe place, and deleting all binlog files and the binlog\n"
"InnoDB: .index file from the datadir.\n", ut_dulint_get_high(trx->id),
ut_dulint_get_low(trx->id)); ut_dulint_get_low(trx->id));
/* trx->conc_state = TRX_PREPARED; */ /* trx->conc_state = TRX_PREPARED; */
...@@ -786,8 +778,8 @@ trx_commit_off_kernel( ...@@ -786,8 +778,8 @@ trx_commit_off_kernel(
mutex_enter(&kernel_mutex); mutex_enter(&kernel_mutex);
} }
ut_ad(trx->conc_state == TRX_ACTIVE || trx->conc_state == TRX_PREPARED); ut_ad(trx->conc_state == TRX_ACTIVE
|| trx->conc_state == TRX_PREPARED);
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex)); ut_ad(mutex_own(&kernel_mutex));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
...@@ -1744,10 +1736,10 @@ trx_prepare_off_kernel( ...@@ -1744,10 +1736,10 @@ trx_prepare_off_kernel(
trx_t* trx) /* in: transaction */ trx_t* trx) /* in: transaction */
{ {
page_t* update_hdr_page; page_t* update_hdr_page;
dulint lsn;
trx_rseg_t* rseg; trx_rseg_t* rseg;
trx_undo_t* undo; trx_undo_t* undo;
ibool must_flush_log = FALSE; ibool must_flush_log = FALSE;
dulint lsn;
mtr_t mtr; mtr_t mtr;
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
...@@ -1765,10 +1757,9 @@ trx_prepare_off_kernel( ...@@ -1765,10 +1757,9 @@ trx_prepare_off_kernel(
must_flush_log = TRUE; must_flush_log = TRUE;
/* Change the undo log segment states from TRX_UNDO_ACTIVE /* Change the undo log segment states from TRX_UNDO_ACTIVE
to some other state: these modifications to the file data to TRX_UNDO_PREPARED: these modifications to the file data
structure define the transaction as prepared in the file structure define the transaction as prepared in the
based world, at the serialization point of the log sequence file-based world, at the serialization point of lsn. */
number lsn obtained below. */
mutex_enter(&(rseg->mutex)); mutex_enter(&(rseg->mutex));
...@@ -1780,18 +1771,20 @@ trx_prepare_off_kernel( ...@@ -1780,18 +1771,20 @@ trx_prepare_off_kernel(
undo = trx->update_undo; undo = trx->update_undo;
if (undo) { if (undo) {
/* It is not necessary to obtain trx->undo_mutex here /* It is not necessary to obtain trx->undo_mutex here
because only a single OS thread is allowed to do the because only a single OS thread is allowed to do the
transaction prepare for this transaction. */ transaction prepare for this transaction. */
update_hdr_page = trx_undo_set_state_at_prepare(trx, undo, &mtr); update_hdr_page = trx_undo_set_state_at_prepare(trx,
undo, &mtr);
} }
mutex_exit(&(rseg->mutex)); mutex_exit(&(rseg->mutex));
/*--------------*/ /*--------------*/
mtr_commit(&mtr); mtr_commit(&mtr); /* This mtr commit makes the
transaction prepared in the file-based
world */
/*--------------*/ /*--------------*/
lsn = mtr.end_lsn; lsn = mtr.end_lsn;
...@@ -1806,13 +1799,6 @@ trx_prepare_off_kernel( ...@@ -1806,13 +1799,6 @@ trx_prepare_off_kernel(
trx->conc_state = TRX_PREPARED; trx->conc_state = TRX_PREPARED;
/*--------------------------------------*/ /*--------------------------------------*/
if (trx->read_view) {
read_view_close(trx->read_view);
mem_heap_empty(trx->read_view_heap);
trx->read_view = NULL;
}
if (must_flush_log) { if (must_flush_log) {
mutex_exit(&kernel_mutex); mutex_exit(&kernel_mutex);
...@@ -1834,7 +1820,7 @@ Does the transaction prepare for MySQL. */ ...@@ -1834,7 +1820,7 @@ Does the transaction prepare for MySQL. */
ulint ulint
trx_prepare_for_mysql( trx_prepare_for_mysql(
/*=================*/ /*====-=============*/
/* out: 0 or error number */ /* out: 0 or error number */
trx_t* trx) /* in: trx handle */ trx_t* trx) /* in: trx handle */
{ {
...@@ -1881,9 +1867,8 @@ trx_recover_for_mysql( ...@@ -1881,9 +1867,8 @@ trx_recover_for_mysql(
fprintf(stderr, fprintf(stderr,
" InnoDB: Starting recovery for XA transactions...\n"); " InnoDB: Starting recovery for XA transactions...\n");
/* We should set those transactions which are in the prepared state
/* We should set those transactions which are in to the xid_list */
the prepared state to the xid_list */
mutex_enter(&kernel_mutex); mutex_enter(&kernel_mutex);
...@@ -1891,14 +1876,7 @@ trx_recover_for_mysql( ...@@ -1891,14 +1876,7 @@ trx_recover_for_mysql(
while (trx) { while (trx) {
if (trx->conc_state == TRX_PREPARED) { if (trx->conc_state == TRX_PREPARED) {
xid_list[count].formatID = trx->xid.formatID; xid_list[count] = trx->xid;
xid_list[count].gtrid_length = trx->xid.gtrid_length;
xid_list[count].bqual_length = trx->xid.bqual_length;
memcpy(xid_list[count].data,
trx->xid.data,
trx->xid.gtrid_length +
trx->xid.bqual_length);
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, fprintf(stderr,
...@@ -1935,7 +1913,7 @@ trx_recover_for_mysql( ...@@ -1935,7 +1913,7 @@ trx_recover_for_mysql(
This function is used to find one X/Open XA distributed transaction This function is used to find one X/Open XA distributed transaction
which is in the prepared state */ which is in the prepared state */
trx_t * trx_t*
trx_get_trx_by_xid( trx_get_trx_by_xid(
/*===============*/ /*===============*/
/* out: trx or NULL */ /* out: trx or NULL */
...@@ -1944,6 +1922,7 @@ trx_get_trx_by_xid( ...@@ -1944,6 +1922,7 @@ trx_get_trx_by_xid(
trx_t* trx; trx_t* trx;
if (xid == NULL) { if (xid == NULL) {
return (NULL); return (NULL);
} }
...@@ -1972,6 +1951,7 @@ trx_get_trx_by_xid( ...@@ -1972,6 +1951,7 @@ trx_get_trx_by_xid(
if (trx) { if (trx) {
if (trx->conc_state != TRX_PREPARED) { if (trx->conc_state != TRX_PREPARED) {
return(NULL); return(NULL);
} }
...@@ -1980,4 +1960,3 @@ trx_get_trx_by_xid( ...@@ -1980,4 +1960,3 @@ trx_get_trx_by_xid(
return(NULL); return(NULL);
} }
} }
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment