104 lines
3.4 KiB
C++
104 lines
3.4 KiB
C++
/* Copyright (c) 2018, 2021, Alibaba and/or its affiliates. All rights reserved.
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License, version 2.0,
|
|
as published by the Free Software Foundation.
|
|
This program is also distributed with certain software (including
|
|
but not limited to OpenSSL) that is licensed under separate terms,
|
|
as designated in a particular file or component or in included license
|
|
documentation. The authors of MySQL/PolarDB-X Engine hereby grant you an
|
|
additional permission to link the program and your derivative works with the
|
|
separately licensed software that they have included with
|
|
MySQL/PolarDB-X Engine.
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License, version 2.0, for more details.
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
|
|
/** @file trx/lizard0xa.cc
|
|
Lizard XA transaction structure.
|
|
|
|
Created 2021-08-10 by Jianwei.zhao
|
|
*******************************************************/
|
|
|
|
#include "lizard0xa.h"
|
|
#include "lizard0read0types.h"
|
|
#include "m_ctype.h"
|
|
#include "mysql/plugin.h"
|
|
#include "sql/xa.h"
|
|
#include "trx0sys.h"
|
|
|
|
/** Bqual format: 'xxx@nnnn' */
|
|
static unsigned int XID_GROUP_SUFFIX_SIZE = 5;
|
|
|
|
static char XID_GROUP_SPLIT_CHAR = '@';
|
|
|
|
/**
|
|
Whether the XID group matched.
|
|
|
|
Requirement:
|
|
1) formatID must be equal
|
|
2) gtrid must be equal
|
|
3) bqual length must be equal
|
|
4) bqual prefix must be equal
|
|
5) bqual suffix must be number
|
|
*/
|
|
bool trx_group_match_by_xid(const XID *lhs, const XID *rhs) {
|
|
/* Require within XA transaction */
|
|
if (lhs->is_null() || rhs->is_null()) return false;
|
|
|
|
/* Require formatID equal */
|
|
if (lhs->formatID != rhs->formatID) return false;
|
|
|
|
int prefix_len =
|
|
lhs->gtrid_length + lhs->bqual_length - XID_GROUP_SUFFIX_SIZE;
|
|
|
|
if (lhs->gtrid_length != rhs->gtrid_length ||
|
|
lhs->bqual_length != rhs->bqual_length ||
|
|
lhs->bqual_length <= XID_GROUP_SUFFIX_SIZE ||
|
|
lhs->data[prefix_len] != XID_GROUP_SPLIT_CHAR ||
|
|
memcmp(lhs->data, rhs->data, prefix_len + 1)) {
|
|
return false;
|
|
}
|
|
|
|
for (unsigned int i = 1; i < XID_GROUP_SUFFIX_SIZE; i++) {
|
|
if (!my_isdigit(&my_charset_latin1, lhs->data[prefix_len + i]) ||
|
|
!my_isdigit(&my_charset_latin1, rhs->data[prefix_len + i])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
Loop all the rw trxs to find xa transaction which belonged to the same group
|
|
and push trx_id into group container.
|
|
|
|
@param[in] trx current trx handler
|
|
@param[in] vision current query view
|
|
*/
|
|
void vision_collect_trx_group_ids(const trx_t *my_trx, lizard::Vision *vision) {
|
|
if (my_trx->mysql_thd == nullptr ||
|
|
!thd_get_transaction_group(my_trx->mysql_thd))
|
|
return;
|
|
|
|
trx_sys_mutex_enter();
|
|
|
|
for (auto trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list); trx != nullptr;
|
|
trx = UT_LIST_GET_NEXT(trx_list, trx)) {
|
|
trx_mutex_enter(trx);
|
|
|
|
if (trx_group_match_by_xid(my_trx->xad.my_xid(), trx->xad.my_xid())) {
|
|
vision->group_ids.push(trx->id);
|
|
}
|
|
|
|
trx_mutex_exit(trx);
|
|
}
|
|
|
|
trx_sys_mutex_exit();
|
|
}
|