Skip to content

Commit

Permalink
Updated wsrep-API, added -Wconversion to compiler flags, fixed errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
temeo committed Oct 11, 2019
1 parent 58aa3e8 commit 477a71d
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 91 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11)
endif()
endif()

# C flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion")
# 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)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++")
endif()
if (WSREP_LIB_MAINTAINER_MODE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()

Expand Down
7 changes: 5 additions & 2 deletions dbsim/db_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ db::client::client(db::server& server,
, client_state_(mutex_, cond_, server_state_, client_service_, client_id, mode)
, client_service_(*this)
, se_trx_(server.storage_engine())
, random_device_()
, random_engine_(random_device_())
, stats_()
{ }

Expand Down Expand Up @@ -109,7 +111,8 @@ void db::client::run_one_transaction()
// wsrep::log_debug() << "Generate write set";
assert(transaction.active());
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;
os << data;
wsrep::key key(wsrep::key::exclusive);
Expand Down Expand Up @@ -172,6 +175,6 @@ void db::client::report_progress(size_t i) const
{
wsrep::log_info() << "client: " << client_state_.id().get()
<< " transactions: " << i
<< " " << 100*double(i)/params_.n_transactions << "%";
<< " " << 100*double(i)/double(params_.n_transactions) << "%";
}
}
4 changes: 4 additions & 0 deletions dbsim/db_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "db_client_service.hpp"
#include "db_high_priority_service.hpp"

#include <random>

namespace db
{
class server;
Expand Down Expand Up @@ -77,6 +79,8 @@ namespace db
db::client_state client_state_;
db::client_service client_service_;
db::storage_engine::transaction se_trx_;
std::random_device random_device_;
std::default_random_engine random_engine_;
struct stats stats_;
};
}
Expand Down
2 changes: 1 addition & 1 deletion dbsim/db_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::string db::simulator::stats() const
<< "\n"
<< "Seconds: " << duration
<< " \n"
<< "Transactions per second: " << transactions/duration
<< "Transactions per second: " << double(transactions)/double(duration)
<< "\n"
<< "BF aborts: "
<< bf_aborts
Expand Down
3 changes: 2 additions & 1 deletion dbsim/db_storage_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ void db::storage_engine::transaction::rollback()

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_);
if (alg_freq_ && (std::rand() % alg_freq_) == 0)
if (alg_freq_ && uniform_dist(random_engine_) == 0)
{
if (transactions_.empty() == false)
{
Expand Down
5 changes: 5 additions & 0 deletions dbsim/db_storage_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <atomic>
#include <unordered_set>
#include <random>

namespace db
{
Expand All @@ -41,6 +42,8 @@ namespace db
, bf_aborts_()
, position_()
, view_()
, random_device_()
, random_engine_(random_device_())
{ }

class transaction
Expand Down Expand Up @@ -80,6 +83,8 @@ namespace db
std::atomic<long long> bf_aborts_;
wsrep::gtid position_;
wsrep::view view_;
std::random_device random_device_;
std::default_random_engine random_engine_;
};
}

Expand Down
5 changes: 3 additions & 2 deletions include/wsrep/client_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define WSREP_CLIENT_ID_HPP

#include <ostream>
#include <limits>

namespace wsrep
{
Expand All @@ -29,14 +30,14 @@ namespace wsrep
public:
typedef unsigned long long type;
client_id()
: id_(-1)
: id_(std::numeric_limits<type>::max())
{ }
template <typename I>
explicit client_id(I id)
: id_(static_cast<type>(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
{
return (id_ < other.id_);
Expand Down
3 changes: 2 additions & 1 deletion include/wsrep/transaction_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define WSREP_TRANSACTION_ID_HPP

#include <iostream>
#include <limits>

namespace wsrep
{
Expand All @@ -31,7 +32,7 @@ namespace wsrep


transaction_id()
: id_(-1)
: id_(std::numeric_limits<type>::max())
{ }

template <typename I>
Expand Down
2 changes: 1 addition & 1 deletion include/wsrep/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace wsrep
wsrep::view::status status() const
{ return status_; }

ssize_t capabilities() const
int capabilities() const
{ return capabilities_; }

ssize_t own_index() const
Expand Down
2 changes: 1 addition & 1 deletion src/gtid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ ssize_t wsrep::gtid_print_to_c_str(
return -ENOBUFS;
}
std::strncpy(buf, os.str().c_str(), os.str().size());
return os.str().size();
return static_cast<ssize_t>(os.str().size());
}
4 changes: 2 additions & 2 deletions src/id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ wsrep::id::id(const std::string& str)
std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::id& id)
{
const char* ptr(static_cast<const char*>(id.data()));
ssize_t size(id.size());
if (std::count_if(ptr, ptr + size, ::isalnum) == size)
size_t size(id.size());
if (static_cast<size_t>(std::count_if(ptr, ptr + size, ::isalnum)) == size)
{
return (os << std::string(ptr, size));
}
Expand Down
6 changes: 3 additions & 3 deletions src/server_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,8 @@ void wsrep::server_state::on_connect(const wsrep::view& view)
throw wsrep::runtime_error(os.str());
}

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

wsrep::log_info() << "Server "
Expand Down
17 changes: 15 additions & 2 deletions src/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,22 @@ int wsrep::transaction::streaming_step(wsrep::unique_lock<wsrep::mutex>& lock)
assert(lock.owns_lock());
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);
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())
{
Expand Down
2 changes: 1 addition & 1 deletion src/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int wsrep::view::member_index(const wsrep::id& member_id) const
{
if (i->id() == member_id)
{
return (i - members_.begin());
return static_cast<int>(i - members_.begin());
}
}
return -1;
Expand Down
Loading

0 comments on commit 477a71d

Please sign in to comment.