[Commits] c23efc7d505: Merge remote-tracking branch 'origin/10.0-galera' into 10.1

jan jan.lindstrom at mariadb.com
Mon Aug 21 13:35:09 EEST 2017


revision-id: c23efc7d50530570e6c13207f3c76adcb9237346 (mariadb-10.1.26-9-gc23efc7d505)
parent(s): 06106c01481401b6d7ef4309391ca2f66242cc85 f1af2114993f884b1a6dc34fb1d972ead08f1966
author: Jan Lindström
committer: Jan Lindström
timestamp: 2017-08-21 13:35:00 +0300
message:

Merge remote-tracking branch 'origin/10.0-galera' into 10.1


 cmake/wsrep.cmake                                  |   2 +-
 include/wsrep.h                                    |  10 +-
 mysql-test/include/galera_cluster.inc              |   2 +
 mysql-test/include/restart_mysqld.inc              |   3 +
 mysql-test/include/start_mysqld.inc                |   3 +
 mysql-test/include/wait_wsrep_ready.inc            |  15 +
 mysql-test/suite/galera/disabled.def               | 109 +++---
 mysql-test/suite/galera/galera_2nodes.cnf          |   4 +-
 .../suite/galera/galera_2nodes_as_master.cnf       |   4 +-
 .../suite/galera/galera_2nodes_as_master_slave.cnf |   4 +-
 .../galera_2nodes_as_master_with_repl_filter.cnf   |   4 +-
 mysql-test/suite/galera/galera_2nodes_as_slave.cnf |   4 +-
 mysql-test/suite/galera/galera_3nodes_as_slave.cnf |   6 +-
 mysql-test/suite/galera/galera_4nodes.cnf          |   2 +-
 mysql-test/suite/galera/r/GAL-401.result           |   3 +
 mysql-test/suite/galera/r/MW-284.result            |   2 +-
 mysql-test/suite/galera/r/MW-329.result            |   1 +
 mysql-test/suite/galera/r/MW-336.result            |  42 +++
 mysql-test/suite/galera/r/MW-357.result            |   6 +
 mysql-test/suite/galera/r/MW-86-wait1.result       |  48 +++
 mysql-test/suite/galera/r/MW-86-wait8.result       |  50 +++
 .../galera/r/galera_applier_ftwrl_table.result     |   2 +-
 .../r/galera_applier_ftwrl_table_alter.result      |   2 +-
 .../suite/galera/r/galera_as_slave_autoinc.result  |   4 +-
 .../r/galera_bf_abort_flush_for_export.result      |   2 +-
 .../suite/galera/r/galera_ddl_multiline.result     |  80 +++++
 mysql-test/suite/galera/r/galera_defaults.result   |   2 +-
 .../suite/galera/r/galera_insert_ignore.result     |   4 +-
 .../suite/galera/r/galera_ist_progress.result      |  19 +
 .../galera/r/galera_ist_restart_joiner.result      |  17 +-
 mysql-test/suite/galera/r/galera_many_rows.result  |   2 +-
 .../r/galera_parallel_apply_lock_table.result      |   2 +-
 .../suite/galera/r/galera_parallel_simple.result   |   2 +-
 .../galera/r/galera_query_cache_sync_wait.result   |   5 -
 .../suite/galera/r/galera_suspend_slave.result     |   3 +
 .../suite/galera/r/galera_sync_wait_show.result    |   2 +-
 .../galera/r/galera_unicode_identifiers.result     |   4 +-
 .../suite/galera/r/galera_var_dirty_reads.result   |  84 +----
 .../suite/galera/r/galera_var_node_address.result  |   1 +
 .../suite/galera/r/galera_var_sync_wait.result     |   7 +-
 .../r/galera_wsrep_provider_unset_set.result       |   1 +
 mysql-test/suite/galera/r/mysql-wsrep#198.result   |   3 +
 mysql-test/suite/galera/r/mysql-wsrep#201.result   |   1 -
 mysql-test/suite/galera/r/pxc-421.result           |   3 +
 mysql-test/suite/galera/suite.pm                   |   8 +
 mysql-test/suite/galera/t/GAL-401.test             |   5 +
 mysql-test/suite/galera/t/MW-286.test              |   1 +
 mysql-test/suite/galera/t/MW-329.test              |   3 +
 mysql-test/suite/galera/t/MW-336.test              |  64 ++++
 mysql-test/suite/galera/t/MW-357.test              |  13 +
 mysql-test/suite/galera/t/MW-369.test              |   1 -
 mysql-test/suite/galera/t/MW-86-wait1-master.opt   |   1 +
 mysql-test/suite/galera/t/MW-86-wait1.test         | 106 ++++++
 mysql-test/suite/galera/t/MW-86-wait8-master.opt   |   1 +
 mysql-test/suite/galera/t/MW-86-wait8.test         | 128 +++++++
 mysql-test/suite/galera/t/galera#414.test          |   6 +
 .../suite/galera/t/galera_applier_ftwrl_table.test |   2 +-
 .../galera/t/galera_applier_ftwrl_table_alter.test |   2 +-
 .../suite/galera/t/galera_as_slave_autoinc.test    |   2 +-
 .../galera/t/galera_bf_abort_flush_for_export.test |   2 +-
 .../suite/galera/t/galera_ddl_multiline.test       |  54 +++
 mysql-test/suite/galera/t/galera_gcs_fc_limit.test |   6 +-
 .../suite/galera/t/galera_insert_ignore.test       |   4 +-
 mysql-test/suite/galera/t/galera_ist_mysqldump.cnf |   1 +
 mysql-test/suite/galera/t/galera_ist_progress.cnf  |   5 +
 mysql-test/suite/galera/t/galera_ist_progress.test |  76 ++++
 .../suite/galera/t/galera_ist_recv_bind.test       |   1 +
 .../suite/galera/t/galera_ist_restart_joiner.test  |  34 +-
 mysql-test/suite/galera/t/galera_ist_rsync.cnf     |   2 +
 mysql-test/suite/galera/t/galera_ist_rsync.test    |   5 +
 mysql-test/suite/galera/t/galera_many_rows.test    |   2 +-
 mysql-test/suite/galera/t/galera_migrate.cnf       |   2 +-
 .../suite/galera/t/galera_parallel_simple.test     |   2 +-
 .../galera/t/galera_query_cache_sync_wait.test     |   5 -
 .../galera/t/galera_restart_on_unknown_option.test |   7 +
 mysql-test/suite/galera/t/galera_ssl.test          |   1 +
 .../suite/galera/t/galera_ssl_compression.test     |   1 +
 .../suite/galera/t/galera_suspend_slave.test       |   3 +
 .../suite/galera/t/galera_sync_wait_show.test      |   3 +-
 .../suite/galera/t/galera_unicode_identifiers.test |   4 +-
 .../suite/galera/t/galera_var_dirty_reads.test     |  77 +---
 .../suite/galera/t/galera_var_node_address.test    |   2 +
 .../suite/galera/t/galera_var_sync_wait.test       |   5 +-
 .../galera/t/galera_wsrep_provider_unset_set.test  |   9 +
 mysql-test/suite/galera/t/lp1376747-4.test         |   2 +-
 mysql-test/suite/galera/t/mysql-wsrep#198.test     |   3 +
 mysql-test/suite/galera/t/mysql-wsrep#201.test     |   1 -
 mysql-test/suite/galera/t/pxc-421.test             |   5 +
 mysql-test/suite/galera/t/query_cache.opt          |   1 +
 mysql-test/suite/galera_3nodes/disabled.def        |   7 +-
 mysql-test/suite/galera_3nodes/galera_3nodes.cnf   |   2 +-
 mysql-test/suite/galera_3nodes/r/GAL-501.result    |  14 +
 .../galera_3nodes/r/galera_ipv6_mysqldump.result   |  26 ++
 .../suite/galera_3nodes/r/galera_ipv6_rsync.result |  14 +
 .../r/galera_ipv6_xtrabackup-v2.result             |  18 +
 .../galera_3nodes/r/galera_var_dirty_reads2.result |  48 +++
 mysql-test/suite/galera_3nodes/t/GAL-501.cnf       |  26 ++
 mysql-test/suite/galera_3nodes/t/GAL-501.test      |  38 ++
 .../galera_3nodes/t/galera_ipv6_mysqldump.cnf      |  22 ++
 .../galera_3nodes/t/galera_ipv6_mysqldump.test     |  56 +++
 .../suite/galera_3nodes/t/galera_ipv6_rsync.cnf    |  22 ++
 .../suite/galera_3nodes/t/galera_ipv6_rsync.test   |  32 ++
 .../galera_3nodes/t/galera_ipv6_xtrabackup-v2.cnf  |  26 ++
 .../galera_3nodes/t/galera_ipv6_xtrabackup-v2.test |  62 ++++
 .../galera_3nodes/t/galera_var_dirty_reads2.test   | 112 ++++++
 .../suite/sys_vars/r/wsrep_sync_wait_basic.result  |   4 +-
 mysql-test/suite/wsrep/disabled.def                |   2 +-
 scripts/wsrep_sst_common.sh                        |  57 +++
 scripts/wsrep_sst_mysqldump.sh                     |   6 +-
 scripts/wsrep_sst_rsync.sh                         |  32 +-
 scripts/wsrep_sst_xtrabackup-v2.sh                 | 396 +++++++++++++++------
 sql/handler.cc                                     |   5 +
 sql/mysqld.cc                                      |  23 +-
 sql/sql_class.cc                                   |   4 +
 sql/sql_class.h                                    |   2 +
 sql/sql_parse.cc                                   |  93 +++--
 sql/sql_partition_admin.cc                         |   4 +-
 sql/sql_table.cc                                   |  14 +-
 sql/sys_vars.cc                                    |  12 +-
 sql/wsrep_applier.cc                               |   7 +-
 sql/wsrep_hton.cc                                  |   1 +
 sql/wsrep_mysqld.cc                                | 291 ++++++++++-----
 sql/wsrep_mysqld.h                                 |   7 +-
 sql/wsrep_sst.cc                                   |   9 +-
 sql/wsrep_utils.cc                                 |  14 +
 sql/wsrep_utils.h                                  |   3 +
 sql/wsrep_var.cc                                   |  49 ++-
 sql/wsrep_var.h                                    |   4 +-
 storage/innobase/buf/buf0dump.cc                   |  15 +
 storage/innobase/handler/ha_innodb.cc              |   2 +-
 storage/innobase/include/trx0sys.h                 |  86 ++++-
 storage/innobase/row/row0ins.cc                    |   2 +-
 storage/innobase/row/row0upd.cc                    |  11 +-
 storage/innobase/srv/srv0start.cc                  |   1 -
 storage/innobase/trx/trx0sys.cc                    | 161 +++++----
 storage/xtradb/buf/buf0dump.cc                     |  15 +
 storage/xtradb/handler/ha_innodb.cc                |   2 +-
 storage/xtradb/include/trx0sys.h                   |  79 +++-
 storage/xtradb/row/row0ins.cc                      |   6 +-
 storage/xtradb/row/row0upd.cc                      |  11 +-
 storage/xtradb/srv/srv0start.cc                    |   1 -
 storage/xtradb/trx/trx0sys.cc                      | 170 ++++-----
 142 files changed, 2584 insertions(+), 786 deletions(-)

diff --cc cmake/wsrep.cmake
index be56a4c0772,1bd1ca51b35..e6d1379aea3
--- a/cmake/wsrep.cmake
+++ b/cmake/wsrep.cmake
@@@ -14,30 -14,51 +14,30 @@@
  # along with this program; if not, write to the Free Software
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
  
 -# We need to generate a proper spec file even without --with-wsrep flag,
 -# so WSREP_VERSION is produced regardless
 +#
 +# Galera library does not compile with windows
 +#
 +IF(UNIX)
 +  SET(with_wsrep_default ON)
 +ELSE()
 +  SET(with_wsrep_default OFF)
 +ENDIF()
 +
 +OPTION(WITH_WSREP "WSREP replication API (to use, e.g. Galera Replication library)" ${with_wsrep_default})
  
  # Set the patch version
- SET(WSREP_PATCH_VERSION "19")
+ SET(WSREP_PATCH_VERSION "20")
  
 -# MariaDB addition: Revision number of the last revision merged from
 -# codership branch visible in @@visible_comment.
 -# Branch : https://github.com/codership/mysql-wsrep/tree/5.6
 -SET(WSREP_PATCH_REVNO "c3fc46e") # Should be updated on every merge.
 -
 -# MariaDB: Obtain patch revision number:
 -# Update WSREP_PATCH_REVNO if WSREP_REV environment variable is set.
 -IF (DEFINED ENV{WSREP_REV})
 -  SET(WSREP_PATCH_REVNO $ENV{WSREP_REV})
 -ENDIF()
 -
  # Obtain wsrep API version
 -EXECUTE_PROCESS(
 -  COMMAND sh -c "grep WSREP_INTERFACE_VERSION ${MySQL_SOURCE_DIR}/wsrep/wsrep_api.h | cut -d '\"' -f 2"
 -  OUTPUT_VARIABLE WSREP_API_VERSION
 -  RESULT_VARIABLE RESULT
 -)
 -#FILE(WRITE "wsrep_config" "Debug: WSREP_API_VERSION result: ${RESULT}\n")
 -STRING(REGEX REPLACE "(\r?\n)+$" "" WSREP_API_VERSION "${WSREP_API_VERSION}")
 +FILE(STRINGS "${MySQL_SOURCE_DIR}/wsrep/wsrep_api.h" WSREP_API_VERSION
 +     LIMIT_COUNT 1 REGEX "WSREP_INTERFACE_VERSION")
 +STRING(REGEX MATCH "([0-9]+)" WSREP_API_VERSION "${WSREP_API_VERSION}")
  
 -IF(NOT WSREP_PATCH_REVNO)
 -  MESSAGE(WARNING "Could not determine bzr revision number, WSREP_VERSION will "
 -          "not contain the revision number.")
 -  SET(WSREP_VERSION
 -      "${WSREP_API_VERSION}.${WSREP_PATCH_VERSION}"
 -  )
 -ELSE()
 -  SET(WSREP_VERSION
 -      "${WSREP_API_VERSION}.${WSREP_PATCH_VERSION}.r${WSREP_PATCH_REVNO}"
 -  )
 -ENDIF()
 +SET(WSREP_VERSION "${WSREP_API_VERSION}.${WSREP_PATCH_VERSION}"
 +    CACHE INTERNAL "WSREP version")
  
 -OPTION(WITH_WSREP "WSREP replication API (to use, e.g. Galera Replication library)" ON)
 -IF (WITH_WSREP)
 -  SET(WSREP_C_FLAGS   "-DWITH_WSREP -DWSREP_PROC_INFO -DMYSQL_MAX_VARIABLE_VALUE_LEN=2048")
 -  SET(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} ${WSREP_C_FLAGS}")
 -  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSREP_C_FLAGS}")
 -  SET(COMPILATION_COMMENT "${COMPILATION_COMMENT}, wsrep_${WSREP_VERSION}")
 -  SET(WITH_EMBEDDED_SERVER OFF CACHE INTERNAL "" FORCE)
 -ENDIF()
 +SET(WSREP_PROC_INFO ${WITH_WSREP})
  
 -#
 +IF(WITH_WSREP)
 +  SET(WSREP_PATCH_VERSION "wsrep_${WSREP_VERSION}")
 +ENDIF()
diff --cc include/wsrep.h
index 532e4339f10,00000000000..0c06bb32b31
mode 100644,000000..100644
--- a/include/wsrep.h
+++ b/include/wsrep.h
@@@ -1,60 -1,0 +1,66 @@@
 +/* Copyright 2014 Codership Oy <http://www.codership.com> & SkySQL Ab
 +
 +   This program is free software; you can redistribute it and/or modify
 +   it under the terms of the GNU General Public License as published by
 +   the Free Software Foundation; version 2 of the License.
 +
 +   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 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 Street, Fifth Floor, Boston, MA 02111-1301 USA */
 +
 +#include <my_config.h>
 +
 +#ifndef WSREP_INCLUDED
 +#define WSREP_INCLUDED
 +
 +#ifdef WITH_WSREP
 +#define IF_WSREP(A,B) A
 +#define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A)
 +
 +#define WSREP_MYSQL_DB (char *)"mysql"
 +#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_)                   \
 +  if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \
 +    goto error;
 +
 +#define WSREP_TO_ISOLATION_END                                              \
 +  if (WSREP_ON && (WSREP(thd) || (thd && thd->wsrep_exec_mode==TOTAL_ORDER))) \
 +    wsrep_to_isolation_end(thd);
 +
 +/*
 +  Checks if lex->no_write_to_binlog is set for statements that use LOCAL or
 +  NO_WRITE_TO_BINLOG.
 +*/
 +#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)                   \
 +  if (WSREP(thd) && !thd->lex->no_write_to_binlog                                   \
 +         && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto error;
 +
 +#define WSREP_DEBUG(...)                                                \
 +    if (wsrep_debug)     WSREP_LOG(sql_print_information, ##__VA_ARGS__)
 +#define WSREP_INFO(...)  WSREP_LOG(sql_print_information, ##__VA_ARGS__)
 +#define WSREP_WARN(...)  WSREP_LOG(sql_print_warning,     ##__VA_ARGS__)
 +#define WSREP_ERROR(...) WSREP_LOG(sql_print_error,       ##__VA_ARGS__)
 +
++#define WSREP_SYNC_WAIT(thd_, before_)                                           \
++    { if (WSREP_CLIENT(thd_) &&                                                  \
++          wsrep_sync_wait(thd_, before_)) goto error; }
++
 +#else
 +#define IF_WSREP(A,B) B
 +#define DBUG_ASSERT_IF_WSREP(A)
 +#define WSREP_DEBUG(...)
 +#define WSREP_INFO(...)
 +#define WSREP_WARN(...)
 +#define WSREP_ERROR(...)
 +#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_)
 +#define WSREP_TO_ISOLATION_END
 +#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_)
- #endif
++#define WSREP_SYNC_WAIT(thd_, before_)
++
++#endif /* WITH_WSREP */
 +
- #endif /* WSERP_INCLUDED */
++#endif /* WSREP_INCLUDED */
diff --cc mysql-test/suite/galera/disabled.def
index 3b4698a7849,f9909914089..1e628b99644
--- a/mysql-test/suite/galera/disabled.def
+++ b/mysql-test/suite/galera/disabled.def
@@@ -1,58 -1,49 +1,51 @@@
- galera_wsrep_provider_unset_set : lp1379204 'Unsupported protocol downgrade: incremental data collection disabled. Expect abort.'
- galera_kill_nochanges : mysql-wsrep#24 Galera server does not restart properly if killed
- galera_bf_abort_for_update : mysql-wsrep#26 SELECT FOR UPDATE sometimes allowed to proceed in the face of a concurrent update
- galera_toi_ddl_fk_insert : qa#39 galera_toi_ddl_fk_insert fails sporadically
- galera_binlog_row_image : MDEV-7471 - Enable binlog_row_image parameter in MariaDB
- galera_binlog_rows_query_log_events : Unknown system variable 'binlog_rows_query_log_events' (see annotate_rows_log_event)
- 
- galera_ist_mysqldump : Lost connection to MySQL server during query
- galera_ist_xtrabackup-v2 : mysqltest failed but provided no output
- galera_ist_innodb_flush_logs : mysqltest failed but provided no output
- galera_sst_mysqldump : query 'show status' failed with wrong errno 1927
- galera_as_master_gtid : Needs to be re-worked
- galera_as_master_gtid_change_master : Needs to be re-worked
- galera_migrate : query 'let $success= `$wait_condition`' failed: 1146
- galera_var_notify_cmd : Result content mismatch
- query_cache : Fails intermittently due to content mismatch. Needs to be investigated
- basic : Fails intermittently without providing any output. Needs to be investigated
- galera_var_auto_inc_control_on : Failing sporadically with content mismatch
- galera_parallel_simple : Failing sporadically
- galera_bf_abort : Failing sporadically
- galera_log_output_csv : Failing sporadically
- galera_as_slave_preordered : wsrep-preordered is not available in MariaDB Galera cluster
- galera_gra_log : TODO: investigate
- galera_as_slave_replication_bundle : TODO: investigate
- galera_ssl_upgrade : TODO: investigate
- mysql-wsrep#90 : TODO: investigate
- galera_flush : mysql-wsrep/issues/229
- galera_transaction_read_only : mysql-wsrep/issues/229
- galera_gcs_fragment : Incorrect arguments to SET
- galera_flush_local : Fails sporadically
- galera_binlog_stmt_autoinc : TODO: investigate
- galera_concurrent_ctas : Test times out, investigate
- MW-286 : TODO: investigate
- galera_sst_xtrabackup-v2-options : TODO: Fix test case
- galera_sst_xtrabackup-v2 : TODO: Fix test case
- galera_sst_xtrabackup-v2_encrypt_with_key : TODO: Fix test case
- mysql-wsrep#33 : TODO: investigate
- MW-258              : MDEV-11229
- galera_as_master    : MDEV-11229
- MW-44               : MDEV-11229
- galera_gcs_fc_limit : MDEV-11229
- galera_roles        : MDEV-11229
- galera_lock_table   : MDEV-11229
- GAL-480 : Investigate
- galera_fk_no_pk :Investigate
- galera_account_management : Investigate
- galera.galera_var_retry_autocommit : MDEV-12319 #Sparodic Faliure
- galera.galera_gcs_fc_limit : MDEV-12319 #Sparodic Faliure
- galera.galera_toi_ddl_nonconflicting : MDEV-12319 #Sparodic Faliure
- galera.mysql-wsrep#198 : MDEV-12319 #Sparodic Faliure
- galera.galera_pc_ignore_sb : MDEV-12319 #Sparodic Faliure
- galera.MW-329 : MDEV-12319 #Sparodic Faliure
- galera.galera_ist_recv_bind : MDEV-12319 #Failed to start mysqld
- galera.galera_ist_restart_joiner : MDEV-12319 #Failed to start mysqld
- galera.galera_ssl_compression : MDEV-12319 #Failed to start mysqld
- galera.galera_wan : MDEV-12319 #Failed to start mysqld
- galera.rpl_row_annotate : MDEV-12319 #Failed to start mysqld
- galera_restart_on_unknown_option : Solve
+ ##############################################################################
+ #
+ #  List the test cases that are to be disabled temporarily.
+ #
+ #  Separate the test case name and the comment with ':'.
+ #
+ #    <testcasename> : MDEV-<xxxx> <comment>
+ #
+ #  Do not use any TAB characters for whitespace.
+ #
+ ##############################################################################
+ MW-336 : MDEV-13549 Galera test failures
+ galera_gra_log : MDEV-13549 Galera test failures
+ galera_flush_local : MDEV-13549 Galera test failures
+ galera_flush :  MDEV-13549 Galera test failures
+ MW-329 : MDEV-13549 Galera test failures
+ galera_account_management : MariaDB 10.0 does not support ALTER USER
+ galera_binlog_row_image : MariaDB 10.0 does not support binlog_row_image
+ galera_binlog_rows_query_log_events: MariaDB does not support binlog_rows_query_log_events
+ GAL-419 : MDEV-13549 Galera test failures
+ galera_toi_ddl_fk_insert : MDEV-13549 Galera test failures
+ galera_var_notify_cmd : MDEV-13549 Galera test failures
+ galera_var_slave_threads : MDEV-13549 Galera test failures
+ mysql-wsrep#90 : MDEV-13549 Galera test failures
+ galera_as_master_gtid : Requires MySQL GTID
+ galera_as_master_gtid_change_master : Requires MySQL GTID
+ galera_as_slave_replication_bundle : MDEV-13549 Galera test failures
+ galera_as_slave_preordered : wsrep-preordered feature not merged to MariaDB
+ galera_gcs_fragment : MDEV-13549 Galera test failures
+ galera_gcache_recover : MDEV-13549 Galera test failures
+ galera_gcache_recover_full_gcache : MDEV-13549 Galera test failures
+ galera_gcache_recover_manytrx : MDEV-13549 Galera test failures
+ galera_ist_mysqldump : MDEV-13549 Galera test failures
+ mysql-wsrep#31 :  MDEV-13549 Galera test failures
+ galera_migrate : MariaDB 10.0 does not support START SLAVE USER
+ galera_concurrent_ctas : MDEV-13549 Galera test failures
+ galera_bf_abort_for_update : MDEV-13549 Galera test failures
+ galera_wsrep_desync_wsrep_on : MDEV-13549 Galera test failures
+ galera_ssl_upgrade : MDEV-13549 Galera test failures
+ mysql-wsrep#33 : MDEV-13549 Galera test failures
+ galera_var_auto_inc_control_on : MDEV-13549 Galera test failures
+ MW-44 : MDEV-13549 Galera test failures
+ galera_var_retry_autocommit : MDEV-13549 Galera test failures
+ pxc-421 : MDEV-13549 Galera test failures
+ lp1376747-2 : MDEV-13549 Galera test failures
+ lp1376747 : MDEV-13549 Galera test failures
+ galera_toi_ddl_nonconflicting : MDEV-13549 Galera test failures
+ galera_parallel_simple : MDEV-13549 Galera test failures
+ galera_admin : MDEV-13549 Galera test failures
++galera_var_max_ws_rows :  MDEV-13549 Galera test failures 10.1
++MW-286 : MDEV-13549 Galera test failures 10.1
diff --cc mysql-test/suite/galera/galera_2nodes.cnf
index f120775d433,3d510d74429..b24f3603894
--- a/mysql-test/suite/galera/galera_2nodes.cnf
+++ b/mysql-test/suite/galera/galera_2nodes.cnf
@@@ -8,8 -7,12 +8,8 @@@ innodb-autoinc-lock-mode=
  default-storage-engine=innodb
  wsrep-provider=@ENV.WSREP_PROVIDER
  wsrep_node_address=127.0.0.1
 -wsrep_cluster_address='gcomm://'
 -wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.1.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S;gcache.size=10M'
 -
  # enforce read-committed characteristics across the cluster
- wsrep-sync-wait=7
 -wsrep-causal-reads=ON
+ wsrep-sync-wait=15
  
  [mysqld.1]
  #galera_port=@OPT.port
@@@ -27,12 -30,6 +27,12 @@@ wsrep_sst_receive_address='127.0.0.1:@m
  wsrep_cluster_address='gcomm://127.0.0.1:@mysqld.1.#galera_port'
  wsrep_provider_options='repl.causal_read_timeout=PT90S;base_port=@mysqld.2.#galera_port;evs.suspect_timeout=PT10S;evs.inactive_timeout=PT30S;evs.install_timeout=PT15S'
  
 +# enforce read-committed characteristics across the cluster
 +wsrep_causal_reads=ON
- wsrep_sync_wait = 7
++wsrep_sync_wait = 15
 +
 +wsrep_node_address=127.0.0.1
 +wsrep_sst_receive_address=127.0.0.2:@mysqld.2.#sst_port
  wsrep_node_incoming_address=127.0.0.1:@mysqld.2.port
  wsrep_sst_receive_address='127.0.0.1:@mysqld.2.#sst_port'
  
diff --cc mysql-test/suite/galera/r/MW-284.result
index 9465370c25b,3ff131674ea..9d1c3e5660d
--- a/mysql-test/suite/galera/r/MW-284.result
+++ b/mysql-test/suite/galera/r/MW-284.result
@@@ -9,7 -8,6 +9,7 @@@ SET GLOBAL wsrep_provider_options='gmca
  include/wait_for_slave_to_start.inc
  INSERT INTO t1 VALUES (1);
  DROP TABLE t1;
- SET global wsrep_sync_wait=7;
++SET global wsrep_sync_wait=15;
  STOP SLAVE;
  RESET SLAVE ALL;
  CALL mtr.add_suppression('failed registering on master');
diff --cc mysql-test/suite/galera/r/galera_var_dirty_reads.result
index 52729395b19,c469e49731d..f141b332b6c
--- a/mysql-test/suite/galera/r/galera_var_dirty_reads.result
+++ b/mysql-test/suite/galera/r/galera_var_dirty_reads.result
@@@ -31,74 -20,28 +20,27 @@@ SET @@session.wsrep_dirty_reads=ON
  SELECT * FROM t1;
  i
  1
- connect  con1, localhost, user1,,test,$NODE_MYPORT_2,$NODE_MYSOCK_2;
- SET SESSION wsrep_sync_wait=0;
- set session wsrep_dirty_reads=1;
- prepare stmt_show from 'select 1';
- prepare stmt_select from 'select * from t1';
- prepare stmt_insert from 'insert into t1 values(1)';
- set session wsrep_dirty_reads=0;
- execute stmt_show;
- ERROR 08S01: WSREP has not yet prepared node for application use
- execute stmt_select;
- ERROR 08S01: WSREP has not yet prepared node for application use
- execute stmt_insert;
- ERROR 08S01: WSREP has not yet prepared node for application use
- SET wsrep_dirty_reads=ON;
- select @@session.wsrep_dirty_reads;
- @@session.wsrep_dirty_reads
- 1
- execute stmt_show;
- 1
+ SELECT 1 FROM t1;
  1
- execute stmt_select;
- i
  1
- execute stmt_insert;
+ SELECT i, variable_name, variable_value FROM t1, information_schema.session_variables WHERE variable_name LIKE "wsrep_dirty_reads" AND i = 1;
+ i	variable_name	variable_value
+ 1	WSREP_DIRTY_READS	ON
+ SET @@session.wsrep_dirty_reads=OFF;
+ SELECT i, variable_name, variable_value FROM t1, information_schema.session_variables WHERE variable_name LIKE "wsrep_dirty_reads" AND i = 1;
  ERROR 08S01: WSREP has not yet prepared node for application use
- SET @@global.wsrep_dirty_reads=ON;
- connect  con2, localhost, user2,,test,$NODE_MYPORT_2,$NODE_MYSOCK_2;
- select @@session.wsrep_dirty_reads;
- @@session.wsrep_dirty_reads
- 1
- prepare stmt_show from 'select 1';
- prepare stmt_select from 'select * from t1';
- prepare stmt_insert from 'insert into t1 values(1)';
- execute stmt_show;
+ SELECT 1;
 -ERROR 08S01: WSREP has not yet prepared node for application use
 +1
 +1
- execute stmt_select;
- i
- 1
- execute stmt_insert;
+ USE information_schema;
  ERROR 08S01: WSREP has not yet prepared node for application use
- SET SESSION wsrep_sync_wait=1;
- execute stmt_show;
- 1
- 1
- execute stmt_select;
- i
- 1
- execute stmt_insert;
+ SELECT * FROM information_schema.session_variables WHERE variable_name LIKE "wsrep_dirty_reads";
  ERROR 08S01: WSREP has not yet prepared node for application use
- SET SESSION wsrep_sync_wait=7;
- execute stmt_show;
- 1
- 1
- execute stmt_select;
- i
- 1
- execute stmt_insert;
+ SELECT COUNT(*) >= 10 FROM performance_schema.events_statements_history;
  ERROR 08S01: WSREP has not yet prepared node for application use
- connection node_2;
- SET @@global.wsrep_dirty_reads=OFF;
- connection node_1;
+ USE test;
  SELECT * FROM t1;
  i
  1
  DROP TABLE t1;
- drop user user1;
- drop user user2;
- disconnect node_2;
- disconnect node_1;
 -set GLOBAL auto_increment_offset = 1;
 -set GLOBAL auto_increment_offset = 2;
  # End of test
diff --cc mysql-test/suite/galera/r/galera_var_sync_wait.result
index df9cdfbd159,f573c251bdd..51c1fb3662b
--- a/mysql-test/suite/galera/r/galera_var_sync_wait.result
+++ b/mysql-test/suite/galera/r/galera_var_sync_wait.result
@@@ -1,17 -1,5 +1,14 @@@
 +#
 +# MDEV-10161: wsrep_sync_wait not enabled when set to 1 in config file
 +#
 +SELECT @@global.wsrep_sync_wait;
 +@@global.wsrep_sync_wait
- 7
++15
 +SELECT @@global.wsrep_causal_reads;
 +@@global.wsrep_causal_reads
 +1
  CREATE TABLE t1 (f1 INT PRIMARY KEY) Engine=InnoDB;
  SET GLOBAL wsrep_sync_wait = 1;
- SHOW TABLES LIKE '%t1';
- Tables_in_test (%t1)
- t1
  SELECT COUNT(*) = 0 FROM t1;
  COUNT(*) = 0
  1
diff --cc mysql-test/suite/galera/suite.pm
index a161301d8ff,d5de3628f75..31593b654ea
--- a/mysql-test/suite/galera/suite.pm
+++ b/mysql-test/suite/galera/suite.pm
@@@ -65,8 -70,11 +68,12 @@@ push @::global_suppressions
       qr(WSREP: TO isolation failed for: .*),
       qr|WSREP: gcs_caused\(\) returned .*|,
       qr|WSREP: Protocol violation. JOIN message sender .* is not in state transfer \(SYNCED\). Message ignored.|,
+      qr|WSREP: Protocol violation. JOIN message sender .* is not in state transfer \(JOINED\). Message ignored.|,
+      qr|WSREP: Unsupported protocol downgrade: incremental data collection disabled. Expect abort.|,
       qr(WSREP: Action message in non-primary configuration from member [0-9]*),
       qr(WSREP: discarding established .*),
+      qr(WSREP: gcs\/src\/gcs_core.cpp:core_handle_uuid_msg\(\):.*),
++     qr(WSREP: --wsrep-causal-reads=ON takes precedence over --wsrep-sync-wait=0. WSREP_SYNC_WAIT_BEFORE_READ is on),
     );
  
  
diff --cc mysql-test/suite/galera/t/MW-286.test
index 1b2e322f078,1b2e322f078..08deb317fbe
--- a/mysql-test/suite/galera/t/MW-286.test
+++ b/mysql-test/suite/galera/t/MW-286.test
@@@ -25,6 -25,6 +25,7 @@@ SET wsrep_on = FALSE
  --error ER_QUERY_INTERRUPTED
  ALTER TABLE t1 ADD PRIMARY KEY (f1);
  
++SET SESSION wsrep_sync_wait = 0;
  SET wsrep_on = TRUE;
  SET GLOBAL wsrep_desync = FALSE;
  
diff --cc mysql-test/suite/galera/t/galera_var_dirty_reads.test
index 1fd30c69a7b,152c875a946..cba8488b879
--- a/mysql-test/suite/galera/t/galera_var_dirty_reads.test
+++ b/mysql-test/suite/galera/t/galera_var_dirty_reads.test
@@@ -45,67 -33,26 +38,25 @@@ SELECT 1 FROM t1
  SET @@session.wsrep_dirty_reads=ON;
  
  SELECT * FROM t1;
+ SELECT 1 FROM t1;
  
- --enable_connect_log
- --connect (con1, localhost, user1,,test,$NODE_MYPORT_2,$NODE_MYSOCK_2)
- #Just test the session behavior
- SET SESSION wsrep_sync_wait=0;
- 
- set session wsrep_dirty_reads=1;
- #Prepared statement creation should be allowed MDEV-11479
- prepare stmt_show from 'select 1';
- prepare stmt_select from 'select * from t1';
- prepare stmt_insert from 'insert into t1 values(1)';
- set session wsrep_dirty_reads=0;
+ SELECT i, variable_name, variable_value FROM t1, information_schema.session_variables WHERE variable_name LIKE "wsrep_dirty_reads" AND i = 1;
  
- #No Preapare stmt/proceure will be allowed
- --error ER_UNKNOWN_COM_ERROR
- execute stmt_show;
- --error ER_UNKNOWN_COM_ERROR
- execute stmt_select;
- --error ER_UNKNOWN_COM_ERROR
- execute stmt_insert;
+ SET @@session.wsrep_dirty_reads=OFF;
  
- SET wsrep_dirty_reads=ON;
- select @@session.wsrep_dirty_reads;
- #Only prepare statement which does not change data should be allowed
- execute stmt_show;
- execute stmt_select;
  --error ER_UNKNOWN_COM_ERROR
- execute stmt_insert;
- SET @@global.wsrep_dirty_reads=ON;
- 
- --connect (con2, localhost, user2,,test,$NODE_MYPORT_2,$NODE_MYSOCK_2)
- #Just test the session behavior
- select @@session.wsrep_dirty_reads;
+ SELECT i, variable_name, variable_value FROM t1, information_schema.session_variables WHERE variable_name LIKE "wsrep_dirty_reads" AND i = 1;
  
- prepare stmt_show from 'select 1';
- prepare stmt_select from 'select * from t1';
- prepare stmt_insert from 'insert into t1 values(1)';
 ---error ER_UNKNOWN_COM_ERROR
+ SELECT 1;
  
- #Only prepare statement which does not change data should be allowed
- execute stmt_show;
- execute stmt_select;
  --error ER_UNKNOWN_COM_ERROR
- execute stmt_insert;
- 
- #wsrep_dirty_read should work when wsrep_sync_wait is 1 or non zero
- #because we already are disconnected , So It does not make any sense
- #to wait for other nodes
- SET SESSION wsrep_sync_wait=1;
- execute stmt_show;
- execute stmt_select;
- --error ER_UNKNOWN_COM_ERROR
- execute stmt_insert;
+ USE information_schema;
  
- SET SESSION wsrep_sync_wait=7;
- execute stmt_show;
- execute stmt_select;
  --error ER_UNKNOWN_COM_ERROR
- execute stmt_insert;
+ SELECT * FROM information_schema.session_variables WHERE variable_name LIKE "wsrep_dirty_reads";
  
- --connection node_2
- SET @@global.wsrep_dirty_reads=OFF;
+ --error ER_UNKNOWN_COM_ERROR
+ SELECT COUNT(*) >= 10 FROM performance_schema.events_statements_history;
  
  --disable_query_log
  --eval SET @@global.wsrep_cluster_address = '$wsrep_cluster_address_saved'
@@@ -116,11 -64,10 +68,8 @@@ USE test
  SELECT * FROM t1;
  # Cleanup
  DROP TABLE t1;
- drop user user1;
- drop user user2;
 -set GLOBAL auto_increment_offset = 1;
  
- # Restore original auto_increment_offset values.
 ---connection node_2
 -set GLOBAL auto_increment_offset = 2;
 +--source include/auto_increment_offset_restore.inc
  
  --source include/galera_end.inc
  --echo # End of test
diff --cc mysql-test/suite/galera/t/query_cache.opt
index 00000000000,00000000000..a00258bc48c
new file mode 100644
--- /dev/null
+++ b/mysql-test/suite/galera/t/query_cache.opt
@@@ -1,0 -1,0 +1,1 @@@
++--query_cache_type=1
diff --cc scripts/wsrep_sst_xtrabackup-v2.sh
index 565e62e4dbe,a702dc641e0..78a7d76da09
--- a/scripts/wsrep_sst_xtrabackup-v2.sh
+++ b/scripts/wsrep_sst_xtrabackup-v2.sh
@@@ -34,9 -34,8 +34,10 @@@ ssystag="
  XTRABACKUP_PID=""
  SST_PORT=""
  REMOTEIP=""
 +REMOTEHOST=""
+ tca=""
  tcert=""
 +tpem=""
  tkey=""
  sockopt=""
  progress=""
@@@ -192,52 -289,105 +291,106 @@@ get_transfer(
              exit 2
          fi
  
-         if [[ $encrypt -eq 2 || $encrypt -eq 3 ]] && ! socat -V | grep -q "WITH_OPENSSL 1";then
-             wsrep_log_error "Encryption requested, but socat is not OpenSSL enabled (encrypt=$encrypt)"
-             exit 2
-         fi
+         donor_extra=""
+         joiner_extra=""
+         if [[ $encrypt -eq 2 || $encrypt -eq 3 || $encrypt -eq 4 ]]; then
+             if ! socat -V | grep -q WITH_OPENSSL; then
+                 wsrep_log_error "******** FATAL ERROR ****************** "
+                 wsrep_log_error "* socat is not openssl enabled.         "
+                 wsrep_log_error "* Unable to encrypt SST communications. "
+                 wsrep_log_error "*************************************** "
+                 exit 2
+             fi
  
-         if [[ $encrypt -eq 2 ]];then 
-             wsrep_log_info "Using openssl based encryption with socat: with crt and pem"
-             if [[ -z $tpem || -z $tcert ]];then 
-                 wsrep_log_error "Both PEM and CRT files required"
-                 exit 22
+             # Determine the socat version
+             SOCAT_VERSION=`socat -V 2>&1 | grep -oe '[0-9]\.[0-9][\.0-9]*' | head -n1`
+             if [[ -z "$SOCAT_VERSION" ]]; then
+                 wsrep_log_error "******** FATAL ERROR **************** "
+                 wsrep_log_error "* Cannot determine the socat version. "
+                 wsrep_log_error "************************************* "
+                 exit 2
+             fi
+ 
+             # socat versions < 1.7.3 will have 512-bit dhparams (too small)
+             #       so create 2048-bit dhparams and send that as a parameter
+             # socat version >= 1.7.3, checks to see if the peername matches the hostname
+             #       set commonname="" to disable the peername checks
+             #
+             if ! check_for_version "$SOCAT_VERSION" "1.7.3"; then
+                 if [[ "$WSREP_SST_OPT_ROLE"  == "joiner" ]]; then
+                     # dhparams check (will create ssl_dhparams if needed)
+                     check_for_dhparams
+                     joiner_extra=",dhparam=$ssl_dhparams"
+                 fi
+             fi
+             if check_for_version "$SOCAT_VERSION" "1.7.3"; then
+                 donor_extra=',commonname=""'
              fi
+         fi
+ 
+         if [[ $encrypt -eq 2 ]]; then
+             wsrep_log_warning "**** WARNING **** encrypt=2 is deprecated and will be removed in a future release"
+             wsrep_log_info "Using openssl based encryption with socat: with crt and ca"
+ 
+             verify_file_exists "$tcert" "Both certificate and CA files are required." \
+                                         "Please check the 'tcert' option.           "
+             verify_file_exists "$tca" "Both certificate and CA files are required." \
+                                       "Please check the 'tca' option.             "
+ 
              stagemsg+="-OpenSSL-Encrypted-2"
              if [[ "$WSREP_SST_OPT_ROLE"  == "joiner" ]];then
-                 wsrep_log_info "Decrypting with cert=${tpem}, cafile=${tcert}"
-                 tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tpem},cafile=${tcert}${sockopt} stdio"
+                 wsrep_log_info "Decrypting with CERT: $tcert, CA: $tca"
+                 tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tcert},cafile=${tca}${joiner_extra}${sockopt} stdio"
              else
-                 wsrep_log_info "Encrypting with cert=${tpem}, cafile=${tcert}"
-                 tcmd="socat -u stdio openssl-connect:${REMOTEHOST}:${TSST_PORT},cert=${tpem},cafile=${tcert}${sockopt}"
+                 wsrep_log_info "Encrypting with CERT: $tcert, CA: $tca"
+                 tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=${tcert},cafile=${tca}${donor_extra}${sockopt}"
              fi
          elif [[ $encrypt -eq 3 ]];then
+             wsrep_log_warning "**** WARNING **** encrypt=3 is deprecated and will be removed in a future release"
              wsrep_log_info "Using openssl based encryption with socat: with key and crt"
-             if [[ -z $tpem || -z $tkey ]];then
-                 wsrep_log_error "Both certificate and key files required"
-                 exit 22
-             fi
+ 
+             verify_file_exists "$tcert" "Both certificate and key files are required." \
+                                         "Please check the 'tcert' option.            "
+             verify_file_exists "$tkey" "Both certificate and key files are required." \
+                                        "Please check the 'tkey' option.             "
+ 
              stagemsg+="-OpenSSL-Encrypted-3"
              if [[ "$WSREP_SST_OPT_ROLE"  == "joiner" ]];then
-                 if [[ -z $tcert ]];then
-                     wsrep_log_info "Decrypting with cert=${tpem}, key=${tkey}, verify=0"
+                 wsrep_log_info "Decrypting with CERT: $tcert, KEY: $tkey"
+                 tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tcert},key=${tkey},verify=0${joiner_extra}${sockopt} stdio"
 -            else
 +                    tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tpem},key=${tkey},verify=0${sockopt} stdio"
 +                else
-                     wsrep_log_info "Decrypting with cert=${tpem}, key=${tkey}, cafile=${tcert}"
-                     tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tpem},key=${tkey},cafile=${tcert}${sockopt} stdio"
-                 fi
+                 wsrep_log_info "Encrypting with CERT: $tcert, KEY: $tkey"
+                 tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=${tcert},key=${tkey},verify=0${sockopt}"
+             fi
+         elif [[ $encrypt -eq 4 ]]; then
+             wsrep_log_info "Using openssl based encryption with socat: with key, crt, and ca"
+ 
+             verify_file_exists "$ssl_ca" "CA, certificate, and key files are required." \
+                                          "Please check the 'ssl-ca' option.           "
+             verify_file_exists "$ssl_cert" "CA, certificate, and key files are required." \
+                                            "Please check the 'ssl-cert' option.         "
+             verify_file_exists "$ssl_key" "CA, certificate, and key files are required." \
+                                           "Please check the 'ssl-key' option.          "
+ 
+             # Check to see that the key matches the cert
+             verify_cert_matches_key $ssl_cert $ssl_key
+ 
+             stagemsg+="-OpenSSL-Encrypted-4"
+             if [[ "$WSREP_SST_OPT_ROLE"  == "joiner" ]]; then
+                 wsrep_log_info "Decrypting with CERT: $ssl_cert, KEY: $ssl_key, CA: $ssl_ca"
+                 tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${ssl_cert},key=${ssl_key},cafile=${ssl_ca},verify=1${joiner_extra}${sockopt} stdio"
              else
-                 if [[ -z $tcert ]];then
-                     wsrep_log_info "Encrypting with cert=${tpem}, key=${tkey}, verify=0"
-                     tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=${tpem},key=${tkey},verify=0${sockopt}"
-                 else
-                     wsrep_log_info "Encrypting with cert=${tpem}, key=${tkey}, cafile=${tcert}"
-                     tcmd="socat -u stdio openssl-connect:${REMOTEHOST}:${TSST_PORT},cert=${tpem},key=${tkey},cafile=${tcert}${sockopt}"
-                 fi
+                 wsrep_log_info "Encrypting with CERT: $ssl_cert, KEY: $ssl_key, CA: $ssl_ca"
+                 tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=${ssl_cert},key=${ssl_key},cafile=${ssl_ca},verify=1${donor_extra}${sockopt}"
              fi
  
-         else 
-             if [[ "$WSREP_SST_OPT_ROLE"  == "joiner" ]];then
+         else
+             if [[ $encrypt -eq 1 ]]; then
+                 wsrep_log_warning "**** WARNING **** encrypt=1 is deprecated and will be removed in a future release"
+             fi
+ 
+             if [[ "$WSREP_SST_OPT_ROLE"  == "joiner" ]]; then
                  tcmd="socat -u TCP-LISTEN:${TSST_PORT},reuseaddr${sockopt} stdio"
              else
                  tcmd="socat -u stdio TCP:${REMOTEIP}:${TSST_PORT}${sockopt}"
@@@ -526,8 -667,8 +670,8 @@@ check_extra(
  {
      local use_socket=1
      if [[ $uextra -eq 1 ]];then 
 -        if $MY_PRINT_DEFAULTS -c $WSREP_SST_OPT_CONF mysqld | tr '_' '-' | grep -- "--thread-handling=" | grep -q 'pool-of-threads';then 
 +        if $MY_PRINT_DEFAULTS --mysqld | tr '_' '-' | grep -- "--thread-handling=" | grep -q 'pool-of-threads';then 
-             local eport=$($MY_PRINT_DEFAULTS --mysqld | tr '_' '-' | grep -- "--extra-port=" | cut -d= -f2)
+             local eport=$($MY_PRINT_DEFAULTS -c $WSREP_SST_OPT_CONF mysqld | tr '_' '-' | grep -- "--extra-port=" | cut -d= -f2)
              if [[ -n $eport ]];then 
                  # Xtrabackup works only locally.
                  # Hence, setting host to 127.0.0.1 unconditionally. 
@@@ -670,14 -864,14 +867,14 @@@ if [[ $ssyslog -eq 1 ]];the
          }
  
          INNOAPPLY="${INNOBACKUPEX_BIN} $disver $iapts --apply-log \$rebuildcmd \${DATA} 2>&1  | logger -p daemon.err -t ${ssystag}innobackupex-apply "
-         INNOMOVE="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} $disver $impts  --move-back --force-non-empty-directories \${DATA} 2>&1 | logger -p daemon.err -t ${ssystag}innobackupex-move "
+         INNOMOVE="${INNOBACKUPEX_BIN} --defaults-file=${WSREP_SST_OPT_CONF} $disver $impts --datadir=${DATA} --move-back --force-non-empty-directories \${DATA} 2>&1 | logger -p daemon.err -t ${ssystag}innobackupex-move "
 -        INNOBACKUP="${INNOBACKUPEX_BIN} --defaults-file=${WSREP_SST_OPT_CONF} $disver $iopts \$tmpopts \$INNOEXTRA --galera-info --stream=\$sfmt \$itmpdir 2> >(logger -p daemon.err -t ${ssystag}innobackupex-backup)"
 +        INNOBACKUP="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} $disver $iopts \$tmpopts \$INNOEXTRA --galera-info --stream=\$sfmt \$itmpdir 2> >(logger -p daemon.err -t ${ssystag}innobackupex-backup)"
      fi
  
  else 
      INNOAPPLY="${INNOBACKUPEX_BIN} $disver $iapts --apply-log \$rebuildcmd \${DATA} &>\${DATA}/innobackup.prepare.log"
-     INNOMOVE="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} $disver $impts  --move-back --force-non-empty-directories \${DATA} &>\${DATA}/innobackup.move.log"
+     INNOMOVE="${INNOBACKUPEX_BIN} --defaults-file=${WSREP_SST_OPT_CONF}  --defaults-group=mysqld${WSREP_SST_OPT_CONF_SUFFIX} $disver $impts --datadir=${DATA} --move-back --force-non-empty-directories \${DATA} &>\${DATA}/innobackup.move.log"
 -    INNOBACKUP="${INNOBACKUPEX_BIN} --defaults-file=${WSREP_SST_OPT_CONF}  --defaults-group=mysqld${WSREP_SST_OPT_CONF_SUFFIX} $disver $iopts \$tmpopts \$INNOEXTRA --galera-info --stream=\$sfmt \$itmpdir 2>\${DATA}/innobackup.backup.log"
 +    INNOBACKUP="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} $disver $iopts \$tmpopts \$INNOEXTRA --galera-info --stream=\$sfmt \$itmpdir 2>\${DATA}/innobackup.backup.log"
  fi
  
  get_stream
diff --cc sql/mysqld.cc
index 3af8750de13,45e6b3666bf..97d63d99458
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@@ -9224,17 -9516,6 +9224,38 @@@ mysqld_get_one_option(int optid, const 
  #endif
      break;
    }
 +#ifdef WITH_WSREP
 +  case OPT_WSREP_CAUSAL_READS:
-     wsrep_causal_reads_update(&global_system_variables);
++  {
++    if (global_system_variables.wsrep_causal_reads)
++    {
++      WSREP_WARN("option --wsrep-causal-reads is deprecated");
++      if (!(global_system_variables.wsrep_sync_wait & WSREP_SYNC_WAIT_BEFORE_READ))
++      {
++        WSREP_WARN("--wsrep-causal-reads=ON takes precedence over --wsrep-sync-wait=%u. "
++                     "WSREP_SYNC_WAIT_BEFORE_READ is on",
++                     global_system_variables.wsrep_sync_wait);
++        global_system_variables.wsrep_sync_wait |= WSREP_SYNC_WAIT_BEFORE_READ;
++      }
++    }
++    else
++    {
++      if (global_system_variables.wsrep_sync_wait & WSREP_SYNC_WAIT_BEFORE_READ) {
++          WSREP_WARN("--wsrep-sync-wait=%u takes precedence over --wsrep-causal-reads=OFF. "
++                     "WSREP_SYNC_WAIT_BEFORE_READ is on",
++                     global_system_variables.wsrep_sync_wait);
++          global_system_variables.wsrep_causal_reads = 1;
++      }
++    }
 +    break;
++  }
 +  case OPT_WSREP_SYNC_WAIT:
 +    global_system_variables.wsrep_causal_reads=
 +      MY_TEST(global_system_variables.wsrep_sync_wait &
 +              WSREP_SYNC_WAIT_BEFORE_READ);
 +    break;
 +#endif /* WITH_WSREP */
 +  }
    return 0;
  }
  
diff --cc sql/sql_class.cc
index 4df257b96a4,83cdaadb3b9..ce1f69b76a9
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@@ -1020,9 -1210,11 +1020,11 @@@ THD::THD(bool is_wsrep_applier
    wsrep_mysql_replicated  = 0;
    wsrep_TOI_pre_query     = NULL;
    wsrep_TOI_pre_query_len = 0;
 +  wsrep_info[sizeof(wsrep_info) - 1] = '\0'; /* make sure it is 0-terminated */
    wsrep_sync_wait_gtid    = WSREP_GTID_UNDEFINED;
    wsrep_affected_rows     = 0;
+   wsrep_replicate_GTID    = false;
+   wsrep_skip_wsrep_GTID   = false;
  #endif
    /* Call to init() below requires fully initialized Open_tables_state. */
    reset_open_tables_state(this);
diff --cc sql/sql_class.h
index 44163333425,8c9b8f92040..d8fc9303949
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@@ -4062,61 -3861,15 +4062,63 @@@ public
  #ifdef GTID_SUPPORT
    rpl_sid                   wsrep_po_sid;
  #endif /*  GTID_SUPPORT */
 -  void*                     wsrep_apply_format;
 -  bool                      wsrep_apply_toi; /* applier processing in TOI */
 -  bool                      wsrep_skip_append_keys;
 +  void                      *wsrep_apply_format;
 +  char                      wsrep_info[128]; /* string for dynamic proc info */
 +  /*
 +    When enabled, do not replicate/binlog updates from the current table that's
 +    being processed. At the moment, it is used to keep mysql.gtid_slave_pos
 +    table updates from being replicated to other nodes via galera replication.
 +  */
 +  bool                      wsrep_ignore_table;
    wsrep_gtid_t              wsrep_sync_wait_gtid;
    ulong                     wsrep_affected_rows;
+   bool                      wsrep_replicate_GTID;
+   bool                      wsrep_skip_wsrep_GTID;
  #endif /* WITH_WSREP */
 +
 +  /* Handling of timeouts for commands */
 +  thr_timer_t query_timer;
 +public:
 +  void set_query_timer()
 +  {
 +#ifndef EMBEDDED_LIBRARY
 +    /*
 +      Don't start a query timer if
 +      - If timeouts are not set
 +      - if we are in a stored procedure or sub statement
 +      - If this is a slave thread
 +      - If we already have set a timeout (happens when running prepared
 +        statements that calls mysql_execute_command())
 +    */
 +    if (!variables.max_statement_time || spcont  || in_sub_stmt ||
 +        slave_thread || query_timer.expired == 0)
 +      return;
 +    thr_timer_settime(&query_timer, variables.max_statement_time);
 +#endif
 +  }
 +  void reset_query_timer()
 +  {
 +#ifndef EMBEDDED_LIBRARY
 +    if (spcont || in_sub_stmt || slave_thread)
 +      return;
 +    if (!query_timer.expired)
 +      thr_timer_end(&query_timer);
 +#endif
 +  }
 +  void restore_set_statement_var()
 +  {
 +    main_lex.restore_set_statement_var();
 +  }
 +  /* Copy relevant `stmt` transaction flags to `all` transaction. */
 +  void merge_unsafe_rollback_flags()
 +  {
 +    if (transaction.stmt.modified_non_trans_table)
 +      transaction.all.modified_non_trans_table= TRUE;
 +    transaction.all.m_unsafe_rollback_flags|=
 +      (transaction.stmt.m_unsafe_rollback_flags &
 +       (THD_TRANS::DID_WAIT | THD_TRANS::CREATED_TEMP_TABLE |
 +        THD_TRANS::DROPPED_TEMP_TABLE | THD_TRANS::DID_DDL));
 +  }
  };
  
  
diff --cc sql/sql_parse.cc
index 65a2382f0d0,e561aa521e2..81b71f71760
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@@ -2943,14 -2794,13 +2944,10 @@@ mysql_execute_command(THD *thd
    case SQLCOM_SHOW_TRIGGERS:
    case SQLCOM_SHOW_TABLE_STATUS:
    case SQLCOM_SHOW_OPEN_TABLES:
 +  case SQLCOM_SHOW_GENERIC:
+   case SQLCOM_SHOW_PLUGINS:
    case SQLCOM_SHOW_FIELDS:
    case SQLCOM_SHOW_KEYS:
-   case SQLCOM_SELECT:
-     if (WSREP_CLIENT(thd) && wsrep_sync_wait(thd))
-       goto error;
-     /* fall through */
-   case SQLCOM_SHOW_PLUGINS:
 -  case SQLCOM_SHOW_CLIENT_STATS:
 -  case SQLCOM_SHOW_USER_STATS:
 -  case SQLCOM_SHOW_TABLE_STATS:
 -  case SQLCOM_SHOW_INDEX_STATS:
    case SQLCOM_SHOW_VARIABLES:
    case SQLCOM_SHOW_CHARSETS:
    case SQLCOM_SHOW_COLLATIONS:
@@@ -3744,12 -3589,9 +3745,13 @@@ end_with_restore_list
    }
    case SQLCOM_UPDATE:
    {
+     WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE);
      ha_rows found= 0, updated= 0;
      DBUG_ASSERT(first_table == all_tables && first_table != 0);
 +      if (WSREP_CLIENT(thd) &&
 +          wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE))
 +        goto error;
 +
      if (update_precheck(thd, all_tables))
        break;
  
@@@ -3900,12 -3735,9 +3896,13 @@@
    /* fall through */
    case SQLCOM_INSERT:
    {
+     WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE);
      DBUG_ASSERT(first_table == all_tables && first_table != 0);
  
 +    if (WSREP_CLIENT(thd) &&
 +        wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_INSERT_REPLACE))
 +      goto error;
 +
      /*
        Since INSERT DELAYED doesn't support temporary tables, we could
        not pre-open temporary tables for SQLCOM_INSERT / SQLCOM_REPLACE.
@@@ -4079,12 -3904,9 +4077,13 @@@
    }
    case SQLCOM_DELETE:
    {
+     WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE);
      select_result *sel_result=lex->result;
      DBUG_ASSERT(first_table == all_tables && first_table != 0);
 +    if (WSREP_CLIENT(thd) &&
 +        wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE))
 +      goto error;
 +
      if ((res= delete_precheck(thd, all_tables)))
        break;
      DBUG_ASSERT(select_lex->offset_limit == 0);
@@@ -4139,12 -3925,11 +4138,13 @@@
    }
    case SQLCOM_DELETE_MULTI:
    {
+     WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE);
      DBUG_ASSERT(first_table == all_tables && first_table != 0);
      TABLE_LIST *aux_tables= thd->lex->auxiliary_table_list.first;
 -    bool explain= MY_TEST(lex->describe);
      multi_delete *result;
 +    if (WSREP_CLIENT(thd) &&
 +        wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE))
 +      goto error;
  
      if ((res= multi_delete_precheck(thd, all_tables)))
        break;
@@@ -4240,12 -4008,26 +4227,26 @@@
      */
      if (thd->slave_thread && !thd->slave_expected_error &&
          slave_ddl_exec_mode_options == SLAVE_EXEC_MODE_IDEMPOTENT)
-       lex->create_info.set(DDL_options_st::OPT_IF_EXISTS);
+       lex->check_exists= 1;
+ 
 -#ifdef WITH_WSREP
 -   for (TABLE_LIST *table= all_tables; table; table= table->next_global)
 -   {
 -     if (!lex->drop_temporary                       &&
 -	 (!thd->is_current_stmt_binlog_format_row() ||
 -	  !find_temporary_table(thd, table)))
 -     {
 -       WSREP_TO_ISOLATION_BEGIN(NULL, NULL, all_tables);
 -       break;
 -     }
 -   }
 -#endif /* WITH_WSREP */
 -
++    if (WSREP(thd))
++    {
++      for (TABLE_LIST *table= all_tables; table; table= table->next_global)
++      {
++        if (!lex->tmp_table() &&
++           (!thd->is_current_stmt_binlog_format_row() ||
++	    !find_temporary_table(thd, table)))
++        {
++          WSREP_TO_ISOLATION_BEGIN(NULL, NULL, all_tables);
++          break;
++        }
++      }
++    }
 +    
      /* DDL and binlog write order are protected by metadata locks. */
 -    res= mysql_rm_table(thd, first_table, lex->check_exists,
 -			lex->drop_temporary);
 +    res= mysql_rm_table(thd, first_table, lex->if_exists(), lex->tmp_table());
 +    break;
    }
 -  break;
    case SQLCOM_SHOW_PROCESSLIST:
      if (!thd->security_ctx->priv_user[0] &&
          check_global_access(thd,PROCESS_ACL))
diff --cc sql/sql_partition_admin.cc
index a9f179e3a10,56c9c5bf3bf..e7f5e3cb59e
--- a/sql/sql_partition_admin.cc
+++ b/sql/sql_partition_admin.cc
@@@ -532,20 -531,17 +532,20 @@@ bool Sql_cmd_alter_table_exchange_parti
      DBUG_RETURN(true);
  
  #ifdef WITH_WSREP
 -  /* Forward declaration */
 -  TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
 +  if (WSREP_ON)
 +  {
 +    /* Forward declaration */
 +    TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
  
 -  if ((!thd->is_current_stmt_binlog_format_row() ||
 -       /* TODO: Do we really need to check for temp tables in this case? */
 -       !find_temporary_table(thd, table_list)) &&
 +    if ((!thd->is_current_stmt_binlog_format_row() ||
 +         /* TODO: Do we really need to check for temp tables in this case? */
 +         !find_temporary_table(thd, table_list)) &&
-         wsrep_to_isolation_begin(thd, table_list->db, table_list->table_name,
+ 	  wsrep_to_isolation_begin(thd, table_list->db, table_list->table_name,
 -                               NULL))
 -  {
 -    WSREP_WARN("ALTER TABLE EXCHANGE PARTITION isolation failure");
 -    DBUG_RETURN(TRUE);
 +                                 NULL))
 +    {
 +      WSREP_WARN("ALTER TABLE EXCHANGE PARTITION isolation failure");
 +      DBUG_RETURN(TRUE);
 +    }
    }
  #endif /* WITH_WSREP */
  
diff --cc sql/sys_vars.cc
index e0b8b522610,e234d441b78..8eb3d35a96e
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@@ -4929,22 -4680,12 +4929,14 @@@ static Sys_var_mybool Sys_wsrep_certify
         GLOBAL_VAR(wsrep_certify_nonPK), 
         CMD_LINE(OPT_ARG), DEFAULT(TRUE));
  
- static bool fix_wsrep_causal_reads(sys_var *self, THD* thd, enum_var_type var_type)
- {
-   if (var_type == OPT_GLOBAL)
-     wsrep_causal_reads_update(&global_system_variables);
-   else
-     wsrep_causal_reads_update(&thd->variables);
-   return false;
- }
  static Sys_var_mybool Sys_wsrep_causal_reads(
 -       "wsrep_causal_reads", "(DEPRECATED) Setting this variable is equivalent "
 +       "wsrep_causal_reads", "Setting this variable is equivalent "
         "to setting wsrep_sync_wait READ flag",
 -       SESSION_VAR(wsrep_causal_reads), CMD_LINE(OPT_ARG), DEFAULT(FALSE),
 +       SESSION_VAR(wsrep_causal_reads),
 +       CMD_LINE(OPT_ARG, OPT_WSREP_CAUSAL_READS), DEFAULT(FALSE),
         NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
-        ON_UPDATE(fix_wsrep_causal_reads),
 -       ON_UPDATE(wsrep_causal_reads_update));
++       ON_UPDATE(wsrep_causal_reads_update),
 +       DEPRECATED("'@@wsrep_sync_wait=1'"));
  
  static Sys_var_uint Sys_wsrep_sync_wait(
         "wsrep_sync_wait", "Ensure \"synchronous\" read view before executing "
diff --cc sql/wsrep_mysqld.cc
index 617aebae82e,49988287933..67b64301ff9
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@@ -16,14 -16,7 +16,15 @@@
  #include <mysqld.h>
  #include <sql_class.h>
  #include <sql_parse.h>
+ #include <sql_base.h> /* find_temporary_table() */
 +#include "slave.h"
 +#include "rpl_mi.h"
 +#include "sql_repl.h"
 +#include "rpl_filter.h"
 +#include "sql_callback.h"
 +#include "sp_head.h"
 +#include "sql_show.h"
 +#include "sp.h"
  #include "wsrep_priv.h"
  #include "wsrep_thd.h"
  #include "wsrep_sst.h"
@@@ -1374,11 -1178,145 +1358,147 @@@ create_view_query(THD *thd, uchar** buf
      return wsrep_to_buf_helper(thd, buff.ptr(), buff.length(), buf, buf_len);
  }
  
 +/* Forward declarations. */
 +static int wsrep_create_sp(THD *thd, uchar** buf, size_t* buf_len);
 +static int wsrep_create_trigger_query(THD *thd, uchar** buf, size_t* buf_len);
 +
  /*
+   Rewrite DROP TABLE for TOI. Temporary tables are eliminated from
+   the query as they are visible only to client connection.
+ 
+   TODO: See comments for sql_base.cc:drop_temporary_table() and refine
+   the function to deal with transactional locked tables.
+  */
+ static int wsrep_drop_table_query(THD* thd, uchar** buf, size_t* buf_len)
+ {
+ 
+   LEX* lex= thd->lex;
+   SELECT_LEX* select_lex= &lex->select_lex;
+   TABLE_LIST* first_table= select_lex->table_list.first;
+   String buff;
+ 
 -  DBUG_ASSERT(!lex->drop_temporary);
 -
+   bool found_temp_table= false;
+   for (TABLE_LIST* table= first_table; table; table= table->next_global)
+   {
+     if (find_temporary_table(thd, table->db, table->table_name))
+     {
+       found_temp_table= true;
+       break;
+     }
+   }
+ 
+   if (found_temp_table)
+   {
+     buff.append("DROP TABLE ");
+     if (lex->check_exists)
+       buff.append("IF EXISTS ");
+ 
+     for (TABLE_LIST* table= first_table; table; table= table->next_global)
+     {
+       if (!find_temporary_table(thd, table->db, table->table_name))
+       {
+         append_identifier(thd, &buff, table->db, strlen(table->db));
+         buff.append(".");
+         append_identifier(thd, &buff, table->table_name,
+                           strlen(table->table_name));
+         buff.append(",");
+       }
+     }
+ 
+     /* Chop the last comma */
+     buff.chop();
+     buff.append(" /* generated by wsrep */");
+ 
+     WSREP_DEBUG("Rewrote '%s' as '%s'", thd->query(), buff.ptr());
+ 
+     return wsrep_to_buf_helper(thd, buff.ptr(), buff.length(), buf, buf_len);
+   }
+   else
+   {
+     return wsrep_to_buf_helper(thd, thd->query(), thd->query_length(),
+                                buf, buf_len);
+   }
+ }
+ 
+ /*
+   Decide if statement should run in TOI.
+ 
+   Look if table or table_list contain temporary tables. If the
+   statement affects only temporary tables,   statement should not run
+   in TOI. If the table list contains mix of regular and temporary tables
+   (DROP TABLE, OPTIMIZE, ANALYZE), statement should be run in TOI but
+   should be rewritten at later time for replication to contain only
+   non-temporary tables.
+  */
+ static bool wsrep_can_run_in_toi(THD *thd, const char *db, const char *table,
+                                  const TABLE_LIST *table_list)
+ {
+   DBUG_ASSERT(!table || db);
+   DBUG_ASSERT(table_list || db);
+ 
+   LEX* lex= thd->lex;
+   SELECT_LEX* select_lex= &lex->select_lex;
+   TABLE_LIST* first_table= select_lex->table_list.first;
+ 
+   switch (lex->sql_command)
+   {
+   case SQLCOM_CREATE_TABLE:
+     DBUG_ASSERT(!table_list);
+     if (thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)
+     {
+       return false;
+     }
+     return true;
+ 
+   case SQLCOM_CREATE_VIEW:
+ 
+     DBUG_ASSERT(!table_list);
+     DBUG_ASSERT(first_table); /* First table is view name */
+     /*
+       If any of the remaining tables refer to temporary table error
+       is returned to client, so TOI can be skipped
+     */
+     for (TABLE_LIST* it= first_table->next_global; it; it= it->next_global)
+     {
+       if (find_temporary_table(thd, it))
+       {
+         return false;
+       }
+     }
+     return true;
+ 
+   case SQLCOM_CREATE_TRIGGER:
+ 
+     DBUG_ASSERT(!table_list);
+     DBUG_ASSERT(first_table);
+ 
+     if (find_temporary_table(thd, first_table))
+     {
+       return false;
+     }
+     return true;
+ 
+   default:
+     if (table && !find_temporary_table(thd, db, table))
+     {
+       return true;
+     }
+ 
+     if (table_list)
+     {
+       for (TABLE_LIST* table= first_table; table; table= table->next_global)
+       {
+         if (!find_temporary_table(thd, table->db, table->table_name))
+         {
+           return true;
+         }
+       }
+     }
+     return !(table || table_list);
+   }
+ }
+ 
+ /*
    returns: 
     0: statement was replicated as TOI
     1: TOI replication was skipped
diff --cc sql/wsrep_mysqld.h
index f02a3cd72f3,6dabdb66022..fd68fab991c
--- a/sql/wsrep_mysqld.h
+++ b/sql/wsrep_mysqld.h
@@@ -224,8 -255,19 +225,10 @@@ extern wsrep_seqno_t wsrep_locked_seqno
  #define WSREP_PROVIDER_EXISTS                                                  \
    (wsrep_provider && strncasecmp(wsrep_provider, WSREP_NONE, FN_REFLEN))
  
+ #define WSREP_QUERY(thd) (thd->query())
+ 
  extern void wsrep_ready_wait();
  
 -enum wsrep_trx_status {
 -    WSREP_TRX_OK,
 -    WSREP_TRX_CERT_FAIL,      /* certification failure, must abort */
 -    WSREP_TRX_SIZE_EXCEEDED,  /* trx size exceeded */
 -    WSREP_TRX_ERROR,          /* native mysql error */
 -};
 -
 -extern enum wsrep_trx_status
 -wsrep_run_wsrep_commit(THD *thd, handlerton *hton, bool all);
  class Ha_trx_info;
  struct THD_TRANS;
  void wsrep_register_hton(THD* thd, bool all);
diff --cc sql/wsrep_sst.cc
index 7f9a88c3aa6,818cb3f28fd..a187c75baa3
--- a/sql/wsrep_sst.cc
+++ b/sql/wsrep_sst.cc
@@@ -689,15 -631,9 +689,15 @@@ ssize_t wsrep_sst_prepare (void** msg
      return ret;
    }
  
 -  // Figure out SST address. Common for all SST methods
 +  /*
 +    Figure out SST receive address. Common for all SST methods.
 +  */
 +  char ip_buf[256];
 +  const ssize_t ip_max= sizeof(ip_buf);
 +
 +  // Attempt 1: wsrep_sst_receive_address
    if (wsrep_sst_receive_address &&
-     strcmp (wsrep_sst_receive_address, WSREP_SST_ADDRESS_AUTO))
+       strcmp (wsrep_sst_receive_address, WSREP_SST_ADDRESS_AUTO))
    {
      addr_in= wsrep_sst_receive_address;
    }
@@@ -835,18 -772,6 +835,15 @@@ static int sst_donate_mysqldump (const 
                                   bool                bypass,
                                   char**              env) // carries auth info
  {
 +  char host[256];
 +  wsp::Address address(addr);
- 
 +  if (!address.is_valid())
 +  {
 +    WSREP_ERROR("Could not parse SST address : %s", addr);
 +    return 0;
 +  }
- 
 +  memcpy(host, address.get_address(), address.get_address_len());
 +  int port= address.get_port();
- 
    int const cmd_len= 4096;
    wsp::string  cmd_str(cmd_len);
  
@@@ -859,22 -784,17 +856,22 @@@
  
    if (!bypass && wsrep_sst_donor_rejects_queries) sst_reject_queries(TRUE);
  
 +  make_wsrep_defaults_file();
 +
    int ret= snprintf (cmd_str(), cmd_len,
                       "wsrep_sst_mysqldump "
-                      WSREP_SST_OPT_HOST" '%s' "
+                      WSREP_SST_OPT_ADDR" '%s' "
 +                     WSREP_SST_OPT_PORT" '%d' "
                       WSREP_SST_OPT_LPORT" '%u' "
                       WSREP_SST_OPT_SOCKET" '%s' "
 -                     WSREP_SST_OPT_CONF" '%s' "
 -                     WSREP_SST_OPT_GTID" '%s:%lld'"
 +                     " %s "
 +                     WSREP_SST_OPT_GTID" '%s:%lld' "
 +                     WSREP_SST_OPT_GTID_DOMAIN_ID" '%d'"
                       "%s",
-                      host, port, mysqld_port, mysqld_unix_port,
 -                     addr, mysqld_port, mysqld_unix_port,
++	             addr, port, mysqld_port, mysqld_unix_port,
                       wsrep_defaults_file, uuid_str,
 -                     (long long)seqno, bypass ? " " WSREP_SST_OPT_BYPASS : "");
 +                     (long long)seqno, wsrep_gtid_domain_id,
 +                     bypass ? " " WSREP_SST_OPT_BYPASS : "");
  
    if (ret < 0 || ret >= cmd_len)
    {
diff --cc sql/wsrep_utils.cc
index a0111354d02,9c5cef6a997..580c8bbd55c
--- a/sql/wsrep_utils.cc
+++ b/sql/wsrep_utils.cc
@@@ -569,8 -552,20 +569,22 @@@ size_t wsrep_guess_ip (char* buf, size_
    }
  #endif /* HAVE_GETIFADDRS */
  
 -  return 0;
 +done:
 +  WSREP_DEBUG("wsrep_guess_ip() : %s", (ret > 0) ? buf : "????");
 +  return ret;
  }
  
+ /* returns the length of the host part of the address string */
+ size_t wsrep_host_len(const char* const addr, size_t const addr_len)
+ {
+   // check for IPv6 notation first
+   const char* const bracket= ('[' == addr[0] ? strchr(addr, ']') : NULL);
+ 
+   if (bracket) { // IPv6
+     return (bracket - addr + 1);
+   }
+   else { // host part ends at ':' or end of string
+     const char* const colon= strchr(addr, ':');
+     return (colon ? colon - addr : addr_len);
+   }
+ }
diff --cc sql/wsrep_utils.h
index f20e02d03a2,0ae5c68df21..88a4c1e1a70
--- a/sql/wsrep_utils.h
+++ b/sql/wsrep_utils.h
@@@ -17,224 -17,34 +17,227 @@@
  #define WSREP_UTILS_H
  
  #include "wsrep_priv.h"
 +#include "wsrep_mysqld.h"
  
 -unsigned int wsrep_check_ip (const char* addr);
 +unsigned int wsrep_check_ip (const char* const addr, bool *is_ipv6);
  size_t wsrep_guess_ip (char* buf, size_t buf_len);
  
+ /* returns the length of the host part of the address string */
+ size_t wsrep_host_len(const char* addr, size_t addr_len);
+ 
  namespace wsp {
 -class node_status
 +
 +class Address {
 +public:
 +  Address()
 +    : m_address_len(0), m_family(UNSPEC), m_port(0), m_valid(false)
 +  {
 +    memset(m_address, 0, sizeof(m_address));
 +  }
 +  Address(const char *addr_in)
 +    : m_address_len(0), m_family(UNSPEC), m_port(0), m_valid(false)
 +  {
 +    memset(m_address, 0, sizeof(m_address));
 +    parse_addr(addr_in);
 +  }
 +  bool is_valid() { return m_valid; }
 +  bool is_ipv6() { return (m_family == INET6); }
 +
 +  const char* get_address() { return m_address; }
 +  size_t get_address_len() { return m_address_len; }
 +  int get_port() { return m_port; }
 +
 +private:
 +  enum family {
 +    UNSPEC= 0,
 +    INET,                                       /* IPv4 */
 +    INET6,                                      /* IPv6 */
 +  };
 +
 +  char   m_address[256];
 +  size_t m_address_len;
 +  family m_family;
 +  int    m_port;
 +  bool   m_valid;
 +
 +  void parse_addr(const char *addr_in) {
 +    const char *start;
 +    const char *end;
 +    const char *port;
 +    const char* open_bracket= strchr(const_cast<char *>(addr_in), '[');
 +    const char* close_bracket= strchr(const_cast<char *>(addr_in), ']');
 +    const char* colon= strchr(const_cast<char *>(addr_in), ':');
 +    const char* dot= strchr(const_cast<char *>(addr_in), '.');
 +
 +    int cc= colon_count(addr_in);
 +
 +    if (open_bracket != NULL ||
 +        dot == NULL ||
 +        (colon != NULL && (dot == NULL || colon < dot)))
 +    {
 +      // This could be an IPv6 address or a hostname
 +      if (open_bracket != NULL) {
 +        /* Sanity check: Address with '[' must include ']' */
 +        if (close_bracket == NULL &&
 +            open_bracket < close_bracket)       /* Error: malformed address */
 +        {
 +          m_valid= false;
 +          return;
 +        }
 +
 +        start= open_bracket + 1;
 +        end= close_bracket;
 +
 +        /* Check for port */
 +        port= strchr(close_bracket, ':');
 +        if ((port != NULL) && parse_port(port + 1))
 +        {
 +          return;                               /* Error: invalid port */
 +        }
 +        m_family= INET6;
 +      }
 +      else
 +      {
 +        switch (cc) {
 +        case 0:
 +          /* Hostname with no port */
 +          start= addr_in;
 +          end= addr_in + strlen(addr_in);
 +          break;
 +        case 1:
 +          /* Hostname with port (host:port) */
 +          start= addr_in;
 +          end= colon;
 +          parse_port(colon + 1);
 +          break;
 +        default:
 +          /* IPv6 address */
 +          start= addr_in;
 +          end= addr_in + strlen(addr_in);
 +          m_family= INET6;
 +          break;
 +        }
 +      }
 +    } else {                                    /* IPv4 address or hostname */
 +      start= addr_in;
 +      if (colon != NULL) {                      /* Port */
 +        end= colon;
 +        if (parse_port(colon + 1))
 +          return;                               /* Error: invalid port */
 +      } else {
 +        end= addr_in + strlen(addr_in);
 +      }
 +    }
 +
 +    size_t len= end - start;
 +
 +    /* Safety */
 +    if (len >= sizeof(m_address))
 +    {
 +      // The supplied address is too large to fit into the internal buffer.
 +      m_valid= false;
 +      return;
 +    }
 +
 +    memcpy(m_address, start, len);
 +    m_address[len]= '\0';
 +    m_address_len= ++ len;
 +    m_valid= true;
 +    return;
 +  }
 +
 +  int colon_count(const char *addr) {
 +    int count= 0, i= 0;
 +
 +    while(addr[i] != '\0')
 +    {
 +      if (addr[i] == ':') ++count;
 +      ++ i;
 +    }
 +    return count;
 +  }
 +
 +  bool parse_port(const char *port) {
 +    errno= 0;                                   /* Reset the errno */
 +    m_port= strtol(port, NULL, 10);
 +    if (errno == EINVAL || errno == ERANGE)
 +    {
 +      m_port= 0;                                /* Error: invalid port */
 +      m_valid= false;
 +      return true;
 +    }
 +    return false;
 +  }
 +};
 +
 +class Config_state
  {
  public:
 -  node_status() : status(WSREP_MEMBER_UNDEFINED) {}
 -  void set(wsrep_member_status_t new_status,
 -           const wsrep_view_info_t* view = 0)
 +  Config_state() : view_(), status_(WSREP_MEMBER_UNDEFINED)
 +  {}
 +
 +  void set(wsrep_member_status_t status, const wsrep_view_info_t* view)
    {
 -    if (status != new_status || 0 != view)
 +    wsrep_notify_status(status, view);
 +
 +    lock();
 +
 +    status_= status;
 +    view_= *view;
 +    member_info_.clear();
 +
 +    wsrep_member_info_t memb;
 +    for(int i= 0; i < view->memb_num; i ++)
      {
 -      wsrep_notify_status(new_status, view);
 -      status = new_status;
 +      memb= view->members[i];
 +      member_info_.append_val(memb);
      }
 +
 +    unlock();
 +  }
 +
 +  void set(wsrep_member_status_t status)
 +  {
 +    wsrep_notify_status(status, 0);
 +    lock();
 +    status_= status;
 +    unlock();
 +  }
 +
 +  wsrep_view_info_t get_view_info() const
 +  {
 +    return view_;
    }
 -  wsrep_member_status_t get() const { return status; }
 +
 +  wsrep_member_status_t get_status() const
 +  {
 +    return status_;
 +  }
 +
 +  Dynamic_array<wsrep_member_info_t> * get_member_info()
 +  {
 +    return &member_info_;
 +  }
 +
 +  int lock()
 +  {
 +    return mysql_mutex_lock(&LOCK_wsrep_config_state);
 +  }
 +
 +  int unlock()
 +  {
 +    return mysql_mutex_unlock(&LOCK_wsrep_config_state);
 +  }
 +
  private:
 -  wsrep_member_status_t status;
 +  wsrep_view_info_t                  view_;
 +  wsrep_member_status_t              status_;
 +  Dynamic_array<wsrep_member_info_t> member_info_;
  };
 +
  } /* namespace wsp */
  
 -extern wsp::node_status local_status;
 +extern wsp::Config_state wsrep_config_state;
  
  namespace wsp {
  /* a class to manage env vars array */
diff --cc sql/wsrep_var.h
index ca77b5c0039,f72df9d098a..7530fd98870
--- a/sql/wsrep_var.h
+++ b/sql/wsrep_var.h
@@@ -41,10 -34,8 +41,8 @@@ int wsrep_init_vars()
  #define DEFAULT_ARGS (THD* thd, enum_var_type var_type)
  #define INIT_ARGS    (const char* opt)
  
- struct system_variables;
- bool wsrep_causal_reads_update(struct system_variables *sv);
- 
++extern bool wsrep_causal_reads_update         UPDATE_ARGS;
  extern bool wsrep_on_update                  UPDATE_ARGS;
 -extern bool wsrep_causal_reads_update        UPDATE_ARGS;
  extern bool wsrep_sync_wait_update           UPDATE_ARGS;
  extern bool wsrep_start_position_check       CHECK_ARGS;
  extern bool wsrep_start_position_update      UPDATE_ARGS;
diff --cc storage/innobase/buf/buf0dump.cc
index 0994d87bc2d,0682b8ef46e..33a39aaed8a
--- a/storage/innobase/buf/buf0dump.cc
+++ b/storage/innobase/buf/buf0dump.cc
@@@ -688,11 -686,19 +691,17 @@@ DECLARE_THREAD(buf_dump_thread)(void*
  	my_thread_init();
  	ut_ad(!srv_read_only_mode);
  
 -	srv_buf_dump_thread_active = TRUE;
 -
 -	buf_dump_status(STATUS_INFO, "not started");
 -	buf_load_status(STATUS_INFO, "not started");
 +	buf_dump_status(STATUS_INFO, "Dumping buffer pool(s) not yet started");
 +	buf_load_status(STATUS_INFO, "Loading buffer pool(s) not yet started");
  
  	if (srv_buffer_pool_load_at_startup) {
+ #ifdef WITH_WSREP
+ 		if (!wsrep_recovery) {
+ #endif /* WITH_WSREP */
  		buf_load();
+ #ifdef WITH_WSREP
+                 }
+ #endif /* WITH_WSREP */
  	}
  
  	while (!SHUTTING_DOWN()) {
@@@ -716,11 -722,17 +725,17 @@@
  	}
  
  	if (srv_buffer_pool_dump_at_shutdown && srv_fast_shutdown != 2) {
+ #ifdef WITH_WSREP
+ 		if (!wsrep_recovery) {
+ #endif /* WITH_WSREP */
  		buf_dump(FALSE /* ignore shutdown down flag,
  		keep going even if we are in a shutdown state */);
+ #ifdef WITH_WSREP
+ 		}
+ #endif /* WITH_WSREP */
  	}
  
 -	srv_buf_dump_thread_active = FALSE;
 +	srv_buf_dump_thread_active = false;
  
  	my_thread_end();
  	/* We count the number of threads in os_thread_exit(). A created
diff --cc storage/innobase/handler/ha_innodb.cc
index 6064c3980eb,17fd02112d9..4c6e13291e0
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@@ -18823,8 -17945,8 +18823,8 @@@ wsrep_fake_trx_id
  	mutex_enter(&trx_sys->mutex);
  	trx_id_t trx_id = trx_sys_get_new_trx_id();
  	mutex_exit(&trx_sys->mutex);
- 
+ 	WSREP_DEBUG("innodb fake trx id: %lu thd: %s", trx_id, wsrep_thd_query(thd));
 -	(void *)wsrep_ws_handle_for_trx(wsrep_thd_ws_handle(thd), trx_id);
 +	wsrep_ws_handle_for_trx(wsrep_thd_ws_handle(thd), trx_id);
  }
  
  #endif /* WITH_WSREP */
diff --cc storage/innobase/srv/srv0start.cc
index 0880f93c7fa,62605262de5..6f471dbf0e3
--- a/storage/innobase/srv/srv0start.cc
+++ b/storage/innobase/srv/srv0start.cc
@@@ -3011,23 -2910,10 +3011,22 @@@ files_checked
  #ifdef WITH_WSREP
  		} else {
  			ib_logf(IB_LOG_LEVEL_WARN,
 -			"Skipping buffer pool dump/restore during wsrep "
 -			"recovery.");
 -                }
 +				"Skipping buffer pool dump/restore during "
 +				"wsrep recovery.");
 +		}
  #endif /* WITH_WSREP */
- 
 +		/* Create thread(s) that handles key rotation */
 +		fil_system_enter();
 +		fil_crypt_threads_init();
 +		fil_system_exit();
 +
 +		/* Init data for datafile scrub threads */
 +		btr_scrub_init();
 +
 +		/* Initialize online defragmentation. */
 +		btr_defragment_init();
 +		btr_defragment_thread_active = true;
 +		os_thread_create(btr_defragment_thread, NULL, NULL);
  	}
  
  	srv_was_started = TRUE;
diff --cc storage/innobase/trx/trx0sys.cc
index f54466c8f82,152813d9f3b..8cb4f9a4135
--- a/storage/innobase/trx/trx0sys.cc
+++ b/storage/innobase/trx/trx0sys.cc
@@@ -337,71 -342,77 +340,77 @@@ static inline void read_wsrep_xid_uuid(
  
  #endif /* UNIV_DEBUG */
  
+ /** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
+ @param[in]	xid		Transaction XID
+ @param[in,out]	sys_header	sys_header
+ @param[in]	mtr		minitransaction */
  void
  trx_sys_update_wsrep_checkpoint(
-         const XID*      xid,        /*!< in: transaction XID */
-         trx_sysf_t*     sys_header, /*!< in: sys_header */
-         mtr_t*          mtr)        /*!< in: mtr */
+ 	const XID*	xid,
+ 	trx_sysf_t*	sys_header,
+ 	mtr_t*		mtr)
  {
  #ifdef UNIV_DEBUG
-         {
-             /* Check that seqno is monotonically increasing */
-             unsigned char xid_uuid[16];
-             long long xid_seqno = read_wsrep_xid_seqno(xid);
-             read_wsrep_xid_uuid(xid, xid_uuid);
-             if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8))
-             {
-                 ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
-                 trx_sys_cur_xid_seqno = xid_seqno;
-             }
-             else
-             {
-                 memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
-             }
-             trx_sys_cur_xid_seqno = xid_seqno;
-         }
+ 	if (xid->formatID != -1
+ 	    && mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+ 			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+ 		== TRX_SYS_WSREP_XID_MAGIC_N) {
+ 		/* Check that seqno is monotonically increasing */
+ 		unsigned char xid_uuid[16];
+ 		long long xid_seqno = read_wsrep_xid_seqno(xid);
+ 		read_wsrep_xid_uuid(xid, xid_uuid);
+ 
+ 		if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8)) {
+ 			ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
+ 			trx_sys_cur_xid_seqno = xid_seqno;
+ 		} else {
+ 			memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
+ 		}
+ 
+ 		trx_sys_cur_xid_seqno = xid_seqno;
+ 	}
  #endif /* UNIV_DEBUG */
  
-         ut_ad(xid && mtr);
-         ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid(xid));
- 
-         if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
-                              + TRX_SYS_WSREP_XID_MAGIC_N_FLD)
-             != TRX_SYS_WSREP_XID_MAGIC_N) {
-                 mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                                  + TRX_SYS_WSREP_XID_MAGIC_N_FLD,
-                                  TRX_SYS_WSREP_XID_MAGIC_N,
-                                  MLOG_4BYTES, mtr);
-         }
+ 	ut_ad(xid && mtr);
 -	ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid((const void *)xid));
++	ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid((const XID *)xid));
  
-         mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_FORMAT,
-                          (int)xid->formatID,
-                          MLOG_4BYTES, mtr);
-         mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_GTRID_LEN,
-                          (int)xid->gtrid_length,
-                          MLOG_4BYTES, mtr);
-         mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_BQUAL_LEN,
-                          (int)xid->bqual_length,
-                          MLOG_4BYTES, mtr);
-         mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
-                           + TRX_SYS_WSREP_XID_DATA,
-                           (const unsigned char*) xid->data,
-                           XIDDATASIZE, mtr);
+ 	if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+ 			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+ 		!= TRX_SYS_WSREP_XID_MAGIC_N) {
+ 		mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD,
+ 			TRX_SYS_WSREP_XID_MAGIC_N,
+ 			MLOG_4BYTES, mtr);
+ 	}
  
+ 	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_FORMAT,
+ 		(int)xid->formatID,
+ 		MLOG_4BYTES, mtr);
+ 	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_GTRID_LEN,
+ 		(int)xid->gtrid_length,
+ 		MLOG_4BYTES, mtr);
+ 	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_BQUAL_LEN,
+ 		(int)xid->bqual_length,
+ 		MLOG_4BYTES, mtr);
+ 	mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_DATA,
+ 		(const unsigned char*) xid->data,
+ 		XIDDATASIZE, mtr);
  }
  
+ /** Read WSREP XID from sys_header of TRX_SYS_PAGE_NO = 5.
+ @param[out]	xid	Transaction XID */
  void
  trx_sys_read_wsrep_checkpoint(XID* xid)
- /*===================================*/
  {
-         trx_sysf_t* sys_header;
+ 	trx_sysf_t* sys_header;
  	mtr_t	    mtr;
-         ulint       magic;
+ 	ulint       magic;
  
-         ut_ad(xid);
+ 	ut_ad(xid);
  
  	mtr_start(&mtr);
  
diff --cc storage/xtradb/buf/buf0dump.cc
index 71b97b770e1,d0892a4f6a5..023a267ee22
--- a/storage/xtradb/buf/buf0dump.cc
+++ b/storage/xtradb/buf/buf0dump.cc
@@@ -689,11 -687,19 +692,17 @@@ DECLARE_THREAD(buf_dump_thread)(void*
  	my_thread_init();
  	ut_ad(!srv_read_only_mode);
  
 -	srv_buf_dump_thread_active = TRUE;
 -
 -	buf_dump_status(STATUS_INFO, "not started");
 -	buf_load_status(STATUS_INFO, "not started");
 +	buf_dump_status(STATUS_INFO, "Dumping buffer pool(s) not yet started");
 +	buf_load_status(STATUS_INFO, "Loading buffer pool(s) not yet started");
  
  	if (srv_buffer_pool_load_at_startup) {
+ #ifdef WITH_WSREP
+ 		if (!wsrep_recovery) {
+ #endif /* WITH_WSREP */
  		buf_load();
+ #ifdef WITH_WSREP
+                 }
+ #endif /* WITH_WSREP */
  	}
  
  	while (!SHUTTING_DOWN()) {
@@@ -717,11 -723,17 +726,17 @@@
  	}
  
  	if (srv_buffer_pool_dump_at_shutdown && srv_fast_shutdown != 2) {
+ #ifdef WITH_WSREP
+ 		if (!wsrep_recovery) {
+ #endif /* WITH_WSREP */
  		buf_dump(FALSE /* ignore shutdown down flag,
  		keep going even if we are in a shutdown state */);
+ #ifdef WITH_WSREP
+ 		}
+ #endif /* WITH_WSREP */
  	}
  
 -	srv_buf_dump_thread_active = FALSE;
 +	srv_buf_dump_thread_active = false;
  
  	my_thread_end();
  	/* We count the number of threads in os_thread_exit(). A created
diff --cc storage/xtradb/handler/ha_innodb.cc
index d4ece1de49e,ac2bf1010d6..c333f3e9686
--- a/storage/xtradb/handler/ha_innodb.cc
+++ b/storage/xtradb/handler/ha_innodb.cc
@@@ -19840,8 -19247,8 +19840,8 @@@ wsrep_fake_trx_id
  	mutex_enter(&trx_sys->mutex);
  	trx_id_t trx_id = trx_sys_get_new_trx_id();
  	mutex_exit(&trx_sys->mutex);
- 
+ 	WSREP_DEBUG("innodb fake trx id: %lu thd: %s", trx_id, wsrep_thd_query(thd));
 -	(void *)wsrep_ws_handle_for_trx(wsrep_thd_ws_handle(thd), trx_id);
 +	wsrep_ws_handle_for_trx(wsrep_thd_ws_handle(thd), trx_id);
  }
  
  #endif /* WITH_WSREP */
diff --cc storage/xtradb/include/trx0sys.h
index 274a8eb9304,7f06d3247a1..1b418dfe380
--- a/storage/xtradb/include/trx0sys.h
+++ b/storage/xtradb/include/trx0sys.h
@@@ -328,20 -329,26 +329,26 @@@ UNIV_INTER
  void
  trx_sys_print_mysql_binlog_offset(void);
  /*===================================*/
+ 
  #ifdef WITH_WSREP
- /** Update WSREP checkpoint XID in sys header. */
+ 
+ /** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
+ @param[in]	xid		Transaction XID
+ @param[in,out]	sys_header	sys_header
+ @param[in]	mtr		minitransaction */
  void
  trx_sys_update_wsrep_checkpoint(
-         const XID*      xid,         /*!< in: WSREP XID */
-         trx_sysf_t*     sys_header,  /*!< in: sys_header */
-         mtr_t*          mtr);        /*!< in: mtr       */
+ 	const XID*	xid,
+ 	trx_sysf_t*	sys_header,
+ 	mtr_t*		mtr);
  
 -/** Read WSREP XID from sys_header of TRX_SYS_PAGE_NO = 5.
 - at param[out]	xid	Transaction XID */
 -void
 -trx_sys_read_wsrep_checkpoint(XID* xid);
 -
 +/** Read WSREP checkpoint XID from sys header. 
 + at return  true on success, false on error. */
 +bool
 +trx_sys_read_wsrep_checkpoint(
 +        XID* xid); /*!< out: WSREP XID */
  #endif /* WITH_WSREP */
+ 
  /*****************************************************************//**
  Prints to stderr the MySQL master log offset info in the trx system header if
  the magic number shows it valid. */
diff --cc storage/xtradb/srv/srv0start.cc
index aab0bc9282b,63d92f37a52..de18db0aacc
--- a/storage/xtradb/srv/srv0start.cc
+++ b/storage/xtradb/srv/srv0start.cc
@@@ -3129,23 -3001,10 +3129,22 @@@ files_checked
  #ifdef WITH_WSREP
  		} else {
  			ib_logf(IB_LOG_LEVEL_WARN,
 -			"Skipping buffer pool dump/restore during wsrep "
 -			"recovery.");
 -                }
 +				"Skipping buffer pool dump/restore during "
 +				"wsrep recovery.");
 +		}
  #endif /* WITH_WSREP */
- 
 +		/* Create thread(s) that handles key rotation */
 +		fil_system_enter();
 +		fil_crypt_threads_init();
 +		fil_system_exit();
 +
 +		/* Init data for datafile scrub threads */
 +		btr_scrub_init();
 +
 +		/* Initialize online defragmentation. */
 +		btr_defragment_init();
 +		btr_defragment_thread_active = true;
 +		os_thread_create(btr_defragment_thread, NULL, NULL);
  	}
  
  	srv_was_started = TRUE;
diff --cc storage/xtradb/trx/trx0sys.cc
index 4e1cc53fec9,8c11d22489a..063a43b177c
--- a/storage/xtradb/trx/trx0sys.cc
+++ b/storage/xtradb/trx/trx0sys.cc
@@@ -341,101 -342,106 +344,108 @@@ static inline void read_wsrep_xid_uuid(
  
  #endif /* UNIV_DEBUG */
  
+ /** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
+ @param[in]	xid		Transaction XID
+ @param[in,out]	sys_header	sys_header
+ @param[in]	mtr		minitransaction */
  void
  trx_sys_update_wsrep_checkpoint(
-         const XID*      xid,        /*!< in: transaction XID */
-         trx_sysf_t*     sys_header, /*!< in: sys_header */
-         mtr_t*          mtr)        /*!< in: mtr */
+ 	const XID*	xid,
+ 	trx_sysf_t*	sys_header,
+ 	mtr_t*		mtr)
  {
  #ifdef UNIV_DEBUG
-         {
-             /* Check that seqno is monotonically increasing */
-             unsigned char xid_uuid[16];
-             long long xid_seqno = read_wsrep_xid_seqno(xid);
-             read_wsrep_xid_uuid(xid, xid_uuid);
-             if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8))
-             {
-                 ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
-                 trx_sys_cur_xid_seqno = xid_seqno;
-             }
-             else
-             {
-                 memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
-             }
-             trx_sys_cur_xid_seqno = xid_seqno;
-         }
+ 	if (xid->formatID != -1
+ 	    && mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+ 			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+ 		== TRX_SYS_WSREP_XID_MAGIC_N) {
+ 		/* Check that seqno is monotonically increasing */
+ 		unsigned char xid_uuid[16];
+ 		long long xid_seqno = read_wsrep_xid_seqno(xid);
+ 		read_wsrep_xid_uuid(xid, xid_uuid);
+ 
+ 		if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8)) {
+ 			ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
+ 			trx_sys_cur_xid_seqno = xid_seqno;
+ 		} else {
+ 			memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
+ 		}
+ 
+ 		trx_sys_cur_xid_seqno = xid_seqno;
+ 	}
  #endif /* UNIV_DEBUG */
  
-         ut_ad(xid && mtr);
-         ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid(xid));
- 
-         if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
-                              + TRX_SYS_WSREP_XID_MAGIC_N_FLD)
-             != TRX_SYS_WSREP_XID_MAGIC_N) {
-                 mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                                  + TRX_SYS_WSREP_XID_MAGIC_N_FLD,
-                                  TRX_SYS_WSREP_XID_MAGIC_N,
-                                  MLOG_4BYTES, mtr);
-         }
- 
-         mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_FORMAT,
-                          (int)xid->formatID,
-                          MLOG_4BYTES, mtr);
-         mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_GTRID_LEN,
-                          (int)xid->gtrid_length,
-                          MLOG_4BYTES, mtr);
-         mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_BQUAL_LEN,
-                          (int)xid->bqual_length,
-                          MLOG_4BYTES, mtr);
-         mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
-                           + TRX_SYS_WSREP_XID_DATA,
-                           (const unsigned char*) xid->data,
-                           XIDDATASIZE, mtr);
+ 	ut_ad(xid && mtr);
 -	ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid((const void *)xid));
++	ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid((const XID *)xid));
+ 
+ 	if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+ 			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+ 		!= TRX_SYS_WSREP_XID_MAGIC_N) {
+ 		mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD,
+ 			TRX_SYS_WSREP_XID_MAGIC_N,
+ 			MLOG_4BYTES, mtr);
+ 	}
  
+ 	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_FORMAT,
+ 		(int)xid->formatID,
+ 		MLOG_4BYTES, mtr);
+ 	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_GTRID_LEN,
+ 		(int)xid->gtrid_length,
+ 		MLOG_4BYTES, mtr);
+ 	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_BQUAL_LEN,
+ 		(int)xid->bqual_length,
+ 		MLOG_4BYTES, mtr);
+ 	mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
+ 		+ TRX_SYS_WSREP_XID_DATA,
+ 		(const unsigned char*) xid->data,
+ 		XIDDATASIZE, mtr);
  }
  
+ /** Read WSREP XID from sys_header of TRX_SYS_PAGE_NO = 5.
 - at param[out]	xid	Transaction XID */
 -void
++ at param[out]	xid	Transaction XID 
++ at retval true if found, false if not */
 +bool
  trx_sys_read_wsrep_checkpoint(XID* xid)
- /*===================================*/
  {
-         trx_sysf_t* sys_header;
 -	trx_sysf_t* sys_header;
--	mtr_t	    mtr;
-         ulint       magic;
 -	ulint       magic;
++	trx_sysf_t*	sys_header;
++	mtr_t		mtr;
++	ulint		magic;
  
-         ut_ad(xid);
+ 	ut_ad(xid);
  
  	mtr_start(&mtr);
  
  	sys_header = trx_sysf_get(&mtr);
  
-         if ((magic = mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
-                                       + TRX_SYS_WSREP_XID_MAGIC_N_FLD))
-             != TRX_SYS_WSREP_XID_MAGIC_N) {
-                 memset(xid, 0, sizeof(*xid));
-                 xid->formatID = -1;
-                 trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
-                 mtr_commit(&mtr);
-                 return false;
-         }
- 
-         xid->formatID     = (int)mach_read_from_4(
-                 sys_header
-                 + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_FORMAT);
-         xid->gtrid_length = (int)mach_read_from_4(
-                 sys_header
-                 + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_GTRID_LEN);
-         xid->bqual_length = (int)mach_read_from_4(
-                 sys_header
-                 + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_BQUAL_LEN);
-         ut_memcpy(xid->data,
-                   sys_header + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_DATA,
-                   XIDDATASIZE);
+ 	if ((magic = mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+ 				+ TRX_SYS_WSREP_XID_MAGIC_N_FLD))
+ 		!= TRX_SYS_WSREP_XID_MAGIC_N) {
+ 		memset(xid, 0, sizeof(*xid));
+ 		xid->formatID = -1;
+ 		trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
+ 		mtr_commit(&mtr);
 -		return;
 -        }
++		return false;
++	}
+ 
+ 	xid->formatID     = (int)mach_read_from_4(
+ 		sys_header
+ 		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_FORMAT);
+ 	xid->gtrid_length = (int)mach_read_from_4(
+ 		sys_header
+ 		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_GTRID_LEN);
+ 	xid->bqual_length = (int)mach_read_from_4(
+ 		sys_header
+ 		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_BQUAL_LEN);
+ 	ut_memcpy(xid->data,
+ 		sys_header + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_DATA,
+ 		XIDDATASIZE);
  
  	mtr_commit(&mtr);
 +	return true;
  }
  
  #endif /* WITH_WSREP */



More information about the commits mailing list