AzerothCore 3.3.5a
OpenSource WoW Emulator
|
#include "DatabaseWorkerPool.h"
Public Types | |
typedef T::Statements | PreparedStatementIndex |
Public Member Functions | |
DatabaseWorkerPool () | |
~DatabaseWorkerPool () | |
void | SetConnectionInfo (std::string_view infoString, uint8 const asyncThreads, uint8 const synchThreads) |
uint32 | Open () |
void | Close () |
bool | PrepareStatements () |
Prepares all prepared statements. More... | |
MySQLConnectionInfo const * | GetConnectionInfo () const |
void | Execute (std::string_view sql) |
template<typename... Args> | |
void | Execute (std::string_view sql, Args &&... args) |
void | Execute (PreparedStatement< T > *stmt) |
void | DirectExecute (std::string_view sql) |
template<typename... Args> | |
void | DirectExecute (std::string_view sql, Args &&... args) |
void | DirectExecute (PreparedStatement< T > *stmt) |
QueryResult | Query (std::string_view sql) |
template<typename... Args> | |
QueryResult | Query (std::string_view sql, Args &&... args) |
PreparedQueryResult | Query (PreparedStatement< T > *stmt) |
QueryCallback | AsyncQuery (std::string_view sql) |
QueryCallback | AsyncQuery (PreparedStatement< T > *stmt) |
SQLQueryHolderCallback | DelayQueryHolder (std::shared_ptr< SQLQueryHolder< T > > holder) |
SQLTransaction< T > | BeginTransaction () |
Begins an automanaged transaction pointer that will automatically rollback if not commited. (Autocommit=0) More... | |
void | CommitTransaction (SQLTransaction< T > transaction) |
TransactionCallback | AsyncCommitTransaction (SQLTransaction< T > transaction) |
void | DirectCommitTransaction (SQLTransaction< T > &transaction) |
void | ExecuteOrAppend (SQLTransaction< T > &trans, std::string_view sql) |
void | ExecuteOrAppend (SQLTransaction< T > &trans, PreparedStatement< T > *stmt) |
PreparedStatement< T > * | GetPreparedStatement (PreparedStatementIndex index) |
void | EscapeString (std::string &str) |
Apply escape string'ing for current collation. (utf8) More... | |
void | KeepAlive () |
Keeps all our MySQL connections alive, prevent the server from disconnecting us. More... | |
void | WarnAboutSyncQueries (bool warn) |
std::size_t | QueueSize () const |
Private Types | |
enum | InternalIndex { IDX_ASYNC , IDX_SYNCH , IDX_SIZE } |
Private Member Functions | |
uint32 | OpenConnections (InternalIndex type, uint8 numConnections) |
unsigned long | EscapeString (char *to, char const *from, unsigned long length) |
void | Enqueue (SQLOperation *op) |
T * | GetFreeConnection () |
std::string_view | GetDatabaseName () const |
Private Attributes | |
std::unique_ptr< ProducerConsumerQueue< SQLOperation * > > | _queue |
Queue shared by async worker threads. More... | |
std::array< std::vector< std::unique_ptr< T > >, IDX_SIZE > | _connections |
std::unique_ptr< MySQLConnectionInfo > | _connectionInfo |
std::vector< uint8 > | _preparedStatementSize |
uint8 | _async_threads |
uint8 | _synch_threads |
typedef T::Statements DatabaseWorkerPool< T >::PreparedStatementIndex |
Other
|
private |
DatabaseWorkerPool< T >::DatabaseWorkerPool |
References MIN_MYSQL_CLIENT_VERSION, and WPFatal.
DatabaseWorkerPool< T >::~DatabaseWorkerPool |
TransactionCallback DatabaseWorkerPool< T >::AsyncCommitTransaction | ( | SQLTransaction< T > | transaction | ) |
Enqueues a collection of one-way SQL operations (can be both adhoc and prepared). The order in which these operations were appended to the transaction will be respected during execution.
References TransactionWithResultTask::GetFuture(), and LOG_DEBUG.
QueryCallback DatabaseWorkerPool< T >::AsyncQuery | ( | PreparedStatement< T > * | stmt | ) |
Enqueues a query in prepared format that will set the value of the PreparedQueryResultFuture return object as soon as the query is executed. The return value is then processed in ProcessQueryCallback methods. Statement must be prepared with CONNECTION_ASYNC flag.
References PreparedStatementTask::GetFuture().
QueryCallback DatabaseWorkerPool< T >::AsyncQuery | ( | std::string_view | sql | ) |
Asynchronous query (with resultset) methods. Enqueues a query in string format that will set the value of the QueryResultFuture return object as soon as the query is executed. The return value is then processed in ProcessQueryCallback methods.
References BasicStatementTask::GetFuture().
SQLTransaction< T > DatabaseWorkerPool< T >::BeginTransaction |
Begins an automanaged transaction pointer that will automatically rollback if not commited. (Autocommit=0)
Transaction context methods.
void DatabaseWorkerPool< T >::Close |
Closes the actualy MySQL connection.
Shut down the synchronous connections There's no need for locking the connection, because DatabaseWorkerPool<>::Close should only be called after any other thread tasks in the core have exited, meaning there can be no concurrent access at this point.
References LOG_INFO.
Referenced by DatabaseLoader::AddDatabase().
void DatabaseWorkerPool< T >::CommitTransaction | ( | SQLTransaction< T > | transaction | ) |
Enqueues a collection of one-way SQL operations (can be both adhoc and prepared). The order in which these operations were appended to the transaction will be respected during execution.
References LOG_DEBUG.
SQLQueryHolderCallback DatabaseWorkerPool< T >::DelayQueryHolder | ( | std::shared_ptr< SQLQueryHolder< T > > | holder | ) |
Enqueues a vector of SQL operations (can be both adhoc and prepared) that will set the value of the QueryResultHolderFuture return object as soon as the query is executed. The return value is then processed in ProcessQueryCallback methods. Any prepared statements added to this holder need to be prepared with the CONNECTION_ASYNC flag.
References SQLQueryHolderTask::GetFuture().
void DatabaseWorkerPool< T >::DirectCommitTransaction | ( | SQLTransaction< T > & | transaction | ) |
Directly executes a collection of one-way SQL operations (can be both adhoc and prepared). The order in which these operations were appended to the transaction will be respected during execution.
Handle MySQL Errno 1213 without extending deadlock to the core itself
Clean up now.
void DatabaseWorkerPool< T >::DirectExecute | ( | PreparedStatement< T > * | stmt | ) |
Directly executes a one-way SQL operation in prepared statement format, that will block the calling thread until finished. Statement must be prepared with the CONNECTION_SYNCH flag.
Delete proxy-class. Not needed anymore
void DatabaseWorkerPool< T >::DirectExecute | ( | std::string_view | sql | ) |
Direct synchronous one-way statement methods. Directly executes a one-way SQL operation in string format, that will block the calling thread until finished. This method should only be used for queries that are only executed once, e.g during startup.
Referenced by DBUpdater< T >::Apply(), and DatabaseWorkerPool< T >::DirectExecute().
|
inline |
Directly executes a one-way SQL operation in string format -with variable args-, that will block the calling thread until finished. This method should only be used for queries that are only executed once, e.g during startup.
References DatabaseWorkerPool< T >::DirectExecute(), and Acore::StringFormat().
|
private |
|
private |
void DatabaseWorkerPool< T >::EscapeString | ( | std::string & | str | ) |
Apply escape string'ing for current collation. (utf8)
void DatabaseWorkerPool< T >::Execute | ( | PreparedStatement< T > * | stmt | ) |
Enqueues a one-way SQL operation in prepared statement format that will be executed asynchronously. Statement must be prepared with CONNECTION_ASYNC flag.
void DatabaseWorkerPool< T >::Execute | ( | std::string_view | sql | ) |
Delayed one-way statement methods. Enqueues a one-way SQL operation in string format that will be executed asynchronously. This method should only be used for queries that are only executed once, e.g during startup.
Referenced by DatabaseWorkerPool< T >::Execute().
|
inline |
Enqueues a one-way SQL operation in string format -with variable args- that will be executed asynchronously. This method should only be used for queries that are only executed once, e.g during startup.
References DatabaseWorkerPool< T >::Execute(), and Acore::StringFormat().
void DatabaseWorkerPool< T >::ExecuteOrAppend | ( | SQLTransaction< T > & | trans, |
PreparedStatement< T > * | stmt | ||
) |
Method used to execute prepared statements in a diverse context. Will be wrapped in a transaction if valid object is present, otherwise executed standalone.
void DatabaseWorkerPool< T >::ExecuteOrAppend | ( | SQLTransaction< T > & | trans, |
std::string_view | sql | ||
) |
Method used to execute ad-hoc statements in a diverse context. Will be wrapped in a transaction if valid object is present, otherwise executed standalone.
|
inline |
References DatabaseWorkerPool< T >::_connectionInfo.
Referenced by DBUpdater< T >::ApplyFile(), DBUpdater< T >::Create(), and DBUpdater< T >::Update().
|
private |
|
private |
Gets a free connection in the synchronous connection pool. Caller MUST call t->Unlock() after touching the MySQL context to prevent deadlocks.
Block forever until a connection is free
Must be matched with t->Unlock() or you will get deadlocks
References LOG_WARN.
PreparedStatement< T > * DatabaseWorkerPool< T >::GetPreparedStatement | ( | PreparedStatementIndex | index | ) |
Automanaged (internally) pointer to a prepared statement object for usage in upper level code. Pointer is deleted in this->DirectExecute(PreparedStatement*), this->Query(PreparedStatement*) or PreparedStatementTask::~PreparedStatementTask. This object is not tied to the prepared statement on the MySQL context yet until execution.
void DatabaseWorkerPool< T >::KeepAlive |
Keeps all our MySQL connections alive, prevent the server from disconnecting us.
Ping synchronous connections
Assuming all worker threads are free, every worker thread will receive 1 ping operation request If one or more worker threads are busy, the ping operations will not be split evenly, but this doesn't matter as the sole purpose is to prevent connections from idling.
uint32 DatabaseWorkerPool< T >::Open |
References LOG_INFO, and WPFatal.
Referenced by DatabaseLoader::AddDatabase().
|
private |
References ABORT, DatabaseIncompatibleVersion(), and LOG_ERROR.
bool DatabaseWorkerPool< T >::PrepareStatements |
Prepares all prepared statements.
Referenced by DatabaseLoader::AddDatabase().
PreparedQueryResult DatabaseWorkerPool< T >::Query | ( | PreparedStatement< T > * | stmt | ) |
Directly executes an SQL query in prepared format that will block the calling thread until finished. Returns reference counted auto pointer, no need for manual memory management in upper level code. Statement must be prepared with CONNECTION_SYNCH flag.
Delete proxy-class. Not needed anymore
References PreparedResultSet::GetRowCount().
QueryResult DatabaseWorkerPool< T >::Query | ( | std::string_view | sql | ) |
Synchronous query (with resultset) methods. Directly executes an SQL query in string format that will block the calling thread until finished. Returns reference counted auto pointer, no need for manual memory management in upper level code.
References ResultSet::GetRowCount(), and ResultSet::NextRow().
Referenced by DatabaseWorkerPool< T >::Query(), and DBUpdater< T >::Retrieve().
|
inline |
Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished. Returns reference counted auto pointer, no need for manual memory management in upper level code.
References DatabaseWorkerPool< T >::Query(), and Acore::StringFormat().
std::size_t DatabaseWorkerPool< T >::QueueSize |
void DatabaseWorkerPool< T >::SetConnectionInfo | ( | std::string_view | infoString, |
uint8 const | asyncThreads, | ||
uint8 const | synchThreads | ||
) |
Referenced by DatabaseLoader::AddDatabase().
|
inline |
|
private |
|
private |
Referenced by DatabaseWorkerPool< T >::GetConnectionInfo().
|
private |
|
private |
|
private |
Queue shared by async worker threads.
|
private |