diff options
Diffstat (limited to 'innobase/os')
-rw-r--r-- | innobase/os/os0file.c | 189 | ||||
-rw-r--r-- | innobase/os/os0proc.c | 5 | ||||
-rw-r--r-- | innobase/os/os0thread.c | 2 |
3 files changed, 123 insertions, 73 deletions
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 7973cfc6fe8..3f14a2158ed 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -234,7 +234,7 @@ os_file_get_last_error( "InnoDB: of the same name as a data file.\n"); } else { fprintf(stderr, - "InnoDB: See section 13.2 at http://www.innodb.com/ibman.html\n" + "InnoDB: See section 13.2 at http://www.innodb.com/ibman.php\n" "InnoDB: about operating system error numbers.\n"); } } @@ -258,7 +258,7 @@ os_file_get_last_error( ut_print_timestamp(stderr); fprintf(stderr, - " InnoDB: Operating system error number %lu in a file operation.\n", err); + " InnoDB: Operating system error number %lu in a file operation.\n", (ulong) err); if (err == ENOENT) { fprintf(stderr, @@ -280,7 +280,7 @@ os_file_get_last_error( } fprintf(stderr, - "InnoDB: See also section 13.2 at http://www.innodb.com/ibman.html\n" + "InnoDB: See also section 13.2 at http://www.innodb.com/ibman.php\n" "InnoDB: about operating system error numbers.\n"); } } @@ -312,7 +312,7 @@ os_file_handle_error( /* out: TRUE if we should retry the operation */ os_file_t file, /* in: file pointer */ - char* name, /* in: name of a file or NULL */ + const char* name, /* in: name of a file or NULL */ const char* operation)/* in: operation */ { ulint err; @@ -369,6 +369,32 @@ os_file_handle_error( return(FALSE); } +#if !defined(__WIN__) && !defined(UNIV_HOTBACKUP) +/******************************************************************** +Obtain an exclusive lock on a file. */ +static +int +os_file_lock( +/*=========*/ + /* out: 0 on success */ + int fd, /* in: file descriptor */ + const char* name) /* in: file name */ +{ + struct flock lk; + lk.l_type = F_WRLCK; + lk.l_whence = SEEK_SET; + lk.l_start = lk.l_len = 0; + if (fcntl(fd, F_SETLK, &lk) == -1) { + fprintf(stderr, + "InnoDB: Unable to lock %s", name); + perror (": fcntl"); + close(fd); + return(-1); + } + return 0; +} +#endif /* !defined(__WIN__) && !defined(UNIV_HOTBACKUP) */ + /******************************************************************** Does error handling when a file operation fails. */ static @@ -781,7 +807,7 @@ try_again: } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; ibool retry; @@ -826,12 +852,17 @@ try_again: if (retry) { goto try_again; } +#ifndef UNIV_HOTBACKUP + } else if (os_file_lock(file, name)) { + *success = FALSE; + file = -1; +#endif } else { *success = TRUE; } return(file); -#endif +#endif /* __WIN__ */ } /******************************************************************** @@ -902,7 +933,7 @@ os_file_create_simple_no_error_handling( } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; @@ -930,12 +961,17 @@ os_file_create_simple_no_error_handling( if (file == -1) { *success = FALSE; +#ifndef UNIV_HOTBACKUP + } else if (os_file_lock(file, name)) { + *success = FALSE; + file = -1; +#endif } else { *success = TRUE; } return(file); -#endif +#endif /* __WIN__ */ } /******************************************************************** @@ -1056,7 +1092,7 @@ try_again: } return(file); -#else +#else /* __WIN__ */ os_file_t file; int create_flag; ibool retry; @@ -1097,7 +1133,7 @@ try_again: ut_error; } -/* printf("Opening file %s, mode %s, type %s, purpose %s\n", +/* fprintf(stderr, "Opening file %s, mode %s, type %s, purpose %s\n", name, mode_str, type_str, purpose_str); */ #ifdef O_SYNC /* We let O_SYNC only affect log files; note that we map O_DSYNC to @@ -1106,7 +1142,7 @@ try_again: if (type == OS_LOG_FILE && srv_unix_file_flush_method == SRV_UNIX_O_DSYNC) { -/* printf("Using O_SYNC for file %s\n", name); */ +/* fprintf(stderr, "Using O_SYNC for file %s\n", name); */ create_flag = create_flag | O_SYNC; } @@ -1116,7 +1152,7 @@ try_again: if (type != OS_LOG_FILE && srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) { -/* printf("Using O_DIRECT for file %s\n", name); */ +/* fprintf(stderr, "Using O_DIRECT for file %s\n", name); */ create_flag = create_flag | O_DIRECT; } @@ -1136,12 +1172,17 @@ try_again: if (retry) { goto try_again; } +#ifndef UNIV_HOTBACKUP + } else if (os_file_lock(file, name)) { + *success = FALSE; + file = -1; +#endif } else { *success = TRUE; } return(file); -#endif +#endif /* __WIN__ */ } /*************************************************************************** @@ -1542,6 +1583,23 @@ error_handling: } /*************************************************************************** +Truncates a file at its current position. */ + +ibool +os_file_set_eof( +/*============*/ + /* out: TRUE if success */ + FILE* file) /* in: file to be truncated */ +{ +#ifdef __WIN__ + HANDLE h = (HANDLE) _get_osfhandle(fileno(file)); + return(SetEndOfFile(h)); +#else /* __WIN__ */ + return(!ftruncate(fileno(file), ftell(file))); +#endif /* __WIN__ */ +} + +/*************************************************************************** Flushes the write buffers of a given file to the disk. */ ibool @@ -1585,7 +1643,7 @@ os_file_flush( #ifdef HAVE_FDATASYNC ret = fdatasync(file); #else -/* printf("Flushing to file %lu\n", (ulint)file); */ +/* fprintf(stderr, "Flushing to file %p\n", file); */ ret = fsync(file); #endif os_n_fsyncs++; @@ -2029,7 +2087,7 @@ retry: fprintf(stderr, " InnoDB: Error: File pointer positioning to file %s failed at\n" "InnoDB: offset %lu %lu. Operating system error number %lu.\n" -"InnoDB: Look from section 13.2 at http://www.innodb.com/ibman.html\n" +"InnoDB: Look from section 13.2 at http://www.innodb.com/ibman.php\n" "InnoDB: what the error number means.\n", name, (ulong) offset_high, (ulong) offset, (ulong) GetLastError()); @@ -2087,7 +2145,7 @@ retry: } fprintf(stderr, -"InnoDB: See also section 13.2 at http://www.innodb.com/ibman.html\n" +"InnoDB: See also section 13.2 at http://www.innodb.com/ibman.php\n" "InnoDB: about operating system error numbers.\n"); os_has_said_disk_full = TRUE; @@ -2122,7 +2180,7 @@ retry: } fprintf(stderr, -"InnoDB: See also section 13.2 at http://www.innodb.com/ibman.html\n" +"InnoDB: See also section 13.2 at http://www.innodb.com/ibman.php\n" "InnoDB: about operating system error numbers.\n"); os_has_said_disk_full = TRUE; @@ -2412,33 +2470,35 @@ os_aio_init( os_io_init_simple(); for (i = 0; i < n_segments; i++) { - srv_io_thread_op_info[i] = (char*)"not started yet"; + srv_set_io_thread_op_info(i, "not started yet"); } n_per_seg = n / n_segments; n_write_segs = (n_segments - 2) / 2; n_read_segs = n_segments - 2 - n_write_segs; - /* printf("Array n per seg %lu\n", n_per_seg); */ + /* fprintf(stderr, "Array n per seg %lu\n", n_per_seg); */ os_aio_ibuf_array = os_aio_array_create(n_per_seg, 1); - srv_io_thread_function[0] = (char*)"insert buffer thread"; + srv_io_thread_function[0] = "insert buffer thread"; os_aio_log_array = os_aio_array_create(n_per_seg, 1); - srv_io_thread_function[1] = (char*)"log thread"; + srv_io_thread_function[1] = "log thread"; os_aio_read_array = os_aio_array_create(n_read_segs * n_per_seg, n_read_segs); for (i = 2; i < 2 + n_read_segs; i++) { - srv_io_thread_function[i] = (char*)"read thread"; + ut_a(i < SRV_MAX_N_IO_THREADS); + srv_io_thread_function[i] = "read thread"; } os_aio_write_array = os_aio_array_create(n_write_segs * n_per_seg, n_write_segs); for (i = 2 + n_read_segs; i < n_segments; i++) { - srv_io_thread_function[i] = (char*)"write thread"; + ut_a(i < SRV_MAX_N_IO_THREADS); + srv_io_thread_function[i] = "write thread"; } os_aio_sync_array = os_aio_array_create(n_slots_sync, 1); @@ -2768,7 +2828,8 @@ loop: SIGRTMIN + 1 + os_aio_get_array_no(array); /* TODO: How to choose the signal numbers? */ /* - printf("AIO signal number %lu\n", (ulint) control->aio_sigevent.sigev_signo); + fprintf(stderr, "AIO signal number %lu\n", + (ulint) control->aio_sigevent.sigev_signo); */ control->aio_sigevent.sigev_value.sival_ptr = slot; #endif @@ -3022,7 +3083,7 @@ try_again: #elif defined(POSIX_ASYNC_IO) slot->control.aio_lio_opcode = LIO_READ; err = (ulint) aio_read(&(slot->control)); - printf("Starting Posix aio read %lu\n", err); + fprintf(stderr, "Starting POSIX aio read %lu\n", err); #endif } else { if (!wake_later) { @@ -3039,7 +3100,7 @@ try_again: #elif defined(POSIX_ASYNC_IO) slot->control.aio_lio_opcode = LIO_WRITE; err = (ulint) aio_write(&(slot->control)); - printf("Starting Posix aio write %lu\n", err); + fprintf(stderr, "Starting POSIX aio write %lu\n", err); #endif } else { if (!wake_later) { @@ -3150,13 +3211,10 @@ os_aio_windows_handle( n = array->n_slots / array->n_segments; if (array == os_aio_sync_array) { - srv_io_thread_op_info[orig_seg] = - "wait Windows aio for 1 page"; os_event_wait(os_aio_array_get_nth_slot(array, pos)->event); i = pos; } else { - srv_io_thread_op_info[orig_seg] = - "wait Windows aio"; + srv_set_io_thread_op_info(orig_seg, "wait Windows aio"); i = os_event_wait_multiple(n, (array->native_events) + segment * n); } @@ -3167,7 +3225,11 @@ os_aio_windows_handle( ut_a(slot->reserved); - srv_io_thread_op_info[orig_seg] = "get windows aio return value"; + if (orig_seg != ULINT_UNDEFINED) { + srv_set_io_thread_op_info(orig_seg, + "get windows aio return value"); + } + ret = GetOverlappedResult(slot->file, &(slot->control), &len, TRUE); *message1 = slot->message1; @@ -3234,7 +3296,7 @@ os_aio_posix_handle( pthread_sigmask(0, NULL, &thr_sigset); for (i = 32 ; i < 40; i++) { - printf("%lu : %lu %lu\n", (ulint)i, + fprintf(stderr, "%lu : %lu %lu\n", (ulint)i, (ulint)sigismember(&proc_sigset, i), (ulint)sigismember(&thr_sigset, i)); } @@ -3249,7 +3311,7 @@ os_aio_posix_handle( return(FALSE); } - printf("Handling Posix aio\n"); + fputs("Handling POSIX aio\n", stderr); array = os_aio_get_array_from_no(array_no); @@ -3489,8 +3551,8 @@ consecutive_loop: offs += consecutive_ios[i]->len; } } - - srv_io_thread_op_info[global_segment] = (char*) "doing file i/o"; + + srv_set_io_thread_op_info(global_segment, "doing file i/o"); if (os_aio_print_debug) { fprintf(stderr, @@ -3541,11 +3603,11 @@ consecutive_loop: } ut_a(ret); - srv_io_thread_op_info[global_segment] = (char*) "file i/o done"; + srv_set_io_thread_op_info(global_segment, "file i/o done"); -/* printf("aio: %lu consecutive %lu:th segment, first offs %lu blocks\n", - n_consecutive, global_segment, slot->offset - / UNIV_PAGE_SIZE); */ +/* fprintf(stderr, + "aio: %lu consecutive %lu:th segment, first offs %lu blocks\n", + n_consecutive, global_segment, slot->offset / UNIV_PAGE_SIZE); */ if (slot->type == OS_FILE_READ && n_consecutive > 1) { /* Copy the combined buffer to individual buffers */ @@ -3599,8 +3661,7 @@ wait_for_io: os_mutex_exit(array->mutex); recommended_sleep: - srv_io_thread_op_info[global_segment] = - (char*)"waiting for i/o request"; + srv_set_io_thread_op_info(global_segment, "waiting for i/o request"); os_event_wait(os_aio_segment_wait_events[global_segment]); @@ -3672,8 +3733,7 @@ Prints info of the aio arrays. */ void os_aio_print( /*=========*/ - char* buf, /* in/out: buffer where to print */ - char* buf_end)/* in: buffer end */ + FILE* file) /* in: file where to print */ { os_aio_array_t* array; os_aio_slot_t* slot; @@ -3683,19 +3743,13 @@ os_aio_print( double avg_bytes_read; ulint i; - if (buf_end - buf < 1200) { - - return; - } - for (i = 0; i < srv_n_file_io_threads; i++) { - buf += sprintf(buf, "I/O thread %lu state: %s (%s)\n", - (ulong) i, + fprintf(file, "I/O thread %lu state: %s (%s)\n", (ulong) i, srv_io_thread_op_info[i], srv_io_thread_function[i]); } - buf += sprintf(buf, "Pending normal aio reads:"); + fputs("Pending normal aio reads:", file); array = os_aio_read_array; loop: @@ -3713,21 +3767,20 @@ loop: if (slot->reserved) { n_reserved++; - /* printf("Reserved slot, messages %lx %lx\n", - (ulint)slot->message1, - (ulint)slot->message2); - */ ut_a(slot->len > 0); + /* fprintf(stderr, "Reserved slot, messages %p %p\n", + slot->message1, slot->message2); */ + ut_a(slot->len > 0); } } ut_a(array->n_reserved == n_reserved); - buf += sprintf(buf, " %lu", (ulong) n_reserved); + fprintf(file, " %lu", (ulong) n_reserved); os_mutex_exit(array->mutex); if (array == os_aio_read_array) { - buf += sprintf(buf, ", aio writes:"); + fputs(", aio writes:", file); array = os_aio_write_array; @@ -3735,42 +3788,40 @@ loop: } if (array == os_aio_write_array) { - buf += sprintf(buf, ",\n ibuf aio reads:"); + fputs(",\n ibuf aio reads:", file); array = os_aio_ibuf_array; goto loop; } if (array == os_aio_ibuf_array) { - buf += sprintf(buf, ", log i/o's:"); + fputs(", log i/o's:", file); array = os_aio_log_array; goto loop; } if (array == os_aio_log_array) { - buf += sprintf(buf, ", sync i/o's:"); + fputs(", sync i/o's:", file); array = os_aio_sync_array; goto loop; } - buf += sprintf(buf, "\n"); - + putc('\n', file); current_time = time(NULL); time_elapsed = 0.001 + difftime(current_time, os_last_printout); - buf += sprintf(buf, - "Pending flushes (fsync) log: %lu; buffer pool: %lu\n", - (ulong) fil_n_pending_log_flushes, - (ulong) fil_n_pending_tablespace_flushes); - buf += sprintf(buf, + fprintf(file, + "Pending flushes (fsync) log: %lu; buffer pool: %lu\n" "%lu OS file reads, %lu OS file writes, %lu OS fsyncs\n", + (ulong) fil_n_pending_log_flushes, + (ulong) fil_n_pending_tablespace_flushes, (ulong) os_n_file_reads, (ulong) os_n_file_writes, (ulong) os_n_fsyncs); if (os_file_n_pending_preads != 0 || os_file_n_pending_pwrites != 0) { - buf += sprintf(buf, + fprintf(file, "%lu pending preads, %lu pending pwrites\n", (ulong) os_file_n_pending_preads, (ulong) os_file_n_pending_pwrites); @@ -3783,7 +3834,7 @@ loop: (os_n_file_reads - os_n_file_reads_old); } - buf += sprintf(buf, + fprintf(file, "%.2f reads/s, %lu avg bytes/read, %.2f writes/s, %.2f fsyncs/s\n", (os_n_file_reads - os_n_file_reads_old) / time_elapsed, diff --git a/innobase/os/os0proc.c b/innobase/os/os0proc.c index 85791c55348..2f155788420 100644 --- a/innobase/os/os0proc.c +++ b/innobase/os/os0proc.c @@ -539,9 +539,8 @@ os_process_set_priority_boost( /* Does not do anything currently! SetProcessPriorityBoost(GetCurrentProcess(), no_boost); */ - printf( - "Warning: process priority boost setting currently not functional!\n" - ); + fputs("Warning: process priority boost setting currently not functional!\n", + stderr); #else UT_NOT_USED(do_boost); #endif diff --git a/innobase/os/os0thread.c b/innobase/os/os0thread.c index 1252cc5e4b7..59d0fdbd8c9 100644 --- a/innobase/os/os0thread.c +++ b/innobase/os/os0thread.c @@ -187,7 +187,7 @@ os_thread_exit( is cast as a DWORD */ { #ifdef UNIV_DEBUG_THREAD_CREATION - printf("Thread exits, id %lu\n", + fprintf(stderr, "Thread exits, id %lu\n", os_thread_pf(os_thread_get_curr_id())); #endif os_mutex_enter(os_sync_mutex); |