[Commits] Rev: 3804: MDEV-4133: Review InnoDB tablespace allocation patch by Toshikuni Fukaya. If innodb_use_posix_fallocate is set we use posix_fallocate call to extent tablespace allocation instead of pwrite.

Jan Lindström jplindst at mariadb.org
Fri Aug 23 09:14:55 EEST 2013


Hi,

Serg, could you please review fix for MDEV-4133 
(https://mariadb.atlassian.net/browse/MDEV-4133?filter=-1)


Revision: 3804 revid:jplindst at mariadb.org-20130823060357-sggot36kd2ilnwbd
Parents: 3803: Fixed compiler warnings
Date: 8/23/13 9:03 AM
Committer: Jan Lindström <jplindst at mariadb.org>
Branch: 10.0

MDEV-4133: Review InnoDB tablespace allocation patch by Toshikuni 
Fukaya. If innodb_use_posix_fallocate is set we use posix_fallocate call 
to extent tablespace allocation instead of pwrite.


=== modified file 'storage/innobase/fil/fil0fil.cc'
--- storage/innobase/fil/fil0fil.cc    2013-07-21 14:39:19 +0000
+++ storage/innobase/fil/fil0fil.cc    2013-08-23 06:03:57 +0000
@@ -4782,6 +4782,23 @@
      start_page_no = space->size;
      file_start_page_no = space->size - node->size;

+#ifdef HAVE_POSIX_FALLOCATE
+    if (srv_use_posix_fallocate) {
+        ulint n_pages = size_after_extend - start_page_no;
+
+        success = os_file_set_size(node->name, node->handle,
+            n_pages * page_size);
+
+        mutex_enter(&fil_system->mutex);
+        if (success) {
+            node->size += n_pages;
+            space->size += n_pages;
+            os_has_said_disk_full = FALSE;
+        }
+        goto complete_io;
+    }
+#endif
+
      /* Extend at most 64 pages at a time */
      buf_size = ut_min(64, size_after_extend - start_page_no) * page_size;
      buf2 = static_cast<byte*>(mem_alloc(buf_size + page_size));
@@ -4835,10 +4852,15 @@

      space->size += pages_added;
      node->size += pages_added;
+
+#ifdef HAVE_POSIX_FALLOCATE
+complete_io:
+    fil_node_complete_io(node, fil_system, OS_FILE_READ);
+#else
+    fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
+#endif
+
      node->being_extended = FALSE;
-
-    fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
-
      *actual_size = space->size;

  #ifndef UNIV_HOTBACKUP

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- storage/innobase/handler/ha_innodb.cc    2013-08-14 08:48:50 +0000
+++ storage/innobase/handler/ha_innodb.cc    2013-08-23 06:03:57 +0000
@@ -3197,6 +3197,7 @@
      srv_use_posix_fallocate = (ibool) innobase_use_fallocate;
  #endif
      srv_use_atomic_writes = (ibool) innobase_use_atomic_writes;
+
      if (innobase_use_atomic_writes) {
          fprintf(stderr, "InnoDB: using atomic writes.\n");

@@ -3211,13 +3212,13 @@
  #ifndef _WIN32
          if(!innobase_file_flush_method ||
              !strstr(innobase_file_flush_method, "O_DIRECT")) {
-            innobase_file_flush_method =
+            innobase_file_flush_method =
                  srv_file_flush_method_str = (char*)"O_DIRECT";
              fprintf(stderr, "InnoDB: using O_DIRECT due to atomic wr
ites.\n");
          }
  #endif
  #ifdef HAVE_POSIX_FALLOCATE
-        /* Due to a bug in directFS, using atomics needs
+        /* Due to a bug in directFS, using atomics needs
           * posix_fallocate to extend the file
           * pwrite()  past end of the file won't work
           */
@@ -16892,7 +16893,11 @@
      str[size - 1] = 0x0;
      vsnprintf(str, size, format, args);
  #elif HAVE_VASPRINTF
-    (void) vasprintf(&str, format, args);
+    if (vasprintf(&str, format, args) == -1) {
+        /* In case of failure use a fixed length string */
+        str = static_cast<char*>(malloc(BUFSIZ));
+        my_vsnprintf(str, BUFSIZ, format, args);
+    }
  #else
      /* Use a fixed length string. */
      str = static_cast<char*>(malloc(BUFSIZ));
@@ -16968,7 +16973,11 @@
      str[size - 1] = 0x0;
      vsnprintf(str, size, format, args);
  #elif HAVE_VASPRINTF
-    (void) vasprintf(&str, format, args);
+    if (vasprintf(&str, format, args) == -1) {
+        /* In case of failure use a fixed length string */
+        str = static_cast<char*>(malloc(BUFSIZ));
+        my_vsnprintf(str, BUFSIZ, format, args);
+    }
  #else
      /* Use a fixed length string. */
      str = static_cast<char*>(malloc(BUFSIZ));
@@ -17002,7 +17011,11 @@
      str[size - 1] = 0x0;
      vsnprintf(str, size, format, args);
  #elif HAVE_VASPRINTF
-    (void) vasprintf(&str, format, args);
+    if (vasprintf(&str, format, args) == -1) {
+        /* In case of failure use a fixed length string */
+        str = static_cast<char*>(malloc(BUFSIZ));
+        my_vsnprintf(str, BUFSIZ, format, args);
+    }
  #else
      /* Use a fixed length string. */
      str = static_cast<char*>(malloc(BUFSIZ));

=== modified file 'storage/innobase/os/os0file.cc'
--- storage/innobase/os/os0file.cc    2013-07-21 14:39:19 +0000
+++ storage/innobase/os/os0file.cc    2013-08-23 06:03:57 +0000
@@ -2099,6 +2099,23 @@

      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);
+            return(FALSE);
+        }
+        return(TRUE);
+    }
+#endif
+
+
      /* Write up to 1 megabyte at a time. */
      buf_size = ut_min(64, (ulint) (size / UNIV_PAGE_SIZE))
          * UNIV_PAGE_SIZE;

=== modified file 'storage/innobase/row/row0log.cc'
--- storage/innobase/row/row0log.cc    2013-03-25 22:03:13 +0000
+++ storage/innobase/row/row0log.cc    2013-08-23 06:03:57 +0000
@@ -2136,7 +2136,12 @@
          if (index->online_log->head.blocks) {
  #ifdef HAVE_FTRUNCATE
              /* Truncate the file in order to save space. */
-            ftruncate(index->online_log->fd, 0);
+            if (ftruncate(index->online_log->fd, 0) == -1) {
+                fprintf(stderr, "InnoDB: Error: Truncate of file "
+                    "\'%s\' failed with error %d:%s\n",
+                    index->name + 1, errno, strerror(errno));
+                goto corruption;
+            }
  #endif /* HAVE_FTRUNCATE */
              index->online_log->head.blocks
                  = index->online_log->tail.blocks = 0;
@@ -2922,7 +2927,12 @@
          if (index->online_log->head.blocks) {
  #ifdef HAVE_FTRUNCATE
              /* Truncate the file in order to save space. */
-            ftruncate(index->online_log->fd, 0);
+            if (ftruncate(index->online_log->fd, 0) == -1) {
+                fprintf(stderr, "InnoDB: Error: Truncate of file "
+                    "\'%s\' failed with error %d:%s\n",
+                    index->name + 1, errno, strerror(errno));
+                goto corruption;
+            }
  #endif /* HAVE_FTRUNCATE */
              index->online_log->head.blocks
                  = index->online_log->tail.blocks = 0;

=== modified file 'storage/xtradb/fil/fil0fil.c'
--- storage/xtradb/fil/fil0fil.c    2013-07-17 14:03:59 +0000
+++ storage/xtradb/fil/fil0fil.c    2013-08-23 06:03:57 +0000
@@ -4938,10 +4938,11 @@

      mem_free(buf2);

+#ifdef HAVE_POSIX_FALLOCATE
+complete_io:
+    fil_node_complete_io(node, fil_system, OS_FILE_READ);
+#else
      fil_node_complete_io(node, fil_system, OS_FILE_WRITE);
-
-#ifdef HAVE_POSIX_FALLOCATE
-complete_io:
  #endif

      *actual_size = space->size;


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.askmonty.org/pipermail/commits/attachments/20130823/09b76db7/attachment-0001.html>


More information about the commits mailing list