00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __REPLICATOR_H__
00012 #define __REPLICATOR_H__
00013
00014 #include "database.h"
00015 #include "sockio.h"
00016
00017 BEGIN_GIGABASE_NAMESPACE
00018
00024 class dbReplicationManager {
00025 public:
00031 virtual bool connectionBroken(char* hostName) = 0;
00032
00037 virtual void transactionCommitted() = 0;
00038
00042 virtual void replicationEnd() = 0;
00043
00052 virtual bool preserveSlaveConsistency() = 0;
00053 };
00054
00058 class GIGABASE_DLL_ENTRY dbReplicatedDatabase : public dbDatabase {
00059 public:
00064 void stopMasterReplication();
00065
00078 dbReplicatedDatabase(dbReplicationManager* mng = NULL,
00079 size_t poolSize = 0,
00080 size_t dbExtensionQuantum = dbDefaultExtensionQuantum,
00081 size_t dbInitIndexSize = dbDefaultInitIndexSize,
00082 int nThreads = 1
00083
00084
00085
00086
00087 #ifdef NO_PTHREADS
00088 , bool usePthreads = false
00089 #endif
00090 )
00091 : dbDatabase(dbAllAccess, poolSize, dbExtensionQuantum, dbInitIndexSize, nThreads),
00092 replicationManager(mng)
00093 {}
00094
00104 bool open(char const* masterHostAddress,
00105 int nReplicas,
00106 char_t const* databaseName,
00107 time_t transactionCommitDelay = 0,
00108 int openAttr = dbFile::no_buffering);
00112 void close();
00113 protected:
00117 void slaveReplication();
00118
00122 void replicatePage(offs_t pageOffs, void* pageData);
00123
00124 int nReplicas;
00125 socket_t** replicationSlaves;
00126 socket_t* replicationMaster;
00127 dbReplicationManager* replicationManager;
00128 dbThread replicationThread;
00129
00130 static void thread_proc slaveReplicationProc(void* arg) {
00131 ((dbReplicatedDatabase*)arg)->slaveReplication();
00132 }
00133 };
00134
00135 END_GIGABASE_NAMESPACE
00136
00137 #endif
00138