1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-28 20:02:00 +03:00

Implemented client last_written_gtid, sync_wait

This commit is contained in:
Teemu Ollakka
2018-06-30 07:44:09 +03:00
parent 3d2af88428
commit db18e91c42
11 changed files with 138 additions and 12 deletions

View File

@ -158,6 +158,7 @@ void wsrep::client_state::after_command_after_result()
{
current_error_ = wsrep::e_success;
}
sync_wait_gtid_ = wsrep::gtid::undefined();
state(lock, s_idle);
debug_log_state("after_command_after_result: leave");
}
@ -293,12 +294,46 @@ int wsrep::client_state::leave_toi()
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
mode(lock, toi_mode_);
toi_mode_ = m_local;
if (toi_meta_.gtid().is_undefined() == false)
{
update_last_written_gtid(toi_meta_.gtid());
}
toi_meta_ = wsrep::ws_meta();
return ret;
}
int wsrep::client_state::sync_wait(int timeout)
{
std::pair<wsrep::gtid, enum wsrep::provider::status> result(
server_state_.causal_read(timeout));
int ret(1);
switch (result.second)
{
case wsrep::provider::success:
sync_wait_gtid_ = result.first;
ret = 0;
break;
case wsrep::provider::error_not_implemented:
override_error(wsrep::e_not_supported_error);
break;
default:
override_error(wsrep::e_timeout_error);
break;
}
return ret;
}
// Private
void wsrep::client_state::update_last_written_gtid(const wsrep::gtid& gtid)
{
assert(last_written_gtid_.is_undefined() ||
(last_written_gtid_.id() == gtid.id() &&
last_written_gtid_.seqno() < gtid.seqno()));
last_written_gtid_ = gtid;
}
void wsrep::client_state::debug_log_state(const char* context) const
{
if (debug_log_level() >= 1)

View File

@ -4,7 +4,9 @@
#include "wsrep/gtid.hpp"
#include <cerrno>
#include <iostream>
#include <sstream>
std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::gtid& gtid)
{
@ -21,3 +23,16 @@ std::istream& wsrep::operator>>(std::istream& is, wsrep::gtid& gtid)
std::cout << "GTID: " << gtid << "\n";
return is;
}
ssize_t wsrep::gtid_print_to_c_str(
const wsrep::gtid& gtid, char* buf, size_t buf_len)
{
std::ostringstream os;
os << gtid;
if (os.str().size() > buf_len)
{
return -ENOBUFS;
}
std::strncpy(buf, os.str().c_str(), os.str().size());
return os.str().size();
}

View File

@ -499,7 +499,7 @@ wsrep::server_state::wait_for_gtid(const wsrep::gtid& gtid, int timeout)
return provider_->wait_for_gtid(gtid, timeout);
}
enum wsrep::provider::status
std::pair<wsrep::gtid, enum wsrep::provider::status>
wsrep::server_state::causal_read(int timeout) const
{
return provider_->causal_read(timeout);

View File

@ -961,8 +961,13 @@ void wsrep::transaction::cleanup()
debug_log_state("cleanup_enter");
id_ = wsrep::transaction_id::undefined();
ws_handle_ = wsrep::ws_handle();
// Keep the state history for troubleshooting. Reset at start_transaction().
// Keep the state history for troubleshooting. Reset
// at start_transaction().
// state_hist_.clear();
if (ordered())
{
client_state_.update_last_written_gtid(ws_meta_.gtid());
}
ws_meta_ = wsrep::ws_meta();
certified_ = false;
pa_unsafe_ = false;

View File

@ -703,10 +703,17 @@ wsrep::wsrep_provider_v26::leave_toi(wsrep::client_id client_id)
wsrep_, client_id.get(), 0));
}
enum wsrep::provider::status
std::pair<wsrep::gtid, enum wsrep::provider::status>
wsrep::wsrep_provider_v26::causal_read(int timeout) const
{
return map_return_value(wsrep_->sync_wait(wsrep_, 0, timeout, 0));
wsrep_gtid_t wsrep_gtid;
wsrep_status_t ret(wsrep_->sync_wait(wsrep_, 0, timeout, &wsrep_gtid));
wsrep::gtid gtid(ret == WSREP_OK ?
wsrep::gtid(wsrep::id(wsrep_gtid.uuid.data,
sizeof(wsrep_gtid.uuid.data)),
wsrep::seqno(wsrep_gtid.seqno)) :
wsrep::gtid::undefined());
return std::make_pair(gtid, map_return_value(ret));
}
enum wsrep::provider::status

View File

@ -56,7 +56,8 @@ namespace wsrep
wsrep::ws_meta&,
int);
enum wsrep::provider::status leave_toi(wsrep::client_id);
enum wsrep::provider::status causal_read(int) const;
std::pair<wsrep::gtid, enum wsrep::provider::status>
causal_read(int) const;
enum wsrep::provider::status wait_for_gtid(const wsrep::gtid&, int) const;
wsrep::gtid last_committed_gtid() const;
int sst_sent(const wsrep::gtid&,int);