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

Updated wsrep-API, added -Wconversion to compiler flags, fixed errors.

This commit is contained in:
Teemu Ollakka
2019-10-10 13:54:05 +03:00
parent 58aa3e821f
commit 477a71dd46
18 changed files with 107 additions and 88 deletions

View File

@ -67,13 +67,16 @@ if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11)
endif() endif()
endif() endif()
# C flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion")
# CXX flags # CXX flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Woverloaded-virtual -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Woverloaded-virtual -Wconversion -g")
if (WSREP_LIB_STRICT_BUILD_FLAGS) if (WSREP_LIB_STRICT_BUILD_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++")
endif() endif()
if (WSREP_LIB_MAINTAINER_MODE) if (WSREP_LIB_MAINTAINER_MODE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif() endif()

View File

@ -34,6 +34,8 @@ db::client::client(db::server& server,
, client_state_(mutex_, cond_, server_state_, client_service_, client_id, mode) , client_state_(mutex_, cond_, server_state_, client_service_, client_id, mode)
, client_service_(*this) , client_service_(*this)
, se_trx_(server.storage_engine()) , se_trx_(server.storage_engine())
, random_device_()
, random_engine_(random_device_())
, stats_() , stats_()
{ } { }
@ -109,7 +111,8 @@ void db::client::run_one_transaction()
// wsrep::log_debug() << "Generate write set"; // wsrep::log_debug() << "Generate write set";
assert(transaction.active()); assert(transaction.active());
assert(err == 0); assert(err == 0);
int data(std::rand() % params_.n_rows); std::uniform_int_distribution<size_t> uniform_dist(0, params_.n_rows);
const size_t data(uniform_dist(random_engine_));
std::ostringstream os; std::ostringstream os;
os << data; os << data;
wsrep::key key(wsrep::key::exclusive); wsrep::key key(wsrep::key::exclusive);
@ -172,6 +175,6 @@ void db::client::report_progress(size_t i) const
{ {
wsrep::log_info() << "client: " << client_state_.id().get() wsrep::log_info() << "client: " << client_state_.id().get()
<< " transactions: " << i << " transactions: " << i
<< " " << 100*double(i)/params_.n_transactions << "%"; << " " << 100*double(i)/double(params_.n_transactions) << "%";
} }
} }

View File

@ -28,6 +28,8 @@
#include "db_client_service.hpp" #include "db_client_service.hpp"
#include "db_high_priority_service.hpp" #include "db_high_priority_service.hpp"
#include <random>
namespace db namespace db
{ {
class server; class server;
@ -77,6 +79,8 @@ namespace db
db::client_state client_state_; db::client_state client_state_;
db::client_service client_service_; db::client_service client_service_;
db::storage_engine::transaction se_trx_; db::storage_engine::transaction se_trx_;
std::random_device random_device_;
std::default_random_engine random_engine_;
struct stats stats_; struct stats stats_;
}; };
} }

View File

@ -89,7 +89,7 @@ std::string db::simulator::stats() const
<< "\n" << "\n"
<< "Seconds: " << duration << "Seconds: " << duration
<< " \n" << " \n"
<< "Transactions per second: " << transactions/duration << "Transactions per second: " << double(transactions)/double(duration)
<< "\n" << "\n"
<< "BF aborts: " << "BF aborts: "
<< bf_aborts << bf_aborts

View File

@ -61,8 +61,9 @@ void db::storage_engine::transaction::rollback()
void db::storage_engine::bf_abort_some(const wsrep::transaction& txc) void db::storage_engine::bf_abort_some(const wsrep::transaction& txc)
{ {
std::uniform_int_distribution<size_t> uniform_dist(0, alg_freq_);
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
if (alg_freq_ && (std::rand() % alg_freq_) == 0) if (alg_freq_ && uniform_dist(random_engine_) == 0)
{ {
if (transactions_.empty() == false) if (transactions_.empty() == false)
{ {

View File

@ -27,6 +27,7 @@
#include <atomic> #include <atomic>
#include <unordered_set> #include <unordered_set>
#include <random>
namespace db namespace db
{ {
@ -41,6 +42,8 @@ namespace db
, bf_aborts_() , bf_aborts_()
, position_() , position_()
, view_() , view_()
, random_device_()
, random_engine_(random_device_())
{ } { }
class transaction class transaction
@ -80,6 +83,8 @@ namespace db
std::atomic<long long> bf_aborts_; std::atomic<long long> bf_aborts_;
wsrep::gtid position_; wsrep::gtid position_;
wsrep::view view_; wsrep::view view_;
std::random_device random_device_;
std::default_random_engine random_engine_;
}; };
} }

View File

@ -21,6 +21,7 @@
#define WSREP_CLIENT_ID_HPP #define WSREP_CLIENT_ID_HPP
#include <ostream> #include <ostream>
#include <limits>
namespace wsrep namespace wsrep
{ {
@ -29,14 +30,14 @@ namespace wsrep
public: public:
typedef unsigned long long type; typedef unsigned long long type;
client_id() client_id()
: id_(-1) : id_(std::numeric_limits<type>::max())
{ } { }
template <typename I> template <typename I>
explicit client_id(I id) explicit client_id(I id)
: id_(static_cast<type>(id)) : id_(static_cast<type>(id))
{ } { }
type get() const { return id_; } type get() const { return id_; }
static type undefined() { return -1; } static type undefined() { return std::numeric_limits<type>::max(); }
bool operator<(const client_id& other) const bool operator<(const client_id& other) const
{ {
return (id_ < other.id_); return (id_ < other.id_);

View File

@ -21,6 +21,7 @@
#define WSREP_TRANSACTION_ID_HPP #define WSREP_TRANSACTION_ID_HPP
#include <iostream> #include <iostream>
#include <limits>
namespace wsrep namespace wsrep
{ {
@ -31,7 +32,7 @@ namespace wsrep
transaction_id() transaction_id()
: id_(-1) : id_(std::numeric_limits<type>::max())
{ } { }
template <typename I> template <typename I>

View File

@ -97,7 +97,7 @@ namespace wsrep
wsrep::view::status status() const wsrep::view::status status() const
{ return status_; } { return status_; }
ssize_t capabilities() const int capabilities() const
{ return capabilities_; } { return capabilities_; }
ssize_t own_index() const ssize_t own_index() const

View File

@ -50,5 +50,5 @@ ssize_t wsrep::gtid_print_to_c_str(
return -ENOBUFS; return -ENOBUFS;
} }
std::strncpy(buf, os.str().c_str(), os.str().size()); std::strncpy(buf, os.str().c_str(), os.str().size());
return os.str().size(); return static_cast<ssize_t>(os.str().size());
} }

View File

@ -51,8 +51,8 @@ wsrep::id::id(const std::string& str)
std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::id& id) std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::id& id)
{ {
const char* ptr(static_cast<const char*>(id.data())); const char* ptr(static_cast<const char*>(id.data()));
ssize_t size(id.size()); size_t size(id.size());
if (std::count_if(ptr, ptr + size, ::isalnum) == size) if (static_cast<size_t>(std::count_if(ptr, ptr + size, ::isalnum)) == size)
{ {
return (os << std::string(ptr, size)); return (os << std::string(ptr, size));
} }

View File

@ -824,8 +824,8 @@ void wsrep::server_state::on_connect(const wsrep::view& view)
throw wsrep::runtime_error(os.str()); throw wsrep::runtime_error(os.str());
} }
if (id_.is_undefined() == false && const size_t own_index(static_cast<size_t>(view.own_index()));
id_ != view.members()[view.own_index()].id()) if (id_.is_undefined() == false && id_ != view.members()[own_index].id())
{ {
std::ostringstream os; std::ostringstream os;
os << "Connection in connected state.\n" os << "Connection in connected state.\n"
@ -840,7 +840,7 @@ void wsrep::server_state::on_connect(const wsrep::view& view)
} }
else else
{ {
id_ = view.members()[view.own_index()].id(); id_ = view.members()[own_index].id();
} }
wsrep::log_info() << "Server " wsrep::log_info() << "Server "

View File

@ -1052,9 +1052,22 @@ int wsrep::transaction::streaming_step(wsrep::unique_lock<wsrep::mutex>& lock)
assert(lock.owns_lock()); assert(lock.owns_lock());
assert(streaming_context_.fragment_size()); assert(streaming_context_.fragment_size());
if (client_service_.bytes_generated() <
streaming_context_.bytes_certified())
{
/* Something went wrong on DBMS side in keeping track of
generated bytes. Return an error to abort the transaction. */
wsrep::log_warning() << "Bytes generated "
<< client_service_.bytes_generated()
<< " less than bytes certified "
<< streaming_context_.bytes_certified()
<< ", aborting streaming transaction";
return 1;
}
int ret(0); int ret(0);
const ssize_t bytes_to_replicate(client_service_.bytes_generated() -
streaming_context_.bytes_certified()); const size_t bytes_to_replicate(client_service_.bytes_generated() -
streaming_context_.bytes_certified());
switch (streaming_context_.fragment_unit()) switch (streaming_context_.fragment_unit())
{ {

View File

@ -27,7 +27,7 @@ int wsrep::view::member_index(const wsrep::id& member_id) const
{ {
if (i->id() == member_id) if (i->id() == member_id)
{ {
return (i - members_.begin()); return static_cast<int>(i - members_.begin());
} }
} }
return -1; return -1;

View File

@ -29,6 +29,7 @@
#include <wsrep_api.h> #include <wsrep_api.h>
#include <cassert> #include <cassert>
#include <climits>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -96,69 +97,51 @@ namespace
inline uint32_t map_one(const int flags, const F from, inline uint32_t map_one(const int flags, const F from,
const T to) const T to)
{ {
return ((flags & from) ? to : 0); // INT_MAX because GCC 4.4 does not eat numeric_limits<int>::max()
// in static_assert
static_assert(WSREP_FLAGS_LAST < INT_MAX,
"WSREP_FLAGS_LAST < INT_MAX");
return static_cast<uint32_t>((flags & static_cast<int>(from)) ?
static_cast<int>(to) : 0);
} }
uint32_t map_flags_to_native(int flags) uint32_t map_flags_to_native(int flags)
{ {
using wsrep::provider; using wsrep::provider;
return (map_one(flags, return static_cast<uint32_t>(
provider::flag::start_transaction, map_one(flags, provider::flag::start_transaction,
WSREP_FLAG_TRX_START) | WSREP_FLAG_TRX_START) |
map_one(flags, map_one(flags, provider::flag::commit, WSREP_FLAG_TRX_END) |
provider::flag::commit, map_one(flags, provider::flag::rollback, WSREP_FLAG_ROLLBACK) |
WSREP_FLAG_TRX_END) | map_one(flags, provider::flag::isolation, WSREP_FLAG_ISOLATION) |
map_one(flags, map_one(flags, provider::flag::pa_unsafe, WSREP_FLAG_PA_UNSAFE) |
provider::flag::rollback, // map_one(flags, provider::flag::commutative, WSREP_FLAG_COMMUTATIVE)
WSREP_FLAG_ROLLBACK) | // |
map_one(flags, // map_one(flags, provider::flag::native, WSREP_FLAG_NATIVE) |
provider::flag::isolation, map_one(flags, provider::flag::prepare, WSREP_FLAG_TRX_PREPARE) |
WSREP_FLAG_ISOLATION) | map_one(flags, provider::flag::snapshot, WSREP_FLAG_SNAPSHOT) |
map_one(flags, map_one(flags, provider::flag::implicit_deps,
provider::flag::pa_unsafe, WSREP_FLAG_IMPLICIT_DEPS));
WSREP_FLAG_PA_UNSAFE) |
// map_one(flags, provider::flag::commutative, WSREP_FLAG_COMMUTATIVE) |
// map_one(flags, provider::flag::native, WSREP_FLAG_NATIVE) |
map_one(flags,
provider::flag::prepare,
WSREP_FLAG_TRX_PREPARE) |
map_one(flags,
provider::flag::snapshot,
WSREP_FLAG_SNAPSHOT) |
map_one(flags,
provider::flag::implicit_deps,
WSREP_FLAG_IMPLICIT_DEPS));
} }
int map_flags_from_native(uint32_t flags) int map_flags_from_native(uint32_t flags_u32)
{ {
using wsrep::provider; using wsrep::provider;
return (map_one(flags, const int flags(static_cast<int>(flags_u32));
WSREP_FLAG_TRX_START, return static_cast<int>(
provider::flag::start_transaction) | map_one(flags, WSREP_FLAG_TRX_START,
map_one(flags, provider::flag::start_transaction) |
WSREP_FLAG_TRX_END, map_one(flags, WSREP_FLAG_TRX_END, provider::flag::commit) |
provider::flag::commit) | map_one(flags, WSREP_FLAG_ROLLBACK, provider::flag::rollback) |
map_one(flags, map_one(flags, WSREP_FLAG_ISOLATION, provider::flag::isolation) |
WSREP_FLAG_ROLLBACK, map_one(flags, WSREP_FLAG_PA_UNSAFE, provider::flag::pa_unsafe) |
provider::flag::rollback) | // map_one(flags, provider::flag::commutative, WSREP_FLAG_COMMUTATIVE)
map_one(flags, // |
WSREP_FLAG_ISOLATION, // map_one(flags, provider::flag::native, WSREP_FLAG_NATIVE) |
provider::flag::isolation) | map_one(flags, WSREP_FLAG_TRX_PREPARE, provider::flag::prepare) |
map_one(flags, map_one(flags, WSREP_FLAG_SNAPSHOT, provider::flag::snapshot) |
WSREP_FLAG_PA_UNSAFE, map_one(flags, WSREP_FLAG_IMPLICIT_DEPS,
provider::flag::pa_unsafe) | provider::flag::implicit_deps));
// map_one(flags, provider::flag::commutative, WSREP_FLAG_COMMUTATIVE) |
// map_one(flags, provider::flag::native, WSREP_FLAG_NATIVE) |
map_one(flags,
WSREP_FLAG_TRX_PREPARE,
provider::flag::prepare) |
map_one(flags,
WSREP_FLAG_SNAPSHOT,
provider::flag::snapshot) |
map_one(flags,
WSREP_FLAG_IMPLICIT_DEPS,
provider::flag::implicit_deps));
} }
class mutable_ws_handle class mutable_ws_handle
@ -288,7 +271,7 @@ namespace
* be made explicit. */ * be made explicit. */
int map_capabilities_from_native(wsrep_cap_t capabilities) int map_capabilities_from_native(wsrep_cap_t capabilities)
{ {
return capabilities; return static_cast<int>(capabilities);
} }
wsrep::view view_from_native(const wsrep_view_info& view_info, wsrep::view view_from_native(const wsrep_view_info& view_info,
const wsrep::id& own_id) const wsrep::id& own_id)
@ -322,7 +305,11 @@ namespace
// by the ID. // by the ID.
for (size_t i(0); i < members.size(); ++i) for (size_t i(0); i < members.size(); ++i)
{ {
if (own_id == members[i].id()) { own_idx = i; break; } if (own_id == members[i].id())
{
own_idx = static_cast<int>(i);
break;
}
} }
} }
@ -351,11 +338,18 @@ namespace
wsrep::server_state& server_state( wsrep::server_state& server_state(
*reinterpret_cast<wsrep::server_state*>(app_ctx)); *reinterpret_cast<wsrep::server_state*>(app_ctx));
wsrep::view view(view_from_native(*view_info, server_state.id())); wsrep::view view(view_from_native(*view_info, server_state.id()));
assert(view.own_index() >= 0); const ssize_t own_index(view.own_index());
assert(own_index >= 0);
if (own_index < 0)
{
wsrep::log_error() << "Connected without being in reported view";
return WSREP_CB_FAILURE;
}
assert(// first connect assert(// first connect
server_state.id().is_undefined() || server_state.id().is_undefined() ||
// reconnect to primary component // reconnect to primary component
server_state.id() == view.members()[view.own_index()].id()); server_state.id() ==
view.members()[static_cast<size_t>(own_index)].id());
try try
{ {
server_state.on_connect(view); server_state.on_connect(view);
@ -661,7 +655,7 @@ int wsrep::wsrep_provider_v26::disconnect()
int wsrep::wsrep_provider_v26::capabilities() const int wsrep::wsrep_provider_v26::capabilities() const
{ {
return wsrep_->capabilities(wsrep_); return map_capabilities_from_native(wsrep_->capabilities(wsrep_));
} }
int wsrep::wsrep_provider_v26::desync() int wsrep::wsrep_provider_v26::desync()
{ {

View File

@ -318,8 +318,6 @@ BOOST_AUTO_TEST_CASE(server_state_state_strings)
wsrep::server_state::s_synced) == "synced"); wsrep::server_state::s_synced) == "synced");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_state::s_disconnecting) == "disconnecting"); wsrep::server_state::s_disconnecting) == "disconnecting");
BOOST_REQUIRE(wsrep::to_string(
static_cast<enum wsrep::server_state::state>(0xff)) == "unknown");
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -1410,8 +1410,4 @@ BOOST_AUTO_TEST_CASE(transaction_state_strings)
BOOST_REQUIRE( BOOST_REQUIRE(
wsrep::to_string( wsrep::to_string(
wsrep::transaction::s_replaying) == "replaying"); wsrep::transaction::s_replaying) == "replaying");
BOOST_REQUIRE(
wsrep::to_string(
static_cast<enum wsrep::transaction::state>(0xff)) == "unknown");
} }