Commit 9f57e595 authored by Marko Mäkelä's avatar Marko Mäkelä

Refactor trx_undo_report_row_operation()

Fix a -fsanitizer=undefined warning that trx_undo_report_row_operation()
was being passed thr=NULL when the BTR_NO_UNDO_LOG_FLAG flag was set.

trx_undo_report_row_operation(): Remove the first two parameters.
The parameter clust_entry!=NULL distinguishes inserts from updates.

This should be a non-functional change (no observable change in
behaviour; slightly smaller code).
parent 8b34aabf
...@@ -1164,18 +1164,21 @@ btr_cur_ins_lock_and_undo( ...@@ -1164,18 +1164,21 @@ btr_cur_ins_lock_and_undo(
index, thr, mtr, inherit); index, thr, mtr, inherit);
if (err != DB_SUCCESS if (err != DB_SUCCESS
|| !(~flags | (BTR_NO_UNDO_LOG_FLAG | BTR_KEEP_SYS_FLAG))
|| !dict_index_is_clust(index) || dict_index_is_ibuf(index)) { || !dict_index_is_clust(index) || dict_index_is_ibuf(index)) {
return(err); return(err);
} }
err = trx_undo_report_row_operation(flags, TRX_UNDO_INSERT_OP, if (flags & BTR_NO_UNDO_LOG_FLAG) {
thr, index, entry, roll_ptr = 0;
NULL, 0, NULL, NULL, } else {
&roll_ptr); err = trx_undo_report_row_operation(thr, index, entry,
if (err != DB_SUCCESS) { NULL, 0, NULL, NULL,
&roll_ptr);
return(err); if (err != DB_SUCCESS) {
return(err);
}
} }
/* Now we can fill in the roll ptr field in entry */ /* Now we can fill in the roll ptr field in entry */
...@@ -1712,9 +1715,10 @@ btr_cur_upd_lock_and_undo( ...@@ -1712,9 +1715,10 @@ btr_cur_upd_lock_and_undo(
/* Append the info about the update in the undo log */ /* Append the info about the update in the undo log */
return(trx_undo_report_row_operation( return((flags & BTR_NO_UNDO_LOG_FLAG)
flags, TRX_UNDO_MODIFY_OP, thr, ? DB_SUCCESS
index, NULL, update, : trx_undo_report_row_operation(
thr, index, NULL, update,
cmpl_info, rec, offsets, roll_ptr)); cmpl_info, rec, offsets, roll_ptr));
} }
...@@ -2985,7 +2989,7 @@ btr_cur_del_mark_set_clust_rec( ...@@ -2985,7 +2989,7 @@ btr_cur_del_mark_set_clust_rec(
return(err); return(err);
} }
err = trx_undo_report_row_operation(0, TRX_UNDO_MODIFY_OP, thr, err = trx_undo_report_row_operation(thr,
index, NULL, NULL, 0, rec, offsets, index, NULL, NULL, 0, rec, offsets,
&roll_ptr); &roll_ptr);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -212,10 +213,6 @@ UNIV_INTERN ...@@ -212,10 +213,6 @@ UNIV_INTERN
dberr_t dberr_t
trx_undo_report_row_operation( trx_undo_report_row_operation(
/*==========================*/ /*==========================*/
ulint flags, /*!< in: if BTR_NO_UNDO_LOG_FLAG bit is
set, does nothing */
ulint op_type, /*!< in: TRX_UNDO_INSERT_OP or
TRX_UNDO_MODIFY_OP */
que_thr_t* thr, /*!< in: query thread */ que_thr_t* thr, /*!< in: query thread */
dict_index_t* index, /*!< in: clustered index */ dict_index_t* index, /*!< in: clustered index */
const dtuple_t* clust_entry, /*!< in: in the case of an insert, const dtuple_t* clust_entry, /*!< in: in the case of an insert,
...@@ -233,7 +230,7 @@ trx_undo_report_row_operation( ...@@ -233,7 +230,7 @@ trx_undo_report_row_operation(
inserted undo log record, inserted undo log record,
0 if BTR_NO_UNDO_LOG 0 if BTR_NO_UNDO_LOG
flag was specified */ flag was specified */
MY_ATTRIBUTE((nonnull(3,4,10), warn_unused_result)); MY_ATTRIBUTE((nonnull(1,2,8), warn_unused_result));
/******************************************************************//** /******************************************************************//**
Copies an undo record to heap. This function can be called if we know that Copies an undo record to heap. This function can be called if we know that
the undo log record exists. the undo log record exists.
...@@ -313,10 +310,6 @@ record */ ...@@ -313,10 +310,6 @@ record */
storage fields: used by purge to storage fields: used by purge to
free the external storage */ free the external storage */
/* Operation type flags used in trx_undo_report_row_operation */
#define TRX_UNDO_INSERT_OP 1
#define TRX_UNDO_MODIFY_OP 2
#ifndef UNIV_NONINL #ifndef UNIV_NONINL
#include "trx0rec.ic" #include "trx0rec.ic"
#endif #endif
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -1185,10 +1186,6 @@ UNIV_INTERN ...@@ -1185,10 +1186,6 @@ UNIV_INTERN
dberr_t dberr_t
trx_undo_report_row_operation( trx_undo_report_row_operation(
/*==========================*/ /*==========================*/
ulint flags, /*!< in: if BTR_NO_UNDO_LOG_FLAG bit is
set, does nothing */
ulint op_type, /*!< in: TRX_UNDO_INSERT_OP or
TRX_UNDO_MODIFY_OP */
que_thr_t* thr, /*!< in: query thread */ que_thr_t* thr, /*!< in: query thread */
dict_index_t* index, /*!< in: clustered index */ dict_index_t* index, /*!< in: clustered index */
const dtuple_t* clust_entry, /*!< in: in the case of an insert, const dtuple_t* clust_entry, /*!< in: in the case of an insert,
...@@ -1221,17 +1218,8 @@ trx_undo_report_row_operation( ...@@ -1221,17 +1218,8 @@ trx_undo_report_row_operation(
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
ut_a(dict_index_is_clust(index)); ut_a(dict_index_is_clust(index));
ut_ad(!rec || rec_offs_validate(rec, index, offsets)); ut_ad(!rec || rec_offs_validate(rec, index, offsets));
if (flags & BTR_NO_UNDO_LOG_FLAG) {
*roll_ptr = 0;
return(DB_SUCCESS);
}
ut_ad(thr); ut_ad(thr);
ut_ad((op_type != TRX_UNDO_INSERT_OP) ut_ad(!clust_entry || (!update && !rec));
|| (clust_entry && !update && !rec));
trx = thr_get_trx(thr); trx = thr_get_trx(thr);
...@@ -1252,8 +1240,7 @@ trx_undo_report_row_operation( ...@@ -1252,8 +1240,7 @@ trx_undo_report_row_operation(
/* If the undo log is not assigned yet, assign one */ /* If the undo log is not assigned yet, assign one */
switch (op_type) { if (clust_entry) {
case TRX_UNDO_INSERT_OP:
undo = trx->insert_undo; undo = trx->insert_undo;
if (undo == NULL) { if (undo == NULL) {
...@@ -1269,10 +1256,7 @@ trx_undo_report_row_operation( ...@@ -1269,10 +1256,7 @@ trx_undo_report_row_operation(
ut_ad(err == DB_SUCCESS); ut_ad(err == DB_SUCCESS);
} }
break; } else {
default:
ut_ad(op_type == TRX_UNDO_MODIFY_OP);
undo = trx->update_undo; undo = trx->update_undo;
if (undo == NULL) { if (undo == NULL) {
...@@ -1296,23 +1280,14 @@ trx_undo_report_row_operation( ...@@ -1296,23 +1280,14 @@ trx_undo_report_row_operation(
buf_block_dbg_add_level(undo_block, SYNC_TRX_UNDO_PAGE); buf_block_dbg_add_level(undo_block, SYNC_TRX_UNDO_PAGE);
do { do {
page_t* undo_page;
ulint offset;
undo_page = buf_block_get_frame(undo_block);
ut_ad(page_no == buf_block_get_page_no(undo_block)); ut_ad(page_no == buf_block_get_page_no(undo_block));
page_t* undo_page = buf_block_get_frame(undo_block);
switch (op_type) { ulint offset = clust_entry
case TRX_UNDO_INSERT_OP: ? trx_undo_page_report_insert(
offset = trx_undo_page_report_insert( undo_page, trx, index, clust_entry, &mtr)
undo_page, trx, index, clust_entry, &mtr); : trx_undo_page_report_modify(
break;
default:
ut_ad(op_type == TRX_UNDO_MODIFY_OP);
offset = trx_undo_page_report_modify(
undo_page, trx, index, rec, offsets, update, undo_page, trx, index, rec, offsets, update,
cmpl_info, &mtr); cmpl_info, &mtr);
}
if (UNIV_UNLIKELY(offset == 0)) { if (UNIV_UNLIKELY(offset == 0)) {
/* The record did not fit on the page. We erase the /* The record did not fit on the page. We erase the
...@@ -1363,7 +1338,7 @@ trx_undo_report_row_operation( ...@@ -1363,7 +1338,7 @@ trx_undo_report_row_operation(
mutex_exit(&trx->undo_mutex); mutex_exit(&trx->undo_mutex);
*roll_ptr = trx_undo_build_roll_ptr( *roll_ptr = trx_undo_build_roll_ptr(
op_type == TRX_UNDO_INSERT_OP, clust_entry != NULL,
rseg->id, page_no, offset); rseg->id, page_no, offset);
return(DB_SUCCESS); return(DB_SUCCESS);
} }
......
...@@ -1269,18 +1269,21 @@ btr_cur_ins_lock_and_undo( ...@@ -1269,18 +1269,21 @@ btr_cur_ins_lock_and_undo(
index, thr, mtr, inherit); index, thr, mtr, inherit);
if (err != DB_SUCCESS if (err != DB_SUCCESS
|| !(~flags | (BTR_NO_UNDO_LOG_FLAG | BTR_KEEP_SYS_FLAG))
|| !dict_index_is_clust(index) || dict_index_is_ibuf(index)) { || !dict_index_is_clust(index) || dict_index_is_ibuf(index)) {
return(err); return(err);
} }
err = trx_undo_report_row_operation(flags, TRX_UNDO_INSERT_OP, if (flags & BTR_NO_UNDO_LOG_FLAG) {
thr, index, entry, roll_ptr = 0;
NULL, 0, NULL, NULL, } else {
&roll_ptr); err = trx_undo_report_row_operation(thr, index, entry,
if (err != DB_SUCCESS) { NULL, 0, NULL, NULL,
&roll_ptr);
return(err); if (err != DB_SUCCESS) {
return(err);
}
} }
/* Now we can fill in the roll ptr field in entry */ /* Now we can fill in the roll ptr field in entry */
...@@ -1851,9 +1854,10 @@ btr_cur_upd_lock_and_undo( ...@@ -1851,9 +1854,10 @@ btr_cur_upd_lock_and_undo(
/* Append the info about the update in the undo log */ /* Append the info about the update in the undo log */
return(trx_undo_report_row_operation( return((flags & BTR_NO_UNDO_LOG_FLAG)
flags, TRX_UNDO_MODIFY_OP, thr, ? DB_SUCCESS
index, NULL, update, : trx_undo_report_row_operation(
thr, index, NULL, update,
cmpl_info, rec, offsets, roll_ptr)); cmpl_info, rec, offsets, roll_ptr));
} }
...@@ -3175,7 +3179,7 @@ btr_cur_del_mark_set_clust_rec( ...@@ -3175,7 +3179,7 @@ btr_cur_del_mark_set_clust_rec(
return(err); return(err);
} }
err = trx_undo_report_row_operation(0, TRX_UNDO_MODIFY_OP, thr, err = trx_undo_report_row_operation(thr,
index, NULL, NULL, 0, rec, offsets, index, NULL, NULL, 0, rec, offsets,
&roll_ptr); &roll_ptr);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -212,10 +213,6 @@ UNIV_INTERN ...@@ -212,10 +213,6 @@ UNIV_INTERN
dberr_t dberr_t
trx_undo_report_row_operation( trx_undo_report_row_operation(
/*==========================*/ /*==========================*/
ulint flags, /*!< in: if BTR_NO_UNDO_LOG_FLAG bit is
set, does nothing */
ulint op_type, /*!< in: TRX_UNDO_INSERT_OP or
TRX_UNDO_MODIFY_OP */
que_thr_t* thr, /*!< in: query thread */ que_thr_t* thr, /*!< in: query thread */
dict_index_t* index, /*!< in: clustered index */ dict_index_t* index, /*!< in: clustered index */
const dtuple_t* clust_entry, /*!< in: in the case of an insert, const dtuple_t* clust_entry, /*!< in: in the case of an insert,
...@@ -233,7 +230,7 @@ trx_undo_report_row_operation( ...@@ -233,7 +230,7 @@ trx_undo_report_row_operation(
inserted undo log record, inserted undo log record,
0 if BTR_NO_UNDO_LOG 0 if BTR_NO_UNDO_LOG
flag was specified */ flag was specified */
MY_ATTRIBUTE((nonnull(3,4,10), warn_unused_result)); MY_ATTRIBUTE((nonnull(1,2,8), warn_unused_result));
/******************************************************************//** /******************************************************************//**
Copies an undo record to heap. This function can be called if we know that Copies an undo record to heap. This function can be called if we know that
the undo log record exists. the undo log record exists.
...@@ -313,10 +310,6 @@ record */ ...@@ -313,10 +310,6 @@ record */
storage fields: used by purge to storage fields: used by purge to
free the external storage */ free the external storage */
/* Operation type flags used in trx_undo_report_row_operation */
#define TRX_UNDO_INSERT_OP 1
#define TRX_UNDO_MODIFY_OP 2
#ifndef UNIV_NONINL #ifndef UNIV_NONINL
#include "trx0rec.ic" #include "trx0rec.ic"
#endif #endif
......
...@@ -1185,10 +1185,6 @@ UNIV_INTERN ...@@ -1185,10 +1185,6 @@ UNIV_INTERN
dberr_t dberr_t
trx_undo_report_row_operation( trx_undo_report_row_operation(
/*==========================*/ /*==========================*/
ulint flags, /*!< in: if BTR_NO_UNDO_LOG_FLAG bit is
set, does nothing */
ulint op_type, /*!< in: TRX_UNDO_INSERT_OP or
TRX_UNDO_MODIFY_OP */
que_thr_t* thr, /*!< in: query thread */ que_thr_t* thr, /*!< in: query thread */
dict_index_t* index, /*!< in: clustered index */ dict_index_t* index, /*!< in: clustered index */
const dtuple_t* clust_entry, /*!< in: in the case of an insert, const dtuple_t* clust_entry, /*!< in: in the case of an insert,
...@@ -1222,16 +1218,8 @@ trx_undo_report_row_operation( ...@@ -1222,16 +1218,8 @@ trx_undo_report_row_operation(
ut_a(dict_index_is_clust(index)); ut_a(dict_index_is_clust(index));
ut_ad(!rec || rec_offs_validate(rec, index, offsets)); ut_ad(!rec || rec_offs_validate(rec, index, offsets));
if (flags & BTR_NO_UNDO_LOG_FLAG) {
*roll_ptr = 0;
return(DB_SUCCESS);
}
ut_ad(thr); ut_ad(thr);
ut_ad((op_type != TRX_UNDO_INSERT_OP) ut_ad(!clust_entry || (!update && !rec));
|| (clust_entry && !update && !rec));
trx = thr_get_trx(thr); trx = thr_get_trx(thr);
...@@ -1252,8 +1240,7 @@ trx_undo_report_row_operation( ...@@ -1252,8 +1240,7 @@ trx_undo_report_row_operation(
/* If the undo log is not assigned yet, assign one */ /* If the undo log is not assigned yet, assign one */
switch (op_type) { if (clust_entry) {
case TRX_UNDO_INSERT_OP:
undo = trx->insert_undo; undo = trx->insert_undo;
if (undo == NULL) { if (undo == NULL) {
...@@ -1269,10 +1256,7 @@ trx_undo_report_row_operation( ...@@ -1269,10 +1256,7 @@ trx_undo_report_row_operation(
ut_ad(err == DB_SUCCESS); ut_ad(err == DB_SUCCESS);
} }
break; } else {
default:
ut_ad(op_type == TRX_UNDO_MODIFY_OP);
undo = trx->update_undo; undo = trx->update_undo;
if (undo == NULL) { if (undo == NULL) {
...@@ -1296,23 +1280,15 @@ trx_undo_report_row_operation( ...@@ -1296,23 +1280,15 @@ trx_undo_report_row_operation(
buf_block_dbg_add_level(undo_block, SYNC_TRX_UNDO_PAGE); buf_block_dbg_add_level(undo_block, SYNC_TRX_UNDO_PAGE);
do { do {
page_t* undo_page;
ulint offset;
undo_page = buf_block_get_frame(undo_block);
ut_ad(page_no == buf_block_get_page_no(undo_block)); ut_ad(page_no == buf_block_get_page_no(undo_block));
switch (op_type) { page_t* undo_page = buf_block_get_frame(undo_block);
case TRX_UNDO_INSERT_OP: ulint offset = clust_entry
offset = trx_undo_page_report_insert( ? trx_undo_page_report_insert(
undo_page, trx, index, clust_entry, &mtr); undo_page, trx, index, clust_entry, &mtr)
break; : trx_undo_page_report_modify(
default:
ut_ad(op_type == TRX_UNDO_MODIFY_OP);
offset = trx_undo_page_report_modify(
undo_page, trx, index, rec, offsets, update, undo_page, trx, index, rec, offsets, update,
cmpl_info, &mtr); cmpl_info, &mtr);
}
if (UNIV_UNLIKELY(offset == 0)) { if (UNIV_UNLIKELY(offset == 0)) {
/* The record did not fit on the page. We erase the /* The record did not fit on the page. We erase the
...@@ -1363,7 +1339,7 @@ trx_undo_report_row_operation( ...@@ -1363,7 +1339,7 @@ trx_undo_report_row_operation(
mutex_exit(&trx->undo_mutex); mutex_exit(&trx->undo_mutex);
*roll_ptr = trx_undo_build_roll_ptr( *roll_ptr = trx_undo_build_roll_ptr(
op_type == TRX_UNDO_INSERT_OP, clust_entry != NULL,
rseg->id, page_no, offset); rseg->id, page_no, offset);
return(DB_SUCCESS); return(DB_SUCCESS);
} }
......
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