Skip to content

Commit d4efa59

Browse files
committed
Added is_empty() method to transaction class
Method is_empty() can be determined if there have no been changes to the transaction.
1 parent 5391de0 commit d4efa59

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

include/wsrep/sr_key_set.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace wsrep
5151

5252
const branch_type& root() const { return root_; }
5353
void clear() { root_.clear(); }
54+
bool empty() const { return root_.empty(); }
5455
private:
5556
branch_type root_;
5657
};

include/wsrep/transaction.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ namespace wsrep
9898
return (streaming_context_.fragments_certified() > 0);
9999
}
100100

101+
/**
102+
* Return true if transaction has not generated any changes.
103+
*/
104+
bool is_empty() const
105+
{
106+
return sr_keys_.empty();
107+
}
108+
101109
bool pa_unsafe() const { return pa_unsafe_; }
102110
void pa_unsafe(bool pa_unsafe) { pa_unsafe_ = pa_unsafe; }
103111

src/transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,6 @@ int wsrep::transaction::certify_commit(
12291229
append_sr_keys_for_commit();
12301230
flags(flags() | wsrep::provider::flag::pa_unsafe);
12311231
}
1232-
sr_keys_.clear();
12331232

12341233
flags(flags() | wsrep::provider::flag::commit);
12351234

@@ -1462,6 +1461,7 @@ void wsrep::transaction::cleanup()
14621461
flags_ = 0;
14631462
certified_ = false;
14641463
pa_unsafe_ = false;
1464+
sr_keys_.clear();
14651465
streaming_context_.cleanup();
14661466
client_service_.cleanup_transaction();
14671467
debug_log_state("cleanup_leave");

test/transaction_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ BOOST_FIXTURE_TEST_CASE(transaction_append_key_data,
3838
{
3939
cc.start_transaction(wsrep::transaction_id(1));
4040
BOOST_REQUIRE(tc.active());
41+
BOOST_REQUIRE(tc.is_empty());
4142
int vals[3] = {1, 2, 3};
4243
wsrep::key key(wsrep::key::exclusive);
4344
for (int i(0); i < 3; ++i)
4445
{
4546
key.append_key_part(&vals[i], sizeof(vals[i]));
4647
}
4748
BOOST_REQUIRE(cc.append_key(key) == 0);
49+
BOOST_REQUIRE(tc.is_empty() == false);
4850
wsrep::const_buffer data(&vals[2], sizeof(vals[2]));
4951
BOOST_REQUIRE(cc.append_data(data) == 0);
5052
BOOST_REQUIRE(cc.before_commit() == 0);

0 commit comments

Comments
 (0)