Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh104 #106

Open
wants to merge 3 commits into
base: gh33
Choose a base branch
from
Open

Gh104 #106

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/wsrep_sst_rsync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ check_pid_and_port()
grep -w '^rsync[[:space:]]\+'"$rsync_pid" 2>/dev/null)

if [ -n "$port_info" -a -z "$is_rsync" ]; then
wsrep_log_error "rsync daemon port '$rsync_port' has been taken"
wsrep_log_error "rsync daemon port '$rsync_port' has been taken by: $port_info"
exit 16 # EBUSY
fi

check_pid $pid_file && \
[ -n "$port_info" ] && [ -n "$is_rsync" ] && \
[ $(cat $pid_file) -eq $rsync_pid ]
Expand Down
2 changes: 1 addition & 1 deletion sql/wsrep_applier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static wsrep_cb_status_t wsrep_apply_events(THD* thd,

thd->server_id = ev->server_id; // use the original server id for logging
thd->set_time(); // time the query
wsrep_xid_init(&thd->transaction.xid_state.xid,
wsrep_xid_init(thd->transaction.xid_state.xid,
thd->wsrep_trx_meta.gtid.uuid,
thd->wsrep_trx_meta.gtid.seqno);
thd->lex->current_select= 0;
Expand Down
2 changes: 1 addition & 1 deletion sql/wsrep_hton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all)
/* Override XID iff it was generated by mysql */
if (thd->transaction.xid_state.xid.get_my_xid())
{
wsrep_xid_init(&thd->transaction.xid_state.xid,
wsrep_xid_init(thd->transaction.xid_state.xid,
thd->wsrep_trx_meta.gtid.uuid,
thd->wsrep_trx_meta.gtid.seqno);
}
Expand Down
77 changes: 60 additions & 17 deletions sql/wsrep_xid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,71 @@
#include "sql_class.h"
#include "wsrep_mysqld.h" // for logging macros

static inline wsrep_seqno_t
wsrep_seqno_byteswap(wsrep_seqno_t const seqno)
{
union { wsrep_seqno_t s; uint8_t b[8]; } from, to;

from.s = seqno;

to.b[0] = from.b[7]; to.b[1] = from.b[6];
to.b[2] = from.b[5]; to.b[3] = from.b[4];
to.b[4] = from.b[3]; to.b[5] = from.b[2];
to.b[6] = from.b[1]; to.b[7] = from.b[0];

return to.s;
}

/* Since vast majority of existing installations are little-endian and
* for the general little-endian cause, canonical XID seqno representation
* is little-endian. */
#ifdef WORDS_BIGENDIAN
#define HOST_TO_XID_SEQNO(s) wsrep_seqno_byteswap(s)
#else
#define HOST_TO_XID_SEQNO(s) (s)
#endif
#define XID_TO_HOST_SEQNO(s) HOST_TO_XID_SEQNO(s)

/*
* WSREPXid
*/

#define WSREP_XID_PREFIX "WSREPXid"
#define WSREP_XID_PREFIX_1 "WSREPXid" // seqno in host order
#define WSREP_XID_PREFIX_2 "WS_XID_2" // seqno in little-endian order
#define WSREP_XID_PREFIX WSREP_XID_PREFIX_2 // current version
#define WSREP_XID_PREFIX_LEN MYSQL_XID_PREFIX_LEN
#define WSREP_XID_UUID_OFFSET 8
#define WSREP_XID_SEQNO_OFFSET (WSREP_XID_UUID_OFFSET + sizeof(wsrep_uuid_t))
#define WSREP_XID_GTRID_LEN (WSREP_XID_SEQNO_OFFSET + sizeof(wsrep_seqno_t))

void wsrep_xid_init(XID* xid, const wsrep_uuid_t& uuid, wsrep_seqno_t seqno)
void wsrep_xid_init(XID& xid, const wsrep_uuid_t& uuid, wsrep_seqno_t seqno)
{
xid->formatID= 1;
xid->gtrid_length= WSREP_XID_GTRID_LEN;
xid->bqual_length= 0;
memset(xid->data, 0, sizeof(xid->data));
memcpy(xid->data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN);
memcpy(xid->data + WSREP_XID_UUID_OFFSET, &uuid, sizeof(wsrep_uuid_t));
memcpy(xid->data + WSREP_XID_SEQNO_OFFSET, &seqno, sizeof(wsrep_seqno_t));
seqno= HOST_TO_XID_SEQNO(seqno);
xid.formatID= 1;
xid.gtrid_length= WSREP_XID_GTRID_LEN;
xid.bqual_length= 0;
memset(xid.data, 0, sizeof(xid.data));
memcpy(xid.data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN);
memcpy(xid.data + WSREP_XID_UUID_OFFSET, &uuid, sizeof(wsrep_uuid_t));
memcpy(xid.data + WSREP_XID_SEQNO_OFFSET, &seqno, sizeof(wsrep_seqno_t));
}

// returns XID version, 0 if not a wsrep XID
int wsrep_is_wsrep_xid(const void* xid_ptr)
{
const XID* xid= reinterpret_cast<const XID*>(xid_ptr);
return (xid->formatID == 1 &&
xid->gtrid_length == WSREP_XID_GTRID_LEN &&
xid->bqual_length == 0 &&
!memcmp(xid->data, WSREP_XID_PREFIX, WSREP_XID_PREFIX_LEN));

if (xid->formatID == 1 &&
xid->gtrid_length == WSREP_XID_GTRID_LEN &&
xid->bqual_length == 0)
{
if (!memcmp(xid->data, WSREP_XID_PREFIX_2, WSREP_XID_PREFIX_LEN))
return 2;
if (!memcmp(xid->data, WSREP_XID_PREFIX_1, WSREP_XID_PREFIX_LEN))
return 1;
}

return 0;
}

const wsrep_uuid_t* wsrep_xid_uuid(const XID& xid)
Expand All @@ -61,11 +98,17 @@ const wsrep_uuid_t* wsrep_xid_uuid(const XID& xid)

wsrep_seqno_t wsrep_xid_seqno(const XID& xid)
{
if (wsrep_is_wsrep_xid(&xid))
int const xid_ver = wsrep_is_wsrep_xid(&xid);
if (xid_ver)
{
wsrep_seqno_t seqno;
memcpy(&seqno, xid.data + WSREP_XID_SEQNO_OFFSET, sizeof(wsrep_seqno_t));
return seqno;
#ifdef WORDS_BIGENDIAN
if (xid_ver >= 2)
return XID_TO_HOST_SEQNO(seqno);
else
#endif /* WORDS_BIGENDIAN */
return seqno; // host and XID orders are the same
}
else
{
Expand Down Expand Up @@ -99,13 +142,13 @@ void wsrep_set_SE_checkpoint(XID& xid)
void wsrep_set_SE_checkpoint(const wsrep_uuid_t& uuid, wsrep_seqno_t seqno)
{
XID xid;
wsrep_xid_init(&xid, uuid, seqno);
wsrep_xid_init(xid, uuid, seqno);
wsrep_set_SE_checkpoint(xid);
}

static my_bool get_SE_checkpoint(THD* unused, plugin_ref plugin, void* arg)
{
XID* xid= reinterpret_cast<XID*>(arg);
XID* xid= static_cast<XID*>(arg);
handlerton* hton= plugin_data(plugin, handlerton *);

if (hton->db_type == DB_TYPE_INNODB)
Expand Down
9 changes: 5 additions & 4 deletions sql/wsrep_xid.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#define WSREP_XID_H

#include "../wsrep/wsrep_api.h"
#include "handler.h" // XID typedef

void wsrep_xid_init(xid_t*, const wsrep_uuid_t&, wsrep_seqno_t);
struct xid_t;

void wsrep_xid_init(xid_t&, const wsrep_uuid_t&, wsrep_seqno_t);
int wsrep_is_wsrep_xid(const void* xid);
const wsrep_uuid_t* wsrep_xid_uuid(const XID&);
wsrep_seqno_t wsrep_xid_seqno(const XID&);
const wsrep_uuid_t* wsrep_xid_uuid(const xid_t&);
wsrep_seqno_t wsrep_xid_seqno(const xid_t&);

//void wsrep_get_SE_checkpoint(XID&); uncomment if needed
void wsrep_get_SE_checkpoint(wsrep_uuid_t&, wsrep_seqno_t&);
Expand Down
30 changes: 9 additions & 21 deletions storage/innobase/trx/trx0sys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,11 @@ trx_sys_print_mysql_binlog_offset(void)

#ifdef WITH_WSREP

#include <wsrep_xid.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces unnecessary dependency between InnoDB and MySQL/wsrep code. Setting xid->formatID = -1 in code below is enough to indicate that the XID is null, so WSREP_* macros and wsrep_xid_init() don't have to be included.

#ifdef UNIV_DEBUG
static long long trx_sys_cur_xid_seqno = -1;
static unsigned char trx_sys_cur_xid_uuid[16];

long long read_wsrep_xid_seqno(const XID* xid)
{
long long seqno;
memcpy(&seqno, xid->data + 24, sizeof(long long));
return seqno;
}

void read_wsrep_xid_uuid(const XID* xid, unsigned char* buf)
{
memcpy(buf, xid->data + 8, 16);
}

static size_t const xid_len = sizeof(trx_sys_cur_xid_uuid);
#endif /* UNIV_DEBUG */

void
Expand All @@ -345,17 +334,17 @@ trx_sys_update_wsrep_checkpoint(
#ifdef UNIV_DEBUG
{
/* Check that seqno is monotonically increasing */
unsigned char xid_uuid[16];
long long xid_seqno = read_wsrep_xid_seqno(xid);
read_wsrep_xid_uuid(xid, xid_uuid);
if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8))
const wsrep_uuid_t* const xid_uuid = wsrep_xid_uuid(*xid);
wsrep_seqno_t const xid_seqno = wsrep_xid_seqno(*xid);
if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, xid_len))
{
ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
ut_ad(xid_seqno > trx_sys_cur_xid_seqno ||
trx_sys_cur_xid_seqno < 0);
trx_sys_cur_xid_seqno = xid_seqno;
}
else
{
memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
memcpy(trx_sys_cur_xid_uuid, xid_uuid, xid_len);
}
trx_sys_cur_xid_seqno = xid_seqno;
}
Expand Down Expand Up @@ -409,8 +398,7 @@ trx_sys_read_wsrep_checkpoint(XID* xid)
if ((magic = mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+ TRX_SYS_WSREP_XID_MAGIC_N_FLD))
!= TRX_SYS_WSREP_XID_MAGIC_N) {
memset(xid, 0, sizeof(*xid));
xid->formatID = -1;
wsrep_xid_init(*xid,WSREP_UUID_UNDEFINED,WSREP_SEQNO_UNDEFINED);
trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
mtr_commit(&mtr);
return;
Expand Down