1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-31 18:24:25 +03:00

NBO applying

- High priority interface method to apply NBO begin, separate from
  apply_toi() in order to avoid implementation to force interpreting
  ws_meta flags.
- Method to put client_state into NBO mode when applying NBO begin.
  The client_state will process in m_local mode.
- Unit tests for applying NBO
This commit is contained in:
Teemu Ollakka
2019-06-06 15:50:58 +03:00
parent 1267e29b8f
commit 85a03394cc
12 changed files with 182 additions and 9 deletions

View File

@ -66,3 +66,80 @@ BOOST_FIXTURE_TEST_CASE(test_local_nbo,
BOOST_REQUIRE(sc.provider().toi_start_transaction() == 1);
BOOST_REQUIRE(sc.provider().toi_commit() == 1);
}
// This test case operates through server_state object in order to
// verify that the high priority service is called with appropriate
// arguments.
BOOST_FIXTURE_TEST_CASE(test_applying_nbo,
applying_client_fixture)
{
wsrep::mock_high_priority_service hps(sc, &cc, false);
wsrep::ws_handle ws_handle(wsrep::transaction_id::undefined(), (void*)(1));
const int nbo_begin_flags(wsrep::provider::flag::start_transaction |
wsrep::provider::flag::isolation);
wsrep::ws_meta ws_meta(wsrep::gtid(wsrep::id("cluster1"),
wsrep::seqno(1)),
wsrep::stid(wsrep::id("s1"),
wsrep::transaction_id::undefined(),
wsrep::client_id(1)),
wsrep::seqno(0),
nbo_begin_flags);
std::string nbo_begin("nbo_begin");
BOOST_REQUIRE(sc.on_apply(hps, ws_handle, ws_meta,
wsrep::const_buffer(nbo_begin.data(),
nbo_begin.size())) == 0);
wsrep::mock_client* nbo_cs(hps.nbo_cs());
BOOST_REQUIRE(nbo_cs);
BOOST_REQUIRE(nbo_cs->toi_mode() == wsrep::client_state::m_local);
BOOST_REQUIRE(nbo_cs->mode() == wsrep::client_state::m_nbo);
// After this point the control is on local process and applier
// has released toi critical section.
wsrep::key key(wsrep::key::exclusive);
key.append_key_part("k1", 2);
key.append_key_part("k2", 2);
wsrep::key_array keys{key};
// Starting phase two should put nbo_cs in toi mode.
BOOST_REQUIRE(nbo_cs->begin_nbo_phase_two(keys) == 0);
BOOST_REQUIRE(nbo_cs->mode() == wsrep::client_state::m_nbo);
BOOST_REQUIRE(nbo_cs->in_toi());
BOOST_REQUIRE(nbo_cs->toi_mode() == wsrep::client_state::m_local);
// Ending phase two should make nbo_cs leave TOI mode and
// return to m_local mode.
BOOST_REQUIRE(nbo_cs->end_nbo_phase_two() == 0);
BOOST_REQUIRE(nbo_cs->mode() == wsrep::client_state::m_local);
BOOST_REQUIRE(nbo_cs->in_toi() == false);
BOOST_REQUIRE(nbo_cs->toi_mode() == wsrep::client_state::m_local);
// There must have been one toi write set with commit flag.
BOOST_REQUIRE(sc.provider().toi_write_sets() == 1);
BOOST_REQUIRE(sc.provider().toi_start_transaction() == 0);
BOOST_REQUIRE(sc.provider().toi_commit() == 1);
}
// This test case operates through server_state object in order to
// verify that the high priority service is called with appropriate
// arguments. The test checks that error is returned in the case if
// launching asynchronous process for NBO fails.
BOOST_FIXTURE_TEST_CASE(test_applying_nbo_fail,
applying_client_fixture)
{
wsrep::mock_high_priority_service hps(sc, &cc, false);
wsrep::ws_handle ws_handle(wsrep::transaction_id::undefined(), (void*)(1));
const int nbo_begin_flags(wsrep::provider::flag::start_transaction |
wsrep::provider::flag::isolation);
wsrep::ws_meta ws_meta(wsrep::gtid(wsrep::id("cluster1"),
wsrep::seqno(1)),
wsrep::stid(wsrep::id("s1"),
wsrep::transaction_id::undefined(),
wsrep::client_id(1)),
wsrep::seqno(0),
nbo_begin_flags);
std::string nbo_begin("nbo_begin");
hps.fail_next_toi_ = true;
BOOST_REQUIRE(sc.on_apply(hps, ws_handle, ws_meta,
wsrep::const_buffer(nbo_begin.data(),
nbo_begin.size())) == 1);
}