Commit 70714d35 authored by Nirbhay Choubey's avatar Nirbhay Choubey

Merge branch '5.5-galera' into 10.0-galera

parents 46024098 71d1f358
--source include/galera_cluster.inc
--source include/have_innodb.inc
--write_file $MYSQLTEST_VARDIR/tmp/galera_concurrent.sql
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
DROP table t1;
CREATE table t1 as SELECT SLEEP(0);
CREATE table t2 as SELECT SLEEP(0);
CREATE table t3 as SELECT SLEEP(0);
CREATE table t4 as SELECT SLEEP(0);
CREATE table t5 as SELECT SLEEP(0);
CREATE table t6 as SELECT SLEEP(0);
CREATE table t7 as SELECT SLEEP(0);
CREATE table t8 as SELECT SLEEP(0);
CREATE table t9 as SELECT SLEEP(0);
DROP table t1;
DROP table t2;
DROP table t3;
DROP table t4;
DROP table t5;
DROP table t6;
DROP table t7;
DROP table t8;
DROP table t9;
EOF
let $run=10;
while($run)
{
--error 0,1
exec $MYSQL --user=root --host=127.0.0.1 --port=$NODE_MYPORT_1 test
< $MYSQLTEST_VARDIR/tmp/galera_concurrent.sql &
$MYSQL --user=root --host=127.0.0.1 --port=$NODE_MYPORT_2 test
< $MYSQLTEST_VARDIR/tmp/galera_concurrent.sql;
dec $run;
}
--remove_file $MYSQLTEST_VARDIR/tmp/galera_concurrent.sql
--source include/galera_end.inc
--echo # End of test
Note: The included AppArmor profiles can be used for MariaDB Galera cluster.
However, since these profiles had been tested for a limited set of scenarios,
it is highly recommended to run them in "complain" mode and report any denials
on mariadb.org/jira.
# Last Modified: Fri Mar 1 18:55:47 2013
# Based on usr.sbin.mysqld packaged in mysql-server in Ubuntu.
# This AppArmor profile has been copied under BSD License from
# Percona XtraDB Cluster, along with some additions.
#include <tunables/global>
/usr/sbin/mysqld flags=(complain) {
#include <abstractions/base>
#include <abstractions/mysql>
#include <abstractions/nameservice>
#include <abstractions/user-tmp>
#include <abstractions/winbind>
capability chown,
capability dac_override,
capability setgid,
capability setuid,
capability sys_rawio,
capability sys_resource,
network tcp,
/bin/dash rcx,
/dev/dm-0 r,
/etc/gai.conf r,
/etc/group r,
/etc/hosts.allow r,
/etc/hosts.deny r,
/etc/ld.so.cache r,
/etc/mtab r,
/etc/my.cnf r,
/etc/mysql/*.cnf r,
/etc/mysql/*.pem r,
/etc/mysql/conf.d/ r,
/etc/mysql/conf.d/* r,
/etc/nsswitch.conf r,
/etc/passwd r,
/etc/services r,
/run/mysqld/mysqld.pid w,
/run/mysqld/mysqld.sock w,
/sys/devices/system/cpu/ r,
owner /tmp/** lk,
/tmp/** rw,
/usr/lib/mysql/plugin/ r,
/usr/lib/mysql/plugin/*.so* mr,
/usr/sbin/mysqld mr,
/usr/share/mysql/** r,
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
/var/log/mysql.err rw,
/var/log/mysql.log rw,
/var/log/mysql/ r,
/var/log/mysql/* rw,
/var/run/mysqld/mysqld.pid w,
/var/run/mysqld/mysqld.sock w,
profile /bin/dash flags=(complain) {
#include <abstractions/base>
#include <abstractions/bash>
#include <abstractions/mysql>
#include <abstractions/nameservice>
#include <abstractions/perl>
/bin/cat rix,
/bin/dash rix,
/bin/date rix,
/bin/grep rix,
/bin/nc.openbsd rix,
/bin/netstat rix,
/bin/ps rix,
/bin/rm rix,
/bin/sed rix,
/bin/sleep rix,
/bin/tar rix,
/bin/which rix,
/dev/tty rw,
/etc/ld.so.cache r,
/etc/my.cnf r,
/proc/ r,
/proc/*/cmdline r,
/proc/*/fd/ r,
/proc/*/net/dev r,
/proc/*/net/if_inet6 r,
/proc/*/net/tcp r,
/proc/*/net/tcp6 r,
/proc/*/stat r,
/proc/*/status r,
/proc/sys/kernel/pid_max r,
/proc/tty/drivers r,
/proc/uptime r,
/proc/version r,
/sbin/ifconfig rix,
/sys/devices/system/cpu/ r,
/tmp/** rw,
/usr/bin/cut rix,
/usr/bin/dirname rix,
/usr/bin/gawk rix,
/usr/bin/innobackupex rix,
/usr/bin/mysql rix,
/usr/bin/perl rix,
/usr/bin/seq rix,
/usr/bin/wsrep_sst* rix,
/usr/bin/wsrep_sst_common r,
/usr/bin/xtrabackup* rix,
/var/lib/mysql/ r,
/var/lib/mysql/** rw,
/var/lib/mysql/*.log w,
/var/lib/mysql/*.err w,
# MariaDB additions
ptrace peer=@{profile_name},
/bin/hostname rix,
/bin/ip rix,
/bin/mktemp rix,
/bin/ss rix,
/bin/sync rix,
/bin/touch rix,
/bin/uname rix,
/etc/mysql/*.cnf r,
/etc/mysql/conf.d/ r,
/etc/mysql/conf.d/* r,
/proc/*/attr/current r,
/proc/*/fdinfo/* r,
/proc/*/net/* r,
/proc/locks r,
/proc/sys/net/ipv4/ip_local_port_range r,
/run/mysqld/mysqld.sock rw,
/sbin/ip rix,
/usr/bin/basename rix,
/usr/bin/du rix,
/usr/bin/find rix,
/usr/bin/lsof rix,
/usr/bin/my_print_defaults rix,
/usr/bin/mysqldump rix,
/usr/bin/pv rix,
/usr/bin/rsync rix,
/usr/bin/socat rix,
/usr/bin/tail rix,
/usr/bin/timeout rix,
/usr/bin/xargs rix,
/usr/bin/xbstream rix,
}
# Site-specific additions and overrides. See local/README for details.
#include <local/usr.sbin.mysqld>
}
# Site-specific additions and overrides for usr.sbin.mysqld..
# For more details, please see /etc/apparmor.d/local/README.
# This AppArmor profile has been copied under BSD License from
# Percona XtraDB Cluster, along with some additions.
Note: The included SELinux policy files can be used for MariaDB Galera cluster.
However, since these policies had been tested for a limited set of scenarios,
it is highly recommended that you run mysqld in "permissive" mode even with
these policies installed and report any denials on mariadb.org/jira.
How to generate and load the policy module of MariaDB Galera cluster ?
* Generate the SELinux policy module.
# cd <source>/policy/selinux/
# make -f /usr/share/selinux/devel/Makefile mariadb-server.pp
* Load the generated policy module.
# semodule -i /path/to/mariadb-server.pp
* Lastly, run the following command to allow tcp/4568 and udp/4567.
# semanage port -a -t mysqld_port_t -p tcp 4568
# semanage port -a -t mysqld_port_t -p udp 4567
How to run mysqld in permissve mode ?
# semanage permissive -a mysqld_t
# This SELinux file contexts (.fc) file has been copied under BSD License from
# Percona XtraDB Cluster.
/etc/init\.d/rc\.d/mysql -- gen_context(system_u:object_r:mysqld_initrc_exec_t,s0)
/var/lib/mysql/.*\.log -- gen_context(system_u:object_r:mysqld_log_t,s0)
/var/lib/mysql/.*\.err -- gen_context(system_u:object_r:mysqld_log_t,s0)
/var/lib/mysql/.*\.pid -- gen_context(system_u:object_r:mysqld_var_run_t,s0)
/var/lib/mysql/.*\.cnf -- gen_context(system_u:object_r:mysqld_etc_t,s0)
/usr/bin/xtrabackup.* -- gen_context(system_u:object_r:mysqld_exec_t,s0)
/usr/bin/wsrep.* -- gen_context(system_u:object_r:mysqld_safe_exec_t,s0)
# This SELinux type enforcement (.te) file has been copied under BSD License
# from Percona XtraDB Cluster, along with some additions.
module mariadb-server 1.0;
require {
type user_tmp_t;
#type kerberos_master_port_t;
type mysqld_safe_t;
type tmp_t;
type tmpfs_t;
type hostname_exec_t;
type ifconfig_exec_t;
type sysctl_net_t;
type proc_net_t;
type port_t;
type mysqld_t;
type var_lib_t;
type rsync_exec_t;
type bin_t;
type shell_exec_t;
type anon_inodefs_t;
type fixed_disk_device_t;
class lnk_file read;
class process { getattr signull };
class unix_stream_socket connectto;
class capability { sys_resource sys_nice };
class tcp_socket { name_bind name_connect };
class file { execute setattr read create getattr execute_no_trans write ioctl open append unlink };
class sock_file { create unlink getattr };
class blk_file { read write open };
class dir { write search getattr add_name read remove_name open };
# MariaDB additions
type kerberos_port_t;
type tram_port_t;
type mysqld_port_t;
class udp_socket name_bind;
class process setpgid;
class netlink_tcpdiag_socket { create nlmsg_read };
}
#============= mysqld_safe_t ==============
allow mysqld_safe_t mysqld_t:process signull;
allow mysqld_safe_t self:capability { sys_resource sys_nice };
allow mysqld_safe_t tmp_t:file { create read write open getattr unlink ioctl setattr };
allow mysqld_safe_t tmp_t:dir { write remove_name add_name };
allow mysqld_safe_t tmp_t:sock_file { getattr unlink };
allow mysqld_safe_t user_tmp_t:sock_file { getattr unlink };
allow mysqld_safe_t var_lib_t:dir { write add_name };
allow mysqld_safe_t var_lib_t:file { write ioctl setattr create open getattr append unlink };
#============= mysqld_t ==============
allow mysqld_t anon_inodefs_t:file write;
allow mysqld_t tmp_t:sock_file { create unlink };
allow mysqld_t tmpfs_t:dir { write search read remove_name open add_name };
allow mysqld_t tmpfs_t:file { write getattr read create unlink open };
allow mysqld_t fixed_disk_device_t:blk_file { read write open };
allow mysqld_t ifconfig_exec_t:file { read execute open execute_no_trans getattr };
#This rule allows connecting on 4444/4567/4568
#allow mysqld_t kerberos_master_port_t:tcp_socket { name_bind name_connect };
allow mysqld_t mysqld_safe_t:dir { getattr search };
allow mysqld_t mysqld_safe_t:file { read open };
allow mysqld_t self:unix_stream_socket connectto;
allow mysqld_t port_t:tcp_socket { name_bind name_connect };
allow mysqld_t proc_net_t:file { read getattr open };
allow mysqld_t sysctl_net_t:dir search;
allow mysqld_t var_lib_t:file { getattr open append };
allow mysqld_t var_lib_t:sock_file { create unlink getattr };
allow mysqld_t rsync_exec_t:file { read getattr open execute execute_no_trans };
allow mysqld_t self:process getattr;
allow mysqld_t hostname_exec_t:file { read getattr execute open execute_no_trans };
allow mysqld_t user_tmp_t:dir { write add_name };
allow mysqld_t user_tmp_t:file create;
allow mysqld_t bin_t:lnk_file read;
allow mysqld_t tmp_t:file { append create read write open getattr unlink setattr };
# Allows too much leeway - the xtrabackup/wsrep rules in fc should fix it, but
# keep for the moment.
allow mysqld_t shell_exec_t:file { execute_no_trans getattr read execute open };
allow mysqld_t bin_t:file { getattr read execute open execute_no_trans ioctl };
# MariaDB additions
allow mysqld_t self:process setpgid;
# This rule allows port tcp/4444
allow mysqld_t kerberos_port_t:tcp_socket { name_bind name_connect };
# This rule allows port tcp/4567 (tram_port_t may not be available on
# older versions)
allow mysqld_t tram_port_t:tcp_socket name_bind;
# This rule allows port udp/4567 (see README)
allow mysqld_t mysqld_port_t:udp_socket name_bind;
# Rules related to XtraBackup
allow mysqld_t self:netlink_tcpdiag_socket { create nlmsg_read };
allow mysqld_t sysctl_net_t:file { read getattr open };
......@@ -1443,6 +1443,13 @@ MDL_wait::timed_wait(MDL_context_owner *owner, struct timespec *abs_timeout,
while (!m_wait_status && !owner->is_killed() &&
wait_result != ETIMEDOUT && wait_result != ETIME)
{
#ifdef WITH_WSREP
if (wsrep_thd_is_BF(owner->get_thd(), true))
{
wait_result= mysql_cond_wait(&m_COND_wait_status, &m_LOCK_wait_status);
}
else
#endif
wait_result= mysql_cond_timedwait(&m_COND_wait_status, &m_LOCK_wait_status,
abs_timeout);
}
......@@ -1527,11 +1534,14 @@ void MDL_lock::Ticket_list::add_ticket(MDL_ticket *ticket)
WSREP_DEBUG("MDL add_ticket inserted before: %lu %s",
wsrep_thd_thread_id(waiting->get_ctx()->wsrep_get_thd()),
wsrep_thd_query(waiting->get_ctx()->wsrep_get_thd()));
/* Insert the ticket before the first non-BF waiting thd. */
m_list.insert_after(prev, ticket);
added= true;
}
prev= waiting;
}
/* Otherwise, insert the ticket at the back of the waiting list. */
if (!added) m_list.push_back(ticket);
while ((granted= itg++))
......
......@@ -4172,6 +4172,8 @@ class select_insert :public select_result_interceptor {
virtual int send_data(List<Item> &items);
virtual void store_values(List<Item> &values);
virtual bool can_rollback_data() { return 0; }
bool prepare_eof();
bool send_ok_packet();
bool send_eof();
virtual void abort_result_set();
/* not implemented: select_insert is never re-used in prepared statements */
......
......@@ -3660,14 +3660,14 @@ void select_insert::store_values(List<Item> &values)
TRG_EVENT_INSERT);
}
bool select_insert::send_eof()
bool select_insert::prepare_eof()
{
int error;
bool const trans_table= table->file->has_transactions();
ulonglong id, row_count;
bool changed;
killed_state killed_status= thd->killed;
DBUG_ENTER("select_insert::send_eof");
DBUG_ENTER("select_insert::prepare_eof");
DBUG_PRINT("enter", ("trans_table=%d, table_type='%s'",
trans_table, table->file->table_type()));
......@@ -3709,11 +3709,10 @@ bool select_insert::send_eof()
*/
#ifdef WITH_WSREP
if ((WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open()) &&
(!error || thd->transaction.stmt.modified_non_trans_table))
#else
if (mysql_bin_log.is_open() &&
(!error || thd->transaction.stmt.modified_non_trans_table))
#endif
(!error || thd->transaction.stmt.modified_non_trans_table))
{
int errcode= 0;
if (!error)
......@@ -3725,7 +3724,7 @@ bool select_insert::send_eof()
trans_table, FALSE, FALSE, errcode))
{
table->file->ha_release_auto_increment();
DBUG_RETURN(1);
DBUG_RETURN(true);
}
}
table->file->ha_release_auto_increment();
......@@ -3733,27 +3732,49 @@ bool select_insert::send_eof()
if (error)
{
table->file->print_error(error,MYF(0));
DBUG_RETURN(1);
DBUG_RETURN(true);
}
char buff[160];
DBUG_RETURN(false);
}
bool select_insert::send_ok_packet() {
char message[160]; /* status message */
ulong row_count; /* rows affected */
ulong id; /* last insert-id */
DBUG_ENTER("select_insert::send_ok_packet");
if (info.ignore)
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
(ulong) (info.records - info.copied),
my_snprintf(message, sizeof(message), ER(ER_INSERT_INFO),
(ulong) info.records, (ulong) (info.records - info.copied),
(long) thd->get_stmt_da()->current_statement_warn_count());
else
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
(ulong) (info.deleted+info.updated),
my_snprintf(message, sizeof(message), ER(ER_INSERT_INFO),
(ulong) info.records, (ulong) (info.deleted + info.updated),
(long) thd->get_stmt_da()->current_statement_warn_count());
row_count= info.copied + info.deleted +
((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
info.touched : info.updated);
id= (thd->first_successful_insert_id_in_cur_stmt > 0) ?
thd->first_successful_insert_id_in_cur_stmt :
(thd->arg_of_last_insert_id_function ?
thd->first_successful_insert_id_in_prev_stmt :
(info.copied ? autoinc_value_of_last_inserted_row : 0));
::my_ok(thd, row_count, id, buff);
DBUG_RETURN(0);
::my_ok(thd, row_count, id, message);
DBUG_RETURN(false);
}
bool select_insert::send_eof()
{
bool res;
DBUG_ENTER("select_insert::send_eof");
res= (prepare_eof() || send_ok_packet());
DBUG_RETURN(res);
}
void select_insert::abort_result_set() {
......@@ -4234,13 +4255,13 @@ void select_create::store_values(List<Item> &values)
bool select_create::send_eof()
{
if (select_insert::send_eof())
DBUG_ENTER("select_create::send_eof");
if (prepare_eof())
{
abort_result_set();
return 1;
DBUG_RETURN(true);
}
exit_done= 1; // Avoid double calls
/*
Do an implicit commit at end of statement for non-temporary
tables. This can fail, but we should unlock the table
......@@ -4259,7 +4280,7 @@ bool select_create::send_eof()
thd->thread_id, thd->wsrep_conflict_state, thd->query());
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
abort_result_set();
return TRUE;
DBUG_RETURN(true);
}
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
#endif /* WITH_WSREP */
......@@ -4267,9 +4288,17 @@ bool select_create::send_eof()
else if (!thd->is_current_stmt_binlog_format_row())
table->s->table_creation_was_logged= 1;
/*
exit_done must only be set after last potential call to
abort_result_set().
*/
exit_done= 1; // Avoid double calls
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
send_ok_packet();
if (m_plock)
{
MYSQL_LOCK *lock= *m_plock;
......@@ -4290,12 +4319,12 @@ bool select_create::send_eof()
create_info->
pos_in_locked_tables,
table, lock))
return 0; // ok
DBUG_RETURN(false); // ok
/* Fail. Continue without locking the table */
}
mysql_unlock_tables(thd, lock);
}
return 0;
DBUG_RETURN(false);
}
......
......@@ -1461,10 +1461,21 @@ void wsrep_to_isolation_end(THD *thd)
gra->wsrep_exec_mode, gra->wsrep_query_state, gra->wsrep_conflict_state, \
gra->get_command(), gra->lex->sql_command, gra->query());
/**
Check if request for the metadata lock should be granted to the requester.
@param requestor_ctx The MDL context of the requestor
@param ticket MDL ticket for the requested lock
@retval TRUE Lock request can be granted
@retval FALSE Lock request cannot be granted
*/
bool
wsrep_grant_mdl_exception(MDL_context *requestor_ctx,
MDL_ticket *ticket
) {
/* Fallback to the non-wsrep behaviour */
if (!WSREP_ON) return FALSE;
THD *request_thd = requestor_ctx->wsrep_get_thd();
......
......@@ -579,6 +579,17 @@ int wsrep_abort_thd(void *bf_thd_ptr, void *victim_thd_ptr, my_bool signal)
bf_thd->wsrep_exec_mode == TOTAL_ORDER) ) &&
victim_thd)
{
if ((victim_thd->wsrep_conflict_state == MUST_ABORT) ||
(victim_thd->wsrep_conflict_state == ABORTED) ||
(victim_thd->wsrep_conflict_state == ABORTING))
{
WSREP_DEBUG("wsrep_abort_thd called by %llu with victim %llu already "
"aborted. Ignoring.",
(bf_thd) ? (long long)bf_thd->real_id : 0,
(long long)victim_thd->real_id);
DBUG_RETURN(1);
}
WSREP_DEBUG("wsrep_abort_thd, by: %llu, victim: %llu", (bf_thd) ?
(long long)bf_thd->real_id : 0, (long long)victim_thd->real_id);
ha_wsrep_abort_transaction(bf_thd, victim_thd, signal);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment