2019-01-23 15:30:00 +04: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_server_service.h"
|
|
|
|
#include "wsrep_server_state.h"
|
|
|
|
#include "wsrep_client_state.h"
|
|
|
|
#include "wsrep_client_service.h"
|
|
|
|
#include "wsrep_storage_service.h"
|
|
|
|
#include "wsrep_high_priority_service.h"
|
|
|
|
|
|
|
|
#include "wsrep_sst.h"
|
|
|
|
#include "wsrep_xid.h"
|
|
|
|
#include "wsrep_mysqld.h"
|
|
|
|
#include "wsrep_schema.h"
|
|
|
|
#include "wsrep_utils.h"
|
2019-08-30 08:42:24 +03:00
|
|
|
#include "wsrep_thd.h"
|
2019-01-23 15:30:00 +04:00
|
|
|
|
|
|
|
#include "log.h" /* sql_print_xxx() */
|
|
|
|
#include "sql_class.h" /* system variables */
|
|
|
|
#include "transaction.h" /* trans_xxx */
|
|
|
|
#include "sql_base.h" /* close_thread_tables */
|
2021-09-02 14:29:59 +02:00
|
|
|
#include "debug_sync.h"
|
2019-01-23 15:30:00 +04:00
|
|
|
|
|
|
|
static void init_service_thd(THD* thd, char* thread_stack)
|
|
|
|
{
|
|
|
|
thd->thread_stack= thread_stack;
|
|
|
|
thd->real_id= pthread_self();
|
|
|
|
thd->prior_thr_create_utime= thd->start_utime= microsecond_interval_timer();
|
2023-11-06 17:37:11 +02:00
|
|
|
thd->mark_connection_idle();
|
2019-01-23 15:30:00 +04:00
|
|
|
thd->reset_for_next_command(true);
|
2021-02-07 17:48:58 +01:00
|
|
|
server_threads.insert(thd); // as wsrep_innobase_kill_one_trx() uses find_thread_by_id()
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
2019-12-11 13:08:06 +01:00
|
|
|
Wsrep_storage_service*
|
|
|
|
wsrep_create_storage_service(THD* orig_THD, const char* ctx)
|
2019-01-23 15:30:00 +04:00
|
|
|
{
|
2019-12-11 13:08:06 +01:00
|
|
|
THD* thd= new THD(true, true);
|
|
|
|
init_service_thd(thd, orig_THD->thread_stack);
|
|
|
|
WSREP_DEBUG("Created storage service in %s context with thread id %llu",
|
|
|
|
ctx, thd->thread_id);
|
2019-08-30 08:42:24 +03:00
|
|
|
/* Use variables from the current thd attached to client_service.
|
|
|
|
This is because we need to be able to BF abort storage access
|
|
|
|
operations. */
|
|
|
|
wsrep_assign_from_threadvars(thd);
|
2019-01-23 15:30:00 +04:00
|
|
|
return new Wsrep_storage_service(thd);
|
|
|
|
}
|
|
|
|
|
2019-12-11 13:08:06 +01:00
|
|
|
wsrep::storage_service* Wsrep_server_service::storage_service(
|
|
|
|
wsrep::client_service& client_service)
|
|
|
|
{
|
|
|
|
Wsrep_client_service& cs=
|
|
|
|
static_cast<Wsrep_client_service&>(client_service);
|
|
|
|
return wsrep_create_storage_service(cs.m_thd, "local");
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:30:00 +04:00
|
|
|
wsrep::storage_service* Wsrep_server_service::storage_service(
|
|
|
|
wsrep::high_priority_service& high_priority_service)
|
|
|
|
{
|
|
|
|
Wsrep_high_priority_service& hps=
|
|
|
|
static_cast<Wsrep_high_priority_service&>(high_priority_service);
|
2019-12-11 13:08:06 +01:00
|
|
|
return wsrep_create_storage_service(hps.m_thd, "high priority");
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wsrep_server_service::release_storage_service(
|
|
|
|
wsrep::storage_service* storage_service)
|
|
|
|
{
|
|
|
|
Wsrep_storage_service* ss=
|
|
|
|
static_cast<Wsrep_storage_service*>(storage_service);
|
|
|
|
THD* thd= ss->m_thd;
|
2019-08-30 08:42:24 +03:00
|
|
|
wsrep_reset_threadvars(thd);
|
2021-02-07 17:48:58 +01:00
|
|
|
server_threads.erase(thd);
|
2019-01-23 15:30:00 +04:00
|
|
|
delete ss;
|
|
|
|
delete thd;
|
|
|
|
}
|
|
|
|
|
2019-08-30 08:42:24 +03:00
|
|
|
Wsrep_applier_service*
|
|
|
|
wsrep_create_streaming_applier(THD *orig_thd, const char *ctx)
|
|
|
|
{
|
|
|
|
/* Reset variables to allow creating new variables in thread local
|
|
|
|
storage for new THD if needed. Note that reset must be done for
|
|
|
|
current_thd, as orig_thd may not be in effect. This may be the case when
|
|
|
|
streaming transaction is BF aborted and streaming applier
|
|
|
|
is created from BF aborter context. */
|
|
|
|
Wsrep_threadvars saved_threadvars(wsrep_save_threadvars());
|
2021-02-07 17:48:58 +01:00
|
|
|
if (saved_threadvars.cur_thd)
|
|
|
|
wsrep_reset_threadvars(saved_threadvars.cur_thd);
|
2019-08-30 08:42:24 +03:00
|
|
|
THD *thd= 0;
|
|
|
|
Wsrep_applier_service *ret= 0;
|
|
|
|
if (!wsrep_create_threadvars() &&
|
|
|
|
(thd= new THD(next_thread_id(), true)))
|
|
|
|
{
|
|
|
|
init_service_thd(thd, orig_thd->thread_stack);
|
|
|
|
wsrep_assign_from_threadvars(thd);
|
|
|
|
WSREP_DEBUG("Created streaming applier service in %s context with "
|
|
|
|
"thread id %llu", ctx, thd->thread_id);
|
|
|
|
if (!(ret= new (std::nothrow) Wsrep_applier_service(thd)))
|
|
|
|
{
|
|
|
|
delete thd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Restore original thread local storage state before returning. */
|
|
|
|
wsrep_restore_threadvars(saved_threadvars);
|
2021-02-07 17:48:58 +01:00
|
|
|
if (saved_threadvars.cur_thd)
|
|
|
|
wsrep_store_threadvars(saved_threadvars.cur_thd);
|
2019-08-30 08:42:24 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:30:00 +04:00
|
|
|
wsrep::high_priority_service*
|
|
|
|
Wsrep_server_service::streaming_applier_service(
|
|
|
|
wsrep::client_service& orig_client_service)
|
|
|
|
{
|
|
|
|
Wsrep_client_service& orig_cs=
|
|
|
|
static_cast<Wsrep_client_service&>(orig_client_service);
|
2019-08-30 08:42:24 +03:00
|
|
|
return wsrep_create_streaming_applier(orig_cs.m_thd, "local");
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
wsrep::high_priority_service*
|
|
|
|
Wsrep_server_service::streaming_applier_service(
|
|
|
|
wsrep::high_priority_service& orig_high_priority_service)
|
|
|
|
{
|
|
|
|
Wsrep_high_priority_service&
|
|
|
|
orig_hps(static_cast<Wsrep_high_priority_service&>(orig_high_priority_service));
|
2019-08-30 08:42:24 +03:00
|
|
|
return wsrep_create_streaming_applier(orig_hps.m_thd, "high priority");
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wsrep_server_service::release_high_priority_service(wsrep::high_priority_service* high_priority_service)
|
|
|
|
{
|
|
|
|
Wsrep_high_priority_service* hps=
|
|
|
|
static_cast<Wsrep_high_priority_service*>(high_priority_service);
|
|
|
|
THD* thd= hps->m_thd;
|
|
|
|
delete hps;
|
2019-08-30 08:42:24 +03:00
|
|
|
wsrep_store_threadvars(thd);
|
2021-02-07 17:48:58 +01:00
|
|
|
server_threads.erase(thd);
|
2019-01-23 15:30:00 +04:00
|
|
|
delete thd;
|
2019-08-30 08:42:24 +03:00
|
|
|
wsrep_delete_threadvars();
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
MDEV-29293 MariaDB stuck on starting commit state
This commit contains a merge from 10.5-MDEV-29293-squash
into 10.6.
Although the bug MDEV-29293 was not reproducible with 10.6,
the fix contains several improvements for wsrep KILL query and
BF abort handling, and addresses the following issues:
* MDEV-30307 KILL command issued inside a transaction is
problematic for galera replication:
This commit will remove KILL TOI replication, so Galera side
transaction context is not lost during KILL.
* MDEV-21075 KILL QUERY maintains nodes data consistency but
breaks GTID sequence: This is fixed as well as KILL does not
use TOI, and thus does not change GTID state.
* MDEV-30372 Assertion in wsrep-lib state: This was caused by
BF abort or KILL when local transaction was in the middle
of group commit. This commit disables THD::killed handling
during commit, so the problem is avoided.
* MDEV-30963 Assertion failure !lock.was_chosen_as_deadlock_victim
in trx0trx.h:1065: The assertion happened when the victim was
BF aborted via MDL while it was committing. This commit changes
MDL BF aborts so that transactions which are committing cannot
be BF aborted via MDL. The RQG grammar attached in the issue
could not reproduce the crash anymore.
Original commit message from 10.5 fix:
MDEV-29293 MariaDB stuck on starting commit state
The problem seems to be a deadlock between KILL command execution
and BF abort issued by an applier, where:
* KILL has locked victim's LOCK_thd_kill and LOCK_thd_data.
* Applier has innodb side global lock mutex and victim trx mutex.
* KILL is calling innobase_kill_query, and is blocked by innodb
global lock mutex.
* Applier is in wsrep_innobase_kill_one_trx and is blocked by
victim's LOCK_thd_kill.
The fix in this commit removes the TOI replication of KILL command
and makes KILL execution less intrusive operation. Aborting the
victim happens now by using awake_no_mutex() and ha_abort_transaction().
If the KILL happens when the transaction is committing, the
KILL operation is postponed to happen after the statement
has completed in order to avoid KILL to interrupt commit
processing.
Notable changes in this commit:
* wsrep client connections's error state may remain sticky after
client connection is closed. This error message will then pop
up for the next client session issuing first SQL statement.
This problem raised with test galera.galera_bf_kill.
The fix is to reset wsrep client error state, before a THD is
reused for next connetion.
* Release THD locks in wsrep_abort_transaction when locking
innodb mutexes. This guarantees same locking order as with applier
BF aborting.
* BF abort from MDL was changed to do BF abort on server/wsrep-lib
side first, and only then do the BF abort on InnoDB side. This
removes the need to call back from InnoDB for BF aborts which originate
from MDL and simplifies the locking.
* Removed wsrep_thd_set_wsrep_aborter() from service_wsrep.h.
The manipulation of the wsrep_aborter can be done solely on
server side. Moreover, it is now debug only variable and
could be excluded from optimized builds.
* Remove LOCK_thd_kill from wsrep_thd_LOCK/UNLOCK to allow more
fine grained locking for SR BF abort which may require locking
of victim LOCK_thd_kill. Added explicit call for
wsrep_thd_kill_LOCK/UNLOCK where appropriate.
* Wsrep-lib was updated to version which allows external
locking for BF abort calls.
Changes to MTR tests:
* Disable galera_bf_abort_group_commit. This test is going to
be removed (MDEV-30855).
* Make galera_var_retry_autocommit result more readable by echoing
cases and expectations into result. Only one expected result for
reap to verify that server returns expected status for query.
* Record galera_gcache_recover_manytrx as result file was incomplete.
Trivial change.
* Make galera_create_table_as_select more deterministic:
Wait until CTAS execution has reached MDL wait for multi-master
conflict case. Expected error from multi-master conflict is
ER_QUERY_INTERRUPTED. This is because CTAS does not yet have open
wsrep transaction when it is waiting for MDL, query gets interrupted
instead of BF aborted. This should be addressed in separate task.
* A new test galera_bf_abort_registering to check that registering trx gets
BF aborted through MDL.
* A new test galera_kill_group_commit to verify correct behavior
when KILL is executed while the transaction is committing.
Co-authored-by: Seppo Jaakola <seppo.jaakola@iki.fi>
Co-authored-by: Jan Lindström <jan.lindstrom@galeracluster.com>
Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
2023-04-19 16:51:55 +03:00
|
|
|
void Wsrep_server_service::background_rollback(
|
|
|
|
wsrep::unique_lock<wsrep::mutex> &lock WSREP_UNUSED,
|
|
|
|
wsrep::client_state &client_state)
|
2019-01-23 15:30:00 +04:00
|
|
|
{
|
MDEV-29293 MariaDB stuck on starting commit state
This commit contains a merge from 10.5-MDEV-29293-squash
into 10.6.
Although the bug MDEV-29293 was not reproducible with 10.6,
the fix contains several improvements for wsrep KILL query and
BF abort handling, and addresses the following issues:
* MDEV-30307 KILL command issued inside a transaction is
problematic for galera replication:
This commit will remove KILL TOI replication, so Galera side
transaction context is not lost during KILL.
* MDEV-21075 KILL QUERY maintains nodes data consistency but
breaks GTID sequence: This is fixed as well as KILL does not
use TOI, and thus does not change GTID state.
* MDEV-30372 Assertion in wsrep-lib state: This was caused by
BF abort or KILL when local transaction was in the middle
of group commit. This commit disables THD::killed handling
during commit, so the problem is avoided.
* MDEV-30963 Assertion failure !lock.was_chosen_as_deadlock_victim
in trx0trx.h:1065: The assertion happened when the victim was
BF aborted via MDL while it was committing. This commit changes
MDL BF aborts so that transactions which are committing cannot
be BF aborted via MDL. The RQG grammar attached in the issue
could not reproduce the crash anymore.
Original commit message from 10.5 fix:
MDEV-29293 MariaDB stuck on starting commit state
The problem seems to be a deadlock between KILL command execution
and BF abort issued by an applier, where:
* KILL has locked victim's LOCK_thd_kill and LOCK_thd_data.
* Applier has innodb side global lock mutex and victim trx mutex.
* KILL is calling innobase_kill_query, and is blocked by innodb
global lock mutex.
* Applier is in wsrep_innobase_kill_one_trx and is blocked by
victim's LOCK_thd_kill.
The fix in this commit removes the TOI replication of KILL command
and makes KILL execution less intrusive operation. Aborting the
victim happens now by using awake_no_mutex() and ha_abort_transaction().
If the KILL happens when the transaction is committing, the
KILL operation is postponed to happen after the statement
has completed in order to avoid KILL to interrupt commit
processing.
Notable changes in this commit:
* wsrep client connections's error state may remain sticky after
client connection is closed. This error message will then pop
up for the next client session issuing first SQL statement.
This problem raised with test galera.galera_bf_kill.
The fix is to reset wsrep client error state, before a THD is
reused for next connetion.
* Release THD locks in wsrep_abort_transaction when locking
innodb mutexes. This guarantees same locking order as with applier
BF aborting.
* BF abort from MDL was changed to do BF abort on server/wsrep-lib
side first, and only then do the BF abort on InnoDB side. This
removes the need to call back from InnoDB for BF aborts which originate
from MDL and simplifies the locking.
* Removed wsrep_thd_set_wsrep_aborter() from service_wsrep.h.
The manipulation of the wsrep_aborter can be done solely on
server side. Moreover, it is now debug only variable and
could be excluded from optimized builds.
* Remove LOCK_thd_kill from wsrep_thd_LOCK/UNLOCK to allow more
fine grained locking for SR BF abort which may require locking
of victim LOCK_thd_kill. Added explicit call for
wsrep_thd_kill_LOCK/UNLOCK where appropriate.
* Wsrep-lib was updated to version which allows external
locking for BF abort calls.
Changes to MTR tests:
* Disable galera_bf_abort_group_commit. This test is going to
be removed (MDEV-30855).
* Make galera_var_retry_autocommit result more readable by echoing
cases and expectations into result. Only one expected result for
reap to verify that server returns expected status for query.
* Record galera_gcache_recover_manytrx as result file was incomplete.
Trivial change.
* Make galera_create_table_as_select more deterministic:
Wait until CTAS execution has reached MDL wait for multi-master
conflict case. Expected error from multi-master conflict is
ER_QUERY_INTERRUPTED. This is because CTAS does not yet have open
wsrep transaction when it is waiting for MDL, query gets interrupted
instead of BF aborted. This should be addressed in separate task.
* A new test galera_bf_abort_registering to check that registering trx gets
BF aborted through MDL.
* A new test galera_kill_group_commit to verify correct behavior
when KILL is executed while the transaction is committing.
Co-authored-by: Seppo Jaakola <seppo.jaakola@iki.fi>
Co-authored-by: Jan Lindström <jan.lindstrom@galeracluster.com>
Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
2023-04-19 16:51:55 +03:00
|
|
|
DBUG_ASSERT(lock.owns_lock());
|
|
|
|
Wsrep_client_state &cs= static_cast<Wsrep_client_state &>(client_state);
|
|
|
|
mysql_mutex_assert_owner(&cs.thd()->LOCK_thd_data);
|
2019-01-23 15:30:00 +04:00
|
|
|
wsrep_fire_rollbacker(cs.thd());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wsrep_server_service::bootstrap()
|
|
|
|
{
|
|
|
|
wsrep::log_info()
|
|
|
|
<< "Bootstrapping a new cluster, setting initial position to "
|
|
|
|
<< wsrep::gtid::undefined();
|
2019-04-01 13:23:05 +02:00
|
|
|
wsrep_set_SE_checkpoint(wsrep::gtid::undefined(), wsrep_gtid_server.undefined());
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wsrep_server_service::log_message(enum wsrep::log::level level,
|
|
|
|
const char* message)
|
|
|
|
{
|
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case wsrep::log::debug:
|
2020-12-30 23:51:29 +02:00
|
|
|
WSREP_DEBUG("%s", message);
|
2019-01-23 15:30:00 +04:00
|
|
|
break;
|
|
|
|
case wsrep::log::info:
|
2020-12-30 23:51:29 +02:00
|
|
|
WSREP_INFO("%s", message);
|
2019-01-23 15:30:00 +04:00
|
|
|
break;
|
|
|
|
case wsrep::log::warning:
|
2020-12-30 23:51:29 +02:00
|
|
|
WSREP_WARN("%s", message);
|
2019-01-23 15:30:00 +04:00
|
|
|
break;
|
|
|
|
case wsrep::log::error:
|
2020-12-30 23:51:29 +02:00
|
|
|
WSREP_ERROR("%s", message);
|
|
|
|
break;
|
|
|
|
case wsrep::log::unknown:
|
|
|
|
WSREP_UNKNOWN("%s", message);
|
2019-01-23 15:30:00 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wsrep_server_service::log_view(
|
|
|
|
wsrep::high_priority_service* high_priority_service,
|
|
|
|
const wsrep::view& view)
|
|
|
|
{
|
|
|
|
Wsrep_high_priority_service* applier=
|
|
|
|
static_cast<Wsrep_high_priority_service*>(high_priority_service);
|
|
|
|
/* Update global system variables */
|
|
|
|
mysql_mutex_lock(&LOCK_global_system_variables);
|
|
|
|
if (wsrep_auto_increment_control && view.own_index() >= 0)
|
|
|
|
{
|
|
|
|
global_system_variables.auto_increment_offset= view.own_index() + 1;
|
|
|
|
global_system_variables.auto_increment_increment= view.members().size();
|
|
|
|
wsrep_protocol_version= view.protocol_version();
|
|
|
|
}
|
|
|
|
mysql_mutex_unlock(&LOCK_global_system_variables);
|
|
|
|
|
|
|
|
/* Update wsrep status variables */
|
|
|
|
mysql_mutex_lock(&LOCK_status);
|
|
|
|
wsrep_cluster_size= view.members().size();
|
|
|
|
wsrep_local_index= view.own_index();
|
|
|
|
std::ostringstream os;
|
|
|
|
os << view.state_id().id();
|
|
|
|
wsrep_update_cluster_state_uuid(os.str().c_str());
|
|
|
|
mysql_mutex_unlock(&LOCK_status);
|
|
|
|
wsrep_config_state->set(view);
|
2020-05-04 11:06:40 +03:00
|
|
|
wsrep_cluster_conf_id= view.view_seqno().get();
|
2019-01-23 15:30:00 +04:00
|
|
|
|
|
|
|
if (view.status() == wsrep::view::primary)
|
|
|
|
{
|
|
|
|
if (applier)
|
|
|
|
{
|
|
|
|
Wsrep_id id;
|
|
|
|
Wsrep_view prev_view= wsrep_schema->restore_view(applier->m_thd, id);
|
2019-02-12 15:58:06 +02:00
|
|
|
bool checkpoint_was_reset= false;
|
2019-01-23 15:30:00 +04:00
|
|
|
if (prev_view.state_id().id() != view.state_id().id())
|
|
|
|
{
|
|
|
|
WSREP_DEBUG("New cluster UUID was generated, resetting position info");
|
2019-04-01 13:23:05 +02:00
|
|
|
wsrep_set_SE_checkpoint(wsrep::gtid::undefined(), wsrep_gtid_server.undefined());
|
2019-02-12 15:58:06 +02:00
|
|
|
checkpoint_was_reset= true;
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wsrep_debug)
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
os << "Storing cluster view:\n" << view;
|
|
|
|
WSREP_INFO("%s", os.str().c_str());
|
|
|
|
DBUG_ASSERT(prev_view.state_id().id() != view.state_id().id() ||
|
2019-02-12 15:58:06 +02:00
|
|
|
view.state_id().seqno().get() >= prev_view.state_id().seqno().get());
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (trans_begin(applier->m_thd, MYSQL_START_TRANS_OPT_READ_WRITE))
|
|
|
|
{
|
|
|
|
WSREP_WARN("Failed to start transaction for store view");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (wsrep_schema->store_view(applier->m_thd, view))
|
|
|
|
{
|
|
|
|
WSREP_WARN("Failed to store view");
|
|
|
|
trans_rollback_stmt(applier->m_thd);
|
|
|
|
if (!trans_rollback(applier->m_thd))
|
|
|
|
{
|
|
|
|
close_thread_tables(applier->m_thd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (trans_commit(applier->m_thd))
|
|
|
|
{
|
|
|
|
WSREP_WARN("Failed to commit transaction for store view");
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 16:16:29 +02:00
|
|
|
applier->m_thd->release_transactional_locks();
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:58:06 +02:00
|
|
|
/*
|
|
|
|
Backwards compatibility: When running in mixed cluster with
|
|
|
|
Galera 3.x, the provider does not generate unique sequence numbers
|
|
|
|
for views. This condition can be checked by inspecting last
|
|
|
|
committed as returned by the provider. If the last_committed
|
|
|
|
matches to view state_id seqno, the cluster runs in backwards
|
|
|
|
compatibility mode and we skip setting the checkpoint for
|
|
|
|
view.
|
|
|
|
*/
|
|
|
|
wsrep::seqno last_committed=
|
|
|
|
Wsrep_server_state::instance().provider().last_committed_gtid().seqno();
|
|
|
|
if (checkpoint_was_reset || last_committed != view.state_id().seqno())
|
|
|
|
{
|
2019-04-01 13:23:05 +02:00
|
|
|
wsrep_set_SE_checkpoint(view.state_id(), wsrep_gtid_server.gtid());
|
2019-02-12 15:58:06 +02:00
|
|
|
}
|
2019-04-01 13:23:05 +02:00
|
|
|
DBUG_ASSERT(wsrep_get_SE_checkpoint<wsrep::gtid>().id() == view.state_id().id());
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WSREP_DEBUG("No applier in Wsrep_server_service::log_view(), "
|
|
|
|
"skipping write to wsrep_schema");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wsrep_server_service::recover_streaming_appliers(wsrep::client_service& cs)
|
|
|
|
{
|
|
|
|
Wsrep_client_service& client_service= static_cast<Wsrep_client_service&>(cs);
|
|
|
|
wsrep_recover_sr_from_storage(client_service.m_thd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wsrep_server_service::recover_streaming_appliers(
|
|
|
|
wsrep::high_priority_service& hs)
|
|
|
|
{
|
|
|
|
Wsrep_high_priority_service& high_priority_service=
|
|
|
|
static_cast<Wsrep_high_priority_service&>(hs);
|
|
|
|
wsrep_recover_sr_from_storage(high_priority_service.m_thd);
|
|
|
|
}
|
|
|
|
|
|
|
|
wsrep::view Wsrep_server_service::get_view(wsrep::client_service& c,
|
|
|
|
const wsrep::id& own_id)
|
|
|
|
{
|
|
|
|
Wsrep_client_service& cs(static_cast<Wsrep_client_service&>(c));
|
|
|
|
wsrep::view v(wsrep_schema->restore_view(cs.m_thd, own_id));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
wsrep::gtid Wsrep_server_service::get_position(wsrep::client_service&)
|
|
|
|
{
|
2019-04-01 13:23:05 +02:00
|
|
|
return wsrep_get_SE_checkpoint<wsrep::gtid>();
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|
|
|
|
|
2020-05-19 15:38:34 +03:00
|
|
|
void Wsrep_server_service::set_position(wsrep::client_service& c WSREP_UNUSED,
|
2020-01-14 06:33:02 +01:00
|
|
|
const wsrep::gtid& gtid)
|
|
|
|
{
|
2020-05-19 15:38:34 +03:00
|
|
|
Wsrep_client_service& cs WSREP_UNUSED (static_cast<Wsrep_client_service&>(c));
|
|
|
|
DBUG_ASSERT(cs.m_client_state.transaction().state()
|
|
|
|
== wsrep::transaction::s_aborted);
|
|
|
|
// Wait until all prior committers have finished.
|
|
|
|
wsrep::gtid wait_for(gtid.id(),
|
|
|
|
wsrep::seqno(gtid.seqno().get() - 1));
|
|
|
|
if (auto err = Wsrep_server_state::instance().provider()
|
|
|
|
.wait_for_gtid(wait_for, std::numeric_limits<int>::max()))
|
|
|
|
{
|
|
|
|
WSREP_WARN("Wait for gtid returned error %d while waiting for "
|
|
|
|
"prior transactions to commit before setting position", err);
|
|
|
|
}
|
2019-04-01 13:23:05 +02:00
|
|
|
wsrep_set_SE_checkpoint(gtid, wsrep_gtid_server.gtid());
|
2020-01-14 06:33:02 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 15:30:00 +04:00
|
|
|
void Wsrep_server_service::log_state_change(
|
|
|
|
enum Wsrep_server_state::state prev_state,
|
|
|
|
enum Wsrep_server_state::state current_state)
|
|
|
|
{
|
|
|
|
WSREP_INFO("Server status change %s -> %s",
|
|
|
|
wsrep::to_c_string(prev_state),
|
|
|
|
wsrep::to_c_string(current_state));
|
|
|
|
mysql_mutex_lock(&LOCK_status);
|
|
|
|
switch (current_state)
|
|
|
|
{
|
|
|
|
case Wsrep_server_state::s_synced:
|
|
|
|
WSREP_INFO("Synchronized with group, ready for connections");
|
2023-06-20 14:57:04 +03:00
|
|
|
wsrep_ready_set(true);
|
2019-01-23 15:30:00 +04:00
|
|
|
/* fall through */
|
|
|
|
case Wsrep_server_state::s_joined:
|
|
|
|
case Wsrep_server_state::s_donor:
|
|
|
|
wsrep_cluster_status= "Primary";
|
|
|
|
break;
|
|
|
|
case Wsrep_server_state::s_connected:
|
|
|
|
wsrep_cluster_status= "non-Primary";
|
2023-06-20 14:57:04 +03:00
|
|
|
wsrep_ready_set(false);
|
2019-01-23 15:30:00 +04:00
|
|
|
wsrep_connected= TRUE;
|
|
|
|
break;
|
|
|
|
case Wsrep_server_state::s_disconnected:
|
2023-06-20 14:57:04 +03:00
|
|
|
wsrep_ready_set(false);
|
2019-01-23 15:30:00 +04:00
|
|
|
wsrep_connected= FALSE;
|
|
|
|
wsrep_cluster_status= "Disconnected";
|
|
|
|
break;
|
|
|
|
default:
|
2023-06-20 14:57:04 +03:00
|
|
|
wsrep_ready_set(false);
|
2019-01-23 15:30:00 +04:00
|
|
|
wsrep_cluster_status= "non-Primary";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mysql_mutex_unlock(&LOCK_status);
|
|
|
|
wsrep_config_state->set(current_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wsrep_server_service::sst_before_init() const
|
|
|
|
{
|
|
|
|
return wsrep_before_SE();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Wsrep_server_service::sst_request()
|
|
|
|
{
|
|
|
|
return wsrep_sst_prepare();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Wsrep_server_service::start_sst(const std::string& sst_request,
|
|
|
|
const wsrep::gtid& gtid,
|
|
|
|
bool bypass)
|
|
|
|
{
|
|
|
|
return wsrep_sst_donate(sst_request, gtid, bypass);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Wsrep_server_service::wait_committing_transactions(int timeout)
|
|
|
|
{
|
|
|
|
return wsrep_wait_committing_connections_close(timeout);
|
|
|
|
}
|
|
|
|
|
2021-09-02 14:29:59 +02:00
|
|
|
void Wsrep_server_service::debug_sync(const char* sync_point)
|
2019-01-23 15:30:00 +04:00
|
|
|
{
|
2022-09-23 17:37:52 +03:00
|
|
|
#ifdef ENABLED_DEBUG_SYNC
|
2021-09-02 14:29:59 +02:00
|
|
|
DBUG_EXECUTE_IF(sync_point, {
|
|
|
|
std::stringstream dbug_action;
|
|
|
|
dbug_action << "now "
|
|
|
|
<< "SIGNAL " << sync_point << "_reached "
|
|
|
|
<< "WAIT_FOR " << sync_point << "_continue";
|
|
|
|
const std::string& action(dbug_action.str());
|
|
|
|
DBUG_ASSERT(!debug_sync_set_action(current_thd,
|
|
|
|
action.c_str(),
|
|
|
|
action.length()));
|
|
|
|
};);
|
2022-09-23 17:37:52 +03:00
|
|
|
#endif
|
2019-01-23 15:30:00 +04:00
|
|
|
}
|