![]() |
TrinityCore
|
#include <DatabaseWorkerPool.h>
Classes | |
struct | QueueSizeTracker |
Public Types | |
typedef T::Statements | PreparedStatementIndex |
Public Member Functions | |
DatabaseWorkerPool () | |
~DatabaseWorkerPool () | |
void | SetConnectionInfo (std::string const &infoString, uint8 const asyncThreads, uint8 const synchThreads) |
uint32 | Open () |
void | Close () |
bool | PrepareStatements () |
Prepares all prepared statements. More... | |
MySQLConnectionInfo const * | GetConnectionInfo () const |
void | Execute (char const *sql) |
template<typename... Args> | |
void | PExecute (Trinity::FormatString< Args... > sql, Args &&... args) |
void | Execute (PreparedStatement< T > *stmt) |
void | DirectExecute (char const *sql) |
template<typename... Args> | |
void | DirectPExecute (Trinity::FormatString< Args... > sql, Args &&... args) |
void | DirectExecute (PreparedStatement< T > *stmt) |
QueryResult | Query (char const *sql, T *connection=nullptr) |
template<typename... Args> | |
QueryResult | PQuery (Trinity::FormatString< Args... > sql, T *conn, Args &&... args) |
template<typename... Args> | |
QueryResult | PQuery (Trinity::FormatString< Args... > sql, Args &&... args) |
PreparedQueryResult | Query (PreparedStatement< T > *stmt) |
QueryCallback | AsyncQuery (char const *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, char const *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... | |
size_t | QueueSize () const |
Static Public Member Functions | |
static void | WarnAboutSyncQueries (bool warn) |
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) |
T * | GetFreeConnection () |
T * | GetAsyncConnectionForCurrentThread () const |
char const * | GetDatabaseName () const |
Private Attributes | |
friend | QueueSizeTracker |
std::unique_ptr< Trinity::Asio::IoContext > | _ioContext |
Queue shared by async worker threads. More... | |
std::atomic< size_t > | _queueSize |
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 |
Definition at line 33 of file DatabaseWorkerPool.h.
typedef T::Statements DatabaseWorkerPool< T >::PreparedStatementIndex |
Other
Definition at line 194 of file DatabaseWorkerPool.h.
|
private |
Enumerator | |
---|---|
IDX_ASYNC | |
IDX_SYNCH | |
IDX_SIZE |
Definition at line 36 of file DatabaseWorkerPool.h.
DatabaseWorkerPool< T >::DatabaseWorkerPool |
Definition at line 112 of file DatabaseWorkerPool.cpp.
DatabaseWorkerPool< T >::~DatabaseWorkerPool |
Definition at line 127 of file DatabaseWorkerPool.cpp.
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.
Definition at line 334 of file DatabaseWorkerPool.cpp.
QueryCallback DatabaseWorkerPool< T >::AsyncQuery | ( | char const * | 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.
Definition at line 268 of file DatabaseWorkerPool.cpp.
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.
Definition at line 279 of file DatabaseWorkerPool.cpp.
SQLTransaction< T > DatabaseWorkerPool< T >::BeginTransaction |
Begins an automanaged transaction pointer that will automatically rollback if not commited. (Autocommit=0)
Transaction context methods.
Definition at line 301 of file DatabaseWorkerPool.cpp.
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.
Definition at line 173 of file DatabaseWorkerPool.cpp.
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.
Definition at line 307 of file DatabaseWorkerPool.cpp.
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.
Definition at line 290 of file DatabaseWorkerPool.cpp.
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.
Definition at line 362 of file DatabaseWorkerPool.cpp.
void DatabaseWorkerPool< T >::DirectExecute | ( | char const * | 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.
Definition at line 565 of file DatabaseWorkerPool.cpp.
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
Definition at line 576 of file DatabaseWorkerPool.cpp.
|
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.
Definition at line 97 of file DatabaseWorkerPool.h.
|
private |
Definition at line 485 of file DatabaseWorkerPool.cpp.
void DatabaseWorkerPool< T >::EscapeString | ( | std::string & | str | ) |
Apply escape string'ing for current collation. (utf8)
Definition at line 398 of file DatabaseWorkerPool.cpp.
void DatabaseWorkerPool< T >::Execute | ( | char const * | 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.
Definition at line 542 of file DatabaseWorkerPool.cpp.
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.
Definition at line 555 of file DatabaseWorkerPool.cpp.
void DatabaseWorkerPool< T >::ExecuteOrAppend | ( | SQLTransaction< T > & | trans, |
char const * | 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.
Definition at line 587 of file DatabaseWorkerPool.cpp.
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.
Definition at line 596 of file DatabaseWorkerPool.cpp.
|
private |
Definition at line 525 of file DatabaseWorkerPool.cpp.
|
inline |
|
private |
Definition at line 536 of file DatabaseWorkerPool.cpp.
|
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
Definition at line 500 of file DatabaseWorkerPool.cpp.
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.
Definition at line 392 of file DatabaseWorkerPool.cpp.
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.
Definition at line 410 of file DatabaseWorkerPool.cpp.
uint32 DatabaseWorkerPool< T >::Open |
Definition at line 142 of file DatabaseWorkerPool.cpp.
|
private |
Definition at line 445 of file DatabaseWorkerPool.cpp.
|
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.
Definition at line 74 of file DatabaseWorkerPool.h.
|
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.
Definition at line 131 of file DatabaseWorkerPool.h.
|
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.
Definition at line 120 of file DatabaseWorkerPool.h.
bool DatabaseWorkerPool< T >::PrepareStatements |
Prepares all prepared statements.
Definition at line 199 of file DatabaseWorkerPool.cpp.
QueryResult DatabaseWorkerPool< T >::Query | ( | char const * | sql, |
T * | connection = nullptr |
||
) |
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.
Definition at line 243 of file DatabaseWorkerPool.cpp.
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
Definition at line 255 of file DatabaseWorkerPool.cpp.
size_t DatabaseWorkerPool< T >::QueueSize |
Definition at line 494 of file DatabaseWorkerPool.cpp.
void DatabaseWorkerPool< T >::SetConnectionInfo | ( | std::string const & | infoString, |
uint8 const | asyncThreads, | ||
uint8 const | synchThreads | ||
) |
|
inlinestatic |
Definition at line 210 of file DatabaseWorkerPool.h.
|
private |
Definition at line 237 of file DatabaseWorkerPool.h.
|
private |
Definition at line 235 of file DatabaseWorkerPool.h.
|
private |
Definition at line 234 of file DatabaseWorkerPool.h.
|
private |
Queue shared by async worker threads.
Definition at line 232 of file DatabaseWorkerPool.h.
|
private |
Definition at line 236 of file DatabaseWorkerPool.h.
|
private |
Definition at line 233 of file DatabaseWorkerPool.h.
|
private |
Definition at line 237 of file DatabaseWorkerPool.h.
|
private |
Definition at line 229 of file DatabaseWorkerPool.h.