1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Initial push of codership-wsrep API implementation for MariaDB.

Merge of:
lp:maria/5.5, #3334: http://bazaar.launchpad.net/~maria-captains/maria/5.5/revision/3334
lp:codership-mysql/5.5, #3725: http://bazaar.launchpad.net/~codership/codership-mysql/wsrep-5.5/revision/3725
This commit is contained in:
Seppo Jaakola
2012-04-13 01:33:24 +03:00
parent 51c77ec5d4
commit 2fc1ec4356
80 changed files with 7196 additions and 64 deletions

View File

@ -52,6 +52,9 @@
#include "../storage/maria/ha_maria.h"
#endif
#ifdef WITH_WSREP
#include "wsrep_mysqld.h"
#endif
/*
While we have legacy_db_type, we have this array to
check for dups and to find handlerton from legacy_db_type.
@ -1192,7 +1195,11 @@ int ha_commit_trans(THD *thd, bool all)
{
/* Free resources and perform other cleanup even for 'empty' transactions. */
if (is_real_trans)
thd->transaction.cleanup();
#ifdef WITH_WSREP
thd->transaction.cleanup(thd);
#else
thd->transaction.cleanup();
#endif /* WITH_WSREP */
DBUG_RETURN(0);
}
@ -1220,7 +1227,12 @@ int ha_commit_trans(THD *thd, bool all)
mdl_request.init(MDL_key::COMMIT, "", "", MDL_INTENTION_EXCLUSIVE,
MDL_EXPLICIT);
#ifdef WITH_WSREP
if (!WSREP(thd) &&
thd->mdl_context.acquire_lock(&mdl_request,
#else
if (thd->mdl_context.acquire_lock(&mdl_request,
#endif /* WITH_WSREP */
thd->variables.lock_wait_timeout))
{
ha_rollback_trans(thd, all);
@ -1267,6 +1279,19 @@ int ha_commit_trans(THD *thd, bool all)
err= ht->prepare(ht, thd, all);
status_var_increment(thd->status_var.ha_prepare_count);
if (err)
#ifdef WITH_WSREP
if (WSREP(thd) && ht->db_type== DB_TYPE_WSREP)
{
error= 1;
/* avoid sending error, if we need to replay */
if (thd->wsrep_conflict_state!= MUST_REPLAY)
{
my_error(ER_LOCK_DEADLOCK, MYF(0), err);
}
}
else
/* not wsrep hton, bail to native mysql behavior */
#endif
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
if (err)
@ -1277,6 +1302,13 @@ int ha_commit_trans(THD *thd, bool all)
}
DBUG_EXECUTE_IF("crash_commit_after_prepare", DBUG_SUICIDE(););
#ifdef WITH_WSREP
if (!error && wsrep_is_wsrep_xid(&thd->transaction.xid_state.xid))
{
// xid was rewritten by wsrep
xid= wsrep_xid_seqno(&thd->transaction.xid_state.xid);
}
#endif // WITH_WSREP
if (!is_real_trans)
{
error= commit_one_phase_2(thd, all, trans, is_real_trans);
@ -1363,6 +1395,18 @@ commit_one_phase_2(THD *thd, bool all, THD_TRANS *trans, bool is_real_trans)
int error= 0;
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
DBUG_ENTER("commit_one_phase_2");
#ifdef WITH_WSREP
#ifdef WSREP_PROC_INFO
char info[64]= { 0, };
snprintf (info, sizeof(info) - 1, "ha_commit_one_phase(%lld)",
(long long)thd->wsrep_trx_seqno);
#else
const char info[]="ha_commit_one_phase()";
#endif /* WSREP_PROC_INFO */
char* tmp_info= NULL;
if (WSREP(thd)) tmp_info= (char *)thd_proc_info(thd, info);
#endif /* WITH_WSREP */
if (ha_info)
{
for (; ha_info; ha_info= ha_info_next)
@ -1391,7 +1435,14 @@ commit_one_phase_2(THD *thd, bool all, THD_TRANS *trans, bool is_real_trans)
}
/* Free resources and perform other cleanup even for 'empty' transactions. */
if (is_real_trans)
#ifdef WITH_WSREP
thd->transaction.cleanup(thd);
#else
thd->transaction.cleanup();
#endif /* WITH_WSREP */
#ifdef WITH_WSREP
if (WSREP(thd)) thd_proc_info(thd, tmp_info);
#endif /* WITH_WSREP */
DBUG_RETURN(error);
}
@ -1466,7 +1517,11 @@ int ha_rollback_trans(THD *thd, bool all)
}
/* Always cleanup. Even if nht==0. There may be savepoints. */
if (is_real_trans)
#ifdef WITH_WSREP
thd->transaction.cleanup(thd);
#else
thd->transaction.cleanup();
#endif /* WITH_WSREP */
if (all)
thd->transaction_rollback_request= FALSE;
@ -1631,7 +1686,13 @@ static my_bool xarecover_handlerton(THD *unused, plugin_ref plugin,
got, hton_name(hton)->str);
for (int i=0; i < got; i ++)
{
#ifdef WITH_WSREP
my_xid x=(wsrep_is_wsrep_xid(&info->list[i]) ?
wsrep_xid_seqno(&info->list[i]) :
info->list[i].get_my_xid());
#else
my_xid x=info->list[i].get_my_xid();
#endif /* WITH_WSREP */
if (!x) // not "mine" - that is generated by external TM
{
#ifndef DBUG_OFF
@ -2635,7 +2696,12 @@ int handler::update_auto_increment()
variables->auto_increment_increment);
auto_inc_intervals_count++;
/* Row-based replication does not need to store intervals in binlog */
#ifdef WITH_WSREP
if (((WSREP(thd) && wsrep_emulate_bin_log) || mysql_bin_log.is_open()) &&
!thd->is_current_stmt_binlog_format_row())
#else
if (mysql_bin_log.is_open() && !thd->is_current_stmt_binlog_format_row())
#endif /* WITH_WSREP */
thd->auto_inc_intervals_in_cur_stmt_for_binlog.append(auto_inc_interval_for_cur_row.minimum(),
auto_inc_interval_for_cur_row.values(),
variables->auto_increment_increment);
@ -4821,7 +4887,11 @@ static bool check_table_binlog_row_based(THD *thd, TABLE *table)
return (thd->is_current_stmt_binlog_format_row() &&
table->s->cached_row_logging_check &&
(thd->variables.option_bits & OPTION_BIN_LOG) &&
#ifdef WITH_WSREP
((WSREP(thd) && wsrep_emulate_bin_log) || mysql_bin_log.is_open()));
#else
mysql_bin_log.is_open());
#endif
}
@ -5142,6 +5212,41 @@ void signal_log_not_needed(struct handlerton, char *log_file)
}
#ifdef WITH_WSREP
/**
@details
This function makes the storage engine to force the victim transaction
to abort. Currently, only innodb has this functionality, but any SE
implementing the wsrep API should provide this service to support
multi-master operation.
@param bf_thd brute force THD asking for the abort
@param victim_thd victim THD to be aborted
@return
always 0
*/
int ha_wsrep_abort_transaction(THD *bf_thd, THD *victim_thd, my_bool signal)
{
DBUG_ENTER("ha_wsrep_abort_transaction");
if (!WSREP(bf_thd)) {
DBUG_RETURN(0);
}
handlerton *hton= installed_htons[DB_TYPE_INNODB];
if (hton && hton->wsrep_abort_transaction)
{
hton->wsrep_abort_transaction(hton, bf_thd, victim_thd, signal);
}
else
{
WSREP_WARN("cannot abort InnoDB transaction");
}
DBUG_RETURN(0);
}
#endif /* WITH_WSREP */
#ifdef TRANS_LOG_MGM_EXAMPLE_CODE
/*
Example of transaction log management functions based on assumption that logs