Core/DBLayer: Properly manage mysql library initialization and shutdown in authserver and worldserver. Prevent multiple calls and make it more elegant.
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool StartDB();
|
bool StartDB();
|
||||||
|
void StopDB();
|
||||||
|
|
||||||
bool stopEvent = false; // Setting it to true stops the server
|
bool stopEvent = false; // Setting it to true stops the server
|
||||||
|
|
||||||
@@ -235,8 +236,8 @@ extern int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the Database Pool
|
// Close the Database Pool and library
|
||||||
LoginDatabase.Close();
|
StopDB();
|
||||||
|
|
||||||
sLog->outString("Halting process...");
|
sLog->outString("Halting process...");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -245,6 +246,8 @@ extern int main(int argc, char **argv)
|
|||||||
// Initialize connection to the database
|
// Initialize connection to the database
|
||||||
bool StartDB()
|
bool StartDB()
|
||||||
{
|
{
|
||||||
|
MySQL::Library_Init();
|
||||||
|
|
||||||
std::string dbstring = sConfig->GetStringDefault("LoginDatabaseInfo", "");
|
std::string dbstring = sConfig->GetStringDefault("LoginDatabaseInfo", "");
|
||||||
if (dbstring.empty())
|
if (dbstring.empty())
|
||||||
{
|
{
|
||||||
@@ -275,3 +278,9 @@ bool StartDB()
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StopDB()
|
||||||
|
{
|
||||||
|
LoginDatabase.Close();
|
||||||
|
MySQL::Library_End();
|
||||||
|
}
|
||||||
@@ -58,14 +58,12 @@ class DatabaseWorkerPool
|
|||||||
memset(m_connectionCount, 0, sizeof(m_connectionCount));
|
memset(m_connectionCount, 0, sizeof(m_connectionCount));
|
||||||
m_connections.resize(IDX_SIZE);
|
m_connections.resize(IDX_SIZE);
|
||||||
|
|
||||||
mysql_library_init(-1, NULL, NULL);
|
|
||||||
WPFatal (mysql_thread_safe(), "Used MySQL library isn't thread-safe.");
|
WPFatal (mysql_thread_safe(), "Used MySQL library isn't thread-safe.");
|
||||||
}
|
}
|
||||||
|
|
||||||
~DatabaseWorkerPool()
|
~DatabaseWorkerPool()
|
||||||
{
|
{
|
||||||
sLog->outSQLDriver("~DatabaseWorkerPool for '%s'.", m_connectionInfo.database.c_str());
|
sLog->outSQLDriver("~DatabaseWorkerPool for '%s'.", m_connectionInfo.database.c_str());
|
||||||
mysql_library_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Open(const std::string& infoString, uint8 async_threads, uint8 synch_threads)
|
bool Open(const std::string& infoString, uint8 async_threads, uint8 synch_threads)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class MySQL
|
|||||||
static void Thread_Init()
|
static void Thread_Init()
|
||||||
{
|
{
|
||||||
mysql_thread_init();
|
mysql_thread_init();
|
||||||
printf("Core thread with ID ["UI64FMTD"] initializing MySQL thread.\n",
|
sLog->outSQLDriver("Core thread with ID ["UI64FMTD"] initializing MySQL thread.",
|
||||||
(uint64)ACE_Based::Thread::currentId());
|
(uint64)ACE_Based::Thread::currentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,9 +44,19 @@ class MySQL
|
|||||||
static void Thread_End()
|
static void Thread_End()
|
||||||
{
|
{
|
||||||
mysql_thread_end();
|
mysql_thread_end();
|
||||||
printf("Core thread with ID ["UI64FMTD"] shutting down MySQL thread.\n",
|
sLog->outSQLDriver("Core thread with ID ["UI64FMTD"] shutting down MySQL thread.",
|
||||||
(uint64)ACE_Based::Thread::currentId());
|
(uint64)ACE_Based::Thread::currentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Library_Init()
|
||||||
|
{
|
||||||
|
mysql_library_init(-1, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Library_End()
|
||||||
|
{
|
||||||
|
mysql_library_end();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -300,10 +300,7 @@ int Master::Run()
|
|||||||
///- Clean database before leaving
|
///- Clean database before leaving
|
||||||
clearOnlineAccounts();
|
clearOnlineAccounts();
|
||||||
|
|
||||||
///- Wait for delay threads to end
|
_StopDB();
|
||||||
CharacterDatabase.Close();
|
|
||||||
WorldDatabase.Close();
|
|
||||||
LoginDatabase.Close();
|
|
||||||
|
|
||||||
sLog->outString("Halting process...");
|
sLog->outString("Halting process...");
|
||||||
|
|
||||||
@@ -368,6 +365,8 @@ int Master::Run()
|
|||||||
/// Initialize connection to the databases
|
/// Initialize connection to the databases
|
||||||
bool Master::_StartDB()
|
bool Master::_StartDB()
|
||||||
{
|
{
|
||||||
|
MySQL::Library_Init();
|
||||||
|
|
||||||
sLog->SetLogDB(false);
|
sLog->SetLogDB(false);
|
||||||
std::string dbstring;
|
std::string dbstring;
|
||||||
uint8 async_threads, synch_threads;
|
uint8 async_threads, synch_threads;
|
||||||
@@ -471,6 +470,15 @@ bool Master::_StartDB()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Master::_StopDB()
|
||||||
|
{
|
||||||
|
CharacterDatabase.Close();
|
||||||
|
WorldDatabase.Close();
|
||||||
|
LoginDatabase.Close();
|
||||||
|
|
||||||
|
MySQL::Library_End();
|
||||||
|
}
|
||||||
|
|
||||||
/// Clear 'online' status for all accounts with characters in this realm
|
/// Clear 'online' status for all accounts with characters in this realm
|
||||||
void Master::clearOnlineAccounts()
|
void Master::clearOnlineAccounts()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class Master
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool _StartDB();
|
bool _StartDB();
|
||||||
|
void _StopDB();
|
||||||
|
|
||||||
void clearOnlineAccounts();
|
void clearOnlineAccounts();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user