Skip to content

Commit 865cec9

Browse files
committed
MDEV-15505 Fix wsrep XID storage byte order
2 parents 4359c6b + 33aad1d commit 865cec9

File tree

9 files changed

+80
-146
lines changed

9 files changed

+80
-146
lines changed

extra/mariabackup/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ IF(NOT HAVE_SYSTEM_REGEX)
4040
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/pcre)
4141
ENDIF()
4242

43+
IF(WITH_WSREP)
44+
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/wsrep)
45+
ENDIF()
46+
4347
ADD_DEFINITIONS(-UMYSQL_SERVER)
4448
########################################################################
4549
# xtrabackup binary

extra/mariabackup/wsrep.cc

Lines changed: 6 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -44,119 +44,16 @@ 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))
5551

56-
/*! undefined seqno */
57-
#define WSREP_SEQNO_UNDEFINED (-1)
52+
#include <wsrep_api.h>
5853

5954
/*! Name of file where Galera info is stored on recovery */
6055
#define XB_GALERA_INFO_FILENAME "xtrabackup_galera_info"
6156

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-
wsrep_seqno_t seqno;
123-
memcpy(&seqno, xid->data + WSREP_XID_SEQNO_OFFSET,
124-
sizeof(wsrep_seqno_t));
125-
126-
return(seqno);
127-
} else {
128-
return(WSREP_SEQNO_UNDEFINED);
129-
}
130-
}
131-
132-
/***********************************************************************//**
133-
Write UUID to string.
134-
135-
@return length of UUID string representation or -EMSGSIZE if string is too
136-
short.
137-
*/
138-
static
139-
int
140-
wsrep_uuid_print(
141-
/*=============*/
142-
const wsrep_uuid_t* uuid,
143-
char* str,
144-
size_t str_len)
145-
{
146-
if (str_len > 36) {
147-
const unsigned char* u = uuid->data;
148-
return snprintf(str, str_len,
149-
"%02x%02x%02x%02x-%02x%02x-%02x%02x-"
150-
"%02x%02x-%02x%02x%02x%02x%02x%02x",
151-
u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6],
152-
u[ 7], u[ 8], u[ 9], u[10], u[11], u[12], u[13],
153-
u[14], u[15]);
154-
}
155-
else {
156-
return -EMSGSIZE;
157-
}
158-
}
159-
16057
/***********************************************************************
16158
Store Galera checkpoint info in the 'xtrabackup_galera_info' file, if that
16259
information is present in the trx system header. Otherwise, do nothing. */
@@ -167,7 +64,7 @@ xb_write_galera_info(bool incremental_prepare)
16764
FILE* fp;
16865
XID xid;
16966
char uuid_str[40];
170-
wsrep_seqno_t seqno;
67+
long long seqno;
17168
MY_STAT statinfo;
17269

17370
/* Do not overwrite existing an existing file to be compatible with
@@ -186,7 +83,9 @@ xb_write_galera_info(bool incremental_prepare)
18683
return;
18784
}
18885

189-
if (wsrep_uuid_print(wsrep_xid_uuid(&xid), uuid_str,
86+
wsrep_uuid_t uuid;
87+
memcpy(uuid.data, wsrep_xid_uuid(&xid), sizeof(uuid.data));
88+
if (wsrep_uuid_print(&uuid, uuid_str,
19089
sizeof(uuid_str)) < 0) {
19190
return;
19291
}

include/mysql/service_wsrep.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ extern struct wsrep_service_st {
8484
void (*wsrep_aborting_thd_enqueue_func)(THD *thd);
8585
bool (*wsrep_consistency_check_func)(THD *thd);
8686
int (*wsrep_is_wsrep_xid_func)(const struct xid_t *xid);
87+
long long (*wsrep_xid_seqno_func)(const struct xid_t *xid);
88+
const unsigned char* (*wsrep_xid_uuid_func)(const struct xid_t *xid);
8789
void (*wsrep_lock_rollback_func)();
8890
int (*wsrep_on_func)(MYSQL_THD);
8991
void (*wsrep_post_commit_func)(THD* thd, bool all);
@@ -125,6 +127,8 @@ extern struct wsrep_service_st {
125127
#define wsrep_aborting_thd_enqueue(T) wsrep_service->wsrep_aborting_thd_enqueue_func(T)
126128
#define wsrep_consistency_check(T) wsrep_service->wsrep_consistency_check_func(T)
127129
#define wsrep_is_wsrep_xid(X) wsrep_service->wsrep_is_wsrep_xid_func(X)
130+
#define wsrep_xid_seqno(X) wsrep_service->wsrep_xid_seqno_func(X)
131+
#define wsrep_xid_uuid(X) wsrep_service->wsrep_xid_uuid_func(X)
128132
#define wsrep_lock_rollback() wsrep_service->wsrep_lock_rollback_func()
129133
#define wsrep_on(X) wsrep_service->wsrep_on_func(X)
130134
#define wsrep_post_commit(T,A) wsrep_service->wsrep_post_commit_func(T,A)
@@ -182,6 +186,8 @@ enum wsrep_exec_mode wsrep_thd_exec_mode(THD *thd);
182186
enum wsrep_query_state wsrep_thd_query_state(THD *thd);
183187
enum wsrep_trx_status wsrep_run_wsrep_commit(THD *thd, bool all);
184188
int wsrep_is_wsrep_xid(const struct xid_t* xid);
189+
long long wsrep_xid_seqno(const struct xid_t* xid);
190+
const unsigned char* wsrep_xid_uuid(const struct xid_t* xid);
185191
int wsrep_on(MYSQL_THD thd);
186192
int wsrep_thd_retry_counter(THD *thd);
187193
int wsrep_trx_is_aborting(MYSQL_THD thd);

sql/handler.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,11 +1484,13 @@ int ha_commit_trans(THD *thd, bool all)
14841484
DEBUG_SYNC(thd, "ha_commit_trans_after_prepare");
14851485
DBUG_EXECUTE_IF("crash_commit_after_prepare", DBUG_SUICIDE(););
14861486

1487+
#ifdef WITH_WSREP
14871488
if (!error && WSREP_ON && wsrep_is_wsrep_xid(&thd->transaction.xid_state.xid))
14881489
{
14891490
// xid was rewritten by wsrep
14901491
xid= wsrep_xid_seqno(thd->transaction.xid_state.xid);
14911492
}
1493+
#endif /* WITH_WSREP */
14921494

14931495
if (!is_real_trans)
14941496
{
@@ -1914,9 +1916,10 @@ static my_bool xarecover_handlerton(THD *unused, plugin_ref plugin,
19141916
got, hton_name(hton)->str);
19151917
for (int i=0; i < got; i ++)
19161918
{
1917-
my_xid x= WSREP_ON && wsrep_is_wsrep_xid(&info->list[i]) ?
1918-
wsrep_xid_seqno(info->list[i]) :
1919-
info->list[i].get_my_xid();
1919+
my_xid x= IF_WSREP(WSREP_ON && wsrep_is_wsrep_xid(&info->list[i]) ?
1920+
wsrep_xid_seqno(info->list[i]) :
1921+
info->list[i].get_my_xid(),
1922+
info->list[i].get_my_xid());
19201923
if (!x) // not "mine" - that is generated by external TM
19211924
{
19221925
#ifndef DBUG_OFF

sql/sql_plugin_services.ic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static struct wsrep_service_st wsrep_handler = {
154154
wsrep_aborting_thd_enqueue,
155155
wsrep_consistency_check,
156156
wsrep_is_wsrep_xid,
157+
wsrep_xid_seqno,
158+
wsrep_xid_uuid,
157159
wsrep_lock_rollback,
158160
wsrep_on,
159161
wsrep_post_commit,

sql/wsrep_dummy.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ enum wsrep_conflict_state wsrep_thd_conflict_state(THD *, my_bool)
2929
int wsrep_is_wsrep_xid(const XID*)
3030
{ return 0; }
3131

32+
long long wsrep_xid_seqno(const XID* x)
33+
{ return -1; }
34+
35+
const unsigned char* wsrep_xid_uuid(const XID*)
36+
{
37+
static const unsigned char uuid[16] = {0};
38+
return uuid;
39+
}
40+
3241
bool wsrep_prepare_key(const uchar*, size_t, const uchar*, size_t, struct wsrep_buf*, size_t*)
3342
{ return 0; }
3443

sql/wsrep_mysqld.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ bool wsrep_node_is_synced();
328328
#define WSREP_FORMAT(my_format) ((ulong)my_format)
329329
#define WSREP_PROVIDER_EXISTS (0)
330330
#define wsrep_emulate_bin_log (0)
331-
#define wsrep_xid_seqno(X) (0)
332331
#define wsrep_to_isolation (0)
333332
#define wsrep_init() (1)
334333
#define wsrep_prepend_PATH(X)

sql/wsrep_xid.cc

Lines changed: 35 additions & 11 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,16 +41,19 @@ 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));
42-
memcpy(xid->data + WSREP_XID_SEQNO_OFFSET, &seqno, sizeof(wsrep_seqno_t));
46+
int8store(xid->data + WSREP_XID_SEQNO_OFFSET,seqno);
4347
}
4448

4549
int wsrep_is_wsrep_xid(const XID* xid)
4650
{
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)
@@ -59,18 +65,36 @@ const wsrep_uuid_t* wsrep_xid_uuid(const XID& xid)
5965
return &WSREP_UUID_UNDEFINED;
6066
}
6167

68+
const unsigned char* wsrep_xid_uuid(const xid_t* xid)
69+
{
70+
DBUG_ASSERT(xid);
71+
return wsrep_xid_uuid(*xid)->data;
72+
}
73+
6274
wsrep_seqno_t wsrep_xid_seqno(const XID& xid)
6375
{
76+
wsrep_seqno_t ret= WSREP_SEQNO_UNDEFINED;
6477
if (wsrep_is_wsrep_xid(&xid))
6578
{
66-
wsrep_seqno_t seqno;
67-
memcpy(&seqno, xid.data + WSREP_XID_SEQNO_OFFSET, sizeof(wsrep_seqno_t));
68-
return seqno;
69-
}
70-
else
71-
{
72-
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+
}
7390
}
91+
return ret;
92+
}
93+
94+
long long wsrep_xid_seqno(const xid_t* xid)
95+
{
96+
DBUG_ASSERT(xid);
97+
return wsrep_xid_seqno(*xid);
7498
}
7599

76100
static my_bool set_SE_checkpoint(THD* unused, plugin_ref plugin, void* arg)

0 commit comments

Comments
 (0)