1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-06-02 21:41:37 +03:00

Add type wsrep::xid

Create type `wsrep::xid`, and change all signatures that take
`std::string xid` to take `wsrep::xid xid`.
This commit is contained in:
Daniele Sciascia 2019-10-16 14:06:16 +02:00
parent 682d1b2034
commit 66ee7bed1b
15 changed files with 105 additions and 21 deletions

View File

@ -42,7 +42,7 @@ namespace db
const wsrep::ws_handle&,
const wsrep::ws_meta&,
const wsrep::const_buffer&,
const std::string&) override
const wsrep::xid&) override
{ return 0; }
int remove_fragments(const wsrep::ws_meta&) override
{ return 0; }

View File

@ -35,7 +35,7 @@ namespace db
wsrep::transaction_id,
int,
const wsrep::const_buffer&,
const std::string&) override
const wsrep::xid&) override
{ throw wsrep::not_implemented_error(); }
int update_fragment_meta(const wsrep::ws_meta&) override
{ throw wsrep::not_implemented_error(); }

View File

@ -41,6 +41,7 @@
#include "lock.hpp"
#include "buffer.hpp"
#include "thread.hpp"
#include "xid.hpp"
namespace wsrep
{
@ -533,7 +534,7 @@ namespace wsrep
*
* @param xid transaction id
*/
void assign_xid(const std::string& xid)
void assign_xid(const wsrep::xid& xid)
{
transaction_.assign_xid(xid);
}
@ -544,7 +545,7 @@ namespace wsrep
* The purpose of this method is to restore transaction state
* during recovery of a prepared XA transaction.
*/
int restore_xid(std::string& xid)
int restore_xid(const wsrep::xid& xid)
{
return transaction_.restore_to_prepared_state(xid);
}
@ -562,7 +563,7 @@ namespace wsrep
* @return Zero on success, non-zero on error. In case of error
* the client_state's current_error is set
*/
int commit_by_xid(const std::string& xid)
int commit_by_xid(const wsrep::xid& xid)
{
return transaction_.commit_or_rollback_by_xid(xid, true);
}
@ -580,7 +581,7 @@ namespace wsrep
* @return Zero on success, non-zero on error. In case of error
* the client_state's current_error is set
*/
int rollback_by_xid(const std::string& xid)
int rollback_by_xid(const wsrep::xid& xid)
{
return transaction_.commit_or_rollback_by_xid(xid, false);
}

View File

@ -24,6 +24,7 @@
#ifndef WSREP_HIGH_PRIORITY_SERVICE_HPP
#define WSREP_HIGH_PRIORITY_SERVICE_HPP
#include "xid.hpp"
#include "server_state.hpp"
namespace wsrep
@ -97,7 +98,7 @@ namespace wsrep
const wsrep::ws_handle& ws_handle,
const wsrep::ws_meta& ws_meta,
const wsrep::const_buffer& data,
const std::string& xid) = 0;
const wsrep::xid& xid) = 0;
/**
* Remove fragments belonging to streaming transaction.

View File

@ -90,6 +90,7 @@
#include "logger.hpp"
#include "provider.hpp"
#include "compiler.hpp"
#include "xid.hpp"
#include <vector>
#include <string>
@ -268,7 +269,7 @@ namespace wsrep
* Find a streaming applier matching xid
*/
wsrep::high_priority_service* find_streaming_applier(
const std::string& xid) const;
const wsrep::xid& xid) const;
/**
* Load WSRep provider.

View File

@ -32,6 +32,7 @@
#include "transaction_id.hpp"
#include "id.hpp"
#include "buffer.hpp"
#include "xid.hpp"
namespace wsrep
{
@ -64,7 +65,7 @@ namespace wsrep
wsrep::transaction_id client_id,
int flags,
const wsrep::const_buffer& data,
const std::string& xid) = 0;
const wsrep::xid& xid) = 0;
/**
* Update fragment meta data after certification process.

View File

@ -29,6 +29,7 @@
#include "sr_key_set.hpp"
#include "buffer.hpp"
#include "client_service.hpp"
#include "xid.hpp"
#include <cassert>
#include <vector>
@ -127,21 +128,21 @@ namespace wsrep
return !xid_.empty();
}
void assign_xid(const std::string& xid)
void assign_xid(const wsrep::xid& xid)
{
assert(active());
assert(xid_.empty());
xid_ = xid;
}
const std::string xid() const
const wsrep::xid xid() const
{
return xid_;
}
int restore_to_prepared_state(const std::string& xid);
int restore_to_prepared_state(const wsrep::xid& xid);
int commit_or_rollback_by_xid(const std::string& xid, bool commit);
int commit_or_rollback_by_xid(const wsrep::xid& xid, bool commit);
bool pa_unsafe() const { return pa_unsafe_; }
void pa_unsafe(bool pa_unsafe) { pa_unsafe_ = pa_unsafe; }
@ -273,7 +274,7 @@ namespace wsrep
wsrep::streaming_context streaming_context_;
wsrep::sr_key_set sr_keys_;
wsrep::mutable_buffer apply_error_buf_;
std::string xid_;
wsrep::xid xid_;
};
static inline const char* to_c_string(enum wsrep::transaction::state state)

47
include/wsrep/xid.hpp Normal file
View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
* Wsrep-lib 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, either version 2 of the License, or
* (at your option) any later version.
*
* Wsrep-lib 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 wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WSREP_XID_HPP
#define WSREP_XID_HPP
#include <iosfwd>
#include <string>
namespace wsrep
{
class xid
{
public:
xid() : xid_() { }
xid(const std::string& str) : xid_(str) { }
xid(const char* s) : xid_(s) { }
bool empty() const { return xid_.empty(); }
void clear() { xid_.clear(); }
bool operator==(const xid& other) const { return xid_ == other.xid_; }
friend std::string to_string(const wsrep::xid& xid);
friend std::ostream& operator<<(std::ostream& os, const wsrep::xid& xid);
private:
std::string xid_;
};
std::string to_string(const wsrep::xid& xid);
std::ostream& operator<<(std::ostream& os, const wsrep::xid& xid);
}
#endif // WSREP_XID_HPP

View File

@ -7,6 +7,7 @@ add_library(wsrep-lib
exception.cpp
gtid.cpp
id.cpp
xid.cpp
key.cpp
logger.cpp
provider.cpp

View File

@ -130,7 +130,7 @@ static int apply_fragment(wsrep::server_state& server_state,
if (!apply_err)
{
high_priority_service.debug_crash("crash_apply_cb_before_append_frag");
const std::string xid(streaming_applier->transaction().xid());
const wsrep::xid xid(streaming_applier->transaction().xid());
ret = high_priority_service.append_fragment_and_commit(
ws_handle, ws_meta, data, xid);
high_priority_service.debug_crash("crash_apply_cb_after_append_frag");
@ -1258,7 +1258,7 @@ wsrep::high_priority_service* wsrep::server_state::find_streaming_applier(
}
wsrep::high_priority_service* wsrep::server_state::find_streaming_applier(
const std::string& xid) const
const wsrep::xid& xid) const
{
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
streaming_appliers_map::const_iterator i(streaming_appliers_.begin());

View File

@ -1040,7 +1040,7 @@ void wsrep::transaction::after_replay(const wsrep::transaction& other)
clear_fragments();
}
int wsrep::transaction::restore_to_prepared_state(const std::string& xid)
int wsrep::transaction::restore_to_prepared_state(const wsrep::xid& xid)
{
wsrep::unique_lock<wsrep::mutex> lock(client_state_.mutex_);
assert(active());
@ -1053,7 +1053,7 @@ int wsrep::transaction::restore_to_prepared_state(const std::string& xid)
return 0;
}
int wsrep::transaction::commit_or_rollback_by_xid(const std::string& xid,
int wsrep::transaction::commit_or_rollback_by_xid(const wsrep::xid& xid,
bool commit)
{
wsrep::unique_lock<wsrep::mutex> lock(client_state_.mutex_);

31
src/xid.cpp Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
* Wsrep-lib 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, either version 2 of the License, or
* (at your option) any later version.
*
* Wsrep-lib 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 wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#include "wsrep/xid.hpp"
#include <ostream>
std::string wsrep::to_string(const wsrep::xid& xid)
{
return xid.xid_;
}
std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::xid& xid)
{
return os << xid.xid_;
}

View File

@ -55,7 +55,7 @@ namespace wsrep
const wsrep::ws_handle&,
const wsrep::ws_meta&,
const wsrep::const_buffer&,
const std::string&) WSREP_OVERRIDE
const wsrep::xid&) WSREP_OVERRIDE
{ return 0; }
int remove_fragments(const wsrep::ws_meta&) WSREP_OVERRIDE
{ return 0; }

View File

@ -40,7 +40,7 @@ class mock_server_state;
wsrep::transaction_id,
int,
const wsrep::const_buffer&,
const std::string&) WSREP_OVERRIDE
const wsrep::xid&) WSREP_OVERRIDE
{ return 0; }
int update_fragment_meta(const wsrep::ws_meta&) WSREP_OVERRIDE

@ -1 +1 @@
Subproject commit 35b9ecedd84bac9931851e3f388fc96271e61f97
Subproject commit 12a50c43b112648fec3b1213a1470a85aca55f2c