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-1335  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-1335  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
xb_write_galera_info(bool incremental_prepare)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 	xid.null();
79 
80 	if (!trx_rseg_read_wsrep_checkpoint(xid)) {
81 
82 		return;
83 	}
84 
85 	wsrep_uuid_t uuid;
86 	memcpy(uuid.data, wsrep_xid_uuid(&xid), sizeof(uuid.data));
87 	if (wsrep_uuid_print(&uuid, uuid_str,
88 			     sizeof(uuid_str)) < 0) {
89 		return;
90 	}
91 
92 	fp = fopen(XB_GALERA_INFO_FILENAME, "w");
93 	if (fp == NULL) {
94 
95 		die(
96 		    "could not create " XB_GALERA_INFO_FILENAME
97 		    ", errno = %d\n",
98 		    errno);
99 		exit(EXIT_FAILURE);
100 	}
101 
102 	seqno = wsrep_xid_seqno(&xid);
103 
104 	msg("mariabackup: Recovered WSREP position: %s:%lld\n",
105 	    uuid_str, (long long) seqno);
106 
107 	if (fprintf(fp, "%s:%lld", uuid_str, (long long) seqno) < 0) {
108 
109 		die(
110 		    "could not write to " XB_GALERA_INFO_FILENAME
111 		    ", errno = %d\n",
112 		    errno);;
113 	}
114 
115 	fclose(fp);
116 }
117 #endif
118