Skip to content

Commit

Permalink
Merge 10.0 into 10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Feb 22, 2017
2 parents 3c47ed4 + a0ce92d commit e1e920b
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 214 deletions.
108 changes: 51 additions & 57 deletions storage/innobase/fil/fil0fil.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1995, 2016, Oracle and/or its affiliates.
Copyright (c) 2013, 2017, MariaDB Corporation.
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2014, 2017, MariaDB Corporation. All Rights Reserved.
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
Expand Down Expand Up @@ -1028,8 +1028,8 @@ fil_space_extend_must_retry(
we have set the node->being_extended flag. */
mutex_exit(&fil_system->mutex);

ulint start_page_no = space->size;
ulint file_start_page_no = start_page_no - node->size;
ulint start_page_no = space->size;
const ulint file_start_page_no = start_page_no - node->size;

/* Determine correct file block size */
if (node->file_block_size == 0) {
Expand All @@ -1039,7 +1039,6 @@ fil_space_extend_must_retry(
}

ulint page_size = fsp_flags_get_zip_size(space->flags);
ulint pages_added = 0;

if (!page_size) {
page_size = UNIV_PAGE_SIZE;
Expand All @@ -1054,51 +1053,56 @@ fil_space_extend_must_retry(
? OS_FILE_READ : OS_FILE_WRITE;

if (srv_use_posix_fallocate) {
pages_added = size - space->size;

const os_offset_t start_offset = static_cast<os_offset_t>(
start_page_no) * page_size;
const os_offset_t len = static_cast<os_offset_t>(
pages_added) * page_size;
const os_offset_t start_offset
= os_offset_t(start_page_no - file_start_page_no)
* page_size;
const ulint n_pages = size - start_page_no;
const os_offset_t len = os_offset_t(n_pages) * page_size;

*success = !posix_fallocate(node->handle, start_offset, len);
int err = posix_fallocate(node->handle, start_offset, len);
*success = !err;
if (!*success) {
ib_logf(IB_LOG_LEVEL_ERROR, "preallocating file "
"space for file \'%s\' failed. Current size "
INT64PF ", desired size " INT64PF,
node->name, start_offset, len+start_offset);
os_file_handle_error_no_exit(
node->name, "posix_fallocate",
FALSE, __FILE__, __LINE__);
ib_logf(IB_LOG_LEVEL_ERROR, "extending file %s"
" from " INT64PF " to " INT64PF " bytes"
" failed with error %d",
node->name, start_offset, len + start_offset,
err);
}

DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28",
*success = FALSE; errno = 28;
*success = FALSE;
os_has_said_disk_full = TRUE;);

if (*success) {
os_has_said_disk_full = FALSE;
} else {
pages_added = 0;
start_page_no = size;
}
} else
#else
const ulint io_completion_type = OS_FILE_WRITE;
#endif
{
byte* buf2;
byte* buf;
ulint buf_size;

#ifdef _WIN32
/* Write 1 page of zeroes at the desired end. */
ulint buf_size = page_size;
start_page_no = size - 1;
#else
/* 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;
buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size));
buf = static_cast<byte*>(ut_align(buf2, page_size));

memset(buf, 0, buf_size);

while (start_page_no < size) {
#endif
byte* buf2 = static_cast<byte*>(
calloc(1, buf_size + page_size));
*success = buf2 != NULL;
if (!buf2) {
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
= ut_min(buf_size / page_size,
size - start_page_no);
Expand All @@ -1107,49 +1111,39 @@ fil_space_extend_must_retry(
start_page_no - file_start_page_no)
* page_size;

const char* name = node->name == NULL
? space->name : node->name;

*success = os_aio(OS_FILE_WRITE, 0, OS_AIO_SYNC,
name, node->handle, buf,
node->name, node->handle, buf,
offset, page_size * n_pages,
page_size, node, NULL, 0);

DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28",
*success = FALSE; errno = 28;
*success = FALSE;
os_has_said_disk_full = TRUE;);

if (*success) {
os_has_said_disk_full = FALSE;
} else {
/* Let us measure the size of the file
to determine how much we were able to
extend it */
os_offset_t size;

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;
}
/* Let us measure the size of the file
to determine how much we were able to
extend it */
os_offset_t fsize = os_file_get_size(node->handle);
ut_a(fsize != os_offset_t(-1));

start_page_no += n_pages;
pages_added += n_pages;
start_page_no = ulint(fsize / page_size)
+ file_start_page_no;
}

mem_free(buf2);
free(buf2);
}

mutex_enter(&fil_system->mutex);

ut_a(node->being_extended);
ut_a(start_page_no - file_start_page_no >= node->size);

space->size += pages_added;
node->size += pages_added;
ulint file_size = start_page_no - file_start_page_no;
space->size += file_size - node->size;
node->size = file_size;

fil_node_complete_io(node, fil_system, io_completion_type);

Expand Down
79 changes: 28 additions & 51 deletions storage/innobase/os/os0file.cc
Expand Up @@ -2,7 +2,7 @@
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
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
by Percona Inc.. Those modifications are
Expand Down Expand Up @@ -2367,48 +2367,47 @@ os_file_set_size(
os_file_t file, /*!< in: handle to a file */
os_offset_t size) /*!< in: file size */
{
os_offset_t current_size;
ibool ret;
byte* buf;
byte* buf2;
ulint buf_size;

current_size = 0;

#ifdef HAVE_POSIX_FALLOCATE
if (srv_use_posix_fallocate) {

if (posix_fallocate(file, current_size, size) == -1) {

fprintf(stderr, "InnoDB: Error: preallocating file "
"space for file \'%s\' failed. Current size "
"%lu, desired size %lu\n",
name, current_size, size);
os_file_handle_error_no_exit(name, "posix_fallocate", FALSE, __FILE__, __LINE__);

return(FALSE);
int err = posix_fallocate(file, 0, size);
if (err) {
ib_logf(IB_LOG_LEVEL_ERROR,
"preallocating " INT64PF " bytes for"
"file %s failed with error %d",
size, name, err);
}
return(TRUE);
return(!err);
}
#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. */
buf_size = ut_min(64, (ulint) (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 */
buf = static_cast<byte*>(ut_align(buf2, UNIV_PAGE_SIZE));

/* Write buffer full of zeros */
memset(buf, 0, buf_size);

if (size >= (os_offset_t) 100 << 20) {

fprintf(stderr, "InnoDB: Progress in MB:");
}

while (current_size < size) {
do {
ulint n_bytes;

if (size - current_size < (os_offset_t) buf_size) {
Expand All @@ -2420,37 +2419,15 @@ os_file_set_size(
ret = os_file_write(name, file, buf, current_size, n_bytes);

if (!ret) {
ut_free(buf2);
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)));
break;
}

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(FALSE);
return(ret && os_file_flush(file));
}

/***********************************************************************//**
Expand Down
Expand Up @@ -8,6 +8,7 @@ select * from t where a=1 for update;
a b
1 0
update t set b=b+1 where a=1;
set session tokudb_lock_timeout= 60000;
set session transaction isolation level read committed;
begin;
select * from t where a=1 for update;
Expand Down
Expand Up @@ -15,6 +15,7 @@ select * from t where a=1 for update;
# t2 update
update t set b=b+1 where a=1;
connect(conn1,localhost,root);
set session tokudb_lock_timeout= 60000;
set session transaction isolation level read committed;
begin;
# t2 select for update, should hang until t1 commits
Expand Down

0 comments on commit e1e920b

Please sign in to comment.