1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-15 18:50:09 +03:00

F #4809: Template for the LogDBManager

This commit is contained in:
Ruben S. Montero 2017-04-20 17:11:56 +02:00
parent c8981e82a3
commit 116425fc99
3 changed files with 105 additions and 113 deletions

View File

@ -18,11 +18,12 @@
#define LOG_DB_MANAGER_H_
#include "ActionManager.h"
#include "LogDBRecord.h"
#include "ZoneServer.h"
extern "C" void * logdb_manager_loop(void *arg);
extern "C" void * replication_thread(void *arg);
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -31,35 +32,29 @@ class LogDBAction : public ActionRequest
public:
enum Actions
{
NEW_LOGDB_RECORD,
START,
STOP,
REPLICATE,
DELETE_SERVER
}
};
LogDBAction(Actions a, LogDBRequest * r):ActionRequest(ActionRequest::USER),
_action(a), _request(r){};
LogDBAction(Actions a):ActionRequest(ActionRequest::USER), _action(a){};
LogDBAction(const LogDBAction& o):ActionRequest(o._type),
_action(o._action), _request(o._request){};
_action(o._action){};
Actions action() const
{
return _action;
}
LogDBRequest * request() const
{
return _request;
}
ActionRequest * clone() const
{
return new LogDBAction(*this);
}
private:
Action _action;
LogDBRequest * _request;
Actions _action;
};
// -----------------------------------------------------------------------------
@ -68,17 +63,30 @@ private:
class LogDBManager : public ActionListener
{
private:
class LogDBManagerThread
friend void * logdb_manager_loop(void *arg);
friend void * replication_thread(void *arg);
/**
* Event engine for the LogDBManager
*/
ActionManager am;
// -------------------------------------------------------------------------
// Replication thread class
// -------------------------------------------------------------------------
class ReplicaThread
{
public:
LogDBManagerThread(ZoneServer * z):replicate(false), zserver(z)
ReplicaThread(ZoneServer * z):zserver(z)
{
pthread_mutex_init(&mutex, 0);
pthread_cond_init(&cond, 0);
};
virtual ~LogDBManagerThread(){};
virtual ~ReplicaThread(){};
void do_replication();
@ -89,27 +97,35 @@ private:
pthread_cond_t cond;
bool replicate;
ZoneServer * zserver;
}
/**
* LogDB records being replicated on followers
*/
std::map<unsigned int, LogDBRecord *> log;
};
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
void finalize_action(const ActionRequest& ar)
{
NebulaLog::log("DBM",Log::INFO,"Stopping LogDB Manager...");
};
void finalize_action(const ActionRequest& ar);
/**
* Start the replication threads, one for each server in the zone
*/
void start(const ActionRequest& ar);
/**
* Stop the replication threads (leader becomes follower)
*/
void stop(const ActionRequest& ar);
/**
* Notify threads there is a new log entry to replicate on followers
*/
void replicate(const ActionRequest& ar);
/**
* Event dispatcher function
*/
void user_action(const ActionRequest& ar);
}
};
#endif /*LOG_DB_H_*/
#endif /*LOG_DB_MANAGER_H_*/

View File

@ -14,102 +14,77 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#ifndef LOG_DB_MANAGER_H_
#define LOG_DB_MANAGER_H_
#include "LogDBManager.h"
#include "Nebula.h"
#include "NebulaLog.h"
#include "ActionManager.h"
#include "LogDBRecord.h"
#include "ZoneServer.h"
extern "C" void * logdb_manager_loop(void *arg);
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class LogDBAction : public ActionRequest
// ----------------------------------------------------------------------------
// Thread wrapper functions
// ----------------------------------------------------------------------------
extern "C" void * logdb_manager_loop(void *arg)
{
public:
enum Actions
LogDBManager * dbm;
if ( arg == 0 )
{
NEW_LOGDB_RECORD,
DELETE_SERVER
return 0;
}
LogDBAction(Actions a, LogDBRequest * r):ActionRequest(ActionRequest::USER),
_action(a), _request(r){};
dbm = static_cast<LogDBManager *>(arg);
LogDBAction(const LogDBAction& o):ActionRequest(o._type),
_action(o._action), _request(o._request){};
NebulaLog::log("DBM",Log::INFO,"LogDB Replication Manager started.");
Actions action() const
dbm->am.loop();
NebulaLog::log("DBM",Log::INFO,"LogDB Replication Manager stopped.");
return 0;
}
extern "C" void * replication_thread(void *arg)
{
LogDBManager::ReplicaThread * rt;
if ( arg == 0 )
{
return _action;
return 0;
}
LogDBRequest * request() const
{
return _request;
}
rt = static_cast<LogDBManager::ReplicaThread *>(arg);
ActionRequest * clone() const
{
return new LogDBAction(*this);
}
rt->do_replication();
private:
Action _action;
return 0;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void LogDBManager::finalize_action(const ActionRequest& ar)
{
NebulaLog::log("DBM",Log::INFO,"Stopping LogDB Manager...");
};
void LogDBManager::user_action(const ActionRequest& ar)
{
};
void LogDBManager::start(const ActionRequest& ar)
{
};
void LogDBManager::stop(const ActionRequest& ar)
{
};
void LogDBManager::replicate(const ActionRequest& ar)
{
LogDBRequest * _request;
};
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
class LogDBManager : public ActionListener
{
private:
class LogDBManagerThread
{
public:
LogDBManagerThread(ZoneServer * z):replicate(false), zserver(z)
{
pthread_mutex_init(&mutex, 0);
pthread_cond_init(&cond, 0);
};
virtual ~LogDBManagerThread(){};
void do_replication();
private:
pthread_t thread_id;
pthread_mutex_t mutex;
pthread_cond_t cond;
bool replicate;
ZoneServer * zserver;
}
/**
* LogDB records being replicated on followers
*/
std::map<unsigned int, LogDBRecord *> log;
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
void finalize_action(const ActionRequest& ar)
{
NebulaLog::log("DBM",Log::INFO,"Stopping LogDB Manager...");
};
void user_action(const ActionRequest& ar);
}
#endif /*LOG_DB_H_*/

View File

@ -23,7 +23,8 @@ lib_name='nebula_logdb'
# Sources to generate the library
source_files=[
'LogDB.cc',
'LogDBRequest.cc'
'LogDBRequest.cc',
'LogDBManager.cc'
]
# Build library