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

- Initialize member cluster ID only on connection to cluster and forget

it on disconnect.
 - Don't rely on own index from the view because the view may come from
   another member (IST/SST), instead always determine own index from own ID.

Refs codership/wsrep-lib#13
This commit is contained in:
Alexey Yurchenko
2018-11-06 15:21:48 +02:00
parent a942811ce7
commit ea9971d54b
13 changed files with 185 additions and 52 deletions

View File

@ -32,11 +32,12 @@ namespace
{
replicating_client_fixture_sync_rm()
: server_service(sc)
, sc("s1", "s1", wsrep::server_state::rm_sync, server_service)
, sc("s1", wsrep::server_state::rm_sync, server_service)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_local)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
@ -54,11 +55,12 @@ namespace
{
replicating_client_fixture_async_rm()
: server_service(sc)
, sc("s1", "s1", wsrep::server_state::rm_async, server_service)
, sc("s1", wsrep::server_state::rm_async, server_service)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_local)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
@ -76,11 +78,12 @@ namespace
{
replicating_client_fixture_2pc()
: server_service(sc)
, sc("s1", "s1", wsrep::server_state::rm_sync, server_service)
, sc("s1", wsrep::server_state::rm_sync, server_service)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_local)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
cc.do_2pc_ = true;
BOOST_REQUIRE(cc.before_command() == 0);
@ -99,11 +102,12 @@ namespace
{
replicating_client_fixture_autocommit()
: server_service(sc)
, sc("s1", "s1", wsrep::server_state::rm_sync, server_service)
, sc("s1", wsrep::server_state::rm_sync, server_service)
, cc(sc, wsrep::client_id(1),
wsrep::client_state::m_local)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
cc.is_autocommit_ = true;
BOOST_REQUIRE(cc.before_command() == 0);
@ -122,13 +126,14 @@ namespace
{
applying_client_fixture()
: server_service(sc)
, sc("s1", "s1",
, sc("s1",
wsrep::server_state::rm_async, server_service)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_high_priority)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
@ -155,13 +160,14 @@ namespace
{
applying_client_fixture_2pc()
: server_service(sc)
, sc("s1", "s1",
, sc("s1",
wsrep::server_state::rm_async, server_service)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_high_priority)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
cc.do_2pc_ = true;
BOOST_REQUIRE(cc.before_command() == 0);
@ -189,12 +195,13 @@ namespace
{
streaming_client_fixture_row()
: server_service(sc)
, sc("s1", "s1", wsrep::server_state::rm_sync, server_service)
, sc("s1", wsrep::server_state::rm_sync, server_service)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_local)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
@ -214,12 +221,13 @@ namespace
{
streaming_client_fixture_byte()
: server_service(sc)
, sc("s1", "s1", wsrep::server_state::rm_sync, server_service)
, sc("s1", wsrep::server_state::rm_sync, server_service)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_local)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
@ -238,12 +246,13 @@ namespace
{
streaming_client_fixture_statement()
: server_service(sc)
, sc("s1", "s1", wsrep::server_state::rm_sync, server_service)
, sc("s1", wsrep::server_state::rm_sync, server_service)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_local)
, tc(cc.transaction())
{
sc.mock_connect();
cc.open(cc.id());
BOOST_REQUIRE(cc.before_command() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);

View File

@ -176,11 +176,10 @@ namespace wsrep
{
public:
mock_server_state(const std::string& name,
const std::string& id,
enum wsrep::server_state::rollback_mode rollback_mode,
wsrep::server_service& server_service)
: wsrep::server_state(mutex_, cond_, server_service,
name, id, "", "", "./",
name, "", "", "./",
wsrep::gtid::undefined(),
1,
rollback_mode)
@ -191,6 +190,48 @@ namespace wsrep
wsrep::mock_provider& provider() const WSREP_OVERRIDE
{ return provider_; }
// mock connected state for tests without overriding the connect()
// method.
int mock_connect(const std::string& own_id,
const std::string& cluster_name,
const std::string& cluster_address,
const std::string& state_donor,
bool bootstrap)
{
int const ret(server_state::connect(cluster_name,
cluster_address,
state_donor,
bootstrap));
if (0 == ret)
{
wsrep::id cluster_id("1");
wsrep::gtid state_id(cluster_id, wsrep::seqno(0));
std::vector<wsrep::view::member> members;
members.push_back(wsrep::view::member(wsrep::id(own_id),
"name", ""));
wsrep::view bootstrap_view(state_id,
wsrep::seqno(1),
wsrep::view::primary,
0,
0,
1,
members);
server_state::on_connect(bootstrap_view);
}
else
{
assert(0);
}
return ret;
}
int mock_connect()
{
return mock_connect(name(), "cluster", "local", "0", false);
}
private:
wsrep::default_mutex mutex_;
wsrep::default_condition_variable cond_;

View File

@ -23,11 +23,11 @@
namespace
{
struct applying_server_fixture
struct server_fixture_base
{
applying_server_fixture()
server_fixture_base()
: server_service(ss)
, ss("s1", "s1",
, ss("s1",
wsrep::server_state::rm_sync, server_service)
, cc(ss,
wsrep::client_id(1),
@ -52,19 +52,28 @@ namespace
wsrep::ws_meta ws_meta;
};
struct sst_first_server_fixture : applying_server_fixture
struct applying_server_fixture : server_fixture_base
{
applying_server_fixture()
: server_fixture_base()
{
ss.mock_connect();
}
};
struct sst_first_server_fixture : server_fixture_base
{
sst_first_server_fixture()
: applying_server_fixture()
: server_fixture_base()
{
server_service.sst_before_init_ = true;
}
};
struct init_first_server_fixture : applying_server_fixture
struct init_first_server_fixture : server_fixture_base
{
init_first_server_fixture()
: applying_server_fixture()
: server_fixture_base()
{
server_service.sst_before_init_ = false;
}
@ -194,7 +203,7 @@ BOOST_FIXTURE_TEST_CASE(server_state_sst_first_boostrap,
1,
members);
BOOST_REQUIRE(ss.connect("cluster", "local", "0", false) == 0);
ss.on_connect(wsrep::gtid(cluster_id, wsrep::seqno(0)));
ss.on_connect(bootstrap_view);
BOOST_REQUIRE(ss.state() == wsrep::server_state::s_connected);
server_service.sync_point_enabled_ = "on_view_wait_initialized";
server_service.sync_point_action_ = server_service.spa_initialize;
@ -222,7 +231,7 @@ BOOST_FIXTURE_TEST_CASE(server_state_init_first_boostrap,
ss.initialized();
BOOST_REQUIRE(ss.state() == wsrep::server_state::s_initialized);
BOOST_REQUIRE(ss.connect("cluster", "local", "0", false) == 0);
ss.on_connect(wsrep::gtid(cluster_id, wsrep::seqno(0)));
ss.on_connect(bootstrap_view);
BOOST_REQUIRE(ss.state() == wsrep::server_state::s_connected);
ss.on_view(bootstrap_view, &hps);
BOOST_REQUIRE(ss.state() == wsrep::server_state::s_joined);