mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
[11045] Rewrite internals of DB layer. Simplify code and use less locking. Spawn and use separate connections for sync and async DB requests. Implement database connection pool for SELECT queries. Up to maximum 16 connections supported. Disable 'autocommit' mode for MySQL.
UPDATE YOUR CONFIGS! Defaults: LoginDatabaseConnections = 1 WorldDatabaseConnections = 1 CharacterDatabaseConnections = 1 If you are not using <mtmaps> patch do not change the default settings - this is useless. You can try following option in your MySQL config to squeeze even more performance from your DB: [mysqld] transaction-isolation = READ-COMMITTED Great thanks to Undergarun, kero99 and selector for making tests and providing very useful feedback and DB statistics! Have fun :) Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
parent
9bc37afa28
commit
631ce36680
19 changed files with 655 additions and 547 deletions
|
|
@ -19,7 +19,11 @@
|
|||
#ifndef _DatabasePostgre_H
|
||||
#define _DatabasePostgre_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "Database.h"
|
||||
#include "Policies/Singleton.h"
|
||||
#include "ace/Thread_Mutex.h"
|
||||
#include "ace/Guard_T.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef WIN32
|
||||
|
|
@ -30,7 +34,32 @@
|
|||
#include <libpq-fe.h>
|
||||
#endif
|
||||
|
||||
class DatabasePostgre : public Database
|
||||
class MANGOS_DLL_SPEC PostgreSQLConnection : public SqlConnection
|
||||
{
|
||||
public:
|
||||
PostgreSQLConnection() : mPGconn(NULL) {}
|
||||
~PostgreSQLConnection() { PQfinish(mPGconn); }
|
||||
|
||||
bool Initialize(const char *infoString);
|
||||
|
||||
QueryResult* Query(const char *sql);
|
||||
QueryNamedResult* QueryNamed(const char *sql);
|
||||
bool Execute(const char *sql);
|
||||
|
||||
unsigned long escape_string(char *to, const char *from, unsigned long length);
|
||||
|
||||
bool BeginTransaction();
|
||||
bool CommitTransaction();
|
||||
bool RollbackTransaction();
|
||||
|
||||
private:
|
||||
bool _TransactionCmd(const char *sql);
|
||||
bool _Query(const char *sql, PGresult **pResult, uint64* pRowCount, uint32* pFieldCount);
|
||||
|
||||
PGconn *mPGconn;
|
||||
};
|
||||
|
||||
class MANGOS_DLL_SPEC DatabasePostgre : public Database
|
||||
{
|
||||
friend class MaNGOS::OperatorNew<DatabasePostgre>;
|
||||
|
||||
|
|
@ -40,30 +69,11 @@ class DatabasePostgre : public Database
|
|||
|
||||
//! Initializes Postgres and connects to a server.
|
||||
/*! infoString should be formated like hostname;username;password;database. */
|
||||
bool Initialize(const char *infoString);
|
||||
void InitDelayThread();
|
||||
void HaltDelayThread();
|
||||
QueryResult* Query(const char *sql);
|
||||
QueryNamedResult* QueryNamed(const char *sql);
|
||||
bool Execute(const char *sql);
|
||||
bool DirectExecute(const char* sql);
|
||||
bool BeginTransaction();
|
||||
bool CommitTransaction();
|
||||
bool RollbackTransaction();
|
||||
|
||||
operator bool () const { return mPGconn != NULL; }
|
||||
protected:
|
||||
virtual SqlConnection * CreateConnection();
|
||||
|
||||
unsigned long escape_string(char *to, const char *from, unsigned long length);
|
||||
using Database::escape_string;
|
||||
private:
|
||||
ACE_Thread_Mutex mMutex;
|
||||
ACE_Based::Thread * tranThread;
|
||||
|
||||
PGconn *mPGconn;
|
||||
|
||||
static size_t db_count;
|
||||
|
||||
bool _TransactionCmd(const char *sql);
|
||||
bool _Query(const char *sql, PGresult **pResult, uint64* pRowCount, uint32* pFieldCount);
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue