1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-04-19 21:02:17 +03:00

83 Commits

Author SHA1 Message Date
Daniele Sciascia
fc8e627815 Add method client_state::stream()
This method forces a streaming replication step.
2023-11-10 10:03:51 +01:00
Teemu Ollakka
f8a20ff00f Make is_rollbacker_active() public, don't unlock for background rollback
Make is_rollbacker_active() public so that the BF thread can
check if the rollbacker was started or not.

Also don't unlock the lock for launching the background
rollbacker to avoid race conditions in accessing the
victim state.
2023-04-05 09:30:55 +03:00
Teemu Ollakka
69b9d7d464 Allow external locking for BF aborts
Added methods bf_abort() and total_order_bf_abort() which take
wsrep::unique_lock<wsrep::mutex> as argument to allow caller
to grab the mutex before attempting BF abort. The old calls
were kept for backwards compatibility and wrap the new calls
with internal locking.
2023-03-17 14:38:03 +02:00
Teemu Ollakka
53638a8384 Removing assert() calls from public headers
Removed calls to assert() from public headers to have
full control when assertions are enabled in wsrep-lib
code regardless of parent project build configuration.
Moved methods containing assertions and non-trivial
code from headers into compilation units.
2023-02-26 10:12:49 +02:00
Daniele Sciascia
f8ff2cfdd4 Remove unnecessary include directives from the public interface 2022-11-10 10:31:36 +01:00
Daniele Sciascia
8bfce04189 Fix cleanup for non-prepared XA transactions
Cleanup XA transaction which is marked as prepared in DBMS, but not in
wsrep-lib side. This may happen if the DBMS runs with wsrep disabled.
2022-04-08 14:47:22 +02:00
sjaakola
608ee82b26 allowing application to set transaction as PA unsafe
* Removed transaction::p_unsafe_ member
* Changed transaction::pa_unsafe(bool) to modify flags member directly
* Modified transaction.cpp to use transaction.pa_unsafe(bool) rather than
  directly changing transaction's flag
* added method mark_transaction_pa_unsafe() for client_state,
  application will use this
2021-05-14 14:56:02 +03:00
Teemu Ollakka
a93955ddee Introduce non-locking variant of client_state::cleanup()
The method takes already locked lock object as an argument.
The caller must ensure that the lock object owns the underlying mutex.

Replaced homegrown wsrep::unique_lock with type alias from
std::unique_lock.
2021-01-07 14:38:32 +02:00
Teemu Ollakka
ff94dfd8a7 Handle the possibility of client command that cannot return results
This patch adds the possibility to have client commands that do not
return results from DBMS. While processing such commands we must be
able to preserve errors until the next interaction with client.
Specifically if the transaction is bf aborted while processing such
a non-returning command, then we have to keep the deadlock error until
the client issues a command that may return the error.
To handle such cases, client_state::before_command() now takes
parameter keep_command_error. The DBMS is supposed set
keep_command_error true to instruct wsrep-lib to preserve errors (if
any) until the next command which sets keep_command_error false.

Dealing with a case where current client command does not return result.

Work in progress.

Fix typo and add assertions in keep_command_error()

Make keep_command_error a parameter to before_commit()

Fix comment about keep_command_error

Handle keep_command_error with s_must_abort in wsrep_before_command()

Fix unit test
2020-11-27 11:17:39 +01:00
Daniele Sciascia
41a6e9dad7 Address review comments
Removed unnecessary assertion in transaction::before_commit().
Assert client state and mode in client_state::xa_detach().
2020-10-28 14:37:46 +01:00
Daniele Sciascia
b12bbd059c Support for replaying prepared XA transactions
This patch implments replaying for prepared XA transactions.
Replay may happen in the following cases:

1) The transaction is BF aborted in prepared state and is idle. In
that case, the transaction is handed over to rollbacker for replay.

2) The transaction is BF aborted while executing the
commit (i.e. before or after successful certification). In
which case the transaction replays itself from fragment storage.

3) The transaction is BF aborted while certifying its commit
fragment. This case is handled like replay for streaming transactions,
where the provider is directly involved and re-delivers the last
fragment.
2020-10-26 14:22:22 +01:00
Daniele Sciascia
965642eded Support for detaching prepared XA transactions
Add support for detaching XA transactions. This is useful for handling
the case where the DBMS client has a transaction in prepared state and
disconnects. Before disconnect, the DBMS calls the newly introduced
client_state::xa_detach(), to cleanup the local transaction and
convert it to a high priority transaction. The DBMS may later attempt
to terminate the transaction through client_state::commit_by_xid() or
client_state::rollback_by_xid().

Also in this patch:

- Fix client_state::close() so that it does not rollback transactions
  in prepared state
- Changed class wsrep::xid representation to hold enough information
  so that DBMS can convert to its native representation
- Fix potential infinite loop in
  server_state::find_streaming_applier(wsrep:xid&)
- Append SR keys on prepare fragment and make it pa_unsafe
- Handle one phase commit (simply fall back to two phase)
- Do not rollback prepared streaming clients in
  server_state::close_orphaned_transactions()
2020-10-26 14:20:21 +01:00
Daniele Sciascia
eac56f19e0 Remove dead code 2020-10-05 15:10:48 +02:00
Teemu Ollakka
76f7249b8d Incorrect assertion and state handling in after_replay().
If the transaction fails during replay because of certification
failure, the provider will return control to applier without
terminating the transaction and transaction remains in
s_replaying.

Fixed transaction::after_statement() to handle the state changes
correctly if certification failure is returned from replay.
Replaying was extracted to separate private method from
after_statement(). Removed transaction::after_replay() as it
seems now unnecessary and it bypassed state change sanity checks.

Allowed replaying -> committed transaction transition to handle
the situation where DBMS allocates a new context and client_state
to do the replay.
2019-12-28 12:28:38 +02:00
Teemu Ollakka
8e37727a27 Removed extra line. 2019-12-08 12:52:36 +02:00
Teemu Ollakka
7d8583983f Fixes to review comments
- Increased loop sleep in poll_enter_toi()
- Fixed typos in comments
- Got rid of unnecessary ostringstreams
2019-12-08 12:52:36 +02:00
Leandro Pacheco
043ff7a7e9 remove has_error arg from begin_nbo_phase_two 2019-12-08 12:52:36 +02:00
Leandro Pacheco
3389b7ad3c better error handling for NBO failures
when losing error voting:
- if NBO has failed locally (DBMS side), don't override original DBMS
  error so it gets reported to the client
- otherwise, report "query interrupted" instead of "error during commit"
2019-12-08 12:52:36 +02:00
Leandro Pacheco
f27f549479 poll_enter_toi timeout handlign 2019-12-08 12:52:36 +02:00
Teemu Ollakka
64fda07e91 Fixed NBO unit tests. 2019-12-08 12:52:36 +02:00
Teemu Ollakka
086c466637 - Added wait-until parameter for begin_nbo_phase_two().
- Retry enter_toi() in poll_enter_toi() also for error_connection_failed
  which means that the connectivity to the cluster has been lost,
  a.k.a non-prim.
2019-12-08 12:52:36 +02:00
Teemu Ollakka
3a1b194741 Pass certification keys also for NBO end.
Certification keys are needed for NBO end to resolve dependencies
for the write sets which follow NBO end. Without keys the following
write sets do not detect dependency to NBO event and may start applying
too early.
2019-12-08 12:52:36 +02:00
Teemu Ollakka
e700ce8c79 Added short sleep between calls to enter_toi(). 2019-12-08 12:52:36 +02:00
Teemu Ollakka
aaa92e130b Made gcc 4.4 work. 2019-12-08 12:52:36 +02:00
Teemu Ollakka
b05abb005f Chrono definitions to work around g++ 4.4 C++11 incompatibilities. 2019-12-08 12:52:36 +02:00
Teemu Ollakka
55fdbb7a05 Added timeout option to enter_toi_local() and begin_nbo_phase_one()
If timeout option is give, enter_toi_local() and begin_nbo_phase_one()
retry provider::enter_toi() as long as return status indicates
certification failure, given timeout expires or the client is interrupted.
2019-12-08 12:52:36 +02:00
Teemu Ollakka
0683654e53 Include <chrono> to check if it compiles with all required compilers. 2019-12-08 12:52:36 +02:00
Leandro Pacheco
5298d2340e error parameter to nbo calls and m_undefined for toi_mode
toi_mode is set only when actually inside phase one and two.
In between it goes back to m_undefined.
2019-12-08 12:52:36 +02:00
Teemu Ollakka
24ad144db3 - Remove unneeded keys from nbo phase two begin.
- Save nbo meta for phase two
- Assign trx_meta in mutable_ws_meta
2019-12-08 12:52:36 +02:00
Teemu Ollakka
85a03394cc NBO applying
- High priority interface method to apply NBO begin, separate from
  apply_toi() in order to avoid implementation to force interpreting
  ws_meta flags.
- Method to put client_state into NBO mode when applying NBO begin.
  The client_state will process in m_local mode.
- Unit tests for applying NBO
2019-12-08 12:52:36 +02:00
Teemu Ollakka
1267e29b8f Implementation of client_state NBO operations.
- Implemented calls to enter and leave NBO phase one and two
- Extended client_state mode checking to include m_nbo
- Changed client_state state and mode change sanity checks to
  print a warning and assert() instead of throwing exceptions
  to be more graceful in release builds.
2019-12-08 12:52:36 +02:00
Daniele Sciascia
66ee7bed1b Add type wsrep::xid
Create type `wsrep::xid`, and change all signatures that take
`std::string xid` to take `wsrep::xid xid`.
2019-10-18 09:36:18 +02:00
Daniele Sciascia
682d1b2034 Split commit_or_rollback_by_xid() in two methods
Split `client_state::commit_or_rollback_by_xid()` into
`client_state::commit_by_xid()` and `client_state::rollback_by_xid()`.
2019-10-16 11:42:44 +02:00
Daniele Sciascia
5d18ce3e75 Minimize client_service interface for XA
Remove methods `is_xa()`, `is_xa_prepare()`, and `xid()` from
client_service interface. Instead, transactions are explicitly
assigned their xid, through at start of XA.
2019-10-16 10:16:39 +02:00
Daniele Sciascia
052247144f Support recovery of XA transactions
* Add method `restore_prepared_transaction` to `client_state` class
  which restores a transaction state from storage given its xid.
* Add method `commit_or_rollback_by_xid` to terminate prepared XA
  transactions by xid.
* Make sure that transactions in prepared state are not rolled back
  when their master fails/partitions away.
2019-10-16 10:16:39 +02:00
Leandro Pacheco
e0118c1378 removing assertion about current thread in next_fragment
next_fragment is called outside the scope of a high_priority_switch,
and we may be in a different thread context then the streaming applier
was created in
2019-10-16 10:15:55 +02:00
Leandro Pacheco
36346beab4 Fixes for XA transactions with streaming enabled
Changes mostly related to handling of XA PREPARE fragments
2019-10-16 10:15:55 +02:00
Teemu Ollakka
eb4cf86c1e Implemented thread service support.
Added a wsrep::thread_service interface to allow application to
inject instrumented thread, mutex and condition variable implementation
for provider.

The interface is defined in include/wsrep/thread_service.hpp.
Sample implementation is provided in dbsim/db_threads.[h|c]pp.

This patch will also clean up some remaining dependencies to
wsrep-API compilation units so that the dependency to wsrep-API
is header only. This will extending the provider support to
later wsrep-API versions.
2019-10-14 09:30:15 +03:00
Teemu Ollakka
0c54cbd3f8 codership/wsrep-lib#106 Relaxed assumptions about threading model
Sanity checks to detect concurrency bugs were assuming a threading
model where each client state would always be processed within
single thread of execution. This however may be too strong assumption
if the application uses some kind of thread pooling.

This patch relaxes those assumptions by removing current_thread_id_
from client_state and relaxing assertions against owning_thread_id_.

This patch also adds a new method
wait_rollback_complete_and_acquire_ownership() into
client_state. This method is idempotent and can be used to gain
control to client_state before before_command() is called.
The method will wait until possible background rollback process is
over and marks the state to s_exec to protect the state against
new background rollbacks.

Other fixes/improvements:
- High priority globals state is restored after discarding streaming.
- Allowed server_state transition donor -> synced.
- Client state method store_globals() was renamed to acquire_ownership()
  to better describe the intent. Method store_globals() was left for
  backwards compatibility and marked deprecated.
2019-08-05 15:12:44 +03:00
Alexey Yurchenko
0f676bd893 codership/wsrep-lib#104 Error voting support
- populate and pass real error description buffer to provider in case
   of applying error
 - return 0 from server_state::on_apply() if error voting confirmed
   consistency
 - remove fragments and rollback after fragment applying failure
 - always release streaming applier on commit or rollback
2019-07-15 03:48:55 +03:00
Alexey Yurchenko
4285ff99ea codership/wsrep-lib#100 Support for assign_read_view() wsrep API call
Marshall the call from the `client_state` interface down to provider.
2019-05-08 15:07:45 +03:00
Teemu Ollakka
e9dafb7373 Provided methods to clone subset of transaction state for replay. 2019-04-03 18:51:27 +03:00
mkaruza
be98517cb3 Debug log level implementation
Debug log will now filter output based on debug level that is enabled.
2019-02-13 13:05:45 +02:00
Teemu Ollakka
20b52ff1dd Allow direct manipulation of streaming context parameters.
Added a method to change streaming context fragment unit and
size. The method has a side effect of resetting unit counter.
2019-02-11 16:50:08 +02:00
sjaakola
cfcf34e70f codership/wsrep-lib#23 before_command() wait for ongoing rollbacks leaks
Storing information that background rollbacker in ongoing in client state has_rollback_
This can be used for detecting if there is ongoing background rollback,
and client should keep waiting in before_command() entry to avoid conflicts
in accessing client state during background rollbacking.

transaction::bf_abort() is modified to set has_rollback_ flag when
backgroung rollbacking has been assigned for the client

sync_rollback_complete() method has been modified to reset the backround
rollbacker flag
2018-11-27 12:26:14 +02:00
Teemu Ollakka
c0c977f9ab Added GPLv2 licence and copyright headers. 2018-10-15 15:14:22 +03:00
Teemu Ollakka
b02200b1ef Fixes to streaming rollback
* Check fragment removal error code in prepare phase. It is possible
  that the transaction gets BF aborted during fragment removal.
* Mark fragment certified in certify_fragment() even if the provider
  returns cert failed error. With current wsrep-API error codes
  it may not be possible to distinquish certification failure
  and BF abort during fragment replication. This may also be a
  provider bug. As a result rollback fragment may sometimes be
  replicated when it would not be necessary.
2018-07-17 14:34:24 +03:00
Teemu Ollakka
13487781d8 Total order BF abort client_state method to differentiate BF
aborts caused by conflicts between transactions and conflicts
between TOI operations and transactions.
2018-07-13 18:33:22 +03:00
Teemu Ollakka
3f4e5dea3b Revised logic to handle SR replaying
* Added server_id into transaction in order to be able to stop
  streaming applier during high priority BF abort
* Added missing commit fragment applying
* Don't clear fragments for replaying SR transaction
2018-07-12 13:36:45 +03:00
Teemu Ollakka
ddc6c6495b Made client_id, transaction_id constructors explicit. 2018-07-11 15:00:31 +03:00