mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-28 20:02:00 +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:
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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
47
include/wsrep/xid.hpp
Normal 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
|
Reference in New Issue
Block a user