![]() |
AzerothCore 3.3.5a
OpenSource WoW Emulator
|
#include "ModuleDatabasePool.h"
Public Member Functions | |
| ModuleDatabasePool () | |
| virtual | ~ModuleDatabasePool () |
| void | SetConnectionInfo (std::string_view infoString, uint8 synchThreads) |
| void | SetConnectionInfo (std::string_view infoString, uint8 asyncThreads, uint8 synchThreads) |
| uint32 | Open () |
| bool | PrepareStatements () |
| Call once the schema is up to date. | |
| void | Close () |
| void | Execute (std::string_view sql) |
| void | DirectExecute (std::string_view sql) override |
| QueryResult | Query (std::string_view sql) override |
| MySQLConnectionInfo const * | GetConnectionInfo () const override |
| template<typename... Args> | |
| void | Execute (std::string_view sql, Args &&... args) |
| template<typename... Args> | |
| void | DirectExecute (std::string_view sql, Args &&... args) |
| template<typename... Args> | |
| QueryResult | Query (std::string_view sql, Args &&... args) |
| void | Execute (PreparedStatementBase *stmt) |
| These take ownership of the statement and delete it. | |
| void | DirectExecute (PreparedStatementBase *stmt) |
| PreparedQueryResult | Query (PreparedStatementBase *stmt) |
| QueryCallback | AsyncQuery (PreparedStatementBase *stmt) |
| QueryCallback | AsyncQuery (std::string_view sql) |
| SQLQueryHolderCallback | DelayQueryHolder (std::shared_ptr< SQLQueryHolderBase > holder) |
| uint8 | GetPreparedStatementParamCount (uint32 index) const |
| Returns 0 until PrepareStatements() has run. | |
| void | CommitTransaction (std::shared_ptr< TransactionBase > transaction) |
| TransactionCallback | AsyncCommitTransaction (std::shared_ptr< TransactionBase > transaction) |
| void | DirectCommitTransaction (std::shared_ptr< TransactionBase > transaction) |
| void | KeepAlive () |
| std::size_t | QueueSize () const |
| void | WarnAboutSyncQueries (bool warn) |
Public Member Functions inherited from DatabaseUpdatePool | |
| virtual | ~DatabaseUpdatePool ()=default |
Protected Member Functions | |
| virtual MySQLConnection * | CreateConnection (MySQLConnectionInfo &connInfo)=0 |
| virtual MySQLConnection * | CreateAsyncConnection (ProducerConsumerQueue< SQLOperation * > *queue, MySQLConnectionInfo &connInfo) |
Private Types | |
| enum | InternalIndex { IDX_ASYNC , IDX_SYNCH , IDX_SIZE } |
Private Member Functions | |
| uint32 | OpenConnections (InternalIndex type, uint8 numConnections) |
| void | Enqueue (SQLOperation *op) |
| bool | TryDirectCommitTransaction (std::shared_ptr< TransactionBase > transaction) |
| MySQLConnection * | GetFreeConnection () |
Private Attributes | |
| MySQLConnectionInfo | _connectionInfo |
| std::unique_ptr< ProducerConsumerQueue< SQLOperation * > > | _queue |
| std::array< std::vector< std::unique_ptr< MySQLConnection > >, IDX_SIZE > | _connections |
| std::vector< uint8 > | _preparedStatementSize |
| uint8 | _asyncThreads |
| uint8 | _synchThreads |
|
private |
| ModuleDatabasePool::ModuleDatabasePool | ( | ) |
| TransactionCallback ModuleDatabasePool::AsyncCommitTransaction | ( | std::shared_ptr< TransactionBase > | transaction | ) |
References _connections, Enqueue(), TransactionWithResultTask::GetFuture(), IDX_ASYNC, LOG_DEBUG, and TryDirectCommitTransaction().
| QueryCallback ModuleDatabasePool::AsyncQuery | ( | PreparedStatementBase * | stmt | ) |
References _connections, Enqueue(), PreparedStatementTask::GetFuture(), IDX_ASYNC, and Query().
| QueryCallback ModuleDatabasePool::AsyncQuery | ( | std::string_view | sql | ) |
References _connections, Enqueue(), BasicStatementTask::GetFuture(), IDX_ASYNC, and Query().
| void ModuleDatabasePool::Close | ( | ) |
References _connections, _preparedStatementSize, _queue, IDX_ASYNC, and IDX_SYNCH.
Referenced by Open(), PrepareStatements(), and ~ModuleDatabasePool().
| void ModuleDatabasePool::CommitTransaction | ( | std::shared_ptr< TransactionBase > | transaction | ) |
References _connections, DirectCommitTransaction(), Enqueue(), IDX_ASYNC, and LOG_DEBUG.
|
protectedvirtual |
Referenced by OpenConnections().
|
protectedpure virtual |
Referenced by OpenConnections().
| SQLQueryHolderCallback ModuleDatabasePool::DelayQueryHolder | ( | std::shared_ptr< SQLQueryHolderBase > | holder | ) |
References _connections, Enqueue(), SQLQueryHolderTask::Execute(), GetFreeConnection(), SQLQueryHolderTask::GetFuture(), IDX_ASYNC, IDX_SYNCH, SQLOperation::SetConnection(), and MySQLConnection::Unlock().
| void ModuleDatabasePool::DirectCommitTransaction | ( | std::shared_ptr< TransactionBase > | transaction | ) |
References TryDirectCommitTransaction().
Referenced by CommitTransaction().
| void ModuleDatabasePool::DirectExecute | ( | PreparedStatementBase * | stmt | ) |
References _connections, MySQLConnection::Execute(), GetFreeConnection(), IDX_SYNCH, and MySQLConnection::Unlock().
|
overridevirtual |
Implements DatabaseUpdatePool.
References _connections, MySQLConnection::Execute(), GetFreeConnection(), IDX_SYNCH, and MySQLConnection::Unlock().
|
inline |
References DatabaseUpdatePool::DirectExecute(), and Acore::StringFormat().
|
private |
References _queue.
Referenced by AsyncCommitTransaction(), AsyncQuery(), AsyncQuery(), CommitTransaction(), DelayQueryHolder(), Execute(), Execute(), and KeepAlive().
| void ModuleDatabasePool::Execute | ( | PreparedStatementBase * | stmt | ) |
These take ownership of the statement and delete it.
References _connections, DirectExecute(), Enqueue(), and IDX_ASYNC.
| void ModuleDatabasePool::Execute | ( | std::string_view | sql | ) |
References _connections, DirectExecute(), Enqueue(), and IDX_ASYNC.
|
inline |
References Acore::StringFormat().
|
overridevirtual |
|
private |
Block forever until a connection is free
Must be matched with connection->Unlock() or you will get deadlocks
References _connections, IDX_SYNCH, MySQLConnection::LockIfReady(), and LOG_WARN.
Referenced by DelayQueryHolder(), DirectExecute(), DirectExecute(), Query(), Query(), and TryDirectCommitTransaction().
Returns 0 until PrepareStatements() has run.
References _preparedStatementSize.
| void ModuleDatabasePool::KeepAlive | ( | ) |
References _connections, Enqueue(), IDX_ASYNC, and IDX_SYNCH.
| uint32 ModuleDatabasePool::Open | ( | ) |
References _asyncThreads, _connectionInfo, _connections, _preparedStatementSize, _queue, _synchThreads, Close(), MySQLConnectionInfo::database, IDX_ASYNC, IDX_SYNCH, LOG_ERROR, LOG_INFO, and OpenConnections().
|
private |
References _connectionInfo, _connections, _queue, CreateAsyncConnection(), CreateConnection(), MySQLConnectionInfo::database, IDX_ASYNC, and LOG_ERROR.
Referenced by Open().
| bool ModuleDatabasePool::PrepareStatements | ( | ) |
Call once the schema is up to date.
Without async connections every statement runs on a synchronous one, so CONNECTION_ASYNC-only ones fail.
References _connectionInfo, _connections, _preparedStatementSize, ASSERT, Close(), MySQLConnectionInfo::database, IDX_ASYNC, IDX_SYNCH, LOG_ERROR, and MySQLConnection::m_stmts.
| PreparedQueryResult ModuleDatabasePool::Query | ( | PreparedStatementBase * | stmt | ) |
Delete proxy-class. Not needed anymore
References _connections, GetFreeConnection(), PreparedResultSet::GetRowCount(), IDX_SYNCH, MySQLConnection::Query(), and MySQLConnection::Unlock().
|
overridevirtual |
Implements DatabaseUpdatePool.
References _connections, GetFreeConnection(), ResultSet::GetRowCount(), IDX_SYNCH, ResultSet::NextRow(), MySQLConnection::Query(), and MySQLConnection::Unlock().
Referenced by AsyncQuery(), and AsyncQuery().
|
inline |
References DatabaseUpdatePool::Query(), and Acore::StringFormat().
| std::size_t ModuleDatabasePool::QueueSize | ( | ) | const |
| void ModuleDatabasePool::SetConnectionInfo | ( | std::string_view | infoString, |
| uint8 | asyncThreads, | ||
| uint8 | synchThreads | ||
| ) |
References _asyncThreads, _connectionInfo, and _synchThreads.
| void ModuleDatabasePool::SetConnectionInfo | ( | std::string_view | infoString, |
| uint8 | synchThreads | ||
| ) |
References SetConnectionInfo().
Referenced by SetConnectionInfo().
|
private |
Handle MySQL Errno 1213 without extending deadlock to the core itself
References _connections, MySQLConnection::ExecuteTransaction(), GetFreeConnection(), IDX_SYNCH, and MySQLConnection::Unlock().
Referenced by AsyncCommitTransaction(), and DirectCommitTransaction().
| void ModuleDatabasePool::WarnAboutSyncQueries | ( | bool | warn | ) |
|
private |
Referenced by Open(), and SetConnectionInfo().
|
private |
Referenced by GetConnectionInfo(), Open(), OpenConnections(), PrepareStatements(), and SetConnectionInfo().
|
private |
Referenced by AsyncCommitTransaction(), AsyncQuery(), AsyncQuery(), Close(), CommitTransaction(), DelayQueryHolder(), DirectExecute(), DirectExecute(), Execute(), Execute(), GetFreeConnection(), KeepAlive(), Open(), OpenConnections(), PrepareStatements(), Query(), Query(), and TryDirectCommitTransaction().
|
private |
Referenced by Close(), GetPreparedStatementParamCount(), Open(), and PrepareStatements().
|
private |
Referenced by Close(), Enqueue(), Open(), OpenConnections(), QueueSize(), and ~ModuleDatabasePool().
|
private |
Referenced by Open(), and SetConnectionInfo().