diff --git a/src/db/db/dbManager.cc b/src/db/db/dbManager.cc index a44fc1195..c767db149 100644 --- a/src/db/db/dbManager.cc +++ b/src/db/db/dbManager.cc @@ -146,15 +146,24 @@ Manager::last_transaction_id () const void Manager::cancel () { + // equivalent to commit and undo. But takes care that an empty commit is not followed by undo + // (which would undo the previous transaction!) if (db::transactions_enabled ()) { - // commit and undo - revert changes done so far - commit (); - undo (); + tl_assert (m_opened); + tl_assert (! m_replay); + m_opened = false; - // delete all following transactions - erase_transactions (m_current, m_transactions.end ()); - m_current = m_transactions.end (); + if (m_current->first.begin () != m_current->first.end ()) { + + ++m_current; + undo (); + + } else { + // empty transactions .. just delete + erase_transactions (m_current, m_transactions.end ()); + m_current = m_transactions.end (); + } } }