Roughly define database pool interface

This commit is contained in:
Zwelf 2020-07-04 12:09:40 +02:00
parent d59cdf47b5
commit 295ce95d64
4 changed files with 92 additions and 1 deletions

View file

@ -1840,6 +1840,8 @@ set_src(ENGINE_SERVER GLOB_RECURSE src/engine/server
authmanager.cpp
authmanager.h
databases/connection.h
databases/connection_pool.cpp
databases/connection_pool.h
databases/mysql.cpp
databases/mysql.h
name_ban.cpp

View file

@ -25,8 +25,9 @@ public:
SUCCESS,
ERROR,
};
// returns true if connection was established
// tries to allocate the connection from the pool established
virtual Status Connect() = 0;
// has to be called to return the connection back to the pool
virtual void Disconnect() = 0;
// get exclusive read/write access to the database

View file

@ -0,0 +1,42 @@
#include "connection_pool.h"
// helper struct to hold thread data
struct CSqlExecData
{
CSqlExecData(
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
const ISqlData *pSqlRequestData
);
~CSqlExecData();
bool (*m_pFuncPtr) (IDbConnection*, const ISqlData *);
std::unique_ptr<const ISqlData> m_pSqlRequestData;
};
CDbConnectionPool::CDbConnectionPool()
{
}
CDbConnectionPool::~CDbConnectionPool()
{
}
void CDbConnectionPool::RegisterDatabase(std::unique_ptr<IDbConnection> pDatabase, Mode DatabaseMode)
{
}
void CDbConnectionPool::Execute(
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
std::unique_ptr<ISqlData> pSqlRequestData)
{
}
void CDbConnectionPool::ExecuteWrite(
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
std::unique_ptr<ISqlData> pSqlRequestData)
{
}
void CDbConnectionPool::Shutdown()
{
}

View file

@ -0,0 +1,46 @@
#ifndef ENGINE_SERVER_DATABASES_CONNECTION_POOL_H
#define ENGINE_SERVER_DATABASES_CONNECTION_POOL_H
#include "connection.h"
#include <base/tl/threading.h>
#include <memory>
#include <vector>
struct ISqlData
{
virtual ~ISqlData();
};
class CDbConnectionPool
{
public:
CDbConnectionPool();
~CDbConnectionPool();
enum Mode
{
READ,
WRITE,
WRITE_BACKUP,
NUM_MODES,
};
void RegisterDatabase(std::unique_ptr<IDbConnection> pDatabase, Mode DatabaseMode);
void Execute(
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
std::unique_ptr<ISqlData> pSqlRequestData);
// writes to WRITE_BACKUP server in case of failure
void ExecuteWrite(
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
std::unique_ptr<ISqlData> pSqlRequestData);
void Shutdown();
private:
std::vector<std::unique_ptr<IDbConnection>> m_aapDbConnections[NUM_MODES];
lock m_ConnectionLookupLock[NUM_MODES];
};
#endif // ENGINE_SERVER_DATABASES_CONNECTION_POOL_H