Skip to content

Commit

Permalink
Internal: Change consistent_snapshot_tid() interface
Browse files Browse the repository at this point in the history
In many places the snapshot_tid() was only used in verbosery.
Don't save it on the stack for that. And just return the tid itself.
  • Loading branch information
kohler committed Oct 22, 2013
1 parent 6935d5a commit 644d655
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
5 changes: 0 additions & 5 deletions txn.h
Expand Up @@ -734,11 +734,6 @@ class transaction : public transaction_base {
*/
bool can_overwrite_record_tid(tid_t prev, tid_t cur) const;

/**
* XXX: document
*/
std::pair<bool, tid_t> consistent_snapshot_tid() const;

inline string_allocator_type &
string_allocator()
{
Expand Down
18 changes: 7 additions & 11 deletions txn_impl.h
Expand Up @@ -254,7 +254,6 @@ transaction<Protocol, Traits>::commit(bool doThrow)
}

dbtuple_write_info_vec write_dbtuples;
const std::pair<bool, tid_t> snapshot_tid_t = cast()->consistent_snapshot_tid();
std::pair<bool, tid_t> commit_tid(false, 0);

// copy write tuples to vector for sorting
Expand All @@ -273,11 +272,10 @@ transaction<Protocol, Traits>::commit(bool doThrow)
}

// read_only txns require consistent snapshots
INVARIANT(!is_snapshot() || snapshot_tid_t.first);
INVARIANT(!is_snapshot() || read_set.empty());
INVARIANT(!is_snapshot() || write_set.empty());
INVARIANT(!is_snapshot() || absent_set.empty());
if (!snapshot_tid_t.first || !write_dbtuples.empty()) {
if (!is_snapshot()) {
// we don't have consistent tids, or not a read-only txn

// lock write nodes
Expand Down Expand Up @@ -348,7 +346,7 @@ transaction<Protocol, Traits>::commit(bool doThrow)
for (; it != it_end; ++it) {
VERBOSE(std::cerr << "validating dbtuple " << util::hexify(it->get_tuple())
<< " at snapshot_tid "
<< g_proto_version_str(snapshot_tid_t.second)
<< g_proto_version_str(cast()->snapshot_tid())
<< std::endl);
const bool found = sorted_dbtuples_contains(
write_dbtuples, it->get_tuple());
Expand All @@ -358,7 +356,7 @@ transaction<Protocol, Traits>::commit(bool doThrow)
continue;

VERBOSE(std::cerr << "validating dbtuple " << util::hexify(it->get_tuple()) << " at snapshot_tid "
<< g_proto_version_str(snapshot_tid_t.second) << " FAILED" << std::endl
<< g_proto_version_str(cast()->snapshot_tid()) << " FAILED" << std::endl
<< " txn read version: " << g_proto_version_str(it->get_tid()) << std::endl
<< " tuple=" << *it->get_tuple() << std::endl);

Expand Down Expand Up @@ -460,8 +458,8 @@ transaction<Protocol, Traits>::commit(bool doThrow)

do_abort:
// XXX: these values are possibly un-initialized
if (snapshot_tid_t.first)
VERBOSE(std::cerr << "aborting txn @ snapshot_tid " << snapshot_tid_t.second << std::endl);
if (this->is_snapshot())
VERBOSE(std::cerr << "aborting txn @ snapshot_tid " << cast()->snapshot_tid() << std::endl);
else
VERBOSE(std::cerr << "aborting txn" << std::endl);

Expand Down Expand Up @@ -572,11 +570,9 @@ transaction<Protocol, Traits>::do_tuple_read(
INVARIANT(tuple);
++evt_local_search_lookups;

const std::pair<bool, transaction_base::tid_t> snapshot_tid_t =
cast()->consistent_snapshot_tid();
const transaction_base::tid_t snapshot_tid = snapshot_tid_t.first ?
snapshot_tid_t.second : static_cast<transaction_base::tid_t>(dbtuple::MAX_TID);
const bool is_snapshot_txn = is_snapshot();
const transaction_base::tid_t snapshot_tid = is_snapshot_txn ?
cast()->snapshot_tid() : static_cast<transaction_base::tid_t>(dbtuple::MAX_TID);
transaction_base::tid_t start_t = 0;

if (Traits::read_own_writes) {
Expand Down
22 changes: 9 additions & 13 deletions txn_proto2_impl.h
Expand Up @@ -949,22 +949,18 @@ class transaction_proto2 : public transaction<transaction_proto2, Traits>,
return this->get_flags() & transaction_base::TXN_FLAG_READ_ONLY;
}

inline std::pair<bool, transaction_base::tid_t>
consistent_snapshot_tid() const
inline transaction_base::tid_t
snapshot_tid() const
{
if (this->is_snapshot()) {
#ifdef PROTO2_CAN_DISABLE_SNAPSHOTS
if (!IsSnapshotsEnabled())
// when snapshots are disabled, but we have a RO txn, we simply allow
// it to read all the latest values and treat them as consistent
//
// it's not correct, but its for the factor analysis
return std::make_pair(true, dbtuple::MAX_TID);
if (!IsSnapshotsEnabled())
// when snapshots are disabled, but we have a RO txn, we simply allow
// it to read all the latest values and treat them as consistent
//
// it's not correct, but its for the factor analysis
return dbtuple::MAX_TID;
#endif
return std::make_pair(true, last_consistent_tid);
} else {
return std::make_pair(false, 0);
}
return last_consistent_tid;
}

void
Expand Down

0 comments on commit 644d655

Please sign in to comment.