Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple rollbacks #148

Merged
merged 7 commits into from
Sep 11, 2013
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions doc/ref_cpp/data/shared_group_ref.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ CATEGORIES:
SUMMARY : &g_shared_group_rollback_summary
Rollback a transaction.
DESCR : &g_shared_group_rollback_descr
This method closes a transaction and discards all changes done to the shared group.
This method closes a transaction and discards all changes done to the shared group,
unless a commit has already been done. It is ok to call rollback multiple times.
Any additional calls to rollback following a commit or rollback are treated as no-ops.
EXAMPLES:
- CODE : ex_cpp_shared_group_rollback
DESCR :
Expand Down Expand Up @@ -297,7 +299,9 @@ CATEGORIES:
- g_shared_group_end_read:
NAMES : end_read
SUMMARY : &g_shared_group_end_read_summary
Terminate read transaction.
Terminate read transaction. It is ok to call end_read multiple times, the
first call will terminate the transaction. Any additional calls are treated
as no-ops
DESCR : &g_shared_group_end_read_descr
This method terminates the read transaction.
EXAMPLES:
Expand Down
22 changes: 13 additions & 9 deletions src/tightdb/group_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ const Group& SharedGroup::begin_read()

void SharedGroup::end_read() TIGHTDB_NOEXCEPT
{
if (!m_group.is_attached()) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return should be on seperate line. (aids debugging and visual flow)


TIGHTDB_ASSERT(m_transact_stage == transact_Reading);
TIGHTDB_ASSERT(m_version != numeric_limits<size_t>::max());

Expand Down Expand Up @@ -480,24 +482,26 @@ void SharedGroup::commit()
// rollback() does not handle all cases.
void SharedGroup::rollback() TIGHTDB_NOEXCEPT
{
TIGHTDB_ASSERT(m_transact_stage == transact_Writing);
if (m_group.is_attached()) {
TIGHTDB_ASSERT(m_transact_stage == transact_Writing);

#ifdef TIGHTDB_ENABLE_REPLICATION
if (Replication* repl = m_group.get_replication())
repl->rollback_write_transact(*this);
if (Replication* repl = m_group.get_replication())
repl->rollback_write_transact(*this);
#endif

SharedInfo* info = m_file_map.get_addr();
SharedInfo* info = m_file_map.get_addr();

// Release write lock
info->writemutex.unlock();
// Release write lock
info->writemutex.unlock();

// Clear all changes made during transaction
m_group.detach();
// Clear all changes made during transaction
m_group.detach();

#ifdef TIGHTDB_DEBUG
m_transact_stage = transact_Ready;
m_transact_stage = transact_Ready;
#endif
}
}


Expand Down
17 changes: 17 additions & 0 deletions test/test_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1322,3 +1322,20 @@ TEST(Shared_MixedWithNonShared)
}
File::remove("test.tightdb");
}


TEST(MultipleRollbacks)
{
SharedGroup sg("test.tightdb");
sg.begin_write();
sg.rollback();
sg.rollback();
}

TEST(MultipleEndReads)
{
SharedGroup sg("test.tightdb");
sg.begin_read();
sg.end_read();
sg.end_read();
}