Skip to content

Commit 21bec97

Browse files
committed
MDEV-32050: Clean up online ALTER
UndorecApplier::assign_rec(): Remove. We will pass the undo record to UndorecApplier::apply_undo_rec(). There is no need to copy the undo record, because nothing else can write to the undo log pages that belong to an active or incomplete transaction. trx_t::apply_log(): Buffer-fix the undo page across mini-transaction boundary in order to avoid repeated page lookups. Reviewed by: Vladislav Lesin
1 parent 9bb5d9f commit 21bec97

File tree

6 files changed

+27
-40
lines changed

6 files changed

+27
-40
lines changed

storage/innobase/include/trx0undo.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ class UndorecApplier
308308
{
309309
/** Undo log block page id */
310310
page_id_t page_id;
311-
/** Undo log record pointer */
311+
/** Pointer to within undo log record */
312312
const trx_undo_rec_t *undo_rec;
313313
/** Undo log record type */
314314
byte type;
315315
/** compiler information */
316316
byte cmpl_info;
317-
/** Offset of the undo log record within the block */
317+
/** page_offset(undo_rec) of the start of undo_rec */
318318
uint16_t offset;
319319
/** Transaction id of the undo log */
320320
const trx_id_t trx_id;
@@ -338,15 +338,10 @@ class UndorecApplier
338338
page_id= next_page_id;
339339
}
340340

341-
/** Assign the undo log record and offset */
342-
inline void assign_rec(const buf_block_t &block, uint16_t offset);
343-
344-
uint16_t get_offset() const { return offset; }
345-
346341
page_id_t get_page_id() const { return page_id; }
347342

348343
/** Handle the DML undo log and apply it on online indexes */
349-
inline void apply_undo_rec();
344+
inline void apply_undo_rec(const trx_undo_rec_t *rec);
350345

351346
~UndorecApplier()
352347
{
@@ -368,12 +363,7 @@ class UndorecApplier
368363
/** Check whether the given roll pointer is generated by
369364
the current undo log record information stored.
370365
@return true if roll pointer matches with current undo log info */
371-
bool is_same(roll_ptr_t roll_ptr) const
372-
{
373-
uint16_t offset= static_cast<uint16_t>(roll_ptr);
374-
uint32_t page_no= static_cast<uint32_t>(roll_ptr >> 16);
375-
return page_no == page_id.page_no() && offset == this->offset;
376-
}
366+
inline bool is_same(roll_ptr_t roll_ptr) const;
377367

378368
/** Clear the undo log record information */
379369
void clear_undo_rec()

storage/innobase/row/row0log.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,6 +3825,12 @@ dberr_t dict_table_t::clear(que_thr_t *thr)
38253825
return err;
38263826
}
38273827

3828+
inline bool UndorecApplier::is_same(roll_ptr_t roll_ptr) const
3829+
{
3830+
return uint16_t(roll_ptr) == offset &&
3831+
uint32_t(roll_ptr >> 16) == page_id.page_no();
3832+
}
3833+
38283834
const rec_t *
38293835
UndorecApplier::get_old_rec(const dtuple_t &tuple, dict_index_t *index,
38303836
const rec_t **clust_rec, rec_offs **offsets)
@@ -3950,8 +3956,7 @@ void UndorecApplier::log_insert(const dtuple_t &tuple,
39503956
/* Update the row with virtual column values present
39513957
in the undo log or update vector */
39523958
if (type == TRX_UNDO_UPD_DEL_REC)
3953-
row_upd_replace_vcol(row, table, update, false,
3954-
nullptr,
3959+
row_upd_replace_vcol(row, table, update, false, nullptr,
39553960
(cmpl_info & UPD_NODE_NO_ORD_CHANGE)
39563961
? nullptr : undo_rec);
39573962
else
@@ -4073,7 +4078,7 @@ void UndorecApplier::log_update(const dtuple_t &tuple,
40734078
if (table->n_v_cols)
40744079
row_upd_replace_vcol(row, table, update, false, nullptr,
40754080
(cmpl_info & UPD_NODE_NO_ORD_CHANGE)
4076-
? nullptr : this->undo_rec);
4081+
? nullptr : undo_rec);
40774082

40784083
bool success= true;
40794084
dict_index_t *index= dict_table_get_next_index(clust_index);

storage/innobase/row/row0umod.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ static bool row_undo_mod_parse_undo_rec(undo_node_t* node, bool dict_locked)
11921192
row_upd_replace_vcol(node->row, node->table,
11931193
node->update, false, node->undo_row,
11941194
(node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)
1195-
? NULL : ptr);
1195+
? nullptr : ptr);
11961196
}
11971197

11981198
return true;

storage/innobase/row/row0upd.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,8 @@ row_upd_replace_vcol(
10601060
bool is_undo_log = true;
10611061

10621062
/* We will read those unchanged (but indexed) virtual columns in */
1063-
if (ptr != NULL) {
1064-
const byte* end_ptr;
1065-
1066-
end_ptr = ptr + mach_read_from_2(ptr);
1063+
if (ptr) {
1064+
const byte* const end_ptr = ptr + mach_read_from_2(ptr);
10671065
ptr += 2;
10681066

10691067
while (ptr != end_ptr) {
@@ -1189,7 +1187,7 @@ row_upd_replace(
11891187
*ext = NULL;
11901188
}
11911189

1192-
row_upd_replace_vcol(row, table, update, true, NULL, NULL);
1190+
row_upd_replace_vcol(row, table, update, true, nullptr, nullptr);
11931191
}
11941192

11951193
/***********************************************************//**

storage/innobase/trx/trx0rec.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ trx_undo_prev_version_build(
23352335
update vector to dtuple vrow */
23362336
if (v_status & TRX_UNDO_GET_OLD_V_VALUE) {
23372337
row_upd_replace_vcol((dtuple_t*)*vrow, index->table, update,
2338-
false, NULL, NULL);
2338+
false, nullptr, nullptr);
23392339
}
23402340

23412341
#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG

storage/innobase/trx/trx0undo.cc

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,13 @@ trx_undo_get_first_rec(const fil_space_t &space, uint32_t page_no,
299299
mtr);
300300
}
301301

302-
inline void UndorecApplier::assign_rec(const buf_block_t &block,
303-
uint16_t offset)
304-
{
305-
ut_ad(block.page.lock.have_s());
306-
this->offset= offset;
307-
this->undo_rec= trx_undo_rec_copy(block.page.frame + offset, heap);
308-
}
309-
310-
inline void UndorecApplier::apply_undo_rec()
302+
inline void UndorecApplier::apply_undo_rec(const trx_undo_rec_t *rec)
311303
{
304+
undo_rec= rec;
312305
if (!undo_rec)
313306
return;
307+
offset= page_offset(undo_rec);
308+
314309
bool updated_extern= false;
315310
undo_no_t undo_no= 0;
316311
table_id_t table_id= 0;
@@ -382,14 +377,14 @@ ATTRIBUTE_COLD void trx_t::apply_log()
382377
undo->hdr_offset);
383378
while (rec)
384379
{
385-
log_applier.assign_rec(*block, page_offset(rec));
380+
block->page.fix();
386381
mtr.commit();
387-
log_applier.apply_undo_rec();
382+
/* Since we are the only thread who could write to this undo page,
383+
it is safe to dereference rec while only holding a buffer-fix. */
384+
log_applier.apply_undo_rec(rec);
388385
mtr.start();
389-
block= buf_page_get(log_applier.get_page_id(), 0, RW_S_LATCH, &mtr);
390-
if (UNIV_UNLIKELY(!block))
391-
goto func_exit;
392-
rec= trx_undo_page_get_next_rec(block, log_applier.get_offset(),
386+
mtr.page_lock(block, RW_S_LATCH);
387+
rec= trx_undo_page_get_next_rec(block, page_offset(rec),
393388
page_id.page_no(), undo->hdr_offset);
394389
}
395390

@@ -406,7 +401,6 @@ ATTRIBUTE_COLD void trx_t::apply_log()
406401
break;
407402
log_applier.assign_next(next_page_id);
408403
}
409-
func_exit:
410404
mtr.commit();
411405
apply_online_log= false;
412406
}

0 commit comments

Comments
 (0)