mirror of
https://github.com/MariaDB/server.git
synced 2026-05-17 20:37:12 +02:00
MDEV-37972 Factor out duplicate code shared by spider_internal_xa_{commit,rollback}_by_xid
This commit is contained in:
parent
15fa5351cd
commit
3c8a5ea128
1 changed files with 45 additions and 259 deletions
|
|
@ -2286,15 +2286,17 @@ error_create_read_record:
|
|||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
int spider_internal_xa_commit_by_xid(
|
||||
static int spider_internal_xa_commit_or_rollback_by_xid(
|
||||
THD* thd,
|
||||
SPIDER_TRX *trx,
|
||||
XID* xid
|
||||
XID* xid,
|
||||
bool is_rollback
|
||||
) {
|
||||
TABLE *table_xa, *table_xa_member = 0;
|
||||
int error_num;
|
||||
char xa_key[MAX_KEY_LENGTH];
|
||||
char xa_member_key[MAX_KEY_LENGTH];
|
||||
/* This share has only one link */
|
||||
SPIDER_SHARE tmp_share;
|
||||
char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT];
|
||||
uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT];
|
||||
|
|
@ -2307,7 +2309,7 @@ int spider_internal_xa_commit_by_xid(
|
|||
bool table_xa_opened = FALSE;
|
||||
bool table_xa_member_opened = FALSE;
|
||||
bool created_tmp_thd = FALSE;
|
||||
DBUG_ENTER("spider_internal_xa_commit_by_xid");
|
||||
DBUG_ENTER("spider_internal_xa_commit_or_rollback_by_xid");
|
||||
if (!thd)
|
||||
{
|
||||
if (!(thd = spider_create_tmp_thd()))
|
||||
|
|
@ -2347,36 +2349,40 @@ int spider_internal_xa_commit_by_xid(
|
|||
goto error;
|
||||
}
|
||||
SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
|
||||
if (
|
||||
force_commit != 2 &&
|
||||
(error_num = spider_check_sys_xa_status(
|
||||
table_xa,
|
||||
SPIDER_SYS_XA_PREPARED_STR,
|
||||
SPIDER_SYS_XA_COMMIT_STR,
|
||||
NULL,
|
||||
ER_SPIDER_XA_NOT_PREPARED_NUM,
|
||||
&mem_root))
|
||||
) {
|
||||
free_root(&mem_root, MYF(0));
|
||||
if (error_num == ER_SPIDER_XA_NOT_PREPARED_NUM)
|
||||
my_message(error_num, ER_SPIDER_XA_NOT_PREPARED_STR, MYF(0));
|
||||
goto error;
|
||||
if (force_commit != 2)
|
||||
{
|
||||
error_num = is_rollback ?
|
||||
spider_check_sys_xa_status(
|
||||
table_xa, SPIDER_SYS_XA_NOT_YET_STR, SPIDER_SYS_XA_PREPARED_STR,
|
||||
SPIDER_SYS_XA_ROLLBACK_STR, ER_SPIDER_XA_PREPARED_NUM, &mem_root) :
|
||||
spider_check_sys_xa_status(
|
||||
table_xa, SPIDER_SYS_XA_PREPARED_STR, SPIDER_SYS_XA_COMMIT_STR,
|
||||
NULL, ER_SPIDER_XA_NOT_PREPARED_NUM, &mem_root);
|
||||
if (error_num)
|
||||
{
|
||||
free_root(&mem_root, MYF(0));
|
||||
if (error_num == ER_SPIDER_XA_PREPARED_NUM)
|
||||
my_message(error_num, ER_SPIDER_XA_PREPARED_STR, MYF(0));
|
||||
if (error_num == ER_SPIDER_XA_NOT_PREPARED_NUM)
|
||||
my_message(error_num, ER_SPIDER_XA_NOT_PREPARED_STR, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
update
|
||||
mysql.spider_xa
|
||||
set
|
||||
status = 'COMMIT'
|
||||
status = 'ROLLBACK' / 'COMMIT'
|
||||
where
|
||||
format_id = trx->xid.format_id and
|
||||
gtrid_length = trx->xid.gtrid_length and
|
||||
data = trx->xid.data
|
||||
*/
|
||||
if (
|
||||
(error_num = spider_update_xa(
|
||||
table_xa, xid, SPIDER_SYS_XA_COMMIT_STR))
|
||||
) {
|
||||
error_num= is_rollback ?
|
||||
spider_update_xa(table_xa, xid, SPIDER_SYS_XA_ROLLBACK_STR) :
|
||||
spider_update_xa(table_xa, xid, SPIDER_SYS_XA_COMMIT_STR);
|
||||
if (error_num)
|
||||
{
|
||||
free_root(&mem_root, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
|
|
@ -2453,8 +2459,10 @@ int spider_internal_xa_commit_by_xid(
|
|||
}
|
||||
conn->error_mode &= spider_param_error_read_mode(thd, 0);
|
||||
conn->error_mode &= spider_param_error_write_mode(thd, 0);
|
||||
if (
|
||||
(error_num = spider_db_xa_commit(conn, xid)) &&
|
||||
error_num = is_rollback ?
|
||||
spider_db_xa_rollback(conn, xid) :
|
||||
spider_db_xa_commit(conn, xid);
|
||||
if (error_num &&
|
||||
(force_commit == 0 ||
|
||||
(force_commit == 1 && error_num != ER_XAER_NOTA))
|
||||
) {
|
||||
|
|
@ -2527,246 +2535,24 @@ error_open_table:
|
|||
DBUG_RETURN(error_num);
|
||||
}
|
||||
|
||||
int spider_internal_xa_commit_by_xid(
|
||||
THD* thd,
|
||||
SPIDER_TRX *trx,
|
||||
XID* xid
|
||||
) {
|
||||
DBUG_ENTER("spider_internal_xa_commit_by_xid");
|
||||
DBUG_RETURN(spider_internal_xa_commit_or_rollback_by_xid(
|
||||
thd, trx, xid, false));
|
||||
}
|
||||
|
||||
int spider_internal_xa_rollback_by_xid(
|
||||
THD* thd,
|
||||
SPIDER_TRX *trx,
|
||||
XID* xid
|
||||
) {
|
||||
TABLE *table_xa, *table_xa_member = 0;
|
||||
int error_num;
|
||||
char xa_key[MAX_KEY_LENGTH];
|
||||
char xa_member_key[MAX_KEY_LENGTH];
|
||||
/* This share has only one link */
|
||||
SPIDER_SHARE tmp_share;
|
||||
char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT];
|
||||
uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT];
|
||||
long tmp_long[SPIDER_TMP_SHARE_LONG_COUNT];
|
||||
longlong tmp_longlong[SPIDER_TMP_SHARE_LONGLONG_COUNT];
|
||||
SPIDER_CONN *conn;
|
||||
uint force_commit = spider_param_force_commit(thd);
|
||||
MEM_ROOT mem_root;
|
||||
SPIDER_Open_tables_backup open_tables_backup;
|
||||
bool table_xa_opened = FALSE;
|
||||
bool table_xa_member_opened = FALSE;
|
||||
bool created_tmp_thd= FALSE;
|
||||
DBUG_ENTER("spider_internal_xa_rollback_by_xid");
|
||||
if (!thd)
|
||||
{
|
||||
if (!(thd = spider_create_tmp_thd()))
|
||||
{
|
||||
error_num = HA_ERR_OUT_OF_MEM;
|
||||
goto error;
|
||||
}
|
||||
created_tmp_thd= TRUE;
|
||||
}
|
||||
/*
|
||||
select
|
||||
status
|
||||
from
|
||||
mysql.spider_xa
|
||||
where
|
||||
format_id = xid->format_id and
|
||||
gtrid_length = xid->gtrid_length and
|
||||
data = xid->data
|
||||
*/
|
||||
if (
|
||||
!(table_xa = spider_open_sys_table(
|
||||
thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN,
|
||||
TRUE, &open_tables_backup, TRUE, &error_num))
|
||||
)
|
||||
goto error_open_table;
|
||||
table_xa_opened = TRUE;
|
||||
spider_store_xa_pk(table_xa, xid);
|
||||
if (
|
||||
(error_num = spider_check_sys_table(table_xa, xa_key))
|
||||
) {
|
||||
if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
|
||||
{
|
||||
table_xa->file->print_error(error_num, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
error_num = ER_SPIDER_XA_NOT_EXISTS_NUM;
|
||||
goto error;
|
||||
}
|
||||
SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
|
||||
if (
|
||||
force_commit != 2 &&
|
||||
(error_num = spider_check_sys_xa_status(
|
||||
table_xa,
|
||||
SPIDER_SYS_XA_NOT_YET_STR,
|
||||
SPIDER_SYS_XA_PREPARED_STR,
|
||||
SPIDER_SYS_XA_ROLLBACK_STR,
|
||||
ER_SPIDER_XA_PREPARED_NUM,
|
||||
&mem_root))
|
||||
) {
|
||||
free_root(&mem_root, MYF(0));
|
||||
if (error_num == ER_SPIDER_XA_PREPARED_NUM)
|
||||
my_message(error_num, ER_SPIDER_XA_PREPARED_STR, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
update
|
||||
mysql.spider_xa
|
||||
set
|
||||
status = 'ROLLBACK'
|
||||
where
|
||||
format_id = trx->xid.format_id and
|
||||
gtrid_length = trx->xid.gtrid_length and
|
||||
data = trx->xid.data
|
||||
*/
|
||||
if (
|
||||
(error_num = spider_update_xa(
|
||||
table_xa, xid, SPIDER_SYS_XA_ROLLBACK_STR))
|
||||
) {
|
||||
free_root(&mem_root, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE);
|
||||
table_xa_opened = FALSE;
|
||||
|
||||
/*
|
||||
select
|
||||
scheme tmp_share.tgt_wrappers,
|
||||
host tmp_share.tgt_hosts,
|
||||
port tmp_share.tgt_ports,
|
||||
socket tmp_share.tgt_sockets,
|
||||
username tmp_share.tgt_usernames,
|
||||
password tmp_share.tgt_passwords
|
||||
from
|
||||
mysql.spider_xa_member
|
||||
where
|
||||
format_id = xid->format_id and
|
||||
gtrid_length = xid->gtrid_length and
|
||||
data = xid->data
|
||||
*/
|
||||
if (
|
||||
!(table_xa_member = spider_open_sys_table(
|
||||
thd, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR,
|
||||
SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE,
|
||||
&error_num))
|
||||
) {
|
||||
free_root(&mem_root, MYF(0));
|
||||
goto error_open_table;
|
||||
}
|
||||
table_xa_member_opened = TRUE;
|
||||
spider_store_xa_pk(table_xa_member, xid);
|
||||
if (
|
||||
(error_num = spider_get_sys_table_by_idx(table_xa_member, xa_member_key, 0,
|
||||
SPIDER_SYS_XA_PK_COL_CNT))
|
||||
) {
|
||||
if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
|
||||
{
|
||||
free_root(&mem_root, MYF(0));
|
||||
table_xa_member->file->print_error(error_num, MYF(0));
|
||||
goto error;
|
||||
} else {
|
||||
free_root(&mem_root, MYF(0));
|
||||
spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE);
|
||||
table_xa_member_opened = FALSE;
|
||||
goto xa_delete;
|
||||
}
|
||||
}
|
||||
|
||||
memset((void*)&tmp_share, 0, sizeof(SPIDER_SHARE));
|
||||
memset(&tmp_connect_info, 0,
|
||||
sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT);
|
||||
spider_set_tmp_share_pointer(&tmp_share, tmp_connect_info,
|
||||
tmp_connect_info_length, tmp_long, tmp_longlong);
|
||||
do {
|
||||
SPIDER_BACKUP_DASTATUS;
|
||||
spider_get_sys_server_info(table_xa_member, &tmp_share, 0, &mem_root);
|
||||
if ((error_num = spider_create_conn_keys(&tmp_share)))
|
||||
{
|
||||
spider_sys_index_end(table_xa_member);
|
||||
free_root(&mem_root, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(conn= spider_get_conn(&tmp_share, 0, tmp_share.conn_keys[0], trx,
|
||||
NULL, FALSE, FALSE, &error_num)) &&
|
||||
(force_commit == 0 ||
|
||||
(force_commit == 1 && error_num != ER_XAER_NOTA)))
|
||||
{
|
||||
spider_sys_index_end(table_xa_member);
|
||||
spider_free_tmp_share_alloc(&tmp_share);
|
||||
free_root(&mem_root, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
conn->error_mode &= spider_param_error_read_mode(thd, 0);
|
||||
conn->error_mode &= spider_param_error_write_mode(thd, 0);
|
||||
if (
|
||||
(error_num = spider_db_xa_rollback(conn, xid)) &&
|
||||
(force_commit == 0 ||
|
||||
(force_commit == 1 && error_num != ER_XAER_NOTA))
|
||||
) {
|
||||
SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM;
|
||||
if (error_num)
|
||||
{
|
||||
spider_sys_index_end(table_xa_member);
|
||||
spider_free_tmp_share_alloc(&tmp_share);
|
||||
free_root(&mem_root, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
spider_free_tmp_share_alloc(&tmp_share);
|
||||
error_num = spider_sys_index_next_same(table_xa_member, xa_member_key);
|
||||
} while (error_num == 0);
|
||||
if ((error_num = spider_sys_index_end(table_xa_member)))
|
||||
{
|
||||
free_root(&mem_root, MYF(0));
|
||||
goto error;
|
||||
}
|
||||
free_root(&mem_root, MYF(0));
|
||||
spider_reuse_trx_ha(trx);
|
||||
spider_free_trx_conn(trx, FALSE);
|
||||
|
||||
/*
|
||||
delete from
|
||||
mysql.spider_xa_member
|
||||
where
|
||||
format_id = xid->format_id and
|
||||
gtrid_length = xid->gtrid_length and
|
||||
data = xid->data
|
||||
*/
|
||||
if ((error_num = spider_delete_xa_member(table_xa_member, xid)))
|
||||
goto error;
|
||||
spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE);
|
||||
table_xa_member_opened = FALSE;
|
||||
|
||||
xa_delete:
|
||||
/*
|
||||
delete from
|
||||
mysql.spider_xa
|
||||
where
|
||||
format_id = xid->format_id and
|
||||
gtrid_length = xid->gtrid_length and
|
||||
data = xid->data
|
||||
*/
|
||||
if (
|
||||
!(table_xa = spider_open_sys_table(
|
||||
thd, SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN,
|
||||
TRUE, &open_tables_backup, TRUE, &error_num))
|
||||
)
|
||||
goto error_open_table;
|
||||
table_xa_opened = TRUE;
|
||||
if ((error_num = spider_delete_xa(table_xa, xid)))
|
||||
goto error;
|
||||
spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE);
|
||||
table_xa_opened = FALSE;
|
||||
if (created_tmp_thd)
|
||||
spider_free_tmp_thd(thd);
|
||||
DBUG_RETURN(0);
|
||||
|
||||
error:
|
||||
if (table_xa_opened)
|
||||
spider_close_sys_table(thd, table_xa, &open_tables_backup, TRUE);
|
||||
if (table_xa_member_opened)
|
||||
spider_close_sys_table(thd, table_xa_member, &open_tables_backup, TRUE);
|
||||
error_open_table:
|
||||
if (created_tmp_thd)
|
||||
spider_free_tmp_thd(thd);
|
||||
DBUG_RETURN(error_num);
|
||||
DBUG_RETURN(spider_internal_xa_commit_or_rollback_by_xid(
|
||||
thd, trx, xid, true));
|
||||
}
|
||||
|
||||
int spider_start_consistent_snapshot(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue