mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-21 12:22:06 +03:00
Removed wsrep_api.h dependency from view.hpp
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
#include "id.hpp"
|
||||
#include "seqno.hpp"
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
class gtid
|
||||
@ -27,6 +29,8 @@ namespace wsrep
|
||||
wsrep::id id_;
|
||||
wsrep::seqno seqno_;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream&, const wsrep::gtid&);
|
||||
}
|
||||
|
||||
#endif // WSREP_GTID_HPP
|
||||
|
@ -193,6 +193,30 @@ namespace wsrep
|
||||
static const int snapshot = (1 << 7);
|
||||
};
|
||||
|
||||
/**
|
||||
* Provider capabilities.
|
||||
*/
|
||||
struct capabilities
|
||||
{
|
||||
static const int multi_master = (1 << 0);
|
||||
static const int certification = (1 << 1);
|
||||
static const int parallel_applying = (1 << 2);
|
||||
static const int transaction_replay = (1 << 3);
|
||||
static const int isolation = (1 << 4);
|
||||
static const int pause = (1 << 5);
|
||||
static const int causal_reads = (1 << 6);
|
||||
static const int causal_transaction = (1 << 7);
|
||||
static const int incremental_writeset = (1 << 8);
|
||||
static const int session_locks = (1 << 9);
|
||||
static const int distributed_locks = (1 << 10);
|
||||
static const int consistency_check = (1 << 11);
|
||||
static const int unordered = (1 << 12);
|
||||
static const int annotation = (1 << 13);
|
||||
static const int preordered = (1 << 14);
|
||||
static const int streaming = (1 << 15);
|
||||
static const int snapshot = (1 << 16);
|
||||
static const int nbo = (1 << 17);
|
||||
};
|
||||
provider(wsrep::server_state& server_state)
|
||||
: server_state_(server_state)
|
||||
{ }
|
||||
|
@ -2,11 +2,16 @@
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
/** @file view.hpp
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef WSREP_VIEW_HPP
|
||||
#define WSREP_VIEW_HPP
|
||||
|
||||
#include <wsrep_api.h>
|
||||
|
||||
#include "id.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace wsrep
|
||||
@ -14,76 +19,78 @@ namespace wsrep
|
||||
class view
|
||||
{
|
||||
public:
|
||||
enum status
|
||||
{
|
||||
primary,
|
||||
non_primary,
|
||||
disconnected
|
||||
};
|
||||
class member
|
||||
{
|
||||
public:
|
||||
member(const wsrep_member_info_t& member_info)
|
||||
: id_()
|
||||
, name_(member_info.name, WSREP_MEMBER_NAME_LEN)
|
||||
, incoming_(member_info.incoming, WSREP_INCOMING_LEN)
|
||||
member(const wsrep::id& id,
|
||||
const std::string& name,
|
||||
const std::string& incoming)
|
||||
: id_(id)
|
||||
, name_(name)
|
||||
, incoming_(incoming)
|
||||
{
|
||||
char uuid_str[WSREP_UUID_STR_LEN + 1];
|
||||
wsrep_uuid_print(&member_info.id, uuid_str, sizeof(uuid_str));
|
||||
id_ = uuid_str;
|
||||
}
|
||||
const std::string& id() const { return id_; }
|
||||
const wsrep::id& id() const { return id_; }
|
||||
const std::string& name() const { return name_; }
|
||||
const std::string& incoming() const { return incoming_; }
|
||||
private:
|
||||
std::string id_;
|
||||
wsrep::id id_;
|
||||
std::string name_;
|
||||
std::string incoming_;
|
||||
};
|
||||
|
||||
view(const wsrep_view_info_t& view_info)
|
||||
: state_id_(view_info.state_id)
|
||||
, view_(view_info.view)
|
||||
, status_(view_info.status)
|
||||
, capabilities_(view_info.capabilities)
|
||||
, my_idx_(view_info.my_idx)
|
||||
, proto_ver_(view_info.proto_ver)
|
||||
, members_()
|
||||
{
|
||||
for (int i(0); i < view_info.memb_num; ++i)
|
||||
{
|
||||
members_.push_back(view_info.members[i]);
|
||||
}
|
||||
}
|
||||
view(const wsrep::gtid& state_id,
|
||||
wsrep::seqno view_seqno,
|
||||
enum wsrep::view::status status,
|
||||
int capabilities,
|
||||
ssize_t own_index,
|
||||
int protocol_version,
|
||||
const std::vector<wsrep::view::member>& members)
|
||||
: state_id_(state_id)
|
||||
, view_seqno_(view_seqno)
|
||||
, status_(status)
|
||||
, capabilities_(capabilities)
|
||||
, own_index_(own_index)
|
||||
, protocol_version_(protocol_version)
|
||||
, members_(members)
|
||||
{ }
|
||||
|
||||
wsrep::gtid state_id() const
|
||||
{ return state_id_; }
|
||||
|
||||
wsrep_seqno_t id() const
|
||||
{ return view_; }
|
||||
wsrep_view_status_t status() const
|
||||
wsrep::seqno view_seqno() const
|
||||
{ return view_seqno_; }
|
||||
|
||||
wsrep::view::status status() const
|
||||
{ return status_; }
|
||||
int own_index() const
|
||||
{ return my_idx_; }
|
||||
|
||||
std::vector<member> members() const
|
||||
{
|
||||
std::vector<member> ret;
|
||||
for (std::vector<wsrep_member_info_t>::const_iterator i(members_.begin());
|
||||
i != members_.end(); ++i)
|
||||
{
|
||||
ret.push_back(member(*i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
//
|
||||
// Return true if the view is final
|
||||
//
|
||||
ssize_t own_index() const
|
||||
{ return own_index_; }
|
||||
|
||||
const std::vector<member>& members() const { return members_; }
|
||||
|
||||
/**
|
||||
* Return true if the view is final
|
||||
*/
|
||||
bool final() const
|
||||
{
|
||||
return (members_.empty() && my_idx_ == -1);
|
||||
return (members_.empty() && own_index_ == -1);
|
||||
}
|
||||
|
||||
private:
|
||||
wsrep_gtid_t state_id_;
|
||||
wsrep_seqno_t view_;
|
||||
wsrep_view_status_t status_;
|
||||
wsrep_cap_t capabilities_;
|
||||
int my_idx_;
|
||||
int proto_ver_;
|
||||
std::vector<wsrep_member_info_t> members_;
|
||||
wsrep::gtid state_id_;
|
||||
wsrep::seqno view_seqno_;
|
||||
enum wsrep::view::status status_;
|
||||
int capabilities_;
|
||||
ssize_t own_index_;
|
||||
int protocol_version_;
|
||||
std::vector<wsrep::view::member> members_;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
add_library(wsrep-lib
|
||||
client_state.cpp
|
||||
gtid.cpp
|
||||
id.cpp
|
||||
logger.cpp
|
||||
provider.cpp
|
||||
|
12
src/gtid.cpp
Normal file
12
src/gtid.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
//
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
#include "wsrep/gtid.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::gtid& gtid)
|
||||
{
|
||||
return (os << gtid.id() << ":" << gtid.seqno());
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
#ifndef WSREP_PROVIDER_IMPL_HPP
|
||||
#define WSREP_PROVIDER_IMPL_HPP
|
||||
|
||||
#include <wsrep_api.h>
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
// Abstract interface for provider implementations
|
||||
class provider_impl
|
||||
{
|
||||
public:
|
||||
virtual int start_transaction(wsrep_ws_handle_t*) = 0;
|
||||
virtual int append_key(wsrep_ws_handle_t*, const wsrep_key_t*) = 0;
|
||||
virtual int append_data(wsrep_ws_handle_t*, const wsrep_buf_t*) = 0;
|
||||
virtual wsrep_status_t
|
||||
certify(wsrep_conn_id_t, wsrep_ws_handle_t*,
|
||||
uint32_t,
|
||||
wsrep_trx_meta_t*) = 0;
|
||||
virtual int rollback(const wsrep_trx_id_t) = 0;
|
||||
virtual wsrep_status commit_order_enter(wsrep_ws_handle_t*) = 0;
|
||||
virtual int commit_order_leave(wsrep_ws_handle_t*) = 0;
|
||||
virtual int release(wsrep_ws_handle_t*) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // WSREP_PROVIDER_IMPL_HPP
|
@ -87,7 +87,7 @@ void wsrep::server_state::on_connect()
|
||||
void wsrep::server_state::on_view(const wsrep::view& view)
|
||||
{
|
||||
wsrep::log() << "================================================\nView:\n"
|
||||
<< "id: " << view.id() << "\n"
|
||||
<< "id: " << view.state_id() << "\n"
|
||||
<< "status: " << view.status() << "\n"
|
||||
<< "own_index: " << view.own_index() << "\n"
|
||||
<< "final: " << view.final() << "\n"
|
||||
|
@ -231,6 +231,54 @@ namespace
|
||||
wsrep_trx_meta_t trx_meta_;
|
||||
};
|
||||
|
||||
enum wsrep::view::status map_view_status_from_native(
|
||||
wsrep_view_status_t status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case WSREP_VIEW_PRIMARY: return wsrep::view::primary;
|
||||
case WSREP_VIEW_NON_PRIMARY: return wsrep::view::non_primary;
|
||||
case WSREP_VIEW_DISCONNECTED: return wsrep::view::disconnected;
|
||||
default: throw wsrep::runtime_error("Unknown view status");
|
||||
}
|
||||
}
|
||||
|
||||
/** @todo Currently capabilities defined in provider.hpp
|
||||
* are one to one with wsrep_api.h. However, the mapping should
|
||||
* be made explicit. */
|
||||
int map_capabilities_from_native(wsrep_cap_t capabilities)
|
||||
{
|
||||
return capabilities;
|
||||
}
|
||||
wsrep::view view_from_native(const wsrep_view_info& view_info)
|
||||
{
|
||||
std::vector<wsrep::view::member> members;
|
||||
for (int i(0); i < view_info.memb_num; ++i)
|
||||
{
|
||||
wsrep::id id(view_info.members[i].id.data, sizeof(view_info.members[i].id.data));
|
||||
std::string name(
|
||||
view_info.members[i].name,
|
||||
strnlen(view_info.members[i].name,
|
||||
sizeof(view_info.members[i].name)));
|
||||
std::string incoming(
|
||||
view_info.members[i].incoming,
|
||||
strnlen(view_info.members[i].incoming,
|
||||
sizeof(view_info.members[i].incoming)));
|
||||
members.push_back(wsrep::view::member(id, name, incoming));
|
||||
}
|
||||
return wsrep::view(
|
||||
wsrep::gtid(
|
||||
wsrep::id(view_info.state_id.uuid.data,
|
||||
sizeof(view_info.state_id.uuid.data)),
|
||||
wsrep::seqno(view_info.state_id.seqno)),
|
||||
wsrep::seqno(view_info.view),
|
||||
map_view_status_from_native(view_info.status),
|
||||
map_capabilities_from_native(view_info.capabilities),
|
||||
view_info.my_idx,
|
||||
view_info.proto_ver,
|
||||
members);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Callbacks //
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
@ -269,7 +317,7 @@ namespace
|
||||
*reinterpret_cast<wsrep::server_state*>(app_ctx));
|
||||
try
|
||||
{
|
||||
wsrep::view view(*view_info);
|
||||
wsrep::view view(view_from_native(*view_info));
|
||||
server_state.on_view(view);
|
||||
return WSREP_CB_SUCCESS;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "wsrep/provider.hpp"
|
||||
|
||||
#include <wsrep_api.h>
|
||||
struct wsrep_st;
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
@ -49,7 +49,7 @@ namespace wsrep
|
||||
private:
|
||||
wsrep_provider_v26(const wsrep_provider_v26&);
|
||||
wsrep_provider_v26& operator=(const wsrep_provider_v26);
|
||||
wsrep_t* wsrep_;
|
||||
struct wsrep_st* wsrep_;
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user