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 2 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
61 changes: 50 additions & 11 deletions sql/wsrep_xid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,44 @@
#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)
static inline wsrep_seqno_t
xid_to_host_seqno(wsrep_seqno_t const seqno)
{
// a little trick to simplify migration for existing installations:
// it is highly inlikely that the current seqno in any big-endian
// production cluster exceeds 0x0000000fffffffffLL (64G).
// Hence any seqno read from XID that is bigger than that must have been
// written in BE format. This BE detection has failure probability of
// 1 in 256M. This must be removed after next release.
wsrep_seqno_t const ret(wsrep_seqno_byteswap(seqno));
return (ret > 0x0000000fffffffffLL || ret < WSREP_SEQNO_UNDEFINED ?
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a time bomb. It would probably be better to change WSREP_XID_PREFIX and do the byteswap if the stored value has the new format.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does WSREP_XID_PREFIX act as a version ID? If so, then indeed it is better.

seqno : ret);
}
#else
#define host_to_xid_seqno(s) (s)
#define xid_to_host_seqno(s) host_to_xid_seqno(s)
#endif

/*
* WSREPXid
*/
Expand All @@ -30,15 +68,16 @@
#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));
}

int wsrep_is_wsrep_xid(const void* xid_ptr)
Expand All @@ -65,7 +104,7 @@ wsrep_seqno_t wsrep_xid_seqno(const XID& xid)
{
wsrep_seqno_t seqno;
memcpy(&seqno, xid.data + WSREP_XID_SEQNO_OFFSET, sizeof(wsrep_seqno_t));
return seqno;
return xid_to_host_seqno(seqno);
}
else
{
Expand Down Expand Up @@ -99,13 +138,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