Core/DBLayer

- Store threadbundlemask internally per database pool and prevent direct access to config file post startup
- Fix threadbundlemask flag checking for ReactorRunnable, WorldRunnable
- Remove CLI threadbundlemask flag, CLI doesn´t need a seperate mysql connection nor thread
- Remove unused Character Database connection from WorldSocketMgr / ReactorRunnable
- Add proper LoginDatabase connection to RA Runnable (soon to be overhauled)

Note: still experimental and not tested for live use

--HG--
branch : trunk
This commit is contained in:
Machiavelli
2010-09-03 10:52:32 +02:00
parent 277f2674ac
commit 273679c5ba
8 changed files with 62 additions and 84 deletions

View File

@@ -346,7 +346,8 @@ bool StartDB()
num_threads = 1;
}
if (!LoginDatabase.Open(dbstring.c_str(), num_threads))
//- Authserver has singlethreaded synchronous DB access, hence MYSQL_BUNDLE_ALL
if (!LoginDatabase.Open(dbstring.c_str(), num_threads, MYSQL_BUNDLE_ALL))
{
sLog.outError("Cannot connect to database");
return false;

View File

@@ -159,18 +159,12 @@ class ReactorRunnable : protected ACE_Task_Base
sLog.outStaticDebug ("Network Thread Starting");
bool needInit = true;
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA))
if (!(LoginDatabase.GetBundleMask() & MYSQL_BUNDLE_RAR))
{
LoginDatabase.Init_MySQL_Connection();
needInit = false;
}
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA))
{
CharacterDatabase.Init_MySQL_Connection();
needInit = false;
}
if (needInit)
MySQL::Thread_Init();
@@ -210,10 +204,8 @@ class ReactorRunnable : protected ACE_Task_Base
}
///- Free MySQL thread resources and deallocate lingering connections
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA))
if (!(LoginDatabase.GetBundleMask() & MYSQL_BUNDLE_RAR))
LoginDatabase.End_MySQL_Connection();
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA))
CharacterDatabase.End_MySQL_Connection();
if (needInit)
MySQL::Thread_End();

View File

@@ -1212,11 +1212,6 @@ void World::LoadConfigSettings(bool reload)
// Dungeon finder
m_bool_configs[CONFIG_DUNGEON_FINDER_ENABLE] = sConfig.GetBoolDefault("DungeonFinder.Enable", false);
// MySQL thread bundling config for other runnable tasks
m_int_configs[CONFIG_MYSQL_BUNDLE_LOGINDB] = sConfig.GetIntDefault("LoginDatabase.ThreadBundleMask", MYSQL_BUNDLE_ALL);
m_int_configs[CONFIG_MYSQL_BUNDLE_CHARDB] = sConfig.GetIntDefault("CharacterDatabase.ThreadBundleMask", MYSQL_BUNDLE_ALL);
m_int_configs[CONFIG_MYSQL_BUNDLE_WORLDDB] = sConfig.GetIntDefault("WorldDatabase.ThreadBundleMask", MYSQL_BUNDLE_ALL);
sScriptMgr.OnConfigLoad(reload);
}

View File

@@ -300,9 +300,6 @@ enum WorldIntConfigs
CONFIG_CHARDELETE_KEEP_DAYS,
CONFIG_CHARDELETE_METHOD,
CONFIG_CHARDELETE_MIN_LEVEL,
CONFIG_MYSQL_BUNDLE_LOGINDB,
CONFIG_MYSQL_BUNDLE_CHARDB,
CONFIG_MYSQL_BUNDLE_WORLDDB,
INT_CONFIG_VALUE_COUNT
};

View File

@@ -33,11 +33,11 @@
enum MySQLThreadBundle
{
MYSQL_BUNDLE_NONE = 0x00, //- Each task will run their own MySQL connection
MYSQL_BUNDLE_CLI = 0x01, //- Commandline interface thread
MYSQL_BUNDLE_UNUSED = 0x01, //- Temp unused
MYSQL_BUNDLE_RA = 0x02, //- Remote admin thread
MYSQL_BUNDLE_RAR = 0x04, //- Reactor runnable thread
MYSQL_BUNDLE_WORLD = 0x08, //- WorldRunnable
MYSQL_BUNDLE_ALL = MYSQL_BUNDLE_CLI | MYSQL_BUNDLE_RA | MYSQL_BUNDLE_RAR | MYSQL_BUNDLE_WORLD,
MYSQL_BUNDLE_ALL = MYSQL_BUNDLE_RA | MYSQL_BUNDLE_RAR | MYSQL_BUNDLE_WORLD,
};
template <class T>
@@ -63,13 +63,18 @@ class DatabaseWorkerPool
mysql_library_end();
}
bool Open(const std::string& infoString, uint8 num_threads)
bool Open(const std::string& infoString, uint8 num_threads, MySQLThreadBundle mask)
{
sLog.outSQLDriver("Creating bundled/master MySQL connection.");
m_bundle_conn = new T();
m_bundle_conn->Open(infoString);
++m_connections;
//- Only created bundled connection if configured
m_bundle_conn = NULL;
if (mask != MYSQL_BUNDLE_NONE)
{
sLog.outSQLDriver("Creating bundled/master MySQL connection.");
m_bundle_conn = new T();
m_bundle_conn->Open(infoString);
++m_connections;
}
m_async_connections.resize(num_threads);
/// Open the Async pool
@@ -97,17 +102,15 @@ class DatabaseWorkerPool
--m_connections;
}
delete m_bundle_conn;
m_bundle_conn = NULL;
--m_connections;
sLog.outSQLDriver("Closed bundled connection.");
if (m_bundleMask != MYSQL_BUNDLE_NONE)
{
delete m_bundle_conn;
m_bundle_conn = NULL;
--m_connections;
sLog.outSQLDriver("Closed bundled connection.");
}
//- MySQL::Thread_End() should be called manually from the aborting calling threads
sLog.outSQLDriver("Waiting for %u synchroneous database threads to exit.", (uint32)m_connections.value());
while (!m_sync_connections.empty())
{
}
sLog.outSQLDriver("Synchroneous database threads exited succesfuly.");
}
void Init_MySQL_Connection()
@@ -282,14 +285,16 @@ class DatabaseWorkerPool
delete[] buf;
}
MySQLThreadBundle GetBundleMask() { return m_bundleMask; }
private:
unsigned long escape_string(char *to, const char *from, unsigned long length)
{
if (!to || !from || !length)
return 0;
return (mysql_real_escape_string(GetConnection()->GetHandle(), to, from, length));
}
private:
void Enqueue(SQLOperation* op)
{
m_queue->enqueue(op);
@@ -320,6 +325,7 @@ class DatabaseWorkerPool
T* m_bundle_conn; //! Bundled connection (see Database.ThreadBundleMask config)
AtomicUInt m_connections; //! Counter of MySQL connections;
std::string m_infoString; //! Infostring that is passed on to child connections.
MySQLThreadBundle m_bundleMask; //! Our configured bundle mask (see enum)
};
#endif

View File

@@ -698,29 +698,6 @@ int kb_hit_return()
/// %Thread start
void CliRunnable::run()
{
///- Init MySQL threads or connections
bool needInit = true;
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA))
{
WorldDatabase.Init_MySQL_Connection();
needInit = false;
}
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA))
{
LoginDatabase.Init_MySQL_Connection();
needInit = false;
}
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA))
{
CharacterDatabase.Init_MySQL_Connection();
needInit = false;
}
if (needInit)
MySQL::Thread_Init();
///- Display the list of available CLI functions then beep
//sLog.outString("");
#if PLATFORM != WINDOWS
@@ -786,15 +763,4 @@ void CliRunnable::run()
}
}
///- Free MySQL thread resources and deallocate lingering connections
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA))
WorldDatabase.End_MySQL_Connection();
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA))
LoginDatabase.End_MySQL_Connection();
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA))
CharacterDatabase.End_MySQL_Connection();
if (needInit)
MySQL::Thread_End();
}

View File

@@ -33,6 +33,7 @@
#include "WorldSocketMgr.h"
#include "Configuration/Config.h"
#include "Database/DatabaseEnv.h"
#include "Database/DatabaseWorkerPool.h"
#include "CliRunnable.h"
#include "Log.h"
@@ -134,9 +135,7 @@ public:
{
loopCounter = 0;
sLog.outDetail ("Ping MySQL to keep connection alive");
WorldDatabase.Query ("SELECT 1 FROM command LIMIT 1");
LoginDatabase.Query ("SELECT 1 FROM realmlist LIMIT 1");
CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
}
}
@@ -163,6 +162,15 @@ public:
sLog.outString ("Starting Remote access listner on port %d on %s", raport, stringip.c_str ());
}
bool needInit = true;
if ((LoginDatabase.GetBundleMask() & MYSQL_BUNDLE_RA))
{
LoginDatabase.Init_MySQL_Connection();
needInit = false;
}
if (needInit)
MySQL::Thread_Init();
}
// Socket Selet time is in microseconds , not miliseconds!!
@@ -176,13 +184,18 @@ public:
h.Select (0, socketSelecttime);
checkping ();
}
if (!needInit)
LoginDatabase.End_MySQL_Connection();
else
MySQL::Thread_End();
}
else
{
while (!World::IsStopped())
{
ACE_Based::Thread::Sleep(static_cast<unsigned long> (socketSelecttime / 1000));
checkping ();
// checkping (); -- What?
}
}
}
@@ -440,6 +453,7 @@ bool Master::_StartDB()
sLog.SetLogDB(false);
std::string dbstring;
uint8 num_threads;
int32 mask;
dbstring = sConfig.GetStringDefault("WorldDatabaseInfo", "");
if (dbstring.empty())
@@ -456,8 +470,10 @@ bool Master::_StartDB()
return false;
}
mask = sConfig.GetIntDefault("WorldDatabase.ThreadBundleMask", MYSQL_BUNDLE_ALL);
///- Initialise the world database
if (!WorldDatabase.Open(dbstring, num_threads))
if (!WorldDatabase.Open(dbstring, num_threads, MySQLThreadBundle(mask)))
{
sLog.outError("Cannot connect to world database %s", dbstring.c_str());
return false;
@@ -478,12 +494,15 @@ bool Master::_StartDB()
return false;
}
mask = sConfig.GetIntDefault("CharacterDatabase.ThreadBundleMask", MYSQL_BUNDLE_ALL);
///- Initialise the Character database
if (!CharacterDatabase.Open(dbstring, num_threads))
if (!CharacterDatabase.Open(dbstring, num_threads, MySQLThreadBundle(mask)))
{
sLog.outError("Cannot connect to Character database %s", dbstring.c_str());
return false;
}
///- Get login database info from configuration file
dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", "");
if (dbstring.empty())
@@ -500,8 +519,10 @@ bool Master::_StartDB()
return false;
}
mask = sConfig.GetIntDefault("LoginDatabase.ThreadBundleMask", MYSQL_BUNDLE_ALL);
///- Initialise the login database
if (!LoginDatabase.Open(dbstring, num_threads))
if (!LoginDatabase.Open(dbstring, num_threads, MySQLThreadBundle(mask)))
{
sLog.outError("Cannot connect to login database %s", dbstring.c_str());
return false;

View File

@@ -45,18 +45,18 @@ void WorldRunnable::run()
{
///- Init MySQL threads or connections
bool needInit = true;
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA))
if (!(WorldDatabase.GetBundleMask() & MYSQL_BUNDLE_WORLD))
{
WorldDatabase.Init_MySQL_Connection();
needInit = false;
}
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA))
if (!(LoginDatabase.GetBundleMask() & MYSQL_BUNDLE_WORLD))
{
LoginDatabase.Init_MySQL_Connection();
needInit = false;
}
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA))
if (!(CharacterDatabase.GetBundleMask() & MYSQL_BUNDLE_WORLD))
{
CharacterDatabase.Init_MySQL_Connection();
needInit = false;
@@ -117,13 +117,13 @@ void WorldRunnable::run()
sMapMgr.UnloadAll(); // unload all grids (including locked in memory)
///- Free MySQL thread resources and deallocate lingering connections
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_WORLDDB) & MYSQL_BUNDLE_RA))
if (!(WorldDatabase.GetBundleMask() & MYSQL_BUNDLE_WORLD))
WorldDatabase.End_MySQL_Connection();
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_LOGINDB) & MYSQL_BUNDLE_RA))
if (!(LoginDatabase.GetBundleMask() & MYSQL_BUNDLE_WORLD))
LoginDatabase.End_MySQL_Connection();
if (!(sWorld.getIntConfig(CONFIG_MYSQL_BUNDLE_CHARDB) & MYSQL_BUNDLE_RA))
if (!(CharacterDatabase.GetBundleMask() & MYSQL_BUNDLE_WORLD))
CharacterDatabase.End_MySQL_Connection();
if (needInit)