[11059] Fix crash in [11054]. As it turned out - we use not only async transactions but async queries too during server startup =/

Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
Ambal 2011-01-21 22:11:26 +02:00
parent 24164ef020
commit d67219e327
5 changed files with 17 additions and 10 deletions

View file

@ -199,9 +199,9 @@ int Master::Run()
//server loaded successfully => enable async DB requests //server loaded successfully => enable async DB requests
//this is done to forbid any async transactions during server startup! //this is done to forbid any async transactions during server startup!
CharacterDatabase.InitDelayThread(); CharacterDatabase.AllowAsyncTransactions();
WorldDatabase.InitDelayThread(); WorldDatabase.AllowAsyncTransactions();
LoginDatabase.InitDelayThread(); LoginDatabase.AllowAsyncTransactions();
///- Catch termination signals ///- Catch termination signals
_HookSignals(); _HookSignals();

View file

@ -288,7 +288,7 @@ extern int main(int argc, char **argv)
#endif #endif
//server has started up successfully => enable async DB requests //server has started up successfully => enable async DB requests
LoginDatabase.InitDelayThread(); LoginDatabase.AllowAsyncTransactions();
// maximum counter for next ping // maximum counter for next ping
uint32 numLoops = (sConfig.GetIntDefault( "MaxPingTime", 30 ) * (MINUTE * 1000000 / 100000)); uint32 numLoops = (sConfig.GetIntDefault( "MaxPingTime", 30 ) * (MINUTE * 1000000 / 100000));

View file

@ -75,6 +75,8 @@ bool Database::Initialize(const char * infoString, int nConns /*= 1*/)
return false; return false;
m_pResultQueue = new SqlResultQueue; m_pResultQueue = new SqlResultQueue;
InitDelayThread();
return true; return true;
} }
@ -277,7 +279,7 @@ bool Database::Execute(const char *sql)
else else
{ {
//if async execution is not available //if async execution is not available
if(!m_threadBody) if(!m_bAllowAsyncTransactions)
return DirectExecute(sql); return DirectExecute(sql);
// Simple sql statement // Simple sql statement
@ -363,7 +365,7 @@ bool Database::CommitTransaction()
return false; return false;
//if async execution is not available //if async execution is not available
if(!m_delayThread) if(!m_bAllowAsyncTransactions)
return CommitTransactionDirect(); return CommitTransactionDirect();
//add SqlTransaction to the async queue //add SqlTransaction to the async queue

View file

@ -82,8 +82,6 @@ class MANGOS_DLL_SPEC Database
virtual bool Initialize(const char *infoString, int nConns = 1); virtual bool Initialize(const char *infoString, int nConns = 1);
//start worker thread for async DB request execution //start worker thread for async DB request execution
//you should call it explicitly after your server successfully started up
//NO ASYNC TRANSACTIONS DURING SERVER STARTUP - ONLY DURING RUNTIME!!!
virtual void InitDelayThread(); virtual void InitDelayThread();
//stop worker thread //stop worker thread
virtual void HaltDelayThread(); virtual void HaltDelayThread();
@ -178,9 +176,14 @@ class MANGOS_DLL_SPEC Database
//function to ping database connections //function to ping database connections
void Ping(); void Ping();
//set this to allow async transactions
//you should call it explicitly after your server successfully started up
//NO ASYNC TRANSACTIONS DURING SERVER STARTUP - ONLY DURING RUNTIME!!!
void AllowAsyncTransactions() { m_bAllowAsyncTransactions = true; }
protected: protected:
Database() : m_pAsyncConn(NULL), m_pResultQueue(NULL), m_threadBody(NULL), m_delayThread(NULL), Database() : m_pAsyncConn(NULL), m_pResultQueue(NULL), m_threadBody(NULL), m_delayThread(NULL),
m_logSQL(false), m_pingIntervallms(0), m_nQueryConnPoolSize(1) m_logSQL(false), m_pingIntervallms(0), m_nQueryConnPoolSize(1), m_bAllowAsyncTransactions(false)
{ {
m_nQueryCounter = -1; m_nQueryCounter = -1;
} }
@ -239,6 +242,8 @@ class MANGOS_DLL_SPEC Database
SqlDelayThread * m_threadBody; ///< Pointer to delay sql executer (owned by m_delayThread) SqlDelayThread * m_threadBody; ///< Pointer to delay sql executer (owned by m_delayThread)
ACE_Based::Thread * m_delayThread; ///< Pointer to executer thread ACE_Based::Thread * m_delayThread; ///< Pointer to executer thread
bool m_bAllowAsyncTransactions; ///< flag which specifies if async transactions are enabled
private: private:
bool m_logSQL; bool m_logSQL;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11058" #define REVISION_NR "11059"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__