summaryrefslogtreecommitdiff
path: root/storage/innobase/buf/buf0dblwr.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2014-12-22 16:53:17 +0200
committerSergei Golubchik <serg@mariadb.org>2015-02-10 10:21:17 +0100
commitd7d589dc01f6d70d1518b74d46fd3b75e76267f5 (patch)
treef9df59951453660f0038ed78cf5ceadc852bf74c /storage/innobase/buf/buf0dblwr.cc
parent3a3ec744b5a31318a00821dc0ed6da8af49fda25 (diff)
downloadmariadb-git-d7d589dc01f6d70d1518b74d46fd3b75e76267f5.tar.gz
Push for testing of encryption
Diffstat (limited to 'storage/innobase/buf/buf0dblwr.cc')
-rw-r--r--storage/innobase/buf/buf0dblwr.cc92
1 files changed, 65 insertions, 27 deletions
diff --git a/storage/innobase/buf/buf0dblwr.cc b/storage/innobase/buf/buf0dblwr.cc
index c903f5fbffa..17e8143943c 100644
--- a/storage/innobase/buf/buf0dblwr.cc
+++ b/storage/innobase/buf/buf0dblwr.cc
@@ -50,6 +50,8 @@ UNIV_INTERN buf_dblwr_t* buf_dblwr = NULL;
/** Set to TRUE when the doublewrite buffer is being created */
UNIV_INTERN ibool buf_dblwr_being_created = FALSE;
+#define TRX_SYS_DOUBLEWRITE_BLOCKS 2
+
/****************************************************************//**
Determines if a page number is located inside the doublewrite buffer.
@return TRUE if the location is inside the two blocks of the
@@ -136,7 +138,7 @@ buf_dblwr_init(
/* There are two blocks of same size in the doublewrite
buffer. */
- buf_size = 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
+ buf_size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
/* There must be atleast one buffer for single page writes
and one buffer for batch writes. */
@@ -216,7 +218,7 @@ start_again:
"Doublewrite buffer not found: creating new");
if (buf_pool_get_curr_size()
- < ((2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
+ < ((TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
+ FSP_EXTENT_SIZE / 2 + 100)
* UNIV_PAGE_SIZE)) {
@@ -252,7 +254,7 @@ start_again:
fseg_header = doublewrite + TRX_SYS_DOUBLEWRITE_FSEG;
prev_page_no = 0;
- for (i = 0; i < 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
+ for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
+ FSP_EXTENT_SIZE / 2; i++) {
new_block = fseg_alloc_free_page(
fseg_header, prev_page_no + 1, FSP_UP, &mtr);
@@ -375,7 +377,7 @@ buf_dblwr_init_or_load_pages(
/* We do the file i/o past the buffer pool */
- unaligned_read_buf = static_cast<byte*>(ut_malloc(2 * UNIV_PAGE_SIZE));
+ unaligned_read_buf = static_cast<byte*>(ut_malloc(3 * UNIV_PAGE_SIZE));
read_buf = static_cast<byte*>(
ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
@@ -387,6 +389,14 @@ buf_dblwr_init_or_load_pages(
doublewrite = read_buf + TRX_SYS_DOUBLEWRITE;
+ if (mach_read_from_4(read_buf + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) != 0) {
+ fil_space_decrypt((ulint)TRX_SYS_SPACE,
+ read_buf,
+ UNIV_PAGE_SIZE, /* page size */
+ read_buf + UNIV_PAGE_SIZE);
+ doublewrite = read_buf + UNIV_PAGE_SIZE + TRX_SYS_DOUBLEWRITE;
+ }
+
if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
== TRX_SYS_DOUBLEWRITE_MAGIC_N) {
/* The doublewrite buffer has been created */
@@ -429,7 +439,7 @@ buf_dblwr_init_or_load_pages(
page = buf;
- for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * 2; i++) {
+ for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * TRX_SYS_DOUBLEWRITE_BLOCKS; i++) {
ulint source_page_no;
@@ -514,11 +524,11 @@ buf_dblwr_process()
fil_io(OS_FILE_READ, true, space_id, zip_size,
page_no, 0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
- read_buf, NULL, 0);
+ read_buf, NULL, 0, 0);
- /* Check if the page is corrupt */
-
- if (buf_page_is_corrupted(true, read_buf, zip_size)) {
+ if (fil_space_verify_crypt_checksum(read_buf, zip_size)) {
+ /* page is encrypted and checksum is OK */
+ } else if (buf_page_is_corrupted(true, read_buf, zip_size)) {
fprintf(stderr,
"InnoDB: Warning: database page"
@@ -529,8 +539,11 @@ buf_dblwr_process()
" the doublewrite buffer.\n",
(ulong) space_id, (ulong) page_no);
- if (buf_page_is_corrupted(true,
- page, zip_size)) {
+ if (fil_space_verify_crypt_checksum(page, zip_size)) {
+ /* the doublewrite buffer page is encrypted and OK */
+ } else if (buf_page_is_corrupted(true,
+ page,
+ zip_size)) {
fprintf(stderr,
"InnoDB: Dump of the page:\n");
buf_page_print(
@@ -566,7 +579,7 @@ buf_dblwr_process()
fil_io(OS_FILE_WRITE, true, space_id,
zip_size, page_no, 0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
- page, NULL, 0);
+ page, NULL, 0, 0);
ib_logf(IB_LOG_LEVEL_INFO,
"Recovered the page from"
@@ -586,14 +599,34 @@ buf_dblwr_process()
zip_size, page_no, 0,
zip_size ? zip_size
: UNIV_PAGE_SIZE,
- page, NULL, 0);
+ page, NULL, 0, 0);
}
}
}
}
fil_flush_file_spaces(FIL_TABLESPACE);
- ut_free(unaligned_read_buf);
+
+ {
+ fprintf(stderr,
+ "Clear dblwr buffer after completing "
+ "processing of it...\n");
+
+ size_t bytes = TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE;
+ byte *unaligned_buf = static_cast<byte*>(
+ ut_malloc(bytes + UNIV_PAGE_SIZE - 1));
+
+ byte *buf = static_cast<byte*>(
+ ut_align(unaligned_buf, UNIV_PAGE_SIZE));
+ memset(buf, 0, bytes);
+
+ fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
+ buf_dblwr->block1, 0, bytes, buf, NULL, NULL, 0);
+ fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
+ buf_dblwr->block2, 0, bytes, buf, NULL, NULL, 0);
+
+ ut_free(unaligned_buf);
+ }
}
/****************************************************************//**
@@ -665,7 +698,7 @@ buf_dblwr_update(
break;
case BUF_FLUSH_SINGLE_PAGE:
{
- const ulint size = 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
+ const ulint size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
ulint i;
mutex_enter(&buf_dblwr->mutex);
for (i = srv_doublewrite_batch_size; i < size; ++i) {
@@ -792,13 +825,15 @@ buf_dblwr_write_block_to_datafile(
? OS_FILE_WRITE
: OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER;
+ void * frame = buf_page_get_frame(bpage);
+
if (bpage->zip.data) {
fil_io(flags, sync, buf_page_get_space(bpage),
buf_page_get_zip_size(bpage),
buf_page_get_page_no(bpage), 0,
buf_page_get_zip_size(bpage),
- (void*) bpage->zip.data,
- (void*) bpage, 0);
+ frame,
+ (void*) bpage, 0, bpage->newest_modification);
return;
}
@@ -810,7 +845,7 @@ buf_dblwr_write_block_to_datafile(
fil_io(flags, sync, buf_block_get_space(block), 0,
buf_block_get_page_no(block), 0, UNIV_PAGE_SIZE,
- (void*) block->frame, (void*) block, (ulint *)&bpage->write_size);
+ frame, (void*) block, (ulint *)&bpage->write_size, bpage->newest_modification );
}
/********************************************************************//**
@@ -904,7 +939,7 @@ try_again:
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block1, 0, len,
- (void*) write_buf, NULL, 0);
+ (void*) write_buf, NULL, 0, 0);
if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
/* No unwritten pages in the second block. */
@@ -920,7 +955,7 @@ try_again:
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block2, 0, len,
- (void*) write_buf, NULL, 0);
+ (void*) write_buf, NULL, 0, 0);
flush:
/* increment the doublewrite flushed pages counter */
@@ -1001,13 +1036,14 @@ try_again:
}
zip_size = buf_page_get_zip_size(bpage);
+ void * frame = buf_page_get_frame(bpage);
if (zip_size) {
UNIV_MEM_ASSERT_RW(bpage->zip.data, zip_size);
/* Copy the compressed page and clear the rest. */
memcpy(buf_dblwr->write_buf
+ UNIV_PAGE_SIZE * buf_dblwr->first_free,
- bpage->zip.data, zip_size);
+ frame, zip_size);
memset(buf_dblwr->write_buf
+ UNIV_PAGE_SIZE * buf_dblwr->first_free
+ zip_size, 0, UNIV_PAGE_SIZE - zip_size);
@@ -1018,7 +1054,7 @@ try_again:
memcpy(buf_dblwr->write_buf
+ UNIV_PAGE_SIZE * buf_dblwr->first_free,
- ((buf_block_t*) bpage)->frame, UNIV_PAGE_SIZE);
+ frame, UNIV_PAGE_SIZE);
}
buf_dblwr->buf_block_arr[buf_dblwr->first_free] = bpage;
@@ -1069,7 +1105,7 @@ buf_dblwr_write_single_page(
/* total number of slots available for single page flushes
starts from srv_doublewrite_batch_size to the end of the
buffer. */
- size = 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
+ size = TRX_SYS_DOUBLEWRITE_BLOCKS * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
ut_a(size > srv_doublewrite_batch_size);
n_slots = size - srv_doublewrite_batch_size;
@@ -1140,23 +1176,25 @@ retry:
bytes in the doublewrite page with zeros. */
zip_size = buf_page_get_zip_size(bpage);
+ void * frame = buf_page_get_frame(bpage);
+
if (zip_size) {
memcpy(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i,
- bpage->zip.data, zip_size);
+ frame, zip_size);
memset(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i
+ zip_size, 0, UNIV_PAGE_SIZE - zip_size);
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
offset, 0, UNIV_PAGE_SIZE,
(void*) (buf_dblwr->write_buf
- + UNIV_PAGE_SIZE * i), NULL, 0);
+ + UNIV_PAGE_SIZE * i), NULL, 0, bpage->newest_modification);
} else {
/* It is a regular page. Write it directly to the
doublewrite buffer */
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
offset, 0, UNIV_PAGE_SIZE,
- (void*) ((buf_block_t*) bpage)->frame,
- NULL, 0);
+ frame,
+ NULL, 0, bpage->newest_modification);
}
/* Now flush the doublewrite buffer data to disk */