mariadb/sql/wsrep_server_state.cc

85 lines
3.1 KiB
C++
Raw Normal View History

2019-01-23 12:30:00 +01:00
/* Copyright 2018 Codership Oy <info@codership.com>
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 St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "my_global.h"
#include "wsrep_api.h"
#include "wsrep_server_state.h"
10.4 wsrep group commit fixes (#1224) * MDEV-16509 Improve wsrep commit performance with binlog disabled Release commit order critical section early after trx_commit_low() if binlog is not transaction coordinator. In order to avoid two phase commit, binlog_hton is not registered for THD during IO_CACHE population. Implemented a test which verifies that the transactions release commit order early. This optimization will change behavior during recovery as the commit is not two phase when binlog is off. Fixed and recorded wsrep-recover-v25 and wsrep-recover to match the behavior. * MDEV-18730 Ordering for wsrep binlog group commit Previously out of order execution was allowed for wsrep commits. Established proper ordering by populating wait_for_commit for every wsrep THD and making group commit leader to wait for prior commits before proceeding to trx_group_commit_leader(). * MDEV-18730 Added a test case to verify correct commit ordering * MDEV-16509, MDEV-18730 Review fixes Use WSREP_EMULATE_BINLOG() macro to decide if the binlog_hton should be registered. Whitespace/syntax fixes and cleanups. * MDEV-16509 Require binlog for galera_var_innodb_disallow_writes test If the commit to InnoDB is done in one phase, the native InnoDB behavior is that the transaction is committed in memory before it is persisted to disk. This means that the innodb_disallow_writes=ON may not prevent transaction to become visible to other readers before commit is completely over. On the other hand, if the commit is two phase (as it is with binlog), the transaction will be blocked in prepare phase. Fixed the test to use binlog, which enforces two phase commit, which in turn makes commit to block before the changes become visible to other connections. This guarantees that the test produces expected result.
2019-03-15 06:09:13 +01:00
#include "wsrep_binlog.h" /* init/deinit group commit */
2019-01-23 12:30:00 +01:00
mysql_mutex_t LOCK_wsrep_server_state;
mysql_cond_t COND_wsrep_server_state;
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key key_LOCK_wsrep_server_state;
PSI_cond_key key_COND_wsrep_server_state;
#endif
Wsrep_server_state::Wsrep_server_state(const std::string& name,
const std::string& incoming_address,
const std::string& address,
const std::string& working_dir,
const wsrep::gtid& initial_position,
int max_protocol_version)
: wsrep::server_state(m_mutex,
m_cond,
m_service,
NULL,
2019-01-23 12:30:00 +01:00
name,
incoming_address,
address,
working_dir,
initial_position,
max_protocol_version,
wsrep::server_state::rm_sync)
, m_mutex(&LOCK_wsrep_server_state)
, m_cond(&COND_wsrep_server_state)
2019-01-23 12:30:00 +01:00
, m_service(*this)
10.4 wsrep group commit fixes (#1224) * MDEV-16509 Improve wsrep commit performance with binlog disabled Release commit order critical section early after trx_commit_low() if binlog is not transaction coordinator. In order to avoid two phase commit, binlog_hton is not registered for THD during IO_CACHE population. Implemented a test which verifies that the transactions release commit order early. This optimization will change behavior during recovery as the commit is not two phase when binlog is off. Fixed and recorded wsrep-recover-v25 and wsrep-recover to match the behavior. * MDEV-18730 Ordering for wsrep binlog group commit Previously out of order execution was allowed for wsrep commits. Established proper ordering by populating wait_for_commit for every wsrep THD and making group commit leader to wait for prior commits before proceeding to trx_group_commit_leader(). * MDEV-18730 Added a test case to verify correct commit ordering * MDEV-16509, MDEV-18730 Review fixes Use WSREP_EMULATE_BINLOG() macro to decide if the binlog_hton should be registered. Whitespace/syntax fixes and cleanups. * MDEV-16509 Require binlog for galera_var_innodb_disallow_writes test If the commit to InnoDB is done in one phase, the native InnoDB behavior is that the transaction is committed in memory before it is persisted to disk. This means that the innodb_disallow_writes=ON may not prevent transaction to become visible to other readers before commit is completely over. On the other hand, if the commit is two phase (as it is with binlog), the transaction will be blocked in prepare phase. Fixed the test to use binlog, which enforces two phase commit, which in turn makes commit to block before the changes become visible to other connections. This guarantees that the test produces expected result.
2019-03-15 06:09:13 +01:00
{ }
2019-01-23 12:30:00 +01:00
Wsrep_server_state::~Wsrep_server_state() = default;
2019-01-23 12:30:00 +01:00
void Wsrep_server_state::init_once(const std::string& name,
const std::string& incoming_address,
const std::string& address,
const std::string& working_dir,
const wsrep::gtid& initial_position,
int max_protocol_version)
{
if (m_instance == 0)
{
mysql_mutex_init(key_LOCK_wsrep_server_state, &LOCK_wsrep_server_state,
MY_MUTEX_INIT_FAST);
mysql_cond_init(key_COND_wsrep_server_state, &COND_wsrep_server_state, 0);
m_instance = new Wsrep_server_state(name,
incoming_address,
address,
working_dir,
initial_position,
max_protocol_version);
}
}
void Wsrep_server_state::destroy()
{
if (m_instance)
{
delete m_instance;
m_instance= 0;
mysql_mutex_destroy(&LOCK_wsrep_server_state);
mysql_cond_destroy(&COND_wsrep_server_state);
}
}