1 | /****************************************************** |
2 | Percona XtraBackup: hot backup tool for InnoDB |
3 | (c) 2009-2014 Percona LLC and/or its affiliates |
4 | Originally Created 3/3/2009 Yasufumi Kinoshita |
5 | Written by Alexey Kopytov, Aleksandr Kuzminsky, Stewart Smith, Vadim Tkachenko, |
6 | Yasufumi Kinoshita, Ignacio Nin and Baron Schwartz. |
7 | |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; version 2 of the License. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20 | |
21 | ******************************************************* |
22 | |
23 | This file incorporates work covered by the following copyright and |
24 | permission notice: |
25 | |
26 | Copyright 2010 Codership Oy <http://www.codership.com> |
27 | |
28 | This program is free software; you can redistribute it and/or modify |
29 | it under the terms of the GNU General Public License as published by |
30 | the Free Software Foundation; version 2 of the License. |
31 | |
32 | This program is distributed in the hope that it will be useful, |
33 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
34 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
35 | GNU General Public License for more details. |
36 | |
37 | You should have received a copy of the GNU General Public License |
38 | along with this program; if not, write to the Free Software |
39 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
40 | |
41 | *******************************************************/ |
42 | |
43 | #include <my_global.h> |
44 | #include <my_base.h> |
45 | #include <handler.h> |
46 | #include <trx0rseg.h> |
47 | #include <mysql/service_wsrep.h> |
48 | |
49 | #include "common.h" |
50 | #ifdef WITH_WSREP |
51 | |
52 | #include <wsrep_api.h> |
53 | |
54 | /*! Name of file where Galera info is stored on recovery */ |
55 | #define XB_GALERA_INFO_FILENAME "xtrabackup_galera_info" |
56 | |
57 | /*********************************************************************** |
58 | Store Galera checkpoint info in the 'xtrabackup_galera_info' file, if that |
59 | information is present in the trx system header. Otherwise, do nothing. */ |
60 | void |
61 | xb_write_galera_info(bool incremental_prepare) |
62 | /*==================*/ |
63 | { |
64 | FILE* fp; |
65 | XID xid; |
66 | char uuid_str[40]; |
67 | long long seqno; |
68 | MY_STAT statinfo; |
69 | |
70 | /* Do not overwrite existing an existing file to be compatible with |
71 | servers with older server versions */ |
72 | if (!incremental_prepare && |
73 | my_stat(XB_GALERA_INFO_FILENAME, &statinfo, MYF(0)) != NULL) { |
74 | |
75 | return; |
76 | } |
77 | |
78 | memset(&xid, 0, sizeof(xid)); |
79 | xid.formatID = -1; |
80 | |
81 | if (!trx_rseg_read_wsrep_checkpoint(xid)) { |
82 | |
83 | return; |
84 | } |
85 | |
86 | wsrep_uuid_t uuid; |
87 | memcpy(uuid.data, wsrep_xid_uuid(&xid), sizeof(uuid.data)); |
88 | if (wsrep_uuid_print(&uuid, uuid_str, |
89 | sizeof(uuid_str)) < 0) { |
90 | return; |
91 | } |
92 | |
93 | fp = fopen(XB_GALERA_INFO_FILENAME, "w" ); |
94 | if (fp == NULL) { |
95 | |
96 | msg("mariabackup: error: " |
97 | "could not create " XB_GALERA_INFO_FILENAME |
98 | ", errno = %d\n" , |
99 | errno); |
100 | exit(EXIT_FAILURE); |
101 | } |
102 | |
103 | seqno = wsrep_xid_seqno(&xid); |
104 | |
105 | msg("mariabackup: Recovered WSREP position: %s:%lld\n" , |
106 | uuid_str, (long long) seqno); |
107 | |
108 | if (fprintf(fp, "%s:%lld" , uuid_str, (long long) seqno) < 0) { |
109 | |
110 | msg("mariabackup: error: " |
111 | "could not write to " XB_GALERA_INFO_FILENAME |
112 | ", errno = %d\n" , |
113 | errno); |
114 | exit(EXIT_FAILURE); |
115 | } |
116 | |
117 | fclose(fp); |
118 | } |
119 | #endif |
120 | |