Skip to content

Commit 4285ff9

Browse files
committed
#100 Support for assign_read_view() wsrep API call
Marshall the call from the `client_state` interface down to provider.
1 parent e9dafb7 commit 4285ff9

File tree

9 files changed

+67
-3
lines changed

9 files changed

+67
-3
lines changed

include/wsrep/client_state.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,25 @@ namespace wsrep
270270
return transaction_.start_transaction(id);
271271
}
272272

273+
/**
274+
* Establish read view ID of the transaction.
275+
*
276+
* This method should be preferably called immediately before any
277+
* first read or write operation in the transaction is performed,
278+
* Then it can be called with default NULL parameter and will use
279+
* the current last committed GTID.
280+
* Alternatively it can be called at any time before commit with an
281+
* explicit GTID that corresponds to transaction read view.
282+
*
283+
* @param gtid optional explicit GTID of the transaction read view.
284+
*/
285+
int assign_read_view(const wsrep::gtid* const gtid = NULL)
286+
{
287+
assert(mode_ == m_local);
288+
assert(state_ == s_exec);
289+
return transaction_.assign_read_view(gtid);
290+
}
291+
273292
/**
274293
* Append a key into transaction write set.
275294
*/

include/wsrep/provider.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ namespace wsrep
274274
// Write set replication
275275
// TODO: Rename to assing_read_view()
276276
virtual int start_transaction(wsrep::ws_handle&) = 0;
277+
virtual enum status assign_read_view(
278+
wsrep::ws_handle&, const wsrep::gtid*) = 0;
277279
virtual int append_key(wsrep::ws_handle&, const wsrep::key&) = 0;
278280
virtual enum status append_data(
279281
wsrep::ws_handle&, const wsrep::const_buffer&) = 0;

include/wsrep/transaction.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ namespace wsrep
138138
const wsrep::ws_meta& ws_meta,
139139
bool is_commit);
140140

141+
int assign_read_view(const wsrep::gtid* gtid);
142+
141143
int append_key(const wsrep::key&);
142144

143145
int append_data(const wsrep::const_buffer&);

src/provider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ std::string wsrep::provider::capability::str(int caps)
7575
WSREP_PRINT_CAPABILITY(annotation, "ANNOTATION");
7676
WSREP_PRINT_CAPABILITY(preordered, "PREORDERED");
7777
WSREP_PRINT_CAPABILITY(streaming, "STREAMING");
78-
WSREP_PRINT_CAPABILITY(snapshot, "SNAPSHOT");
78+
WSREP_PRINT_CAPABILITY(snapshot, "READ_VIEW");
7979
WSREP_PRINT_CAPABILITY(nbo, "NBO");
8080

8181
#undef WSREP_PRINT_CAPABILITY
@@ -107,7 +107,7 @@ std::string wsrep::flags_to_string(int flags)
107107
if (flags & provider::flag::prepare)
108108
oss << "prepare | ";
109109
if (flags & provider::flag::snapshot)
110-
oss << "snapshot | ";
110+
oss << "read_view | ";
111111
if (flags & provider::flag::implicit_deps)
112112
oss << "implicit_deps | ";
113113

src/transaction.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ int wsrep::transaction::prepare_for_ordering(
208208
return 0;
209209
}
210210

211+
int wsrep::transaction::assign_read_view(const wsrep::gtid* const gtid)
212+
{
213+
try
214+
{
215+
return provider().assign_read_view(ws_handle_, gtid);
216+
}
217+
catch (...)
218+
{
219+
wsrep::log_error() << "Failed to assign read view";
220+
return 1;
221+
}
222+
}
223+
211224
int wsrep::transaction::append_key(const wsrep::key& key)
212225
{
213226
try

src/wsrep_provider_v26.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,25 @@ wsrep::wsrep_provider_v26::run_applier(
690690
return map_return_value(wsrep_->recv(wsrep_, applier_ctx));
691691
}
692692

693+
enum wsrep::provider::status
694+
wsrep::wsrep_provider_v26::assign_read_view(wsrep::ws_handle& ws_handle,
695+
const wsrep::gtid* gtid)
696+
{
697+
const wsrep_gtid_t* gtid_ptr(NULL);
698+
wsrep_gtid_t tmp;
699+
700+
if (gtid)
701+
{
702+
::memcpy(&tmp.uuid, gtid->id().data(), sizeof(tmp.uuid));
703+
tmp.seqno = gtid->seqno().get();
704+
gtid_ptr = &tmp;
705+
}
706+
707+
mutable_ws_handle mwsh(ws_handle);
708+
return map_return_value(wsrep_->assign_read_view(wsrep_, mwsh.native(),
709+
gtid_ptr));
710+
}
711+
693712
int wsrep::wsrep_provider_v26::append_key(wsrep::ws_handle& ws_handle,
694713
const wsrep::key& key)
695714
{
@@ -714,7 +733,7 @@ int wsrep::wsrep_provider_v26::append_key(wsrep::ws_handle& ws_handle,
714733

715734
enum wsrep::provider::status
716735
wsrep::wsrep_provider_v26::append_data(wsrep::ws_handle& ws_handle,
717-
const wsrep::const_buffer& data)
736+
const wsrep::const_buffer& data)
718737
{
719738
const wsrep_buf_t wsrep_buf = {data.data(), data.size()};
720739
mutable_ws_handle mwsh(ws_handle);

src/wsrep_provider_v26.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ namespace wsrep
4646

4747
enum wsrep::provider::status run_applier(wsrep::high_priority_service*);
4848
int start_transaction(wsrep::ws_handle&) { return 0; }
49+
enum wsrep::provider::status
50+
assign_read_view(wsrep::ws_handle&, const wsrep::gtid*);
4951
int append_key(wsrep::ws_handle&, const wsrep::key&);
5052
enum wsrep::provider::status
5153
append_data(wsrep::ws_handle&, const wsrep::const_buffer&);

test/mock_provider.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ namespace wsrep
143143
}
144144
}
145145

146+
enum wsrep::provider::status
147+
assign_read_view(wsrep::ws_handle&, const wsrep::gtid*)
148+
WSREP_OVERRIDE
149+
{ return wsrep::provider::success; }
146150
int append_key(wsrep::ws_handle&, const wsrep::key&)
147151
WSREP_OVERRIDE
148152
{ return 0; }

test/transaction_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(transaction_1pc, T,
6868
BOOST_REQUIRE(tc.id() == wsrep::transaction_id(1));
6969
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
7070

71+
// Establish default read view
72+
BOOST_REQUIRE(0 == cc.assign_read_view(NULL));
73+
7174
// Verify that the commit can be succesfully executed in separate command
7275
BOOST_REQUIRE(cc.after_statement() == 0);
7376
cc.after_command_before_result();

0 commit comments

Comments
 (0)