Merge lp:~percona-dev/percona-xtrabackup/percona-xtrabackup-windows into lp:percona-xtrabackup/2.0

Proposed by Alexey Kopytov
Status: Merged
Approved by: Vadim Tkachenko
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~percona-dev/percona-xtrabackup/percona-xtrabackup-windows
Merge into: lp:percona-xtrabackup/2.0
Diff against target: 1336 lines (+573/-208)
7 files modified
BUILD-WIN.txt (+83/-0)
CMakeLists.txt (+59/-0)
Makefile (+1/-4)
test/t/ib_partition.sh (+4/-4)
utils/build.sh (+1/-1)
xb_regex.h (+71/-0)
xtrabackup.c (+354/-199)
To merge this branch: bzr merge lp:~percona-dev/percona-xtrabackup/percona-xtrabackup-windows
Reviewer Review Type Date Requested Status
Vadim Tkachenko Approve
Valentine Gostev (community) qa Approve
Review via email: mp+58045@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Vadim Tkachenko (vadim-tk) wrote :

Looks good. I assume Unix test pass.?

review: Approve
Revision history for this message
Vadim Tkachenko (vadim-tk) wrote :

I am trying to build on x64 under
"Visual Studio 10 Win64"
and I got:

2>xtrabackup.c(5909): error C2198: 'my_regex_init' : too few arguments for call

review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) wrote :

It's not merged into trunk yet, restoring the status.

Revision history for this message
Valentine Gostev (longbow) wrote :

Linux tests are good.

review: Approve (qa)
Revision history for this message
Vadim Tkachenko (vadim-tk) wrote :

ok for me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'BUILD-WIN.txt'
2--- BUILD-WIN.txt 1970-01-01 00:00:00 +0000
3+++ BUILD-WIN.txt 2011-04-21 06:37:17 +0000
4@@ -0,0 +1,83 @@
5+How to build XtraBackup on Windows
6+==================================
7+
8+Prerequisites:
9+--------------
10+
11+To build XtraBackup on Windows you need the following:
12+
13+- a Windows installation. These instructions have been tested on
14+ Windows XP.
15+
16+- CMake, an open source build system available from
17+ http://www.cmake.org/
18+
19+- Visual Studio. Both commercial and Express editions should work. These
20+ instructions have been tested on Visual Studio 2005 Express.
21+
22+- the patch utility. The Windows version can be downloaded from
23+ http://gnuwin32.sourceforge.net/packages/patch.htm
24+
25+*** Important note for Windows Vista and Windows 7 users ***
26+
27+These Windows versions demand running any executable with the word
28+'patch' in the name only with administrative privileges. So if want to
29+use the patch utility under an unprivileged user account, you should
30+rename "patch.exe" to something else, e.g. "patsh.exe".
31+
32+Building instructions:
33+----------------------
34+
35+1. Download the source code for the appropriate version of the
36+server. You can check the currently supported version by looking up the
37+value of the MYSQL_55_VERSION variable in utils/build.sh.
38+
39+The currently supported version is usually older than the latest
40+released one. Older versions are available from
41+http://downloads.mysql.com/archives.php
42+
43+2. Unpack and patch the server source.
44+
45+- unpack the server source archive downloaded at step 1.
46+
47+- start Visual Studio Command Prompt and run the following commands:
48+
49+cd "folder with the server source tree"
50+patch --binary -p1 -i "path to the xtrabackup source tree"\patches\innodb55.patch
51+
52+Make sure the patch utility is in the PATH environment variable or
53+specify the full path to it. Replace "patch" with the new name if you
54+had to rename it on Vista/7 (see the notes above ).
55+
56+The --binary switch is required to make patch work with the Unix
57+end-of-line format.
58+
59+3. Build the patched server source:
60+
61+Run the following commands from the server source folder:
62+
63+cmake . -G "Visual Studio 8 2005" -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=ON -DWITH_PARTITION_STORAGE_ENGINE=ON -DWITH_ZLIB=bundled -DWITH_EXTRA_CHARSETS=all
64+
65+devenv mysql.sln /build relwithdebinfo
66+
67+The -G argument should be the Visual Studio version that will be used to
68+build. The complete list of available generators can be found in the
69+CMake documentation. Make sure to add the "Win64" suffix when creating
70+an x64 build.
71+
72+You may also need to replace "devenv" with "vcexpress" for Express editions
73+of Visual Studio.
74+
75+4. Build XtraBackup:
76+
77+From the XtraBackup source folder:
78+
79+cmake . -G "Visual Studio 8 2005"
80+ -DMYSQL_ROOT_DIR="path to the server source folder built at step #3"
81+
82+devenv xtrabackup.sln /build relwithdebinfo
83+
84+The same comments about the -G argument and devenv from #3 apply here as well.
85+
86+Once the build completes xtrabackup.exe can be found in the
87+relwithdebinfo subfolder of the XtraBackup source folder.
88
89=== added file 'CMakeLists.txt'
90--- CMakeLists.txt 1970-01-01 00:00:00 +0000
91+++ CMakeLists.txt 2011-04-21 06:37:17 +0000
92@@ -0,0 +1,59 @@
93+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
94+IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.6)
95+ CMAKE_POLICY(VERSION 2.8)
96+ENDIF()
97+
98+IF (NOT DEFINED MYSQL_ROOT_DIR)
99+ MESSAGE(FATAL_ERROR
100+ "You must specify a path to the server source directory with
101+ -DMYSQL_ROOT_DIR")
102+ENDIF()
103+
104+if(COMMAND cmake_policy)
105+ cmake_policy(SET CMP0015 NEW)
106+endif(COMMAND cmake_policy)
107+
108+LINK_DIRECTORIES (
109+ ${MYSQL_ROOT_DIR}/mysys/RelWithDebInfo
110+ ${MYSQL_ROOT_DIR}/strings/RelWithDebInfo
111+ ${MYSQL_ROOT_DIR}/storage/innobase/RelWithDebInfo
112+ ${MYSQL_ROOT_DIR}/zlib/RelWithDebInfo
113+ ${MYSQL_ROOT_DIR}/regex/RelWithDebInfo
114+)
115+
116+PROJECT(XtraBackup)
117+ADD_EXECUTABLE(xtrabackup
118+ xtrabackup.c
119+ xb_regex.h
120+)
121+
122+if(COMMAND cmake_policy)
123+ cmake_policy(SET CMP0016 NEW)
124+endif(COMMAND cmake_policy)
125+
126+# Enable debug info also in Release build, and create PDB to be able to
127+# analyze crashes
128+SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
129+SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /debug")
130+
131+# Force static runtime libraries
132+FOREACH(flag
133+ CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
134+ CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
135+ CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO
136+ CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG_INIT)
137+ STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}")
138+ENDFOREACH()
139+
140+# Silence "deprecated API" warnings.
141+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
142+
143+INCLUDE_DIRECTORIES(
144+ ${MYSQL_ROOT_DIR}/include
145+ ${MYSQL_ROOT_DIR}/regex
146+ ${MYSQL_ROOT_DIR}/storage/innobase/include
147+)
148+
149+TARGET_LINK_LIBRARIES(xtrabackup mysys strings innobase zlib regex)
150+ADD_DEFINITIONS(-DDBUG_OFF -DHAVE_CONFIG_H -DWIN_ASYNC_IO
151+ -DHAVE_WINDOWS_ATOMICS)
152
153=== modified file 'Makefile'
154--- Makefile 2011-03-23 20:08:04 +0000
155+++ Makefile 2011-04-21 06:37:17 +0000
156@@ -128,7 +128,7 @@
157 xtradb55: $(TARGET)
158
159
160-xtrabackup.o: xtrabackup.c
161+xtrabackup.o: xtrabackup.c xb_regex.h
162 $(CC) $(CFLAGS) $(INC) $(DEFS) -c $*.c
163
164 $(TARGET): xtrabackup.o $(INNODBOBJS) $(MYSQLOBJS)
165@@ -136,6 +136,3 @@
166
167 clean:
168 rm -f *.o xtrabackup_*
169-install:
170- install -m 755 innobackupex-1.5.1 $(BIN_DIR)
171- install -m 755 xtrabackup_* $(BIN_DIR)
172
173=== removed symlink 'innobackupex-1.5.1'
174=== target was 'innobackupex'
175=== modified file 'test/t/ib_partition.sh'
176--- test/t/ib_partition.sh 2011-03-16 18:07:07 +0000
177+++ test/t/ib_partition.sh 2011-04-21 06:37:17 +0000
178@@ -29,12 +29,12 @@
179 # partial backup of partitioned table
180 mkdir -p $topdir/data/full
181 vlog "Starting backup"
182-innobackupex-1.5.1 --user=root --socket=$mysql_socket --defaults-file=$topdir/my.cnf --tables-file=$topdir/list $topdir/data/full > $OUTFILE 2>&1 || die "innobackupex-1.5.1 died with exit code $?"
183-backup_dir=`grep "innobackupex-1.5.1: Backup created in directory" $OUTFILE | awk -F\' '{ print $2}'`
184+innobackupex --user=root --socket=$mysql_socket --defaults-file=$topdir/my.cnf --tables-file=$topdir/list $topdir/data/full > $OUTFILE 2>&1 || die "innobackupex-1.5.1 died with exit code $?"
185+backup_dir=`grep "innobackupex: Backup created in directory" $OUTFILE | awk -F\' '{ print $2}'`
186 vlog "Partial backup done"
187
188 # Prepare backup
189-innobackupex-1.5.1 --defaults-file=$topdir/my.cnf --apply-log $backup_dir
190+innobackupex --defaults-file=$topdir/my.cnf --apply-log $backup_dir
191 vlog "Log applied to backup"
192
193 # removing rows
194@@ -47,7 +47,7 @@
195
196 vlog "Copying files"
197 rm -rf $mysql_datadir/part_range_sample
198-innobackupex-1.5.1 --copy-back --defaults-file=$topdir/my.cnf $backup_dir
199+innobackupex --copy-back --defaults-file=$topdir/my.cnf $backup_dir
200 vlog "Data restored"
201
202 run_mysqld --innodb_file_per_table
203
204=== modified file 'utils/build.sh'
205--- utils/build.sh 2011-04-17 10:13:53 +0000
206+++ utils/build.sh 2011-04-21 06:37:17 +0000
207@@ -90,7 +90,7 @@
208 {
209 echo "Building XtraBackup"
210 mkdir $build_dir
211- cp $top_dir/Makefile $top_dir/xtrabackup.c $build_dir
212+ cp $top_dir/Makefile $top_dir/xtrabackup.c $top_dir/xb_regex.h $build_dir
213
214 cd $build_dir
215 $MAKE_CMD $xtrabackup_target
216
217=== added file 'xb_regex.h'
218--- xb_regex.h 1970-01-01 00:00:00 +0000
219+++ xb_regex.h 2011-04-21 06:37:17 +0000
220@@ -0,0 +1,71 @@
221+/******************************************************
222+Copyright (c) 2011 Percona Inc.
223+
224+This program is free software; you can redistribute it and/or modify
225+it under the terms of the GNU General Public License as published by
226+the Free Software Foundation; version 2 of the License.
227+
228+This program is distributed in the hope that it will be useful,
229+but WITHOUT ANY WARRANTY; without even the implied warranty of
230+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231+GNU General Public License for more details.
232+
233+You should have received a copy of the GNU General Public License
234+along with this program; if not, write to the Free Software
235+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
236+
237+*******************************************************/
238+
239+/* This file is required to abstract away regex(3) calls so that
240+my_regex is used on Windows and native calls are used on POSIX platforms. */
241+
242+#ifndef XB_REGEX_H
243+#define XB_REGEX_H
244+
245+#ifdef _WIN32
246+
247+#include <my_regex.h>
248+
249+typedef my_regex_t xb_regex_t;
250+typedef my_regmatch_t xb_regmatch_t;
251+
252+#define xb_regex_init() my_regex_init(&my_charset_latin1)
253+
254+#define xb_regexec(preg,string,nmatch,pmatch,eflags) \
255+ my_regexec(preg, string, nmatch, pmatch, eflags)
256+
257+#define xb_regerror(errcode,preg,errbuf,errbuf_size) \
258+ my_regerror(errcode, preg, errbuf, errbuf_size)
259+
260+#define xb_regcomp(preg,regex,cflags) \
261+ my_regcomp(preg, regex, cflags, &my_charset_latin1)
262+
263+#define xb_regfree(preg) my_regfree(preg)
264+
265+#define xb_regex_end() my_regex_end()
266+
267+#else /* ! _WIN32 */
268+
269+#include <regex.h>
270+
271+typedef regex_t xb_regex_t;
272+typedef regmatch_t xb_regmatch_t;
273+
274+#define xb_regex_init() do { } while(0)
275+
276+#define xb_regexec(preg,string,nmatch,pmatch,eflags) \
277+ regexec(preg, string, nmatch, pmatch, eflags)
278+
279+#define xb_regerror(errcode,preg,errbuf,errbuf_size) \
280+ regerror(errcode, preg, errbuf, errbuf_size)
281+
282+#define xb_regcomp(preg,regex,cflags) \
283+ regcomp(preg, regex, cflags)
284+
285+#define xb_regfree(preg) regfree(preg)
286+
287+#define xb_regex_end() do { } while (0)
288+
289+#endif /* _WIN32 */
290+
291+#endif /* XB_REGEX_H */
292
293=== modified file 'xtrabackup.c'
294--- xtrabackup.c 2011-04-11 00:44:07 +0000
295+++ xtrabackup.c 2011-04-21 06:37:17 +0000
296@@ -62,11 +62,14 @@
297 #include <sync0sync.h>
298 #include <fil0fil.h>
299 #include <trx0xa.h>
300+#include <fcntl.h>
301
302 #ifdef INNODB_VERSION_SHORT
303 #include <ibuf0ibuf.h>
304 #endif
305
306+#include "xb_regex.h"
307+
308 #ifndef INNODB_VERSION_SHORT
309 #define IB_INT64 ib_longlong
310 #define LSN64 dulint
311@@ -232,8 +235,77 @@
312 a file, so this is either "open" or
313 "create" */
314
315-#include <fcntl.h>
316-#include <regex.h>
317+/****************************************************************//**
318+A simple function to open or create a file.
319+@return own: handle to the file, not defined if error, error number
320+can be retrieved with os_file_get_last_error */
321+UNIV_INLINE
322+os_file_t
323+xb_file_create_no_error_handling(
324+/*=============================*/
325+ const char* name, /*!< in: name of the file or path as a
326+ null-terminated string */
327+ ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
328+ is opened (if does not exist, error), or
329+ OS_FILE_CREATE if a new file is created
330+ (if exists, error) */
331+ ulint access_type,/*!< in: OS_FILE_READ_ONLY,
332+ OS_FILE_READ_WRITE, or
333+ OS_FILE_READ_ALLOW_DELETE; the last option is
334+ used by a backup program reading the file */
335+ ibool* success);/*!< out: TRUE if succeed, FALSE if error */
336+
337+/****************************************************************//**
338+Opens an existing file or creates a new.
339+@return own: handle to the file, not defined if error, error number
340+can be retrieved with os_file_get_last_error */
341+UNIV_INLINE
342+os_file_t
343+xb_file_create(
344+/*===========*/
345+ const char* name, /*!< in: name of the file or path as a
346+ null-terminated string */
347+ ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
348+ is opened (if does not exist, error), or
349+ OS_FILE_CREATE if a new file is created
350+ (if exists, error),
351+ OS_FILE_OVERWRITE if a new file is created
352+ or an old overwritten;
353+ OS_FILE_OPEN_RAW, if a raw device or disk
354+ partition should be opened */
355+ ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
356+ non-buffered i/o is desired,
357+ OS_FILE_NORMAL, if any normal file;
358+ NOTE that it also depends on type, os_aio_..
359+ and srv_.. variables whether we really use
360+ async i/o or unbuffered i/o: look in the
361+ function source code for the exact rules */
362+ ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
363+ ibool* success);/*!< out: TRUE if succeed, FALSE if error */
364+
365+/***********************************************************************//**
366+Renames a file (can also move it to another directory). It is safest that the
367+file is closed before calling this function.
368+@return TRUE if success */
369+UNIV_INLINE
370+ibool
371+xb_file_rename(
372+/*===========*/
373+ const char* oldpath,/*!< in: old file path as a null-terminated
374+ string */
375+ const char* newpath);/*!< in: new file path */
376+
377+UNIV_INLINE
378+void
379+xb_file_set_nocache(
380+/*================*/
381+ os_file_t fd, /* in: file descriptor to alter */
382+ const char* file_name, /* in: used in the diagnostic message */
383+ const char* operation_name);/* in: used in the diagnostic message,
384+ we call os_file_set_nocache()
385+ immediately after opening or creating
386+ a file, so this is either "open" or
387+ "create" */
388
389 #ifdef POSIX_FADV_NORMAL
390 #define USE_POSIX_FADVISE
391@@ -586,8 +658,8 @@
392
393 char *xtrabackup_tables = NULL;
394 int tables_regex_num;
395-regex_t *tables_regex;
396-regmatch_t tables_regmatch[1];
397+xb_regex_t *tables_regex;
398+xb_regmatch_t tables_regmatch[1];
399
400 char *xtrabackup_tables_file = NULL;
401 hash_table_t* tables_hash;
402@@ -633,8 +705,14 @@
403
404 #define XB_DELTA_INFO_SUFFIX ".meta"
405
406+#ifdef __WIN__
407+#define XB_FILE_UNDEFINED NULL
408+#else
409+#define XB_FILE_UNDEFINED (-1)
410+#endif
411+
412 /* === sharing with thread === */
413-os_file_t dst_log = -1;
414+os_file_t dst_log = XB_FILE_UNDEFINED;
415 char dst_log_path[FN_REFLEN];
416
417 /* === some variables from mysqld === */
418@@ -1390,7 +1468,29 @@
419 will be passed to fdopen(), it will be closed by invoking
420 fclose(), which in turn will invoke close() instead of
421 my_close(). */
422+#ifdef _WIN32
423+ /* Note that on Windows, the integer returned by mysql_tmpfile
424+ has no relation to C runtime file descriptor. Here, we need
425+ to call my_get_osfhandle to get the HANDLE and then convert it
426+ to C runtime filedescriptor. */
427+ {
428+ HANDLE hFile = my_get_osfhandle(fd);
429+ HANDLE hDup;
430+ BOOL bOK =
431+ DuplicateHandle(GetCurrentProcess(), hFile,
432+ GetCurrentProcess(), &hDup, 0,
433+ FALSE, DUPLICATE_SAME_ACCESS);
434+ if(bOK) {
435+ fd2 = _open_osfhandle((intptr_t)hDup,0);
436+ }
437+ else {
438+ my_osmaperr(GetLastError());
439+ fd2 = -1;
440+ }
441+ }
442+#else
443 fd2 = dup(fd);
444+#endif
445 if (fd2 < 0) {
446 fprintf(stderr, "xtrabackup: Got error %d on dup\n",fd2);
447 }
448@@ -1430,19 +1530,16 @@
449 void
450 innobase_print_identifier(
451 FILE* f,
452- trx_t* trx,
453- ibool table_id,
454+ trx_t* trx __attribute__((unused)),
455+ ibool table_id __attribute__((unused)),
456 const char* name,
457 ulint namelen)
458 {
459- (void)trx;
460- (void)table_id;
461-
462 const char* s = name;
463 const char* e = s + namelen;
464 int q;
465
466- q = '"';
467+ q = '"';
468
469 putc(q, f);
470 while (s < e) {
471@@ -1467,13 +1564,12 @@
472 ulint buflen, /*!< in: length of buf, in bytes */
473 const char* id, /*!< in: identifier to convert */
474 ulint idlen, /*!< in: length of id, in bytes */
475- void* thd, /*!< in: MySQL connection thread, or NULL */
476- ibool file_id)/*!< in: TRUE=id is a table or database name;
477- FALSE=id is an UTF-8 string */
478+ void* thd __attribute__((unused)),
479+ /*!< in: MySQL connection thread, or NULL */
480+ ibool file_id __attribute__((unused)))
481+ /*!< in: TRUE=id is a table or database name;
482+ FALSE=id is an UTF-8 string */
483 {
484- (void)thd;
485- (void)file_id;
486-
487 const char* s = id;
488 int q;
489
490@@ -2116,7 +2212,7 @@
491 #ifndef INNODB_VERSION_SHORT
492 srv_use_adaptive_hash_indexes = (ibool) innobase_adaptive_hash_index;
493 #else
494- btr_search_enabled = (ibool) innobase_adaptive_hash_index;
495+ btr_search_enabled = (char) innobase_adaptive_hash_index;
496 #endif
497
498 os_use_large_pages = (ibool) innobase_use_large_pages;
499@@ -2124,7 +2220,7 @@
500
501 row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
502
503- srv_file_per_table = (ibool) innobase_file_per_table;
504+ srv_file_per_table = (my_bool) innobase_file_per_table;
505
506 srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog;
507
508@@ -2424,6 +2520,119 @@
509 }
510 }
511
512+#ifdef INNODB_VERSION_SHORT
513+#define XB_HASH_SEARCH(NAME, TABLE, FOLD, DATA, ASSERTION, TEST) \
514+ HASH_SEARCH(NAME, TABLE, FOLD, xtrabackup_tables_t*, DATA, ASSERTION, \
515+ TEST)
516+#else
517+#define XB_HASH_SEARCH(NAME, TABLE, FOLD, DATA, ASSERTION, TEST) \
518+ HASH_SEARCH(NAME, TABLE, FOLD, DATA, TEST)
519+#endif
520+
521+/****************************************************************//**
522+A simple function to open or create a file.
523+@return own: handle to the file, not defined if error, error number
524+can be retrieved with os_file_get_last_error */
525+UNIV_INLINE
526+os_file_t
527+xb_file_create_no_error_handling(
528+/*=============================*/
529+ const char* name, /*!< in: name of the file or path as a
530+ null-terminated string */
531+ ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
532+ is opened (if does not exist, error), or
533+ OS_FILE_CREATE if a new file is created
534+ (if exists, error) */
535+ ulint access_type,/*!< in: OS_FILE_READ_ONLY,
536+ OS_FILE_READ_WRITE, or
537+ OS_FILE_READ_ALLOW_DELETE; the last option is
538+ used by a backup program reading the file */
539+ ibool* success)/*!< out: TRUE if succeed, FALSE if error */
540+{
541+#if MYSQL_VERSION_ID > 50500
542+ return os_file_create_simple_no_error_handling(
543+ 0, /* innodb_file_data_key */
544+ name, create_mode, access_type, success);
545+#else
546+ return os_file_create_simple_no_error_handling(
547+ name, create_mode, access_type, success);
548+#endif
549+}
550+
551+/****************************************************************//**
552+Opens an existing file or creates a new.
553+@return own: handle to the file, not defined if error, error number
554+can be retrieved with os_file_get_last_error */
555+UNIV_INLINE
556+os_file_t
557+xb_file_create(
558+/*===========*/
559+ const char* name, /*!< in: name of the file or path as a
560+ null-terminated string */
561+ ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
562+ is opened (if does not exist, error), or
563+ OS_FILE_CREATE if a new file is created
564+ (if exists, error),
565+ OS_FILE_OVERWRITE if a new file is created
566+ or an old overwritten;
567+ OS_FILE_OPEN_RAW, if a raw device or disk
568+ partition should be opened */
569+ ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
570+ non-buffered i/o is desired,
571+ OS_FILE_NORMAL, if any normal file;
572+ NOTE that it also depends on type, os_aio_..
573+ and srv_.. variables whether we really use
574+ async i/o or unbuffered i/o: look in the
575+ function source code for the exact rules */
576+ ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
577+ ibool* success)/*!< out: TRUE if succeed, FALSE if error */
578+{
579+#if MYSQL_VERSION_ID > 50500
580+ return os_file_create(0 /* innodb_file_data_key */,
581+ name, create_mode, purpose, type, success);
582+#else
583+ return os_file_create(name, create_mode, purpose, type, success);
584+#endif
585+}
586+
587+/***********************************************************************//**
588+Renames a file (can also move it to another directory). It is safest that the
589+file is closed before calling this function.
590+@return TRUE if success */
591+UNIV_INLINE
592+ibool
593+xb_file_rename(
594+/*===========*/
595+ const char* oldpath,/*!< in: old file path as a null-terminated
596+ string */
597+ const char* newpath)/*!< in: new file path */
598+{
599+#if MYSQL_VERSION_ID > 50500
600+ return os_file_rename(
601+ 0 /* innodb_file_data_key */, oldpath, newpath);
602+#else
603+ return os_file_rename(oldpath, newpath);
604+#endif
605+}
606+
607+UNIV_INLINE
608+void
609+xb_file_set_nocache(
610+/*================*/
611+ os_file_t fd, /* in: file descriptor to alter */
612+ const char* file_name, /* in: used in the diagnostic message */
613+ const char* operation_name) /* in: used in the diagnostic message,
614+ we call os_file_set_nocache()
615+ immediately after opening or creating
616+ a file, so this is either "open" or
617+ "create" */
618+{
619+#ifndef __WIN__
620+ if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
621+ os_file_set_nocache(fd, file_name, operation_name);
622+ }
623+#endif
624+}
625
626 /* TODO: We may tune the behavior (e.g. by fil_aio)*/
627 #define COPY_CHUNK 64
628@@ -2431,8 +2640,8 @@
629 static my_bool
630 xtrabackup_copy_datafile(fil_node_t* node, uint thread_n)
631 {
632- os_file_t src_file = -1;
633- os_file_t dst_file = -1;
634+ os_file_t src_file = XB_FILE_UNDEFINED;
635+ os_file_t dst_file = XB_FILE_UNDEFINED;
636 char dst_path[FN_REFLEN];
637 char meta_path[FN_REFLEN];
638 ibool success;
639@@ -2483,7 +2692,8 @@
640 *(p - 1) = '.';
641
642 for (i = 0; i < tables_regex_num; i++) {
643- regres = regexec(&tables_regex[i], prev, 1, tables_regmatch, 0);
644+ regres = xb_regexec(&tables_regex[i], prev, 1,
645+ tables_regmatch, 0);
646 if (regres != REG_NOMATCH)
647 break;
648 }
649@@ -2528,15 +2738,10 @@
650 tmp = p[p_len];
651 p[p_len] = 0;
652
653- HASH_SEARCH(name_hash, tables_hash, ut_fold_string(prev),
654-#ifdef INNODB_VERSION_SHORT
655- xtrabackup_tables_t*,
656-#endif
657- table,
658-#ifdef INNODB_VERSION_SHORT
659- ut_ad(table->name),
660-#endif
661- !strcmp(table->name, prev));
662+ XB_HASH_SEARCH(name_hash, tables_hash, ut_fold_string(prev),
663+ table,
664+ ut_ad(table->name),
665+ !strcmp(table->name, prev));
666
667 p[p_len] = tmp;
668
669@@ -2611,12 +2816,10 @@
670
671 /* open src_file*/
672 if (!node->open) {
673- src_file = os_file_create_simple_no_error_handling(
674-#if (MYSQL_VERSION_ID > 50500)
675- 0 /* dummy of innodb_file_data_key */,
676-#endif
677- node->name, OS_FILE_OPEN,
678- OS_FILE_READ_ONLY, &success);
679+ src_file = xb_file_create_no_error_handling(node->name,
680+ OS_FILE_OPEN,
681+ OS_FILE_READ_ONLY,
682+ &success);
683 if (!success) {
684 /* The following call prints an error message */
685 os_file_get_last_error(TRUE);
686@@ -2630,9 +2833,7 @@
687 goto skip;
688 }
689
690- if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
691- os_file_set_nocache(src_file, node->name, "OPEN");
692- }
693+ xb_file_set_nocache(src_file, node->name, "OPEN");
694 } else {
695 src_file = node->handle;
696 }
697@@ -2643,21 +2844,17 @@
698 #endif
699
700 /* open dst_file */
701- /* os_file_create reads srv_unix_file_flush_method */
702- dst_file = os_file_create(
703-#if (MYSQL_VERSION_ID > 50500)
704- 0 /* dummy of innodb_file_data_key */,
705-#endif
706- dst_path, OS_FILE_CREATE,
707- OS_FILE_NORMAL, OS_DATA_FILE, &success);
708- if (!success) {
709- /* The following call prints an error message */
710- os_file_get_last_error(TRUE);
711+ /* xb_file_create reads srv_unix_file_flush_method */
712+ dst_file = xb_file_create(dst_path, OS_FILE_CREATE,
713+ OS_FILE_NORMAL, OS_DATA_FILE, &success);
714+ if (!success) {
715+ /* The following call prints an error message */
716+ os_file_get_last_error(TRUE);
717
718- fprintf(stderr,"[%02u] xtrabackup: error: "
719- "cannot open %s\n", thread_n, dst_path);
720- goto error;
721- }
722+ fprintf(stderr,"[%02u] xtrabackup: error: "
723+ "cannot open %s\n", thread_n, dst_path);
724+ goto error;
725+ }
726
727 #ifdef USE_POSIX_FADVISE
728 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
729@@ -2857,9 +3054,9 @@
730 ut_free(buf2);
731 return(FALSE);
732 error:
733- if (src_file != -1 && !node->open)
734+ if (src_file != XB_FILE_UNDEFINED && !node->open)
735 os_file_close(src_file);
736- if (dst_file != -1)
737+ if (dst_file != XB_FILE_UNDEFINED)
738 os_file_close(dst_file);
739 if (buf2)
740 ut_free(buf2);
741@@ -2868,9 +3065,9 @@
742 return(TRUE); /*ERROR*/
743
744 skip:
745- if (src_file != -1 && !node->open)
746+ if (src_file != XB_FILE_UNDEFINED && !node->open)
747 os_file_close(src_file);
748- if (dst_file != -1)
749+ if (dst_file != XB_FILE_UNDEFINED)
750 os_file_close(dst_file);
751 if (buf2)
752 ut_free(buf2);
753@@ -2890,7 +3087,7 @@
754 ibool success;
755
756 if (!xtrabackup_stream)
757- ut_a(dst_log != -1);
758+ ut_a(dst_log != XB_FILE_UNDEFINED);
759
760 /* read from checkpoint_lsn_start to current */
761 contiguous_lsn = ut_dulint_align_down(from_lsn,
762@@ -3042,7 +3239,7 @@
763 if (!finished) {
764 write_size = RECV_SCAN_SIZE;
765 } else {
766- write_size = ut_dulint_minus(
767+ write_size = (ulint) ut_dulint_minus(
768 ut_dulint_align_up(group_scanned_lsn, OS_FILE_LOG_BLOCK_SIZE),
769 start_lsn);
770 }
771@@ -3158,13 +3355,12 @@
772 ulint
773 #endif
774 log_copying_thread(
775- void* arg)
776+ void* arg __attribute__((unused)))
777 {
778- (void)arg;
779 ulint counter = 0;
780
781 if (!xtrabackup_stream)
782- ut_a(dst_log != -1);
783+ ut_a(dst_log != XB_FILE_UNDEFINED);
784
785 log_copying_running = TRUE;
786
787@@ -3378,6 +3574,7 @@
788 if(innodb_init_param())
789 exit(EXIT_FAILURE);
790
791+#ifndef __WIN__
792 if (srv_file_flush_method_str == NULL) {
793 /* These are the default options */
794 #if (MYSQL_VERSION_ID < 50100)
795@@ -3385,8 +3582,6 @@
796 #else /* MYSQL_VERSION_ID < 51000 */
797 srv_unix_file_flush_method = SRV_UNIX_FSYNC;
798 #endif
799- srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
800-#ifndef __WIN__
801 #if (MYSQL_VERSION_ID < 50100)
802 } else if (0 == ut_strcmp(srv_file_flush_method_str, "fdatasync")) {
803 srv_unix_file_flush_method = SRV_UNIX_FDATASYNC;
804@@ -3406,25 +3601,23 @@
805
806 } else if (0 == ut_strcmp(srv_file_flush_method_str, "nosync")) {
807 srv_unix_file_flush_method = SRV_UNIX_NOSYNC;
808-#else
809- } else if (0 == ut_strcmp(srv_file_flush_method_str, "normal")) {
810- srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
811- os_aio_use_native_aio = FALSE;
812-
813- } else if (0 == ut_strcmp(srv_file_flush_method_str, "unbuffered")) {
814- srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
815- os_aio_use_native_aio = FALSE;
816-
817- } else if (0 == ut_strcmp(srv_file_flush_method_str,
818- "async_unbuffered")) {
819- srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
820-#endif
821 } else {
822 fprintf(stderr,
823 "xtrabackup: Unrecognized value %s for innodb_flush_method\n",
824 srv_file_flush_method_str);
825 exit(EXIT_FAILURE);
826 }
827+#else /* __WIN__ */
828+ /* We can only use synchronous unbuffered IO on Windows for now */
829+ if (srv_file_flush_method_str != NULL) {
830+ fprintf(stderr,
831+ "xtrabackupp: Warning: "
832+ "ignoring innodb_flush_method = %s on Windows.\n");
833+ }
834+
835+ srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
836+ srv_use_native_aio = FALSE;
837+#endif
838
839 #ifndef INNODB_VERSION_SHORT
840 if (srv_pool_size >= 1000 * 1024) {
841@@ -3703,13 +3896,11 @@
842 /* open 'xtrabackup_logfile' */
843 sprintf(dst_log_path, "%s%s", xtrabackup_target_dir, "/xtrabackup_logfile");
844 srv_normalize_path_for_win(dst_log_path);
845- /* os_file_create reads srv_unix_file_flush_method for OS_DATA_FILE*/
846- dst_log = os_file_create(
847-#if (MYSQL_VERSION_ID > 50500)
848- 0 /* dummy of innodb_file_data_key */,
849-#endif
850- dst_log_path, OS_FILE_CREATE,
851- OS_FILE_NORMAL, OS_DATA_FILE, &success);
852+ /* xb_file_create reads srv_unix_file_flush_method for
853+ OS_DATA_FILE*/
854+ dst_log = xb_file_create(dst_log_path, OS_FILE_CREATE,
855+ OS_FILE_NORMAL, OS_DATA_FILE,
856+ &success);
857
858 if (!success) {
859 /* The following call prints an error message */
860@@ -3749,7 +3940,7 @@
861
862 log_copy_offset += LOG_FILE_HDR_SIZE;
863 if (!success) {
864- if (dst_log != -1)
865+ if (dst_log != XB_FILE_UNDEFINED)
866 os_file_close(dst_log);
867 exit(EXIT_FAILURE);
868 }
869@@ -3839,7 +4030,7 @@
870
871 /* suspend-at-end */
872 if (xtrabackup_suspend_at_end) {
873- os_file_t suspend_file = -1;
874+ os_file_t suspend_file = XB_FILE_UNDEFINED;
875 char suspend_path[FN_REFLEN];
876 ibool success, exists;
877 os_file_type_t type;
878@@ -3848,19 +4039,16 @@
879 "/xtrabackup_suspended");
880
881 srv_normalize_path_for_win(suspend_path);
882- /* os_file_create reads srv_unix_file_flush_method */
883- suspend_file = os_file_create(
884-#if (MYSQL_VERSION_ID > 50500)
885- 0 /* dummy of innodb_file_data_key */,
886-#endif
887- suspend_path, OS_FILE_OVERWRITE,
888- OS_FILE_NORMAL, OS_DATA_FILE, &success);
889+ /* xb_file_create reads srv_unix_file_flush_method */
890+ suspend_file = xb_file_create(suspend_path, OS_FILE_OVERWRITE,
891+ OS_FILE_NORMAL, OS_DATA_FILE,
892+ &success);
893
894 if (!success) {
895 fprintf(stderr, "xtrabackup: Error: failed to create file 'xtrabackup_suspended'\n");
896 }
897
898- if (suspend_file != -1)
899+ if (suspend_file != XB_FILE_UNDEFINED)
900 os_file_close(suspend_file);
901
902 exists = TRUE;
903@@ -4011,14 +4199,12 @@
904 ulonglong sum_data, sum_data_extern;
905 ulonglong n_recs;
906 ulint page_size;
907+ buf_block_t* block;
908+ ulint zip_size;
909
910 n_pages = sum_data = n_recs = 0;
911 n_pages_extern = sum_data_extern = 0;
912
913-#ifdef INNODB_VERSION_SHORT
914- buf_block_t* block;
915- ulint zip_size;
916-#endif
917
918 if (level == 0)
919 fprintf(stdout, " leaf pages: ");
920@@ -4388,7 +4574,9 @@
921 *p = '.';
922
923 for (i = 0; i < tables_regex_num; i++) {
924- regres = regexec(&tables_regex[i], table->name, 1, tables_regmatch, 0);
925+ regres = xb_regexec(&tables_regex[i],
926+ table->name, 1,
927+ tables_regmatch, 0);
928 if (regres != REG_NOMATCH)
929 break;
930 }
931@@ -4403,15 +4591,11 @@
932 if (xtrabackup_tables_file) {
933 xtrabackup_tables_t* xtable;
934
935- HASH_SEARCH(name_hash, tables_hash, ut_fold_string(table->name),
936-#ifdef INNODB_VERSION_SHORT
937- xtrabackup_tables_t*,
938-#endif
939- xtable,
940-#ifdef INNODB_VERSION_SHORT
941- ut_ad(xtable->name),
942-#endif
943- !strcmp(xtable->name, table->name));
944+ XB_HASH_SEARCH(name_hash, tables_hash,
945+ ut_fold_string(table->name),
946+ xtable,
947+ ut_ad(xtable->name),
948+ !strcmp(xtable->name, table->name));
949
950 if (!xtable)
951 goto skip;
952@@ -4527,7 +4711,7 @@
953 static my_bool
954 xtrabackup_init_temp_log(void)
955 {
956- os_file_t src_file = -1;
957+ os_file_t src_file = XB_FILE_UNDEFINED;
958 char src_path[FN_REFLEN];
959 char dst_path[FN_REFLEN];
960 ibool success;
961@@ -4557,12 +4741,9 @@
962 srv_normalize_path_for_win(dst_path);
963 srv_normalize_path_for_win(src_path);
964 retry:
965- src_file = os_file_create_simple_no_error_handling(
966-#if (MYSQL_VERSION_ID > 50500)
967- 0 /* dummy of innodb_file_data_key */,
968-#endif
969- src_path, OS_FILE_OPEN,
970- OS_FILE_READ_WRITE /* OS_FILE_READ_ONLY */, &success);
971+ src_file = xb_file_create_no_error_handling(src_path, OS_FILE_OPEN,
972+ OS_FILE_READ_WRITE,
973+ &success);
974 if (!success) {
975 /* The following call prints an error message */
976 os_file_get_last_error(TRUE);
977@@ -4572,12 +4753,10 @@
978 src_path);
979
980 /* check if ib_logfile0 may be xtrabackup_logfile */
981- src_file = os_file_create_simple_no_error_handling(
982-#if (MYSQL_VERSION_ID > 50500)
983- 0 /* dummy of innodb_file_data_key */,
984-#endif
985- dst_path, OS_FILE_OPEN,
986- OS_FILE_READ_WRITE /* OS_FILE_READ_ONLY */, &success);
987+ src_file = xb_file_create_no_error_handling(dst_path,
988+ OS_FILE_OPEN,
989+ OS_FILE_READ_WRITE,
990+ &success);
991 if (!success) {
992 os_file_get_last_error(TRUE);
993 fprintf(stderr,
994@@ -4604,14 +4783,10 @@
995 log_buf_ = NULL;
996
997 os_file_close(src_file);
998- src_file = -1;
999+ src_file = XB_FILE_UNDEFINED;
1000
1001 /* rename and try again */
1002- success = os_file_rename(
1003-#if (MYSQL_VERSION_ID > 50500)
1004- 0 /* dummy of innodb_file_data_key */,
1005-#endif
1006- dst_path, src_path);
1007+ success = xb_file_rename(dst_path, src_path);
1008 if (!success) {
1009 goto error;
1010 }
1011@@ -4627,7 +4802,7 @@
1012 log_buf_ = NULL;
1013
1014 os_file_close(src_file);
1015- src_file = -1;
1016+ src_file = XB_FILE_UNDEFINED;
1017
1018 goto error;
1019 }
1020@@ -4637,9 +4812,7 @@
1021 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
1022 #endif
1023
1024- if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
1025- os_file_set_nocache(src_file, src_path, "OPEN");
1026- }
1027+ xb_file_set_nocache(src_file, src_path, "OPEN");
1028
1029 file_size = os_file_get_size_as_iblonglong(src_file);
1030
1031@@ -4702,7 +4875,7 @@
1032 /* It seems to be needed to overwrite the both checkpoint area. */
1033 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_LSN, max_lsn);
1034 mach_write_to_4(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_OFFSET,
1035- LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
1036+ LOG_FILE_HDR_SIZE + (ulint) ut_dulint_minus(max_lsn,
1037 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
1038 #ifdef XTRADB_BASED
1039 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_1 + LOG_CHECKPOINT_ARCHIVED_LSN,
1040@@ -4718,7 +4891,7 @@
1041
1042 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_LSN, max_lsn);
1043 mach_write_to_4(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_OFFSET,
1044- LOG_FILE_HDR_SIZE + ut_dulint_minus(max_lsn,
1045+ LOG_FILE_HDR_SIZE + (ulint) ut_dulint_minus(max_lsn,
1046 ut_dulint_align_down(max_lsn,OS_FILE_LOG_BLOCK_SIZE)));
1047 #ifdef XTRADB_BASED
1048 MACH_WRITE_64(log_buf + LOG_CHECKPOINT_2 + LOG_CHECKPOINT_ARCHIVED_LSN,
1049@@ -4745,7 +4918,7 @@
1050 success = os_file_write(src_path, src_file, log_buf,
1051 (ulint)(file_size & 0xFFFFFFFFUL),
1052 (ulint)(file_size >> 32),
1053- UNIV_PAGE_SIZE - (file_size % UNIV_PAGE_SIZE));
1054+ UNIV_PAGE_SIZE - (ulint) (file_size % UNIV_PAGE_SIZE));
1055 if (!success) {
1056 goto error;
1057 }
1058@@ -4758,7 +4931,7 @@
1059 ulint expand;
1060
1061 memset(log_buf, 0, UNIV_PAGE_SIZE * 128);
1062- expand = file_size / UNIV_PAGE_SIZE / 8;
1063+ expand = (ulint) (file_size / UNIV_PAGE_SIZE / 8);
1064
1065 for (; expand > 128; expand -= 128) {
1066 success = os_file_write(src_path, src_file, log_buf,
1067@@ -4808,7 +4981,7 @@
1068 #endif
1069
1070 os_file_close(src_file);
1071- src_file = -1;
1072+ src_file = XB_FILE_UNDEFINED;
1073
1074 /* Backup log parameters */
1075 innobase_log_group_home_dir_backup = innobase_log_group_home_dir;
1076@@ -4823,11 +4996,7 @@
1077 srv_thread_concurrency = 0;
1078
1079 /* rename 'xtrabackup_logfile' to 'ib_logfile0' */
1080- success = os_file_rename(
1081-#if (MYSQL_VERSION_ID > 50500)
1082- 0 /* dummy of innodb_file_data_key */,
1083-#endif
1084- src_path, dst_path);
1085+ success = xb_file_rename(src_path, dst_path);
1086 if (!success) {
1087 goto error;
1088 }
1089@@ -4839,12 +5008,12 @@
1090
1091 skip_modify:
1092 os_file_close(src_file);
1093- src_file = -1;
1094+ src_file = XB_FILE_UNDEFINED;
1095 ut_free(log_buf_);
1096 return(FALSE);
1097
1098 error:
1099- if (src_file != -1)
1100+ if (src_file != XB_FILE_UNDEFINED)
1101 os_file_close(src_file);
1102 if (log_buf_)
1103 ut_free(log_buf_);
1104@@ -4881,11 +5050,10 @@
1105 const char* dbname, /* in: database name (ibdata: NULL) */
1106 const char* filename, /* in: file name (not a path),
1107 including the .delta extension */
1108- my_bool check_newer)
1109+ my_bool check_newer __attribute__((unused)))
1110 {
1111- (void)check_newer;
1112- os_file_t src_file = -1;
1113- os_file_t dst_file = -1;
1114+ os_file_t src_file = XB_FILE_UNDEFINED;
1115+ os_file_t dst_file = XB_FILE_UNDEFINED;
1116 char src_path[FN_REFLEN];
1117 char dst_path[FN_REFLEN];
1118 char meta_path[FN_REFLEN];
1119@@ -4938,11 +5106,9 @@
1120 goto error;
1121 }
1122
1123- src_file = os_file_create_simple_no_error_handling(
1124-#if (MYSQL_VERSION_ID > 50500)
1125- 0 /* dummy of innodb_file_data_key */,
1126-#endif
1127- src_path, OS_FILE_OPEN, OS_FILE_READ_WRITE, &success);
1128+ src_file = xb_file_create_no_error_handling(src_path, OS_FILE_OPEN,
1129+ OS_FILE_READ_WRITE,
1130+ &success);
1131 if (!success) {
1132 os_file_get_last_error(TRUE);
1133 fprintf(stderr,
1134@@ -4956,15 +5122,11 @@
1135 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
1136 #endif
1137
1138- if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
1139- os_file_set_nocache(src_file, src_path, "OPEN");
1140- }
1141+ xb_file_set_nocache(src_file, src_path, "OPEN");
1142
1143- dst_file = os_file_create_simple_no_error_handling(
1144-#if (MYSQL_VERSION_ID > 50500)
1145- 0 /* dummy of innodb_file_data_key */,
1146-#endif
1147- dst_path, OS_FILE_OPEN, OS_FILE_READ_WRITE, &success);
1148+ dst_file = xb_file_create_no_error_handling(dst_path, OS_FILE_OPEN,
1149+ OS_FILE_READ_WRITE,
1150+ &success);
1151 if (!success) {
1152 os_file_get_last_error(TRUE);
1153 fprintf(stderr,
1154@@ -4977,9 +5139,7 @@
1155 posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED);
1156 #endif
1157
1158- if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
1159- os_file_set_nocache(dst_file, dst_path, "OPEN");
1160- }
1161+ xb_file_set_nocache(dst_file, dst_path, "OPEN");
1162
1163 printf("Applying %s ...\n", src_path);
1164
1165@@ -5063,16 +5223,16 @@
1166 incremental_buffers++;
1167 }
1168
1169- if (src_file != -1)
1170+ if (src_file != XB_FILE_UNDEFINED)
1171 os_file_close(src_file);
1172- if (dst_file != -1)
1173+ if (dst_file != XB_FILE_UNDEFINED)
1174 os_file_close(dst_file);
1175 return;
1176
1177 error:
1178- if (src_file != -1)
1179+ if (src_file != XB_FILE_UNDEFINED)
1180 os_file_close(src_file);
1181- if (dst_file != -1)
1182+ if (dst_file != XB_FILE_UNDEFINED)
1183 os_file_close(dst_file);
1184 fprintf(stderr, "xtrabackup: Error: xtrabackup_apply_delta() failed.\n");
1185 return;
1186@@ -5188,7 +5348,7 @@
1187 static my_bool
1188 xtrabackup_close_temp_log(my_bool clear_flag)
1189 {
1190- os_file_t src_file = -1;
1191+ os_file_t src_file = XB_FILE_UNDEFINED;
1192 char src_path[FN_REFLEN];
1193 char dst_path[FN_REFLEN];
1194 ibool success;
1195@@ -5217,11 +5377,7 @@
1196 srv_normalize_path_for_win(dst_path);
1197 srv_normalize_path_for_win(src_path);
1198
1199- success = os_file_rename(
1200-#if (MYSQL_VERSION_ID > 50500)
1201- 0 /* dummy of innodb_file_data_key */,
1202-#endif
1203- dst_path, src_path);
1204+ success = xb_file_rename(dst_path, src_path);
1205 if (!success) {
1206 goto error;
1207 }
1208@@ -5231,12 +5387,9 @@
1209 return(FALSE);
1210
1211 /* clear LOG_FILE_WAS_CREATED_BY_HOT_BACKUP field */
1212- src_file = os_file_create_simple_no_error_handling(
1213-#if (MYSQL_VERSION_ID > 50500)
1214- 0 /* dummy of innodb_file_data_key */,
1215-#endif
1216- src_path, OS_FILE_OPEN,
1217- OS_FILE_READ_WRITE, &success);
1218+ src_file = xb_file_create_no_error_handling(src_path, OS_FILE_OPEN,
1219+ OS_FILE_READ_WRITE,
1220+ &success);
1221 if (!success) {
1222 goto error;
1223 }
1224@@ -5245,9 +5398,7 @@
1225 posix_fadvise(src_file, 0, 0, POSIX_FADV_DONTNEED);
1226 #endif
1227
1228- if (srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) {
1229- os_file_set_nocache(src_file, src_path, "OPEN");
1230- }
1231+ xb_file_set_nocache(src_file, src_path, "OPEN");
1232
1233 log_buf_ = ut_malloc(LOG_FILE_HDR_SIZE * 2);
1234 log_buf = ut_align(log_buf_, LOG_FILE_HDR_SIZE);
1235@@ -5265,11 +5416,11 @@
1236 }
1237
1238 os_file_close(src_file);
1239- src_file = -1;
1240+ src_file = XB_FILE_UNDEFINED;
1241
1242 return(FALSE);
1243 error:
1244- if (src_file != -1)
1245+ if (src_file != XB_FILE_UNDEFINED)
1246 os_file_close(src_file);
1247 if (log_buf_)
1248 ut_free(log_buf_);
1249@@ -5471,7 +5622,7 @@
1250 fil_system_t* f_system = fil_system;
1251 fil_space_t* space;
1252 fil_node_t* node;
1253- os_file_t info_file = -1;
1254+ os_file_t info_file = XB_FILE_UNDEFINED;
1255 char info_file_path[FN_REFLEN];
1256 ibool success;
1257 char table_name[FN_REFLEN];
1258@@ -5587,12 +5738,11 @@
1259 }
1260
1261 srv_normalize_path_for_win(info_file_path);
1262- info_file = os_file_create(
1263-#if (MYSQL_VERSION_ID > 50500)
1264- 0 /* dummy of innodb_file_data_key */,
1265-#endif
1266- info_file_path, OS_FILE_OVERWRITE,
1267- OS_FILE_NORMAL, OS_DATA_FILE, &success);
1268+ info_file = xb_file_create(
1269+ info_file_path,
1270+ OS_FILE_OVERWRITE,
1271+ OS_FILE_NORMAL, OS_DATA_FILE,
1272+ &success);
1273 if (!success) {
1274 os_file_get_last_error(TRUE);
1275 goto next_node;
1276@@ -5609,9 +5759,9 @@
1277 goto next_node;
1278 }
1279 next_node:
1280- if (info_file != -1) {
1281+ if (info_file != XB_FILE_UNDEFINED) {
1282 os_file_close(info_file);
1283- info_file = -1;
1284+ info_file = XB_FILE_UNDEFINED;
1285 }
1286 mutex_exit(&(dict_sys->mutex));
1287 mutex_enter(&(f_system->mutex));
1288@@ -5756,6 +5906,7 @@
1289 int ho_error;
1290
1291 MY_INIT(argv[0]);
1292+ xb_regex_init();
1293
1294 load_defaults("my",load_default_groups,&argc,&argv);
1295
1296@@ -5824,7 +5975,7 @@
1297 tables_regex_num++;
1298 }
1299
1300- tables_regex = ut_malloc(sizeof(regex_t) * tables_regex_num);
1301+ tables_regex = ut_malloc(sizeof(xb_regex_t) * tables_regex_num);
1302
1303 p = xtrabackup_tables;
1304 for (i=0; i < tables_regex_num; i++) {
1305@@ -5835,9 +5986,11 @@
1306 if (i != tables_regex_num - 1)
1307 *(next - 1) = '\0';
1308
1309- regerror(regcomp(&tables_regex[i],p,REG_EXTENDED),
1310- &tables_regex[i],errbuf,sizeof(errbuf));
1311- fprintf(stderr, "xtrabackup: tables regcomp(%s): %s\n",p,errbuf);
1312+ xb_regerror(xb_regcomp(&tables_regex[i], p,
1313+ REG_EXTENDED),
1314+ &tables_regex[i], errbuf, sizeof(errbuf));
1315+ fprintf(stderr, "xtrabackup: tables regcomp(%s): %s\n",
1316+ p, errbuf);
1317
1318 if (i != tables_regex_num - 1)
1319 *(next - 1) = ',';
1320@@ -6080,7 +6233,7 @@
1321 int i;
1322
1323 for (i = 0; i < tables_regex_num; i++) {
1324- regfree(&tables_regex[i]);
1325+ xb_regfree(&tables_regex[i]);
1326 }
1327 ut_free(tables_regex);
1328 }
1329@@ -6109,5 +6262,7 @@
1330 hash_table_free(tables_hash);
1331 }
1332
1333+ xb_regex_end();
1334+
1335 exit(EXIT_SUCCESS);
1336 }

Subscribers

People subscribed via source and target branches