Skip to content

Commit b125ae0

Browse files
committed
MDEV-15505 New wsrep XID format for backwards compatibility
A new wsrep XID format was added to keep the XID implementation backwards compatible. Original version always reads XID seqno part in host byte order, the new version in little endian byte order. Wsrep XID will always be written in the new format. Included wsrep_api.h from service_wsrep.h for wsrep type definitions. Removed redundant wsrep XID code from mariabackup and included service_wsrep.h in order to use
1 parent dd74b94 commit b125ae0

File tree

5 files changed

+34
-126
lines changed

5 files changed

+34
-126
lines changed

cmake/wsrep.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ SET(WSREP_PROC_INFO ${WITH_WSREP})
4040

4141
IF(WITH_WSREP)
4242
SET(WSREP_PATCH_VERSION "wsrep_${WSREP_VERSION}")
43+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/wsrep)
4344
ENDIF()

extra/mariabackup/wsrep.cc

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -44,115 +44,14 @@ permission notice:
4444
#include <my_base.h>
4545
#include <handler.h>
4646
#include <trx0rseg.h>
47+
#include <mysql/service_wsrep.h>
4748

4849
#include "common.h"
4950
#ifdef WITH_WSREP
50-
#define WSREP_XID_PREFIX "WSREPXid"
51-
#define WSREP_XID_PREFIX_LEN MYSQL_XID_PREFIX_LEN
52-
#define WSREP_XID_UUID_OFFSET 8
53-
#define WSREP_XID_SEQNO_OFFSET (WSREP_XID_UUID_OFFSET + sizeof(wsrep_uuid_t))
54-
#define WSREP_XID_GTRID_LEN (WSREP_XID_SEQNO_OFFSET + sizeof(wsrep_seqno_t))
55-
56-
/*! undefined seqno */
57-
#define WSREP_SEQNO_UNDEFINED (-1)
5851

5952
/*! Name of file where Galera info is stored on recovery */
6053
#define XB_GALERA_INFO_FILENAME "xtrabackup_galera_info"
6154

62-
/* Galera UUID type - for all unique IDs */
63-
typedef struct wsrep_uuid {
64-
unsigned char data[16];
65-
} wsrep_uuid_t;
66-
67-
/* sequence number of a writeset, etc. */
68-
typedef long long wsrep_seqno_t;
69-
70-
/* Undefined UUID */
71-
static const wsrep_uuid_t WSREP_UUID_UNDEFINED = {{0,}};
72-
73-
/***********************************************************************//**
74-
Check if a given WSREP XID is valid.
75-
76-
@return true if valid.
77-
*/
78-
static
79-
bool
80-
wsrep_is_wsrep_xid(
81-
/*===============*/
82-
const void* xid_ptr)
83-
{
84-
const XID* xid = reinterpret_cast<const XID*>(xid_ptr);
85-
86-
return((xid->formatID == 1 &&
87-
xid->gtrid_length == WSREP_XID_GTRID_LEN &&
88-
xid->bqual_length == 0 &&
89-
!memcmp(xid->data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN)));
90-
}
91-
92-
/***********************************************************************//**
93-
Retrieve binary WSREP UUID from XID.
94-
95-
@return binary WSREP UUID represenataion, if UUID is valid, or
96-
WSREP_UUID_UNDEFINED otherwise.
97-
*/
98-
static
99-
const wsrep_uuid_t*
100-
wsrep_xid_uuid(
101-
/*===========*/
102-
const XID* xid)
103-
{
104-
if (wsrep_is_wsrep_xid(xid)) {
105-
return(reinterpret_cast<const wsrep_uuid_t*>
106-
(xid->data + WSREP_XID_UUID_OFFSET));
107-
} else {
108-
return(&WSREP_UUID_UNDEFINED);
109-
}
110-
}
111-
112-
/***********************************************************************//**
113-
Retrieve WSREP seqno from XID.
114-
115-
@return WSREP seqno, if it is valid, or WSREP_SEQNO_UNDEFINED otherwise.
116-
*/
117-
wsrep_seqno_t wsrep_xid_seqno(
118-
/*==========================*/
119-
const XID* xid)
120-
{
121-
if (wsrep_is_wsrep_xid(xid)) {
122-
return sint8korr(xid->data + WSREP_XID_SEQNO_OFFSET);
123-
} else {
124-
return(WSREP_SEQNO_UNDEFINED);
125-
}
126-
}
127-
128-
/***********************************************************************//**
129-
Write UUID to string.
130-
131-
@return length of UUID string representation or -EMSGSIZE if string is too
132-
short.
133-
*/
134-
static
135-
int
136-
wsrep_uuid_print(
137-
/*=============*/
138-
const wsrep_uuid_t* uuid,
139-
char* str,
140-
size_t str_len)
141-
{
142-
if (str_len > 36) {
143-
const unsigned char* u = uuid->data;
144-
return snprintf(str, str_len,
145-
"%02x%02x%02x%02x-%02x%02x-%02x%02x-"
146-
"%02x%02x-%02x%02x%02x%02x%02x%02x",
147-
u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6],
148-
u[ 7], u[ 8], u[ 9], u[10], u[11], u[12], u[13],
149-
u[14], u[15]);
150-
}
151-
else {
152-
return -EMSGSIZE;
153-
}
154-
}
155-
15655
/***********************************************************************
15756
Store Galera checkpoint info in the 'xtrabackup_galera_info' file, if that
15857
information is present in the trx system header. Otherwise, do nothing. */
@@ -182,7 +81,9 @@ xb_write_galera_info(bool incremental_prepare)
18281
return;
18382
}
18483

185-
if (wsrep_uuid_print(wsrep_xid_uuid(&xid), uuid_str,
84+
wsrep_uuid_t uuid;
85+
memcpy(uuid.data, wsrep_xid_uuid(&xid), sizeof(uuid.data));
86+
if (wsrep_uuid_print(&uuid, uuid_str,
18687
sizeof(uuid_str)) < 0) {
18788
return;
18889
}

include/mysql/service_wsrep.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
For engines that want to support galera.
2323
*/
2424

25+
#include <wsrep_api.h>
26+
2527
#ifdef __cplusplus
2628
extern "C" {
2729
#endif
@@ -67,11 +69,7 @@ enum wsrep_trx_status {
6769
};
6870

6971
struct xid_t;
70-
struct wsrep;
7172
struct wsrep_ws_handle;
72-
struct wsrep_buf;
73-
/* must match to typedef in wsrep/wsrep_api.h */
74-
typedef int64_t wsrep_seqno_t;
7573

7674
extern struct wsrep_service_st {
7775
struct wsrep * (*get_wsrep_func)();

sql/wsrep_xid.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
* WSREPXid
2626
*/
2727

28-
#define WSREP_XID_PREFIX "WSREPXid"
29-
#define WSREP_XID_PREFIX_LEN MYSQL_XID_PREFIX_LEN
28+
#define WSREP_XID_PREFIX "WSREPXi"
29+
#define WSREP_XID_PREFIX_LEN 7
30+
#define WSREP_XID_VERSION_OFFSET WSREP_XID_PREFIX_LEN
31+
#define WSREP_XID_VERSION_1 'd'
32+
#define WSREP_XID_VERSION_2 'e'
3033
#define WSREP_XID_UUID_OFFSET 8
3134
#define WSREP_XID_SEQNO_OFFSET (WSREP_XID_UUID_OFFSET + sizeof(wsrep_uuid_t))
3235
#define WSREP_XID_GTRID_LEN (WSREP_XID_SEQNO_OFFSET + sizeof(wsrep_seqno_t))
@@ -38,6 +41,7 @@ void wsrep_xid_init(XID* xid, const wsrep_uuid_t& uuid, wsrep_seqno_t seqno)
3841
xid->bqual_length= 0;
3942
memset(xid->data, 0, sizeof(xid->data));
4043
memcpy(xid->data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN);
44+
xid->data[WSREP_XID_VERSION_OFFSET] = WSREP_XID_VERSION_2;
4145
memcpy(xid->data + WSREP_XID_UUID_OFFSET, &uuid, sizeof(wsrep_uuid_t));
4246
int8store(xid->data + WSREP_XID_SEQNO_OFFSET,seqno);
4347
}
@@ -47,7 +51,9 @@ int wsrep_is_wsrep_xid(const XID* xid)
4751
return (xid->formatID == 1 &&
4852
xid->gtrid_length == WSREP_XID_GTRID_LEN &&
4953
xid->bqual_length == 0 &&
50-
!memcmp(xid->data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN));
54+
!memcmp(xid->data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN) &&
55+
(xid->data[WSREP_XID_VERSION_OFFSET] == WSREP_XID_VERSION_1 ||
56+
xid->data[WSREP_XID_VERSION_OFFSET] == WSREP_XID_VERSION_2));
5157
}
5258

5359
const wsrep_uuid_t* wsrep_xid_uuid(const XID& xid)
@@ -67,14 +73,22 @@ const unsigned char* wsrep_xid_uuid(const xid_t* xid)
6773

6874
wsrep_seqno_t wsrep_xid_seqno(const XID& xid)
6975
{
76+
wsrep_seqno_t ret= WSREP_SEQNO_UNDEFINED;
7077
if (wsrep_is_wsrep_xid(&xid))
7178
{
72-
return sint8korr(xid.data + WSREP_XID_SEQNO_OFFSET);
73-
}
74-
else
75-
{
76-
return WSREP_SEQNO_UNDEFINED;
79+
switch (xid.data[WSREP_XID_VERSION_OFFSET])
80+
{
81+
case WSREP_XID_VERSION_1:
82+
memcpy(&ret, xid.data + WSREP_XID_SEQNO_OFFSET, sizeof ret);
83+
break;
84+
case WSREP_XID_VERSION_2:
85+
ret= sint8korr(xid.data + WSREP_XID_SEQNO_OFFSET);
86+
break;
87+
default:
88+
break;
89+
}
7790
}
91+
return ret;
7892
}
7993

8094
wsrep_seqno_t wsrep_xid_seqno(const xid_t* xid)

storage/innobase/trx/trx0rseg.cc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,6 @@ static bool trx_rseg_init_wsrep_xid(const page_t* page, XID& xid)
186186
memcpy(xid.data,
187187
TRX_SYS + TRX_SYS_WSREP_XID_INFO
188188
+ TRX_SYS_WSREP_XID_DATA + page, XIDDATASIZE);
189-
190-
/* Wsrep XID seqno part in TRX_SYS page was written in host byte
191-
order. However, in the XID which gets written to the rollback
192-
segment header the byte order is little endian. On big endian
193-
machines swap the seqno part byte order. */
194-
#ifdef WORDS_BIGENDIAN
195-
wsrep_seqno_t seqno;
196-
memcpy(&seqno, xid.data + 24, sizeof seqno);
197-
mach_swap_byte_order(xid.data + 24, &seqno, sizeof seqno);
198-
#endif /* WORDS_BIGENDIAN */
199-
200189
return true;
201190
}
202191

@@ -216,6 +205,11 @@ bool trx_rseg_read_wsrep_checkpoint(XID& xid)
216205
if (rseg_id == 0) {
217206
found = trx_rseg_init_wsrep_xid(sys->frame, xid);
218207
ut_ad(!found || xid.formatID == 1);
208+
if (found) {
209+
max_xid_seqno = wsrep_xid_seqno(&xid);
210+
memcpy(wsrep_uuid, wsrep_xid_uuid(&xid),
211+
sizeof wsrep_uuid);
212+
}
219213
}
220214

221215
const uint32_t page_no = trx_sysf_rseg_get_page_no(

0 commit comments

Comments
 (0)