Commit af5947f4 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-21174: Replace mlog_write_string() with mtr_t::memcpy()

mtr_t::memcpy(): Replaces mlog_write_string(), mlog_log_string().
The buf_block_t is passed a parameter, so that
mlog_write_initial_log_record_low() can be used instead of
mlog_write_initial_log_record_fast().

fil_space_crypt_t::write_page0(): Remove the fil_space_t* parameter.
parent 87839258
......@@ -1627,15 +1627,11 @@ btr_page_reorganize_low(
mach_read_from_2(instant));
if (!index->table->instant) {
} else if (page_is_comp(block->frame)) {
mlog_log_string(PAGE_NEW_INFIMUM + block->frame, 8,
mtr);
mlog_log_string(PAGE_NEW_SUPREMUM + block->frame, 8,
mtr);
mtr->memcpy(*block, PAGE_NEW_INFIMUM, 8);
mtr->memcpy(*block, PAGE_NEW_SUPREMUM, 8);
} else {
mlog_log_string(PAGE_OLD_INFIMUM + block->frame, 8,
mtr);
mlog_log_string(PAGE_OLD_SUPREMUM + block->frame, 8,
mtr);
mtr->memcpy(*block, PAGE_OLD_INFIMUM, 8);
mtr->memcpy(*block, PAGE_OLD_SUPREMUM, 8);
}
}
......
......@@ -7723,7 +7723,7 @@ btr_store_big_rec_extern_fields(
be made simpler. Before InnoDB Plugin
1.0.4, the initialization of
FIL_PAGE_TYPE was logged as part of
the mlog_log_string() below. */
the mtr_t::memcpy() below. */
mtr.write<2>(*block,
block->frame + FIL_PAGE_TYPE,
......@@ -7770,12 +7770,11 @@ btr_store_big_rec_extern_fields(
mtr.write<4>(*block, block->frame
+ FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION + 4,
rec_page_no);
mlog_log_string(block->frame
+ FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION,
page_zip_get_size(page_zip)
- FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION
- c_stream.avail_out,
&mtr);
mtr.memcpy(*block,
FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION,
page_zip_get_size(page_zip)
- FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION
- c_stream.avail_out);
/* Zero out the unused part of the page. */
if (c_stream.avail_out) {
mtr.memset(block,
......@@ -7852,14 +7851,12 @@ btr_store_big_rec_extern_fields(
store_len = extern_len;
}
mlog_write_string(FIL_PAGE_DATA
+ BTR_BLOB_HDR_SIZE
+ block->frame,
(const byte*)
big_rec_vec->fields[i].data
+ big_rec_vec->fields[i].len
- extern_len,
store_len, &mtr);
mtr.memcpy(block,
FIL_PAGE_DATA + BTR_BLOB_HDR_SIZE,
(const byte*)
big_rec_vec->fields[i].data
+ big_rec_vec->fields[i].len
- extern_len, store_len);
mtr.write<4>(*block, BTR_BLOB_HDR_PART_LEN
+ FIL_PAGE_DATA + block->frame,
store_len);
......
......@@ -408,25 +408,17 @@ fil_space_crypt_t::fill_page0(
encryption);
}
/******************************************************************
Write crypt data to a page (0)
@param[in] space tablespace
@param[in,out] page0 first page of the tablespace
/** Write encryption metadata to the first page.
@param[in,out] block first page of the tablespace
@param[in,out] mtr mini-transaction */
UNIV_INTERN
void
fil_space_crypt_t::write_page0(
const fil_space_t* space,
byte* page,
mtr_t* mtr)
void fil_space_crypt_t::write_page0(buf_block_t* block, mtr_t* mtr)
{
ut_ad(this == space->crypt_data);
const ulint offset = FSP_HEADER_OFFSET
+ fsp_header_get_encryption_offset(space->zip_size());
byte* b = page + offset;
+ fsp_header_get_encryption_offset(block->zip_size());
byte* b = block->frame + offset;
if (memcmp(b, CRYPT_MAGIC, MAGIC_SZ)) {
mlog_write_string(b, CRYPT_MAGIC, MAGIC_SZ, mtr);
mtr->memcpy(block, offset, CRYPT_MAGIC, MAGIC_SZ);
}
b += MAGIC_SZ;
......@@ -443,7 +435,7 @@ fil_space_crypt_t::write_page0(
b += 4;
*b++ = byte(encryption);
ut_ad(b - start == 11 + MY_AES_BLOCK_SIZE);
mlog_log_string(start, b - start, mtr);
mtr->memcpy(*block, offset + MAGIC_SZ, b - start);
}
/******************************************************************
......@@ -1255,9 +1247,8 @@ static bool fil_crypt_start_encrypting_space(fil_space_t* space)
/* 3 - write crypt data to page 0 */
byte* frame = buf_block_get_frame(block);
crypt_data->type = CRYPT_SCHEME_1;
crypt_data->write_page0(space, frame, &mtr);
crypt_data->write_page0(block, &mtr);
mtr.commit();
......@@ -2243,7 +2234,7 @@ fil_crypt_flush_space(
RW_X_LATCH, NULL, BUF_GET,
__FILE__, __LINE__, &mtr, &err)) {
mtr.set_named_space(space);
crypt_data->write_page0(space, block->frame, &mtr);
crypt_data->write_page0(block, &mtr);
}
mtr.commit();
......
......@@ -608,7 +608,7 @@ void fsp_header_init(fil_space_t* space, ulint size, mtr_t* mtr)
if (space->crypt_data &&
(space->crypt_data->should_encrypt() ||
space->crypt_data->not_encrypted())) {
space->crypt_data->write_page0(space, block->frame, mtr);
space->crypt_data->write_page0(block, mtr);
}
}
......
......@@ -183,11 +183,10 @@ struct fil_space_crypt_t : st_encryption_scheme
@param[in,out] page first page of the tablespace */
void fill_page0(ulint flags, byte* page);
/** Write crypt data to a page (0)
@param[in] space tablespace
@param[in,out] page0 first page of the tablespace
/** Write encryption metadata to the first page.
@param[in,out] block first page of the tablespace
@param[in,out] mtr mini-transaction */
void write_page0(const fil_space_t* space, byte* page0, mtr_t* mtr);
void write_page0(buf_block_t* block, mtr_t* mtr);
uint min_key_version; // min key version for this space
fil_encryption_t encryption; // Encryption setup
......
......@@ -33,26 +33,6 @@ Created 12/7/1995 Heikki Tuuri
// Forward declaration
struct dict_index_t;
/********************************************************//**
Writes a string to a file page buffered in the buffer pool. Writes the
corresponding log record to the mini-transaction log. */
void
mlog_write_string(
/*==============*/
byte* ptr, /*!< in: pointer where to write */
const byte* str, /*!< in: string to write */
ulint len, /*!< in: string length */
mtr_t* mtr); /*!< in: mini-transaction handle */
/********************************************************//**
Logs a write of a string to a file page buffered in the buffer pool.
Writes the corresponding log record to the mini-transaction log. */
void
mlog_log_string(
/*============*/
byte* ptr, /*!< in: pointer written to */
ulint len, /*!< in: string length */
mtr_t* mtr); /*!< in: mini-transaction handle */
/********************************************************//**
Catenates 1 - 4 bytes to the mtr log. The value is not compressed. */
UNIV_INLINE
......@@ -157,6 +137,18 @@ inline void mtr_t::write(const buf_block_t &block, byte *ptr, V val)
static_cast<uint32_t>(val));
}
/** Write a byte string to a page.
@param[in,out] b buffer page
@param[in] ofs byte offset from b->frame
@param[in] str the data to write
@param[in] len length of the data to write */
inline
void mtr_t::memcpy(buf_block_t *b, ulint offset, const void *str, ulint len)
{
::memcpy(b->frame + offset, str, len);
memcpy(*b, offset, len);
}
/** Writes a log record about an operation.
@param[in] type redo log record type
@param[in] space_id tablespace identifier
......@@ -213,7 +205,7 @@ mlog_parse_nbytes(
or NULL */
void* page_zip);/*!< in/out: compressed page, or NULL */
/********************************************************//**
Parses a log record written by mlog_write_string.
Parses a log record written by mtr_t::memcpy().
@return parsed record end, NULL if not a complete record */
const byte*
mlog_parse_string(
......
......@@ -447,6 +447,20 @@ struct mtr_t {
inline void write(const buf_block_t &block, byte *ptr, V val)
MY_ATTRIBUTE((nonnull));
/** Log a write of a byte string to a page.
@param[in] b buffer page
@param[in] ofs byte offset from b->frame
@param[in] str the data to write
@param[in] len length of the data to write */
void memcpy(const buf_block_t &b, ulint ofs, ulint len);
/** Write a byte string to a page.
@param[in,out] b buffer page
@param[in] ofs byte offset from b->frame
@param[in] str the data to write
@param[in] len length of the data to write */
inline void memcpy(buf_block_t *b, ulint offset, const void *str, ulint len);
/** Initialize a string of bytes.
@param[in,out] b buffer page
@param[in] ofs byte offset from b->frame
......
......@@ -298,63 +298,38 @@ void mtr_t::log_write(const buf_block_t &block, byte *ptr, mlog_id_t l,
mlog_close(this, log_ptr);
}
/********************************************************//**
Writes a string to a file page buffered in the buffer pool. Writes the
corresponding log record to the mini-transaction log. */
void
mlog_write_string(
/*==============*/
byte* ptr, /*!< in: pointer where to write */
const byte* str, /*!< in: string to write */
ulint len, /*!< in: string length */
mtr_t* mtr) /*!< in: mini-transaction handle */
{
ut_ad(ptr && mtr);
ut_a(len < srv_page_size);
memcpy(ptr, str, len);
mlog_log_string(ptr, len, mtr);
}
/********************************************************//**
Logs a write of a string to a file page buffered in the buffer pool.
Writes the corresponding log record to the mini-transaction log. */
void
mlog_log_string(
/*============*/
byte* ptr, /*!< in: pointer written to */
ulint len, /*!< in: string length */
mtr_t* mtr) /*!< in: mini-transaction handle */
/** Log a write of a byte string to a page.
@param[in] b buffer page
@param[in] ofs byte offset from b->frame
@param[in] str the data to write
@param[in] len length of the data to write */
void mtr_t::memcpy(const buf_block_t &b, ulint ofs, ulint len)
{
byte* log_ptr;
ut_ad(ptr && mtr);
ut_ad(len <= srv_page_size);
log_ptr = mlog_open(mtr, 30);
/* If no logging is requested, we may return now */
if (log_ptr == NULL) {
return;
}
log_ptr = mlog_write_initial_log_record_fast(ptr, MLOG_WRITE_STRING,
log_ptr, mtr);
mach_write_to_2(log_ptr, page_offset(ptr));
log_ptr += 2;
mach_write_to_2(log_ptr, len);
log_ptr += 2;
ut_ad(len);
ut_ad(ofs <= ulint(srv_page_size));
ut_ad(ofs + len <= ulint(srv_page_size));
ut_ad(ofs + len < PAGE_DATA || !b.page.zip.data ||
mach_read_from_2(b.frame + FIL_PAGE_TYPE) <= FIL_PAGE_TYPE_ZBLOB2);
mlog_close(mtr, log_ptr);
set_modified();
if (get_log_mode() != MTR_LOG_ALL)
{
ut_ad(get_log_mode() == MTR_LOG_NONE ||
get_log_mode() == MTR_LOG_NO_REDO);
return;
}
mlog_catenate_string(mtr, ptr, len);
byte *l= get_log()->open(11 + 2 + 2);
l= mlog_write_initial_log_record_low(MLOG_WRITE_STRING, b.page.id.space(),
b.page.id.page_no(), l, this);
mach_write_to_2(l, ofs);
mach_write_to_2(l + 2, len);
mlog_close(this, l + 4);
mlog_catenate_string(this, b.frame + ofs, len);
}
/********************************************************//**
Parses a log record written by mlog_write_string.
Parses a log record written by mtr_t::memcpy().
@return parsed record end, NULL if not a complete record */
const byte*
mlog_parse_string(
......
......@@ -838,8 +838,15 @@ static void row_purge_reset_trx_id(purge_node_t* node, mtr_t* mtr)
byte* ptr = rec_get_nth_field(
rec, offsets, trx_id_pos, &len);
ut_ad(len == DATA_TRX_ID_LEN);
mlog_write_string(ptr, reset_trx_id,
sizeof reset_trx_id, mtr);
buf_block_t* block = btr_pcur_get_block(
&node->pcur);
uint16_t offs = page_offset(ptr);
mtr->memset(block, offs, DATA_TRX_ID_LEN, 0);
offs += DATA_TRX_ID_LEN;
mtr->write<1,mtr_t::OPT>(*block, block->frame
+ offs, 0x80U);
mtr->memset(block, offs + 1,
DATA_ROLL_PTR_LEN - 1, 0);
}
}
}
......
......@@ -226,8 +226,10 @@ row_undo_ins_remove_clust_rec(
static const byte str[8 + 8] = "supremuminfimum";
if (memcmp(infimum, str + 8, 8)
|| memcmp(supremum, str, 8)) {
mlog_write_string(infimum, str + 8, 8, &mtr);
mlog_write_string(supremum, str, 8, &mtr);
mtr.memcpy(root, page_offset(infimum),
str + 8, 8);
mtr.memcpy(root, page_offset(supremum),
str, 8);
}
}
}
......
......@@ -156,26 +156,27 @@ row_undo_mod_clust_low(
&& node->ref == &trx_undo_metadata
&& btr_cur_get_index(btr_cur)->table->instant
&& node->update->info_bits == REC_INFO_METADATA_ADD) {
if (page_t* root = btr_root_get(
btr_cur_get_index(btr_cur), mtr)) {
byte* infimum;
byte *supremum;
if (page_is_comp(root)) {
infimum = PAGE_NEW_INFIMUM + root;
supremum = PAGE_NEW_SUPREMUM + root;
if (buf_block_t* root = btr_root_block_get(
btr_cur_get_index(btr_cur), RW_SX_LATCH,
mtr)) {
uint16_t infimum, supremum;
if (page_is_comp(root->frame)) {
infimum = PAGE_NEW_INFIMUM;
supremum = PAGE_NEW_SUPREMUM;
} else {
infimum = PAGE_OLD_INFIMUM + root;
supremum = PAGE_OLD_SUPREMUM + root;
infimum = PAGE_OLD_INFIMUM;
supremum = PAGE_OLD_SUPREMUM;
}
ut_ad(!memcmp(infimum, INFIMUM, 8)
== !memcmp(supremum, SUPREMUM, 8));
ut_ad(!memcmp(root->frame + infimum,
INFIMUM, 8)
== !memcmp(root->frame + supremum,
SUPREMUM, 8));
if (memcmp(infimum, INFIMUM, 8)) {
mlog_write_string(infimum, INFIMUM,
8, mtr);
mlog_write_string(supremum, SUPREMUM,
8, mtr);
if (memcmp(root->frame + infimum, INFIMUM, 8)) {
mtr->memcpy(root, infimum, INFIMUM, 8);
mtr->memcpy(root, supremum, SUPREMUM,
8);
}
}
}
......@@ -457,7 +458,7 @@ row_undo_mod_clust(
if (trx_id_offset) {
} else if (rec_is_metadata(rec, *index)) {
ut_ad(!buf_block_get_page_zip(btr_pcur_get_block(
&node->pcur)));
pcur)));
for (unsigned i = index->first_user_field(); i--; ) {
trx_id_offset += index->fields[i].fixed_len;
}
......@@ -479,15 +480,21 @@ row_undo_mod_clust(
|| rec_is_alter_metadata(rec, *index));
index->set_modified(mtr);
if (page_zip_des_t* page_zip = buf_block_get_page_zip(
btr_pcur_get_block(&node->pcur))) {
btr_pcur_get_block(pcur))) {
page_zip_write_trx_id_and_roll_ptr(
page_zip, rec, offsets, trx_id_pos,
0, 1ULL << ROLL_PTR_INSERT_FLAG_POS,
&mtr);
} else {
mlog_write_string(rec + trx_id_offset,
reset_trx_id,
sizeof reset_trx_id, &mtr);
buf_block_t* block = btr_pcur_get_block(pcur);
uint16_t offs = page_offset(rec
+ trx_id_offset);
mtr.memset(block, offs, DATA_TRX_ID_LEN, 0);
offs += DATA_TRX_ID_LEN;
mtr.write<1,mtr_t::OPT>(*block, block->frame
+ offs, 0x80U);
mtr.memset(block, offs + 1,
DATA_ROLL_PTR_LEN - 1, 0);
}
}
} else {
......
......@@ -71,10 +71,8 @@ trx_rseg_write_wsrep_checkpoint(
const ulint xid_length = static_cast<ulint>(xid->gtrid_length
+ xid->bqual_length);
mlog_write_string(TRX_RSEG + TRX_RSEG_WSREP_XID_DATA
+ rseg_header->frame,
reinterpret_cast<const byte*>(xid->data),
xid_length, mtr);
mtr->memcpy(rseg_header, TRX_RSEG + TRX_RSEG_WSREP_XID_DATA,
xid->data, xid_length);
if (UNIV_LIKELY(xid_length < XIDDATASIZE)) {
mtr->memset(rseg_header,
TRX_RSEG + TRX_RSEG_WSREP_XID_DATA + xid_length,
......@@ -787,11 +785,10 @@ void trx_rseg_update_binlog_offset(buf_block_t *rseg_header, const trx_t *trx,
TRX_RSEG + TRX_RSEG_BINLOG_OFFSET
+ rseg_header->frame,
trx->mysql_log_offset);
byte* p = TRX_RSEG + TRX_RSEG_BINLOG_NAME + rseg_header->frame;
const byte* binlog_name = reinterpret_cast<const byte*>
(trx->mysql_log_file_name);
if (memcmp(binlog_name, p, len)) {
mlog_write_string(p, binlog_name, len, mtr);
if (memcmp(trx->mysql_log_file_name, TRX_RSEG + TRX_RSEG_BINLOG_NAME
+ rseg_header->frame, len)) {
mtr->memcpy(rseg_header, TRX_RSEG + TRX_RSEG_BINLOG_NAME,
trx->mysql_log_file_name, len);
}
}
......@@ -597,9 +597,7 @@ static void trx_undo_write_xid(buf_block_t *block, uint16_t offset,
static_cast<uint32_t>(xid.bqual_length));
const ulint xid_length= static_cast<ulint>(xid.gtrid_length
+ xid.bqual_length);
mlog_write_string(log_hdr + TRX_UNDO_XA_XID,
reinterpret_cast<const byte*>(xid.data),
xid_length, mtr);
mtr->memcpy(block, offset + TRX_UNDO_XA_XID, xid.data, xid_length);
if (UNIV_LIKELY(xid_length < XIDDATASIZE))
mtr->memset(block, offset + TRX_UNDO_XA_XID + xid_length,
XIDDATASIZE - xid_length, 0);
......
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