diff options
Diffstat (limited to 'sql/wsrep_xid.cc')
-rw-r--r-- | sql/wsrep_xid.cc | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/sql/wsrep_xid.cc b/sql/wsrep_xid.cc index 923abe53c6c..d8f6e013820 100644 --- a/sql/wsrep_xid.cc +++ b/sql/wsrep_xid.cc @@ -21,8 +21,9 @@ #include "sql_class.h" #include "wsrep_mysqld.h" // for logging macros -#include <algorithm> /* std::sort() */ +#include <mysql/service_wsrep.h> +#include <algorithm> /* std::sort() */ /* * WSREPXid */ @@ -36,20 +37,22 @@ #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::gtid& wsgtid) { 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); - xid->data[WSREP_XID_VERSION_OFFSET] = WSREP_XID_VERSION_2; - memcpy(xid->data + WSREP_XID_UUID_OFFSET, &uuid, sizeof(wsrep_uuid_t)); - int8store(xid->data + WSREP_XID_SEQNO_OFFSET,seqno); + xid->data[WSREP_XID_VERSION_OFFSET]= WSREP_XID_VERSION_2; + memcpy(xid->data + WSREP_XID_UUID_OFFSET, wsgtid.id().data(),sizeof(wsrep::id)); + int8store(xid->data + WSREP_XID_SEQNO_OFFSET, wsgtid.seqno().get()); } -int wsrep_is_wsrep_xid(const XID* xid) +extern "C" +int wsrep_is_wsrep_xid(const void* xid_ptr) { + const XID* xid= static_cast<const XID*>(xid_ptr); return (xid->formatID == 1 && xid->gtrid_length == WSREP_XID_GTRID_LEN && xid->bqual_length == 0 && @@ -58,33 +61,36 @@ int wsrep_is_wsrep_xid(const XID* xid) xid->data[WSREP_XID_VERSION_OFFSET] == WSREP_XID_VERSION_2)); } -const wsrep_uuid_t* wsrep_xid_uuid(const XID& xid) +const unsigned char* wsrep_xid_uuid(const xid_t* xid) { - if (wsrep_is_wsrep_xid(&xid)) - return reinterpret_cast<const wsrep_uuid_t*>(xid.data - + WSREP_XID_UUID_OFFSET); + DBUG_ASSERT(xid); + static wsrep::id const undefined; + if (wsrep_is_wsrep_xid(xid)) + return reinterpret_cast<const unsigned char*> + (xid->data + WSREP_XID_UUID_OFFSET); else - return &WSREP_UUID_UNDEFINED; + return static_cast<const unsigned char*>(wsrep::id::undefined().data()); } -const unsigned char* wsrep_xid_uuid(const xid_t* xid) +const wsrep::id& wsrep_xid_uuid(const XID& xid) { - DBUG_ASSERT(xid); - return wsrep_xid_uuid(*xid)->data; + compile_time_assert(sizeof(wsrep::id) == sizeof(wsrep_uuid_t)); + return *reinterpret_cast<const wsrep::id*>(wsrep_xid_uuid(&xid)); } -wsrep_seqno_t wsrep_xid_seqno(const XID& xid) +long long wsrep_xid_seqno(const xid_t* xid) { - wsrep_seqno_t ret= WSREP_SEQNO_UNDEFINED; - if (wsrep_is_wsrep_xid(&xid)) + DBUG_ASSERT(xid); + long long ret= wsrep::seqno::undefined().get(); + if (wsrep_is_wsrep_xid(xid)) { - switch (xid.data[WSREP_XID_VERSION_OFFSET]) + switch (xid->data[WSREP_XID_VERSION_OFFSET]) { case WSREP_XID_VERSION_1: - memcpy(&ret, xid.data + WSREP_XID_SEQNO_OFFSET, sizeof ret); + memcpy(&ret, xid->data + WSREP_XID_SEQNO_OFFSET, sizeof ret); break; case WSREP_XID_VERSION_2: - ret= sint8korr(xid.data + WSREP_XID_SEQNO_OFFSET); + ret= sint8korr(xid->data + WSREP_XID_SEQNO_OFFSET); break; default: break; @@ -93,10 +99,9 @@ wsrep_seqno_t wsrep_xid_seqno(const XID& xid) return ret; } -long long wsrep_xid_seqno(const xid_t* xid) +wsrep::seqno wsrep_xid_seqno(const XID& xid) { - DBUG_ASSERT(xid); - return wsrep_xid_seqno(*xid); + return wsrep::seqno(wsrep_xid_seqno(&xid)); } static my_bool set_SE_checkpoint(THD* unused, plugin_ref plugin, void* arg) @@ -106,11 +111,11 @@ static my_bool set_SE_checkpoint(THD* unused, plugin_ref plugin, void* arg) if (hton->set_checkpoint) { - const wsrep_uuid_t* uuid(wsrep_xid_uuid(*xid)); - char uuid_str[40] = {0, }; - wsrep_uuid_print(uuid, uuid_str, sizeof(uuid_str)); + const unsigned char* uuid= wsrep_xid_uuid(xid); + char uuid_str[40]= {0, }; + wsrep_uuid_print((const wsrep_uuid_t*)uuid, uuid_str, sizeof(uuid_str)); WSREP_DEBUG("Set WSREPXid for InnoDB: %s:%lld", - uuid_str, (long long)wsrep_xid_seqno(*xid)); + uuid_str, (long long)wsrep_xid_seqno(xid)); hton->set_checkpoint(hton, xid); } return FALSE; @@ -122,10 +127,10 @@ bool wsrep_set_SE_checkpoint(XID& xid) &xid); } -bool wsrep_set_SE_checkpoint(const wsrep_uuid_t& uuid, wsrep_seqno_t seqno) +bool wsrep_set_SE_checkpoint(const wsrep::gtid& wsgtid) { XID xid; - wsrep_xid_init(&xid, uuid, seqno); + wsrep_xid_init(&xid, wsgtid); return wsrep_set_SE_checkpoint(xid); } @@ -137,11 +142,12 @@ static my_bool get_SE_checkpoint(THD* unused, plugin_ref plugin, void* arg) if (hton->get_checkpoint) { hton->get_checkpoint(hton, xid); - const wsrep_uuid_t* uuid(wsrep_xid_uuid(*xid)); - char uuid_str[40] = {0, }; - wsrep_uuid_print(uuid, uuid_str, sizeof(uuid_str)); + wsrep_uuid_t uuid; + memcpy(&uuid, wsrep_xid_uuid(xid), sizeof(uuid)); + char uuid_str[40]= {0, }; + wsrep_uuid_print(&uuid, uuid_str, sizeof(uuid_str)); WSREP_DEBUG("Read WSREPXid from InnoDB: %s:%lld", - uuid_str, (long long)wsrep_xid_seqno(*xid)); + uuid_str, (long long)wsrep_xid_seqno(xid)); } return FALSE; } @@ -152,34 +158,28 @@ bool wsrep_get_SE_checkpoint(XID& xid) &xid); } -bool wsrep_get_SE_checkpoint(wsrep_uuid_t& uuid, wsrep_seqno_t& seqno) +wsrep::gtid wsrep_get_SE_checkpoint() { - uuid= WSREP_UUID_UNDEFINED; - seqno= WSREP_SEQNO_UNDEFINED; - XID xid; xid.null(); if (wsrep_get_SE_checkpoint(xid)) { - return true; + return wsrep::gtid(); } if (xid.is_null()) { - return false; + return wsrep::gtid(); } if (!wsrep_is_wsrep_xid(&xid)) { WSREP_WARN("Read non-wsrep XID from storage engines."); - return false; + return wsrep::gtid(); } - uuid= *wsrep_xid_uuid(xid); - seqno= wsrep_xid_seqno(xid); - - return false; + return wsrep::gtid(wsrep_xid_uuid(xid),wsrep_xid_seqno(xid)); } /* @@ -196,7 +196,7 @@ struct Wsrep_xid_cmp const bool right_is_wsrep= wsrep_is_wsrep_xid(&right); if (left_is_wsrep && right_is_wsrep) { - return (wsrep_xid_seqno(left) < wsrep_xid_seqno(right)); + return (wsrep_xid_seqno(&left) < wsrep_xid_seqno(&right)); } else if (left_is_wsrep) { |