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

Merge 10.0 into 10.1

parents 3c47ed48 a0ce92dd
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2016, Oracle and/or its affiliates. Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2013, 2017, MariaDB Corporation. Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved.
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
...@@ -1029,7 +1029,7 @@ fil_space_extend_must_retry( ...@@ -1029,7 +1029,7 @@ fil_space_extend_must_retry(
mutex_exit(&fil_system->mutex); mutex_exit(&fil_system->mutex);
ulint start_page_no = space->size; ulint start_page_no = space->size;
ulint file_start_page_no = start_page_no - node->size; const ulint file_start_page_no = start_page_no - node->size;
/* Determine correct file block size */ /* Determine correct file block size */
if (node->file_block_size == 0) { if (node->file_block_size == 0) {
...@@ -1039,7 +1039,6 @@ fil_space_extend_must_retry( ...@@ -1039,7 +1039,6 @@ fil_space_extend_must_retry(
} }
ulint page_size = fsp_flags_get_zip_size(space->flags); ulint page_size = fsp_flags_get_zip_size(space->flags);
ulint pages_added = 0;
if (!page_size) { if (!page_size) {
page_size = UNIV_PAGE_SIZE; page_size = UNIV_PAGE_SIZE;
...@@ -1054,51 +1053,56 @@ fil_space_extend_must_retry( ...@@ -1054,51 +1053,56 @@ fil_space_extend_must_retry(
? OS_FILE_READ : OS_FILE_WRITE; ? OS_FILE_READ : OS_FILE_WRITE;
if (srv_use_posix_fallocate) { if (srv_use_posix_fallocate) {
pages_added = size - space->size; const os_offset_t start_offset
= os_offset_t(start_page_no - file_start_page_no)
const os_offset_t start_offset = static_cast<os_offset_t>( * page_size;
start_page_no) * page_size; const ulint n_pages = size - start_page_no;
const os_offset_t len = static_cast<os_offset_t>( const os_offset_t len = os_offset_t(n_pages) * page_size;
pages_added) * page_size;
*success = !posix_fallocate(node->handle, start_offset, len); int err = posix_fallocate(node->handle, start_offset, len);
*success = !err;
if (!*success) { if (!*success) {
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file " ib_logf(IB_LOG_LEVEL_ERROR, "extending file %s"
"space for file \'%s\' failed. Current size " " from " INT64PF " to " INT64PF " bytes"
INT64PF ", desired size " INT64PF, " failed with error %d",
node->name, start_offset, len+start_offset); node->name, start_offset, len + start_offset,
os_file_handle_error_no_exit( err);
node->name, "posix_fallocate",
FALSE, __FILE__, __LINE__);
} }
DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28",
*success = FALSE; errno = 28; *success = FALSE;
os_has_said_disk_full = TRUE;); os_has_said_disk_full = TRUE;);
if (*success) { if (*success) {
os_has_said_disk_full = FALSE; os_has_said_disk_full = FALSE;
} else { start_page_no = size;
pages_added = 0;
} }
} else } else
#else #else
const ulint io_completion_type = OS_FILE_WRITE; const ulint io_completion_type = OS_FILE_WRITE;
#endif #endif
{ {
byte* buf2; #ifdef _WIN32
byte* buf; /* Write 1 page of zeroes at the desired end. */
ulint buf_size; ulint buf_size = page_size;
start_page_no = size - 1;
#else
/* Extend at most 64 pages at a time */ /* Extend at most 64 pages at a time */
buf_size = ut_min(64, size - start_page_no) ulint buf_size = ut_min(64, size - start_page_no)
* page_size; * page_size;
buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size)); #endif
buf = static_cast<byte*>(ut_align(buf2, page_size)); byte* buf2 = static_cast<byte*>(
calloc(1, buf_size + page_size));
memset(buf, 0, buf_size); *success = buf2 != NULL;
if (!buf2) {
while (start_page_no < size) { ib_logf(IB_LOG_LEVEL_ERROR, "Cannot allocate " ULINTPF
" bytes to extend file",
buf_size + page_size);
}
byte* const buf = static_cast<byte*>(
ut_align(buf2, page_size));
while (*success && start_page_no < size) {
ulint n_pages ulint n_pages
= ut_min(buf_size / page_size, = ut_min(buf_size / page_size,
size - start_page_no); size - start_page_no);
...@@ -1107,49 +1111,39 @@ fil_space_extend_must_retry( ...@@ -1107,49 +1111,39 @@ fil_space_extend_must_retry(
start_page_no - file_start_page_no) start_page_no - file_start_page_no)
* page_size; * page_size;
const char* name = node->name == NULL
? space->name : node->name;
*success = os_aio(OS_FILE_WRITE, 0, OS_AIO_SYNC, *success = os_aio(OS_FILE_WRITE, 0, OS_AIO_SYNC,
name, node->handle, buf, node->name, node->handle, buf,
offset, page_size * n_pages, offset, page_size * n_pages,
page_size, node, NULL, 0); page_size, node, NULL, 0);
DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28",
*success = FALSE; errno = 28; *success = FALSE;
os_has_said_disk_full = TRUE;); os_has_said_disk_full = TRUE;);
if (*success) { if (*success) {
os_has_said_disk_full = FALSE; os_has_said_disk_full = FALSE;
} else { }
/* Let us measure the size of the file /* Let us measure the size of the file
to determine how much we were able to to determine how much we were able to
extend it */ extend it */
os_offset_t size; os_offset_t fsize = os_file_get_size(node->handle);
ut_a(fsize != os_offset_t(-1));
size = os_file_get_size(node->handle);
ut_a(size != (os_offset_t) -1);
n_pages = ((ulint) (size / page_size))
- node->size - pages_added;
pages_added += n_pages;
break;
}
start_page_no += n_pages; start_page_no = ulint(fsize / page_size)
pages_added += n_pages; + file_start_page_no;
} }
mem_free(buf2); free(buf2);
} }
mutex_enter(&fil_system->mutex); mutex_enter(&fil_system->mutex);
ut_a(node->being_extended); ut_a(node->being_extended);
ut_a(start_page_no - file_start_page_no >= node->size);
space->size += pages_added; ulint file_size = start_page_no - file_start_page_no;
node->size += pages_added; space->size += file_size - node->size;
node->size = file_size;
fil_node_complete_io(node, fil_system, io_completion_type); fil_node_complete_io(node, fil_system, io_completion_type);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2009, Percona Inc. Copyright (c) 2009, Percona Inc.
Copyright (c) 2013, 2017, MariaDB Corporation. All Rights Reserved. Copyright (c) 2012, 2017, MariaDB Corporation. All Rights Reserved.
Portions of this file contain modifications contributed and copyrighted Portions of this file contain modifications contributed and copyrighted
by Percona Inc.. Those modifications are by Percona Inc.. Those modifications are
...@@ -2367,48 +2367,47 @@ os_file_set_size( ...@@ -2367,48 +2367,47 @@ os_file_set_size(
os_file_t file, /*!< in: handle to a file */ os_file_t file, /*!< in: handle to a file */
os_offset_t size) /*!< in: file size */ os_offset_t size) /*!< in: file size */
{ {
os_offset_t current_size;
ibool ret; ibool ret;
byte* buf; byte* buf;
byte* buf2; byte* buf2;
ulint buf_size; ulint buf_size;
current_size = 0;
#ifdef HAVE_POSIX_FALLOCATE #ifdef HAVE_POSIX_FALLOCATE
if (srv_use_posix_fallocate) { if (srv_use_posix_fallocate) {
int err = posix_fallocate(file, 0, size);
if (posix_fallocate(file, current_size, size) == -1) { if (err) {
ib_logf(IB_LOG_LEVEL_ERROR,
fprintf(stderr, "InnoDB: Error: preallocating file " "preallocating " INT64PF " bytes for"
"space for file \'%s\' failed. Current size " "file %s failed with error %d",
"%lu, desired size %lu\n", size, name, err);
name, current_size, size);
os_file_handle_error_no_exit(name, "posix_fallocate", FALSE, __FILE__, __LINE__);
return(FALSE);
} }
return(TRUE); return(!err);
} }
#endif #endif
#ifdef _WIN32
/* Write 1 page of zeroes at the desired end. */
buf_size = UNIV_PAGE_SIZE;
os_offset_t current_size = size - buf_size;
#else
/* Write up to 1 megabyte at a time. */ /* Write up to 1 megabyte at a time. */
buf_size = ut_min(64, (ulint) (size / UNIV_PAGE_SIZE)) buf_size = ut_min(64, (ulint) (size / UNIV_PAGE_SIZE))
* UNIV_PAGE_SIZE; * UNIV_PAGE_SIZE;
buf2 = static_cast<byte*>(ut_malloc(buf_size + UNIV_PAGE_SIZE)); os_offset_t current_size = 0;
#endif
buf2 = static_cast<byte*>(calloc(1, buf_size + UNIV_PAGE_SIZE));
if (!buf2) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Cannot allocate " ULINTPF " bytes to extend file\n",
buf_size + UNIV_PAGE_SIZE);
return(FALSE);
}
/* Align the buffer for possible raw i/o */ /* Align the buffer for possible raw i/o */
buf = static_cast<byte*>(ut_align(buf2, UNIV_PAGE_SIZE)); buf = static_cast<byte*>(ut_align(buf2, UNIV_PAGE_SIZE));
/* Write buffer full of zeros */ do {
memset(buf, 0, buf_size);
if (size >= (os_offset_t) 100 << 20) {
fprintf(stderr, "InnoDB: Progress in MB:");
}
while (current_size < size) {
ulint n_bytes; ulint n_bytes;
if (size - current_size < (os_offset_t) buf_size) { if (size - current_size < (os_offset_t) buf_size) {
...@@ -2420,37 +2419,15 @@ os_file_set_size( ...@@ -2420,37 +2419,15 @@ os_file_set_size(
ret = os_file_write(name, file, buf, current_size, n_bytes); ret = os_file_write(name, file, buf, current_size, n_bytes);
if (!ret) { if (!ret) {
ut_free(buf2); break;
goto error_handling;
}
/* Print about progress for each 100 MB written */
if ((current_size + n_bytes) / (100 << 20)
!= current_size / (100 << 20)) {
fprintf(stderr, " %lu00",
(ulong) ((current_size + n_bytes)
/ (100 << 20)));
} }
current_size += n_bytes; current_size += n_bytes;
} } while (current_size < size);
if (size >= (os_offset_t) 100 << 20) { free(buf2);
fprintf(stderr, "\n");
}
ut_free(buf2); return(ret && os_file_flush(file));
ret = os_file_flush(file);
if (ret) {
return(TRUE);
}
error_handling:
return(FALSE);
} }
/***********************************************************************//** /***********************************************************************//**
......
...@@ -8,6 +8,7 @@ select * from t where a=1 for update; ...@@ -8,6 +8,7 @@ select * from t where a=1 for update;
a b a b
1 0 1 0
update t set b=b+1 where a=1; update t set b=b+1 where a=1;
set session tokudb_lock_timeout= 60000;
set session transaction isolation level read committed; set session transaction isolation level read committed;
begin; begin;
select * from t where a=1 for update; select * from t where a=1 for update;
......
...@@ -15,6 +15,7 @@ select * from t where a=1 for update; ...@@ -15,6 +15,7 @@ select * from t where a=1 for update;
# t2 update # t2 update
update t set b=b+1 where a=1; update t set b=b+1 where a=1;
connect(conn1,localhost,root); connect(conn1,localhost,root);
set session tokudb_lock_timeout= 60000;
set session transaction isolation level read committed; set session transaction isolation level read committed;
begin; begin;
# t2 select for update, should hang until t1 commits # t2 select for update, should hang until t1 commits
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2013, 2017, MariaDB Corporation. Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved.
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
...@@ -1034,7 +1034,7 @@ fil_space_extend_must_retry( ...@@ -1034,7 +1034,7 @@ fil_space_extend_must_retry(
mutex_exit(&fil_system->mutex); mutex_exit(&fil_system->mutex);
ulint start_page_no = space->size; ulint start_page_no = space->size;
ulint file_start_page_no = start_page_no - node->size; const ulint file_start_page_no = start_page_no - node->size;
/* Determine correct file block size */ /* Determine correct file block size */
if (node->file_block_size == 0) { if (node->file_block_size == 0) {
...@@ -1044,7 +1044,6 @@ fil_space_extend_must_retry( ...@@ -1044,7 +1044,6 @@ fil_space_extend_must_retry(
} }
ulint page_size = fsp_flags_get_zip_size(space->flags); ulint page_size = fsp_flags_get_zip_size(space->flags);
ulint pages_added = 0;
if (!page_size) { if (!page_size) {
page_size = UNIV_PAGE_SIZE; page_size = UNIV_PAGE_SIZE;
...@@ -1059,51 +1058,56 @@ fil_space_extend_must_retry( ...@@ -1059,51 +1058,56 @@ fil_space_extend_must_retry(
? OS_FILE_READ : OS_FILE_WRITE; ? OS_FILE_READ : OS_FILE_WRITE;
if (srv_use_posix_fallocate) { if (srv_use_posix_fallocate) {
pages_added = size - space->size; const os_offset_t start_offset
= os_offset_t(start_page_no - file_start_page_no)
const os_offset_t start_offset = static_cast<os_offset_t>( * page_size;
start_page_no) * page_size; const ulint n_pages = size - start_page_no;
const os_offset_t len = static_cast<os_offset_t>( const os_offset_t len = os_offset_t(n_pages) * page_size;
pages_added) * page_size;
*success = !posix_fallocate(node->handle, start_offset, len); int err = posix_fallocate(node->handle, start_offset, len);
*success = !err;
if (!*success) { if (!*success) {
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file " ib_logf(IB_LOG_LEVEL_ERROR, "extending file %s"
"space for file \'%s\' failed. Current size " " from " INT64PF " to " INT64PF " bytes"
INT64PF ", desired size " INT64PF, " failed with error %d",
node->name, start_offset, len+start_offset); node->name, start_offset, len + start_offset,
os_file_handle_error_no_exit( err);
node->name, "posix_fallocate",
FALSE, __FILE__, __LINE__);
} }
DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28",
*success = FALSE; errno = 28; *success = FALSE;
os_has_said_disk_full = TRUE;); os_has_said_disk_full = TRUE;);
if (*success) { if (*success) {
os_has_said_disk_full = FALSE; os_has_said_disk_full = FALSE;
} else { start_page_no = size;
pages_added = 0;
} }
} else } else
#else #else
const ulint io_completion_type = OS_FILE_WRITE; const ulint io_completion_type = OS_FILE_WRITE;
#endif #endif
{ {
byte* buf2; #ifdef _WIN32
byte* buf; /* Write 1 page of zeroes at the desired end. */
ulint buf_size; ulint buf_size = page_size;
start_page_no = size - 1;
#else
/* Extend at most 64 pages at a time */ /* Extend at most 64 pages at a time */
buf_size = ut_min(64, size - start_page_no) ulint buf_size = ut_min(64, size - start_page_no)
* page_size; * page_size;
buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size)); #endif
buf = static_cast<byte*>(ut_align(buf2, page_size)); byte* buf2 = static_cast<byte*>(
calloc(1, buf_size + page_size));
memset(buf, 0, buf_size); *success = buf2 != NULL;
if (!buf2) {
while (start_page_no < size) { ib_logf(IB_LOG_LEVEL_ERROR, "Cannot allocate " ULINTPF
" bytes to extend file",
buf_size + page_size);
}
byte* const buf = static_cast<byte*>(
ut_align(buf2, page_size));
while (*success && start_page_no < size) {
ulint n_pages ulint n_pages
= ut_min(buf_size / page_size, = ut_min(buf_size / page_size,
size - start_page_no); size - start_page_no);
...@@ -1112,50 +1116,40 @@ fil_space_extend_must_retry( ...@@ -1112,50 +1116,40 @@ fil_space_extend_must_retry(
start_page_no - file_start_page_no) start_page_no - file_start_page_no)
* page_size; * page_size;
const char* name = node->name == NULL
? space->name : node->name;
*success = os_aio(OS_FILE_WRITE, 0, OS_AIO_SYNC, *success = os_aio(OS_FILE_WRITE, 0, OS_AIO_SYNC,
name, node->handle, buf, node->name, node->handle, buf,
offset, page_size * n_pages, offset, page_size * n_pages,
page_size, node, NULL, page_size, node, NULL,
space->id, NULL, 0); space->id, NULL, 0);
DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28",
*success = FALSE; errno = 28; *success = FALSE;
os_has_said_disk_full = TRUE;); os_has_said_disk_full = TRUE;);
if (*success) { if (*success) {
os_has_said_disk_full = FALSE; os_has_said_disk_full = FALSE;
} else { }
/* Let us measure the size of the file /* Let us measure the size of the file
to determine how much we were able to to determine how much we were able to
extend it */ extend it */
os_offset_t size; os_offset_t fsize = os_file_get_size(node->handle);
ut_a(fsize != os_offset_t(-1));
size = os_file_get_size(node->handle);
ut_a(size != (os_offset_t) -1);
n_pages = ((ulint) (size / page_size))
- node->size - pages_added;
pages_added += n_pages;
break;
}
start_page_no += n_pages; start_page_no = ulint(fsize / page_size)
pages_added += n_pages; + file_start_page_no;
} }
mem_free(buf2); free(buf2);
} }
mutex_enter(&fil_system->mutex); mutex_enter(&fil_system->mutex);
ut_a(node->being_extended); ut_a(node->being_extended);
ut_a(start_page_no - file_start_page_no >= node->size);
space->size += pages_added; ulint file_size = start_page_no - file_start_page_no;
node->size += pages_added; space->size += file_size - node->size;
node->size = file_size;
fil_node_complete_io(node, fil_system, io_completion_type); fil_node_complete_io(node, fil_system, io_completion_type);
......
...@@ -2553,48 +2553,47 @@ os_file_set_size( ...@@ -2553,48 +2553,47 @@ os_file_set_size(
os_file_t file, /*!< in: handle to a file */ os_file_t file, /*!< in: handle to a file */
os_offset_t size) /*!< in: file size */ os_offset_t size) /*!< in: file size */
{ {
os_offset_t current_size;
ibool ret; ibool ret;
byte* buf; byte* buf;
byte* buf2; byte* buf2;
ulint buf_size; ulint buf_size;
current_size = 0;
#ifdef HAVE_POSIX_FALLOCATE #ifdef HAVE_POSIX_FALLOCATE
if (srv_use_posix_fallocate) { if (srv_use_posix_fallocate) {
int err = posix_fallocate(file, 0, size);
if (posix_fallocate(file, current_size, size) == -1) { if (err) {
ib_logf(IB_LOG_LEVEL_ERROR,
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file " "preallocating " INT64PF " bytes for"
"space for file \'%s\' failed. Current size " "file %s failed with error %d",
INT64PF ", desired size " INT64PF, size, name, err);
name, current_size, size);
os_file_handle_error_no_exit (name, "posix_fallocate",
FALSE, __FILE__, __LINE__);
return(FALSE);
} }
return(TRUE); return(!err);
} }
#endif #endif
#ifdef _WIN32
/* Write 1 page of zeroes at the desired end. */
buf_size = UNIV_PAGE_SIZE;
os_offset_t current_size = size - buf_size;
#else
/* Write up to 1 megabyte at a time. */ /* Write up to 1 megabyte at a time. */
buf_size = ut_min(64, (ulint) (size / UNIV_PAGE_SIZE)) buf_size = ut_min(64, (ulint) (size / UNIV_PAGE_SIZE))
* UNIV_PAGE_SIZE; * UNIV_PAGE_SIZE;
buf2 = static_cast<byte*>(ut_malloc(buf_size + UNIV_PAGE_SIZE)); os_offset_t current_size = 0;
#endif
buf2 = static_cast<byte*>(calloc(1, buf_size + UNIV_PAGE_SIZE));
if (!buf2) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Cannot allocate " ULINTPF " bytes to extend file\n",
buf_size + UNIV_PAGE_SIZE);
return(FALSE);
}
/* Align the buffer for possible raw i/o */ /* Align the buffer for possible raw i/o */
buf = static_cast<byte*>(ut_align(buf2, UNIV_PAGE_SIZE)); buf = static_cast<byte*>(ut_align(buf2, UNIV_PAGE_SIZE));
/* Write buffer full of zeros */ do {
memset(buf, 0, buf_size);
if (size >= (os_offset_t) 100 << 20) {
fprintf(stderr, "InnoDB: Progress in MB:");
}
while (current_size < size) {
ulint n_bytes; ulint n_bytes;
if (size - current_size < (os_offset_t) buf_size) { if (size - current_size < (os_offset_t) buf_size) {
...@@ -2606,37 +2605,15 @@ os_file_set_size( ...@@ -2606,37 +2605,15 @@ os_file_set_size(
ret = os_file_write(name, file, buf, current_size, n_bytes); ret = os_file_write(name, file, buf, current_size, n_bytes);
if (!ret) { if (!ret) {
ut_free(buf2); break;
goto error_handling;
}
/* Print about progress for each 100 MB written */
if ((current_size + n_bytes) / (100 << 20)
!= current_size / (100 << 20)) {
fprintf(stderr, " %lu00",
(ulong) ((current_size + n_bytes)
/ (100 << 20)));
} }
current_size += n_bytes; current_size += n_bytes;
} } while (current_size < size);
if (size >= (os_offset_t) 100 << 20) {
fprintf(stderr, "\n"); free(buf2);
}
ut_free(buf2);
ret = os_file_flush(file);
if (ret) {
return(TRUE);
}
error_handling: return(ret && os_file_flush(file));
return(FALSE);
} }
/***********************************************************************//** /***********************************************************************//**
......
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