From 550a538d3287caaac4e2169b77f47712ed95f7fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= <marko.makela@mariadb.com>
Date: Mon, 10 Jun 2019 14:56:08 +0300
Subject: [PATCH 2/2] WIP: remove recv_data_t. Does not work!

FIXME: Parse records directly from log_sys.buf (needs new redo log format)
and store to a buffer. Allocate also recv_sys.pages from this same buffer!
---
 extra/mariabackup/xtrabackup.cc     |  7 ++-
 storage/innobase/include/log0recv.h | 15 +----
 storage/innobase/log/log0recv.cc    | 92 +----------------------------
 3 files changed, 11 insertions(+), 103 deletions(-)

diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc
index fb6c1f519a3..07e8444839c 100644
--- a/extra/mariabackup/xtrabackup.cc
+++ b/extra/mariabackup/xtrabackup.cc
@@ -2679,7 +2679,12 @@ static lsn_t xtrabackup_copy_log(lsn_t start_lsn, lsn_t end_lsn, bool last)
 		return(0);
 	}
 
-	recv_sys_justify_left_parsing_buf();
+	memmove(recv_sys.buf, recv_sys.buf + recv_sys.recovered_offset,
+		recv_sys.len - recv_sys.recovered_offset);
+
+	recv_sys.len -= recv_sys.recovered_offset;
+
+	recv_sys.recovered_offset = 0;
 
 	log_sys.log.scanned_lsn = scanned_lsn;
 
diff --git a/storage/innobase/include/log0recv.h b/storage/innobase/include/log0recv.h
index 71d75104d22..9fff28eaad9 100644
--- a/storage/innobase/include/log0recv.h
+++ b/storage/innobase/include/log0recv.h
@@ -113,9 +113,6 @@ to wait merging to file pages.
 or corruption was noticed */
 bool recv_parse_log_recs(lsn_t checkpoint_lsn, store_t store, bool apply);
 
-/** Moves the parsing buffer data left to the buffer start. */
-void recv_sys_justify_left_parsing_buf();
-
 /** Report optimized DDL operation (without redo log),
 corresponding to MLOG_INDEX_LOAD.
 @param[in]	space_id	tablespace identifier
@@ -133,22 +130,14 @@ extern void (*log_file_op)(ulint space_id, const byte* flags,
 			   const byte* name, ulint len,
 			   const byte* new_name, ulint new_len);
 
-/** Block of log record data */
-struct recv_data_t{
-	recv_data_t*	next;	/*!< pointer to the next block or NULL */
-				/*!< the log record data is stored physically
-				immediately after this struct, max amount
-				RECV_DATA_BLOCK_SIZE bytes of it */
-};
-
 /** Stored log record struct */
 struct recv_t{
 	/** next record */
 	recv_t*		next;
 	mlog_id_t	type;	/*!< log record type */
 	uint32_t	len;	/*!< log record body length in bytes */
-	recv_data_t*	data;	/*!< chain of blocks containing the log record
-				body */
+	/** log record body */
+	const byte*	data;
 	lsn_t		start_lsn;/*!< start lsn of the log segment written by
 				the mtr which generated this log record: NOTE
 				that this is not necessarily the start lsn of
diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc
index 08a28013dc4..aad3c440ebd 100644
--- a/storage/innobase/log/log0recv.cc
+++ b/storage/innobase/log/log0recv.cc
@@ -56,10 +56,6 @@ Created 9/20/1997 Heikki Tuuri
 #include "srv0srv.h"
 #include "srv0start.h"
 
-/** Log records are stored in the hash table in chunks at most of this size;
-this must be less than srv_page_size as it is stored in the buffer pool */
-#define RECV_DATA_BLOCK_SIZE	(MEM_MAX_ALLOC_IN_BUF - sizeof(recv_data_t))
-
 /** Read-ahead area in applying log records to file pages */
 #define RECV_READ_AHEAD_AREA	32U
 
@@ -1637,58 +1633,8 @@ inline void recv_sys_t::add(mlog_id_t type, const page_id_t page_id,
 	}
 
 	*prev = new(mem_heap_alloc(heap, sizeof(recv_t)))
-		recv_t{NULL, type, uint32_t(rec_end - body), NULL,
+		recv_t{NULL, type, uint32_t(rec_end - body), body,
 		       lsn, end_lsn};
-
-	recv_data_t** prev_field = &(*prev)->data;
-
-	/* Store the log record body in chunks of less than srv_page_size:
-	heap grows into the buffer pool, and bigger chunks could not
-	be allocated */
-
-	while (rec_end > body) {
-		ulint rec_len = ulint(rec_end - body);
-
-		if (rec_len > RECV_DATA_BLOCK_SIZE) {
-			rec_len = RECV_DATA_BLOCK_SIZE;
-		}
-
-		recv_data_t* recv_data = static_cast<recv_data_t*>(
-			mem_heap_alloc(heap, sizeof(recv_data_t) + rec_len));
-
-		*prev_field = recv_data;
-
-		memcpy(recv_data + 1, body, rec_len);
-
-		prev_field = &recv_data->next;
-
-		body += rec_len;
-	}
-
-	*prev_field = NULL;
-}
-
-/*********************************************************************//**
-Copies the log record body from recv to buf. */
-static
-void
-recv_data_copy_to_buf(
-/*==================*/
-	byte*	buf,	/*!< in: buffer of length at least recv->len */
-	const recv_t& recv)	/*!< in: log record */
-{
-	const recv_data_t* recv_data = recv.data;
-	ulint len = recv.len;
-
-	do {
-		const ulint part_len = std::min(len, RECV_DATA_BLOCK_SIZE);
-		memcpy(buf, &reinterpret_cast<const byte*>(recv_data)[
-			       sizeof(recv_data_t)],
-		       part_len);
-		recv_data = recv_data->next;
-		buf += part_len;
-		len -= part_len;
-	} while (len);
 }
 
 /** Apply the hashed log records to the page, if the page lsn is less than the
@@ -1780,21 +1726,10 @@ static void recv_recover_page(buf_block_t* block, mtr_t& mtr,
 				 << " len " << recv->len
 				 << " page " << block->page.id);
 
-			byte* buf;
-
-			if (recv->len > RECV_DATA_BLOCK_SIZE) {
-				/* We have to copy the record body to
-				a separate buffer */
-				buf = static_cast<byte*>
-					(ut_malloc_nokey(recv->len));
-				recv_data_copy_to_buf(buf, *recv);
-			} else {
-				buf = reinterpret_cast<byte*>(recv->data)
-					+ sizeof *recv->data;
-			}
+			byte* data = const_cast<byte*>(recv->data);
 
 			recv_parse_or_apply_log_rec_body(
-				recv->type, buf, buf + recv->len,
+				recv->type, data, data + recv->len,
 				block->page.id.space(),
 				block->page.id.page_no(), true, block, &mtr);
 
@@ -1808,10 +1743,6 @@ static void recv_recover_page(buf_block_t* block, mtr_t& mtr,
 				mach_write_to_8(FIL_PAGE_LSN + page_zip->data,
 						end_lsn);
 			}
-
-			if (recv->len > RECV_DATA_BLOCK_SIZE) {
-				ut_free(buf);
-			}
 		}
 	}
 
@@ -2799,17 +2730,6 @@ bool recv_sys_add_to_parsing_buf(const byte* log_block, lsn_t scanned_lsn)
 	return(true);
 }
 
-/** Moves the parsing buffer data left to the buffer start. */
-void recv_sys_justify_left_parsing_buf()
-{
-	ut_memmove(recv_sys.buf, recv_sys.buf + recv_sys.recovered_offset,
-		   recv_sys.len - recv_sys.recovered_offset);
-
-	recv_sys.len -= recv_sys.recovered_offset;
-
-	recv_sys.recovered_offset = 0;
-}
-
 /** Scan redo log from a buffer and stores new log data to the parsing buffer.
 Parse and hash the log records if new data found.
 Apply log records automatically when the hash table becomes full.
@@ -2994,12 +2914,6 @@ recv_scan_log_recs(
 			recv_sys.last_stored_lsn = recv_sys.recovered_lsn;
 			*store_to_hash = STORE_NO;
 		}
-
-		if (recv_sys.recovered_offset > recv_parsing_buf_size / 4) {
-			/* Move parsing buffer data to the buffer start */
-
-			recv_sys_justify_left_parsing_buf();
-		}
 	}
 
 func_exit:
-- 
2.20.1

