Completely removed the transaction checker in release (which was here but as a noop checker)
This commit is contained in:
@@ -18,12 +18,15 @@ add_library(lmsdatabase SHARED
|
|||||||
impl/SqlQuery.cpp
|
impl/SqlQuery.cpp
|
||||||
impl/Track.cpp
|
impl/Track.cpp
|
||||||
impl/TrackBookmark.cpp
|
impl/TrackBookmark.cpp
|
||||||
impl/TransactionChecker.cpp
|
|
||||||
impl/Types.cpp
|
impl/Types.cpp
|
||||||
impl/User.cpp
|
impl/User.cpp
|
||||||
impl/Utils.cpp
|
impl/Utils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||||
|
target_sources(lmsdatabase PRIVATE impl/TransactionChecker.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(lmsdatabase INTERFACE
|
target_include_directories(lmsdatabase INTERFACE
|
||||||
include
|
include
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -53,26 +53,34 @@ namespace lms::db
|
|||||||
: _lock{ mutex },
|
: _lock{ mutex },
|
||||||
_transaction{ session }
|
_transaction{ session }
|
||||||
{
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
TransactionChecker::pushWriteTransaction(_transaction.session());
|
TransactionChecker::pushWriteTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteTransaction::~WriteTransaction()
|
WriteTransaction::~WriteTransaction()
|
||||||
{
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
TransactionChecker::popWriteTransaction(_transaction.session());
|
TransactionChecker::popWriteTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
|
|
||||||
core::tracing::ScopedTrace _trace{ "Database", core::tracing::Level::Detailed, "CommitWriteTransaction" };
|
core::tracing::ScopedTrace _trace{ "Database", core::tracing::Level::Detailed, "Commit" };
|
||||||
_transaction.commit();
|
_transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadTransaction::ReadTransaction(Wt::Dbo::Session& session)
|
ReadTransaction::ReadTransaction(Wt::Dbo::Session& session)
|
||||||
: _transaction{ session }
|
: _transaction{ session }
|
||||||
{
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
TransactionChecker::pushReadTransaction(_transaction.session());
|
TransactionChecker::pushReadTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadTransaction::~ReadTransaction()
|
ReadTransaction::~ReadTransaction()
|
||||||
{
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
TransactionChecker::popReadTransaction(_transaction.session());
|
TransactionChecker::popReadTransaction(_transaction.session());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Session::Session(Db& db)
|
Session::Session(Db& db)
|
||||||
@@ -119,6 +127,7 @@ namespace lms::db
|
|||||||
// Initial creation case
|
// Initial creation case
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
auto transaction{ createWriteTransaction() };
|
||||||
_session.createTables();
|
_session.createTables();
|
||||||
LMS_LOG(DB, INFO, "Tables created");
|
LMS_LOG(DB, INFO, "Tables created");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,19 +19,13 @@
|
|||||||
|
|
||||||
#include "database/TransactionChecker.hpp"
|
#include "database/TransactionChecker.hpp"
|
||||||
|
|
||||||
|
static_assert(LMS_CHECK_TRANSACTION_ACCESSES, "File should be excluded from build");
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "database/Session.hpp"
|
#include "database/Session.hpp"
|
||||||
|
|
||||||
#if !defined(NDEBUG)
|
|
||||||
#define LMS_CHECK_TRANSACTION_ACCESSES 1
|
|
||||||
#else
|
|
||||||
#define LMS_CHECK_TRANSACTION_ACCESSES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace lms::db
|
namespace lms::db
|
||||||
{
|
{
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct StackEntry
|
struct StackEntry
|
||||||
@@ -42,7 +36,6 @@ namespace lms::db
|
|||||||
|
|
||||||
static thread_local std::vector<StackEntry> transactionStack;
|
static thread_local std::vector<StackEntry> transactionStack;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void TransactionChecker::pushWriteTransaction(Wt::Dbo::Session& session)
|
void TransactionChecker::pushWriteTransaction(Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
@@ -64,26 +57,21 @@ namespace lms::db
|
|||||||
popTransaction(TransactionType::Read, session);
|
popTransaction(TransactionType::Read, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::pushTransaction([[maybe_unused]] TransactionType type, [[maybe_unused]] Wt::Dbo::Session& session)
|
void TransactionChecker::pushTransaction(TransactionType type, Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
assert(transactionStack.empty() || transactionStack.back().session == &session);
|
assert(transactionStack.empty() || transactionStack.back().session == &session);
|
||||||
transactionStack.push_back(StackEntry{ type, &session });
|
transactionStack.push_back(StackEntry{ type, &session });
|
||||||
#endif // LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::popTransaction([[maybe_unused]] TransactionType type, [[maybe_unused]] Wt::Dbo::Session& session)
|
void TransactionChecker::popTransaction(TransactionType type, Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
#if LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
|
|
||||||
assert(!transactionStack.empty());
|
assert(!transactionStack.empty());
|
||||||
assert(transactionStack.back().type == type);
|
assert(transactionStack.back().type == type);
|
||||||
assert(transactionStack.back().session == &session);
|
assert(transactionStack.back().session == &session);
|
||||||
transactionStack.pop_back();
|
transactionStack.pop_back();
|
||||||
#endif // LMS_CHECK_TRANSACTION_ACCESSES
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::checkWriteTransaction([[maybe_unused]] Wt::Dbo::Session& session)
|
void TransactionChecker::checkWriteTransaction(Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
assert(!transactionStack.empty());
|
assert(!transactionStack.empty());
|
||||||
assert(transactionStack.back().type == TransactionType::Write);
|
assert(transactionStack.back().type == TransactionType::Write);
|
||||||
@@ -95,7 +83,7 @@ namespace lms::db
|
|||||||
checkWriteTransaction(session.getDboSession());
|
checkWriteTransaction(session.getDboSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionChecker::checkReadTransaction([[maybe_unused]] Wt::Dbo::Session& session)
|
void TransactionChecker::checkReadTransaction(Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
assert(!transactionStack.empty());
|
assert(!transactionStack.empty());
|
||||||
assert(transactionStack.back().session == &session);
|
assert(transactionStack.back().session == &session);
|
||||||
|
|||||||
@@ -39,10 +39,19 @@ namespace lms::db
|
|||||||
bool operator==(const ObjectPtr& other) const { return _obj == other._obj; }
|
bool operator==(const ObjectPtr& other) const { return _obj == other._obj; }
|
||||||
bool operator!=(const ObjectPtr& other) const { return other._obj != _obj; }
|
bool operator!=(const ObjectPtr& other) const { return other._obj != _obj; }
|
||||||
|
|
||||||
auto modify() { TransactionChecker::checkWriteTransaction(*_obj.session()); return _obj.modify(); }
|
auto modify()
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::checkWriteTransaction(*_obj.session());
|
||||||
|
#endif
|
||||||
|
return _obj.modify();
|
||||||
|
}
|
||||||
|
|
||||||
void remove()
|
void remove()
|
||||||
{
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
TransactionChecker::checkWriteTransaction(*_obj.session());
|
TransactionChecker::checkWriteTransaction(*_obj.session());
|
||||||
|
#endif
|
||||||
|
|
||||||
if (_obj->hasOnPreRemove())
|
if (_obj->hasOnPreRemove())
|
||||||
_obj.modify()->onPreRemove();
|
_obj.modify()->onPreRemove();
|
||||||
|
|||||||
@@ -71,8 +71,18 @@ namespace lms::db
|
|||||||
[[nodiscard]] WriteTransaction createWriteTransaction();
|
[[nodiscard]] WriteTransaction createWriteTransaction();
|
||||||
[[nodiscard]] ReadTransaction createReadTransaction();
|
[[nodiscard]] ReadTransaction createReadTransaction();
|
||||||
|
|
||||||
void checkWriteTransaction() { TransactionChecker::checkWriteTransaction(_session); }
|
void checkWriteTransaction()
|
||||||
void checkReadTransaction() { TransactionChecker::checkReadTransaction(_session); }
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::checkWriteTransaction(_session);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void checkReadTransaction()
|
||||||
|
{
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
TransactionChecker::checkReadTransaction(_session);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void analyze();
|
void analyze();
|
||||||
void optimize();
|
void optimize();
|
||||||
@@ -85,7 +95,7 @@ namespace lms::db
|
|||||||
template <typename Object, typename... Args>
|
template <typename Object, typename... Args>
|
||||||
typename Object::pointer create(Args&&... args)
|
typename Object::pointer create(Args&&... args)
|
||||||
{
|
{
|
||||||
TransactionChecker::checkWriteTransaction(_session);
|
checkWriteTransaction();
|
||||||
|
|
||||||
typename Object::pointer res{ Object::create(*this, std::forward<Args>(args)...) };
|
typename Object::pointer res{ Object::create(*this, std::forward<Args>(args)...) };
|
||||||
getDboSession().flush();
|
getDboSession().flush();
|
||||||
|
|||||||
@@ -19,6 +19,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
#define LMS_CHECK_TRANSACTION_ACCESSES 1
|
||||||
|
#else
|
||||||
|
#define LMS_CHECK_TRANSACTION_ACCESSES 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LMS_CHECK_TRANSACTION_ACCESSES
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <Wt/Dbo/Session.h>
|
#include <Wt/Dbo/Session.h>
|
||||||
|
|
||||||
@@ -50,4 +58,6 @@ namespace lms::db
|
|||||||
static void pushTransaction(TransactionType type, Wt::Dbo::Session& session);
|
static void pushTransaction(TransactionType type, Wt::Dbo::Session& session);
|
||||||
static void popTransaction(TransactionType type, Wt::Dbo::Session& session);
|
static void popTransaction(TransactionType type, Wt::Dbo::Session& session);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user