232
235
a file, so this is either "open" or
238
/****************************************************************//**
239
A simple function to open or create a file.
240
@return own: handle to the file, not defined if error, error number
241
can be retrieved with os_file_get_last_error */
244
xb_file_create_no_error_handling(
245
/*=============================*/
246
const char* name, /*!< in: name of the file or path as a
247
null-terminated string */
248
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
249
is opened (if does not exist, error), or
250
OS_FILE_CREATE if a new file is created
251
(if exists, error) */
252
ulint access_type,/*!< in: OS_FILE_READ_ONLY,
253
OS_FILE_READ_WRITE, or
254
OS_FILE_READ_ALLOW_DELETE; the last option is
255
used by a backup program reading the file */
256
ibool* success);/*!< out: TRUE if succeed, FALSE if error */
258
/****************************************************************//**
259
Opens an existing file or creates a new.
260
@return own: handle to the file, not defined if error, error number
261
can be retrieved with os_file_get_last_error */
266
const char* name, /*!< in: name of the file or path as a
267
null-terminated string */
268
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
269
is opened (if does not exist, error), or
270
OS_FILE_CREATE if a new file is created
272
OS_FILE_OVERWRITE if a new file is created
273
or an old overwritten;
274
OS_FILE_OPEN_RAW, if a raw device or disk
275
partition should be opened */
276
ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
277
non-buffered i/o is desired,
278
OS_FILE_NORMAL, if any normal file;
279
NOTE that it also depends on type, os_aio_..
280
and srv_.. variables whether we really use
281
async i/o or unbuffered i/o: look in the
282
function source code for the exact rules */
283
ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
284
ibool* success);/*!< out: TRUE if succeed, FALSE if error */
286
/***********************************************************************//**
287
Renames a file (can also move it to another directory). It is safest that the
288
file is closed before calling this function.
289
@return TRUE if success */
294
const char* oldpath,/*!< in: old file path as a null-terminated
296
const char* newpath);/*!< in: new file path */
302
os_file_t fd, /* in: file descriptor to alter */
303
const char* file_name, /* in: used in the diagnostic message */
304
const char* operation_name);/* in: used in the diagnostic message,
305
we call os_file_set_nocache()
306
immediately after opening or creating
307
a file, so this is either "open" or
238
310
#ifdef POSIX_FADV_NORMAL
239
311
#define USE_POSIX_FADVISE
1390
1468
will be passed to fdopen(), it will be closed by invoking
1391
1469
fclose(), which in turn will invoke close() instead of
1472
/* Note that on Windows, the integer returned by mysql_tmpfile
1473
has no relation to C runtime file descriptor. Here, we need
1474
to call my_get_osfhandle to get the HANDLE and then convert it
1475
to C runtime filedescriptor. */
1477
HANDLE hFile = my_get_osfhandle(fd);
1480
DuplicateHandle(GetCurrentProcess(), hFile,
1481
GetCurrentProcess(), &hDup, 0,
1482
FALSE, DUPLICATE_SAME_ACCESS);
1484
fd2 = _open_osfhandle((intptr_t)hDup,0);
1487
my_osmaperr(GetLastError());
1395
1495
fprintf(stderr, "xtrabackup: Got error %d on dup\n",fd2);
2523
#ifdef INNODB_VERSION_SHORT
2524
#define XB_HASH_SEARCH(NAME, TABLE, FOLD, DATA, ASSERTION, TEST) \
2525
HASH_SEARCH(NAME, TABLE, FOLD, xtrabackup_tables_t*, DATA, ASSERTION, \
2528
#define XB_HASH_SEARCH(NAME, TABLE, FOLD, DATA, ASSERTION, TEST) \
2529
HASH_SEARCH(NAME, TABLE, FOLD, DATA, TEST)
2532
/****************************************************************//**
2533
A simple function to open or create a file.
2534
@return own: handle to the file, not defined if error, error number
2535
can be retrieved with os_file_get_last_error */
2538
xb_file_create_no_error_handling(
2539
/*=============================*/
2540
const char* name, /*!< in: name of the file or path as a
2541
null-terminated string */
2542
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
2543
is opened (if does not exist, error), or
2544
OS_FILE_CREATE if a new file is created
2545
(if exists, error) */
2546
ulint access_type,/*!< in: OS_FILE_READ_ONLY,
2547
OS_FILE_READ_WRITE, or
2548
OS_FILE_READ_ALLOW_DELETE; the last option is
2549
used by a backup program reading the file */
2550
ibool* success)/*!< out: TRUE if succeed, FALSE if error */
2552
#if MYSQL_VERSION_ID > 50500
2553
return os_file_create_simple_no_error_handling(
2554
0, /* innodb_file_data_key */
2555
name, create_mode, access_type, success);
2557
return os_file_create_simple_no_error_handling(
2558
name, create_mode, access_type, success);
2562
/****************************************************************//**
2563
Opens an existing file or creates a new.
2564
@return own: handle to the file, not defined if error, error number
2565
can be retrieved with os_file_get_last_error */
2570
const char* name, /*!< in: name of the file or path as a
2571
null-terminated string */
2572
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
2573
is opened (if does not exist, error), or
2574
OS_FILE_CREATE if a new file is created
2576
OS_FILE_OVERWRITE if a new file is created
2577
or an old overwritten;
2578
OS_FILE_OPEN_RAW, if a raw device or disk
2579
partition should be opened */
2580
ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
2581
non-buffered i/o is desired,
2582
OS_FILE_NORMAL, if any normal file;
2583
NOTE that it also depends on type, os_aio_..
2584
and srv_.. variables whether we really use
2585
async i/o or unbuffered i/o: look in the
2586
function source code for the exact rules */
2587
ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
2588
ibool* success)/*!< out: TRUE if succeed, FALSE if error */
2590
#if MYSQL_VERSION_ID > 50500
2591
return os_file_create(0 /* innodb_file_data_key */,
2592
name, create_mode, purpose, type, success);
2594
return os_file_create(name, create_mode, purpose, type, success);
2598
/***********************************************************************//**
2599
Renames a file (can also move it to another directory). It is safest that the
2600
file is closed before calling this function.
2601
@return TRUE if success */
2606
const char* oldpath,/*!< in: old file path as a null-terminated
2608
const char* newpath)/*!< in: new file path */
2610
#if MYSQL_VERSION_ID > 50500
2611
return os_file_rename(
2612
0 /* innodb_file_data_key */, oldpath, newpath);
2614
return os_file_rename(oldpath, newpath);
2620
xb_file_set_nocache(
2621
/*================*/
2622
os_file_t fd, /* in: file descriptor to alter */
2623
const char* file_name, /* in: used in the diagnostic message */
2624
const char* operation_name) /* in: used in the diagnostic message,
2625
we call os_file_set_nocache()
2626
immediately after opening or creating
2627
a file, so this is either "open" or
2631
if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
2632
os_file_set_nocache(fd, file_name, operation_name);
2428
2637
/* TODO: We may tune the behavior (e.g. by fil_aio)*/
2429
2638
#define COPY_CHUNK 64
2645
2846
/* open dst_file */
2646
/* os_file_create reads srv_unix_file_flush_method */
2647
dst_file = os_file_create(
2648
#if (MYSQL_VERSION_ID > 50500)
2649
0 /* dummy of innodb_file_data_key */,
2651
dst_path, OS_FILE_CREATE,
2652
OS_FILE_NORMAL, OS_DATA_FILE, &success);
2654
/* The following call prints an error message */
2655
os_file_get_last_error(TRUE);
2847
/* xb_file_create reads srv_unix_file_flush_method */
2848
dst_file = xb_file_create(dst_path, OS_FILE_CREATE,
2849
OS_FILE_NORMAL, OS_DATA_FILE, &success);
2851
/* The following call prints an error message */
2852
os_file_get_last_error(TRUE);
2657
fprintf(stderr,"[%02u] xtrabackup: error: "
2658
"cannot open %s\n", thread_n, dst_path);
2854
fprintf(stderr,"[%02u] xtrabackup: error: "
2855
"cannot open %s\n", thread_n, dst_path);
2662
2859
#ifdef USE_POSIX_FADVISE
2663
2860
posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
3407
3602
} else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
3408
3603
srv_unix_file_flush_method = SRV_UNIX_NOSYNC;
3410
} else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
3411
srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
3412
os_aio_use_native_aio = FALSE;
3414
} else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
3415
srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
3416
os_aio_use_native_aio = FALSE;
3418
} else if (0 == ut_strcmp(srv_file_flush_method_str,
3419
"async_unbuffered")) {
3420
srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
3423
3605
fprintf(stderr,
3424
3606
"xtrabackup: Unrecognized value %s for innodb_flush_method\n",
3425
3607
srv_file_flush_method_str);
3426
3608
exit(EXIT_FAILURE);
3611
/* We can only use synchronous unbuffered IO on Windows for now */
3612
if (srv_file_flush_method_str != NULL) {
3614
"xtrabackupp: Warning: "
3615
"ignoring innodb_flush_method = %s on Windows.\n");
3618
srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
3619
srv_use_native_aio = FALSE;
3429
3622
#ifndef INNODB_VERSION_SHORT
3430
3623
if (srv_pool_size >= 1000 * 1024) {
3703
3896
/* open 'xtrabackup_logfile' */
3704
3897
sprintf(dst_log_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
3705
3898
srv_normalize_path_for_win(dst_log_path);
3706
/* os_file_create reads srv_unix_file_flush_method for OS_DATA_FILE*/
3707
dst_log = os_file_create(
3708
#if (MYSQL_VERSION_ID > 50500)
3709
0 /* dummy of innodb_file_data_key */,
3711
dst_log_path, OS_FILE_CREATE,
3712
OS_FILE_NORMAL, OS_DATA_FILE, &success);
3899
/* xb_file_create reads srv_unix_file_flush_method for
3901
dst_log = xb_file_create(dst_log_path, OS_FILE_CREATE,
3902
OS_FILE_NORMAL, OS_DATA_FILE,
3714
3905
if (!success) {
3715
3906
/* The following call prints an error message */
3848
4039
"/xtrabackup_suspended");
3850
4041
srv_normalize_path_for_win(suspend_path);
3851
/* os_file_create reads srv_unix_file_flush_method */
3852
suspend_file = os_file_create(
3853
#if (MYSQL_VERSION_ID > 50500)
3854
0 /* dummy of innodb_file_data_key */,
3856
suspend_path, OS_FILE_OVERWRITE,
3857
OS_FILE_NORMAL, OS_DATA_FILE, &success);
4042
/* xb_file_create reads srv_unix_file_flush_method */
4043
suspend_file = xb_file_create(suspend_path, OS_FILE_OVERWRITE,
4044
OS_FILE_NORMAL, OS_DATA_FILE,
3859
4047
if (!success) {
3860
4048
fprintf(stderr, "xtrabackup: Error: failed to create file 'xtrabackup_suspended'\n");
3863
if (suspend_file != -1)
4051
if (suspend_file != XB_FILE_UNDEFINED)
3864
4052
os_file_close(suspend_file);