Merge lp:~sergei.glushchenko/percona-xtrabackup/2.2-xb-bug1375383 into lp:percona-xtrabackup/2.2

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 5035
Proposed branch: lp:~sergei.glushchenko/percona-xtrabackup/2.2-xb-bug1375383
Merge into: lp:percona-xtrabackup/2.2
Diff against target: 429 lines (+166/-150)
1 file modified
storage/innobase/os/os0file.cc (+166/-150)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-xtrabackup/2.2-xb-bug1375383
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+237383@code.launchpad.net

Description of the change

1. os_file_handle_error_cond_exit to call ut_error instead of exit
2. Port fix for MySQL bug #54430 from 5.7 tree.

http://jenkins.percona.com/view/PXB%202.2/job/percona-xtrabackup-2.2-param/227/

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) wrote :

Sergei,

Wouldn't it be better to port the _current_ version of the code, rather than the original revision. That is, no HAVE_BROKEN_PREAD (HP-UX specific) code paths, and no spurious whitespace changes like in lines 289-290. Those have been fixed in later revisions.

review: Needs Information
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

I updated related code parts to the latest available state.

http://jenkins.percona.com/view/PXB%202.2/job/percona-xtrabackup-2.2-param/232/

Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'storage/innobase/os/os0file.cc'
--- storage/innobase/os/os0file.cc 2014-09-15 08:52:36 +0000
+++ storage/innobase/os/os0file.cc 2014-10-09 19:02:11 +0000
@@ -66,6 +66,9 @@
66/** Log segment id */66/** Log segment id */
67static const ulint IO_LOG_SEGMENT = 1;67static const ulint IO_LOG_SEGMENT = 1;
6868
69/** Number of retries for partial I/O's */
70static const ulint NUM_RETRIES_ON_PARTIAL_IO = 10;
71
69/* This specifies the file permissions InnoDB uses when it creates files in72/* This specifies the file permissions InnoDB uses when it creates files in
70Unix; the value of os_innodb_umask is initialized in ha_innodb.cc to73Unix; the value of os_innodb_umask is initialized in ha_innodb.cc to
71my_umask */74my_umask */
@@ -652,7 +655,7 @@
652 }655 }
653656
654 if (should_exit) {657 if (should_exit) {
655 exit(1);658 ut_error;
656 }659 }
657 }660 }
658661
@@ -2336,11 +2339,75 @@
2336#endif2339#endif
2337}2340}
23382341
2339#ifndef __WIN__2342#ifndef _WIN32
2343/*******************************************************************//**
2344Does a syncronous read or write depending upon the type specified
2345In case of partial reads/writes the function tries
2346NUM_RETRIES_ON_PARTIAL_IO times to read/write the complete data.
2347@return number of bytes read/written, -1 if error */
2348static __attribute__((warn_unused_result))
2349ssize_t
2350os_file_io(
2351/*==========*/
2352 os_file_t file, /*!< in: handle to a file */
2353 void* buf, /*!< in: buffer where to read/write */
2354 ulint n, /*!< in: number of bytes to read/write */
2355 off_t offset, /*!< in: file offset from where to read/write */
2356 ulint type) /*!< in: type for read or write */
2357{
2358 ssize_t bytes_returned = 0;
2359 ssize_t n_bytes;
2360
2361 for (ulint i = 0; i < NUM_RETRIES_ON_PARTIAL_IO; ++i) {
2362 if (type == OS_FILE_READ ) {
2363 n_bytes = pread(file, buf, n, offset);
2364 } else {
2365 ut_ad(type == OS_FILE_WRITE);
2366 n_bytes = pwrite(file, buf, n, offset);
2367 }
2368
2369 if ((ulint) n_bytes == n) {
2370 bytes_returned += n_bytes;
2371 return(bytes_returned);
2372 } else if (n_bytes > 0 && (ulint) n_bytes < n) {
2373 /* For partial read/write scenario */
2374 if (type == OS_FILE_READ) {
2375 ib_logf(IB_LOG_LEVEL_WARN,
2376 "%lu bytes should have"
2377 " been read. Only %lu bytes"
2378 " read. Retrying again to read"
2379 " the remaining bytes.",
2380 (ulong) n, (ulong) n_bytes);
2381 } else {
2382 ib_logf(IB_LOG_LEVEL_WARN,
2383 "%lu bytes should have"
2384 " been written. Only %lu bytes"
2385 " written. Retrying again to"
2386 " write the remaining bytes.",
2387 (ulong) n, (ulong) n_bytes);
2388 }
2389
2390 buf = (uchar*) buf + (ulint) n_bytes;
2391 n -= (ulint) n_bytes;
2392 offset += n_bytes;
2393 bytes_returned += (ulint) n_bytes;
2394
2395 } else {
2396 break;
2397 }
2398 }
2399
2400 ib_logf(IB_LOG_LEVEL_WARN,
2401 "Retry attempts for %s partial data failed.",
2402 type == OS_FILE_READ ? "reading" : "writing");
2403
2404 return(bytes_returned);
2405}
2406
2340/*******************************************************************//**2407/*******************************************************************//**
2341Does a synchronous read operation in Posix.2408Does a synchronous read operation in Posix.
2342@return number of bytes read, -1 if error */2409@return number of bytes read, -1 if error */
2343static __attribute__((nonnull, warn_unused_result))2410static __attribute__((warn_unused_result))
2344ssize_t2411ssize_t
2345os_file_pread(2412os_file_pread(
2346/*==========*/2413/*==========*/
@@ -2349,10 +2416,8 @@
2349 ulint n, /*!< in: number of bytes to read */2416 ulint n, /*!< in: number of bytes to read */
2350 os_offset_t offset) /*!< in: file offset from where to read */2417 os_offset_t offset) /*!< in: file offset from where to read */
2351{2418{
2352 off_t offs;2419 off_t offs;
2353#if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)2420 ssize_t read_bytes;
2354 ssize_t n_bytes;
2355#endif /* HAVE_PREAD && !HAVE_BROKEN_PREAD */
23562421
2357 ut_ad(n);2422 ut_ad(n);
23582423
@@ -2360,98 +2425,45 @@
2360 64-bit address */2425 64-bit address */
2361 offs = (off_t) offset;2426 offs = (off_t) offset;
23622427
2363 if (sizeof(off_t) <= 4) {2428 if (sizeof(off_t) <= 4 && offset != (os_offset_t) offs) {
2364 if (offset != (os_offset_t) offs) {2429 ib_logf(IB_LOG_LEVEL_ERROR, "File read at offset > 4 GB");
2365 ib_logf(IB_LOG_LEVEL_ERROR,
2366 "File read at offset > 4 GB");
2367 }
2368 }2430 }
23692431
2370 os_n_file_reads++;2432 os_n_file_reads++;
23712433
2372#if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)2434# if defined(HAVE_ATOMIC_BUILTINS)
2373#if defined(HAVE_ATOMIC_BUILTINS) && UNIV_WORD_SIZE == 8
2374 (void) os_atomic_increment_ulint(&os_n_pending_reads, 1);2435 (void) os_atomic_increment_ulint(&os_n_pending_reads, 1);
2375 (void) os_atomic_increment_ulint(&os_file_n_pending_preads, 1);2436 (void) os_atomic_increment_ulint(&os_file_n_pending_preads, 1);
2376 MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_READS);2437 MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_READS);
2377#else2438# else
2378 os_mutex_enter(os_file_count_mutex);2439 mutex_enter(&os_file_count_mutex);
2379 os_file_n_pending_preads++;2440 os_file_n_pending_preads++;
2380 os_n_pending_reads++;2441 os_n_pending_reads++;
2381 MONITOR_INC(MONITOR_OS_PENDING_READS);2442 MONITOR_INC(MONITOR_OS_PENDING_READS);
2382 os_mutex_exit(os_file_count_mutex);2443 mutex_exit(&os_file_count_mutex);
2383#endif /* HAVE_ATOMIC_BUILTINS && UNIV_WORD == 8 */2444# endif /* HAVE_ATOMIC_BUILTINS */
23842445
2385 n_bytes = pread(file, buf, n, offs);2446 read_bytes = os_file_io(file, buf, n, offs, OS_FILE_READ);
23862447
2387#if defined(HAVE_ATOMIC_BUILTINS) && UNIV_WORD_SIZE == 82448# ifdef HAVE_ATOMIC_BUILTINS
2388 (void) os_atomic_decrement_ulint(&os_n_pending_reads, 1);2449 (void) os_atomic_decrement_ulint(&os_n_pending_reads, 1);
2389 (void) os_atomic_decrement_ulint(&os_file_n_pending_preads, 1);2450 (void) os_atomic_decrement_ulint(&os_file_n_pending_preads, 1);
2390 MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_READS);2451 MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_READS);
2391#else2452# else
2392 os_mutex_enter(os_file_count_mutex);2453 mutex_enter(&os_file_count_mutex);
2393 os_file_n_pending_preads--;2454 os_file_n_pending_preads--;
2394 os_n_pending_reads--;2455 os_n_pending_reads--;
2395 MONITOR_DEC(MONITOR_OS_PENDING_READS);2456 MONITOR_DEC(MONITOR_OS_PENDING_READS);
2396 os_mutex_exit(os_file_count_mutex);2457 mutex_exit(&os_file_count_mutex);
2397#endif /* !HAVE_ATOMIC_BUILTINS || UNIV_WORD == 8 */2458# endif /* HAVE_ATOMIC_BUILTINS */
23982459
2399 return(n_bytes);2460 return(read_bytes);
2400#else
2401 {
2402 off_t ret_offset;
2403 ssize_t ret;
2404#ifndef UNIV_HOTBACKUP
2405 ulint i;
2406#endif /* !UNIV_HOTBACKUP */
2407
2408#if defined(HAVE_ATOMIC_BUILTINS) && UNIV_WORD_SIZE == 8
2409 (void) os_atomic_increment_ulint(&os_n_pending_reads, 1);
2410 MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_READS);
2411#else
2412 os_mutex_enter(os_file_count_mutex);
2413 os_n_pending_reads++;
2414 MONITOR_INC(MONITOR_OS_PENDING_READS);
2415 os_mutex_exit(os_file_count_mutex);
2416#endif /* HAVE_ATOMIC_BUILTINS && UNIV_WORD == 8 */
2417#ifndef UNIV_HOTBACKUP
2418 /* Protect the seek / read operation with a mutex */
2419 i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
2420
2421 os_mutex_enter(os_file_seek_mutexes[i]);
2422#endif /* !UNIV_HOTBACKUP */
2423
2424 ret_offset = lseek(file, offs, SEEK_SET);
2425
2426 if (ret_offset < 0) {
2427 ret = -1;
2428 } else {
2429 ret = read(file, buf, (ssize_t) n);
2430 }
2431
2432#ifndef UNIV_HOTBACKUP
2433 os_mutex_exit(os_file_seek_mutexes[i]);
2434#endif /* !UNIV_HOTBACKUP */
2435
2436#if defined(HAVE_ATOMIC_BUILTINS) && UNIV_WORD_SIZE == 8
2437 (void) os_atomic_decrement_ulint(&os_n_pending_reads, 1);
2438 MONITOR_ATOIC_DEC(MONITOR_OS_PENDING_READS);
2439#else
2440 os_mutex_enter(os_file_count_mutex);
2441 os_n_pending_reads--;
2442 MONITOR_DEC(MONITOR_OS_PENDING_READS);
2443 os_mutex_exit(os_file_count_mutex);
2444#endif /* HAVE_ATOMIC_BUILTINS && UNIV_WORD_SIZE == 8 */
2445
2446 return(ret);
2447 }
2448#endif
2449}2461}
24502462
2451/*******************************************************************//**2463/*******************************************************************//**
2452Does a synchronous write operation in Posix.2464Does a synchronous write operation in Posix.
2453@return number of bytes written, -1 if error */2465@return number of bytes written, -1 if error */
2454static __attribute__((nonnull, warn_unused_result))2466static __attribute__((warn_unused_result))
2455ssize_t2467ssize_t
2456os_file_pwrite(2468os_file_pwrite(
2457/*===========*/2469/*===========*/
@@ -2460,95 +2472,49 @@
2460 ulint n, /*!< in: number of bytes to write */2472 ulint n, /*!< in: number of bytes to write */
2461 os_offset_t offset) /*!< in: file offset where to write */2473 os_offset_t offset) /*!< in: file offset where to write */
2462{2474{
2463 ssize_t ret;2475 off_t offs;
2464 off_t offs;2476 ssize_t written_bytes;
24652477
2466 ut_ad(n);2478 ut_ad(n);
2467 ut_ad(!srv_read_only_mode);
24682479
2469 /* If off_t is > 4 bytes in size, then we assume we can pass a2480 /* If off_t is > 4 bytes in size, then we assume we can pass a
2470 64-bit address */2481 64-bit address */
2471 offs = (off_t) offset;2482 offs = (off_t) offset;
24722483
2473 if (sizeof(off_t) <= 4) {2484 if (sizeof(off_t) <= 4 && offset != (os_offset_t) offs) {
2474 if (offset != (os_offset_t) offs) {2485 ib_logf(IB_LOG_LEVEL_ERROR, "file write at offset > 4 GB.");
2475 ib_logf(IB_LOG_LEVEL_ERROR,
2476 "File write at offset > 4 GB.");
2477 }
2478 }2486 }
24792487
2480 os_n_file_writes++;2488 os_n_file_writes++;
24812489
2482#if defined(HAVE_PWRITE) && !defined(HAVE_BROKEN_PREAD)2490#ifdef HAVE_ATOMIC_BUILTINS
2483#if !defined(HAVE_ATOMIC_BUILTINS) || UNIV_WORD_SIZE < 8
2484 os_mutex_enter(os_file_count_mutex);
2485 os_file_n_pending_pwrites++;
2486 os_n_pending_writes++;
2487 MONITOR_INC(MONITOR_OS_PENDING_WRITES);
2488 os_mutex_exit(os_file_count_mutex);
2489#else
2490 (void) os_atomic_increment_ulint(&os_n_pending_writes, 1);2491 (void) os_atomic_increment_ulint(&os_n_pending_writes, 1);
2491 (void) os_atomic_increment_ulint(&os_file_n_pending_pwrites, 1);2492 (void) os_atomic_increment_ulint(&os_file_n_pending_pwrites, 1);
2492 MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_WRITES);2493 MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_WRITES);
2493#endif /* !HAVE_ATOMIC_BUILTINS || UNIV_WORD < 8 */
2494
2495 ret = pwrite(file, buf, (ssize_t) n, offs);
2496
2497#if !defined(HAVE_ATOMIC_BUILTINS) || UNIV_WORD_SIZE < 8
2498 os_mutex_enter(os_file_count_mutex);
2499 os_file_n_pending_pwrites--;
2500 os_n_pending_writes--;
2501 MONITOR_DEC(MONITOR_OS_PENDING_WRITES);
2502 os_mutex_exit(os_file_count_mutex);
2503#else2494#else
2495 mutex_enter(&os_file_count_mutex);
2496 os_file_n_pending_pwrites++;
2497 os_n_pending_writes++;
2498 MONITOR_INC(MONITOR_OS_PENDING_WRITES);
2499 mutex_exit(&os_file_count_mutex);
2500#endif /* HAVE_ATOMIC_BUILTINS */
2501
2502 written_bytes = os_file_io(
2503 file, (void*) buf, n, offs, OS_FILE_WRITE);
2504
2505#ifdef HAVE_ATOMIC_BUILTINS
2504 (void) os_atomic_decrement_ulint(&os_n_pending_writes, 1);2506 (void) os_atomic_decrement_ulint(&os_n_pending_writes, 1);
2505 (void) os_atomic_decrement_ulint(&os_file_n_pending_pwrites, 1);2507 (void) os_atomic_decrement_ulint(&os_file_n_pending_pwrites, 1);
2506 MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_WRITES);2508 MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_WRITES);
2507#endif /* !HAVE_ATOMIC_BUILTINS || UNIV_WORD < 8 */
2508
2509 return(ret);
2510#else2509#else
2511 {2510 mutex_enter(&os_file_count_mutex);
2512 off_t ret_offset;2511 os_file_n_pending_pwrites--;
2513# ifndef UNIV_HOTBACKUP2512 os_n_pending_writes--;
2514 ulint i;2513 MONITOR_DEC(MONITOR_OS_PENDING_WRITES);
2515# endif /* !UNIV_HOTBACKUP */2514 mutex_exit(&os_file_count_mutex);
25162515#endif /* HAVE_ATOMIC_BUILTINS */
2517 os_mutex_enter(os_file_count_mutex);2516
2518 os_n_pending_writes++;2517 return(written_bytes);
2519 MONITOR_INC(MONITOR_OS_PENDING_WRITES);
2520 os_mutex_exit(os_file_count_mutex);
2521
2522# ifndef UNIV_HOTBACKUP
2523 /* Protect the seek / write operation with a mutex */
2524 i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
2525
2526 os_mutex_enter(os_file_seek_mutexes[i]);
2527# endif /* UNIV_HOTBACKUP */
2528
2529 ret_offset = lseek(file, offs, SEEK_SET);
2530
2531 if (ret_offset < 0) {
2532 ret = -1;
2533
2534 goto func_exit;
2535 }
2536
2537 ret = write(file, buf, (ssize_t) n);
2538
2539func_exit:
2540# ifndef UNIV_HOTBACKUP
2541 os_mutex_exit(os_file_seek_mutexes[i]);
2542# endif /* !UNIV_HOTBACKUP */
2543
2544 os_mutex_enter(os_file_count_mutex);
2545 os_n_pending_writes--;
2546 MONITOR_DEC(MONITOR_OS_PENDING_WRITES);
2547 os_mutex_exit(os_file_count_mutex);
2548
2549 return(ret);
2550 }
2551#endif /* !UNIV_HOTBACKUP */
2552}2518}
2553#endif2519#endif
25542520
@@ -2659,6 +2625,13 @@
2659 retry = os_file_handle_error(NULL, "read");2625 retry = os_file_handle_error(NULL, "read");
26602626
2661 if (retry) {2627 if (retry) {
2628#ifndef _WIN32
2629 if (ret > 0 && (ulint) ret < n) {
2630 buf = (uchar*) buf + (ulint) ret;
2631 offset += (ulint) ret;
2632 n -= (ulint) ret;
2633 }
2634#endif
2662 goto try_again;2635 goto try_again;
2663 }2636 }
26642637
@@ -2782,6 +2755,13 @@
2782 retry = os_file_handle_error_no_exit(NULL, "read", FALSE);2755 retry = os_file_handle_error_no_exit(NULL, "read", FALSE);
27832756
2784 if (retry) {2757 if (retry) {
2758#ifndef _WIN32
2759 if (ret > 0 && (ulint) ret < n) {
2760 buf = (uchar*) buf + (ulint) ret;
2761 offset += ret;
2762 n -= (ulint) ret;
2763 }
2764#endif /* _WIN32 */
2785 goto try_again;2765 goto try_again;
2786 }2766 }
27872767
@@ -5047,6 +5027,7 @@
5047 segment = os_aio_get_array_and_local_segment(&array, global_seg);5027 segment = os_aio_get_array_and_local_segment(&array, global_seg);
5048 n = array->n_slots / array->n_segments;5028 n = array->n_slots / array->n_segments;
50495029
5030wait_for_event:
5050 /* Loop until we have found a completed request. */5031 /* Loop until we have found a completed request. */
5051 for (;;) {5032 for (;;) {
5052 ibool any_reserved = FALSE;5033 ibool any_reserved = FALSE;
@@ -5108,6 +5089,41 @@
5108 if (slot->ret == 0 && slot->n_bytes == (long) slot->len) {5089 if (slot->ret == 0 && slot->n_bytes == (long) slot->len) {
51095090
5110 ret = TRUE;5091 ret = TRUE;
5092 } else if ((slot->ret == 0) && (slot->n_bytes > 0)
5093 && (slot->n_bytes < (long) slot->len)) {
5094 /* Partial read or write scenario */
5095 int submit_ret;
5096 struct iocb* iocb;
5097 slot->buf = (byte*)slot->buf + slot->n_bytes;
5098 slot->offset = slot->offset + slot->n_bytes;
5099 slot->len = slot->len - slot->n_bytes;
5100 /* Resetting the bytes read/written */
5101 slot->n_bytes = 0;
5102 slot->io_already_done = false;
5103 iocb = &(slot->control);
5104
5105 if (slot->type == OS_FILE_READ) {
5106 io_prep_pread(&slot->control, slot->file, slot->buf,
5107 slot->len, (off_t) slot->offset);
5108 } else {
5109 ut_a(slot->type == OS_FILE_WRITE);
5110 io_prep_pwrite(&slot->control, slot->file, slot->buf,
5111 slot->len, (off_t) slot->offset);
5112 }
5113 /* Resubmit an I/O request */
5114 submit_ret = io_submit(array->aio_ctx[segment], 1, &iocb);
5115 if (submit_ret < 0 ) {
5116 /* Aborting in case of submit failure */
5117 ib_logf(IB_LOG_LEVEL_FATAL,
5118 "Native Linux AIO interface. io_submit()"
5119 " call failed when resubmitting a partial"
5120 " I/O request on the file %s.",
5121 slot->name);
5122 } else {
5123 ret = false;
5124 os_mutex_exit(array->mutex);
5125 goto wait_for_event;
5126 }
5111 } else {5127 } else {
5112 errno = -slot->ret;5128 errno = -slot->ret;
51135129

Subscribers

People subscribed via source and target branches