Main Page   Class Hierarchy   Compound List   File List   Compound Members  

replicator.h

00001 //-< REPLICATPOR.H >----------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     13-Mar-2002  K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 13-Mar-2002   K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // Replicated database 
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 GIGABASE_DLL_ENTRY 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     virtual ~dbReplicationManager();
00055 };
00056 
00060 class GIGABASE_DLL_ENTRY dbReplicatedDatabase : public dbDatabase { 
00061   public:    
00066     void stopMasterReplication();
00067     
00080     dbReplicatedDatabase(dbReplicationManager* mng = NULL, 
00081                   size_t poolSize = 0, // autodetect size of available memory
00082                   size_t dbExtensionQuantum = dbDefaultExtensionQuantum,
00083                   size_t dbInitIndexSize = dbDefaultInitIndexSize,
00084                   int nThreads = 1
00085                   // Do not specify the last parameter - it is only for checking
00086                   // that application and GigaBASE library were built with the
00087                   // same compiler options (-DNO_PTHREADS is critical)
00088                   // Mismached parameters should cause linker error
00089 #ifdef NO_PTHREADS
00090                   , bool usePthreads = false
00091 #endif
00092                   )
00093         : dbDatabase(dbAllAccess, poolSize, dbExtensionQuantum, dbInitIndexSize, nThreads), 
00094           replicationManager(mng)
00095         {}
00096     
00106     bool open(char const* masterHostAddress,
00107               int nReplicas, // number of slaves for master or 0 for slave
00108               char_t const* databaseName, 
00109               time_t transactionCommitDelay = 0, 
00110               int openAttr = dbFile::no_buffering);
00114     void close();
00115   protected:  
00119     void slaveReplication();
00120     
00124     void replicatePage(offs_t pageOffs, void* pageData);
00125     
00126     int                       nReplicas;
00127     socket_t**                replicationSlaves;
00128     socket_t*                 replicationMaster;
00129     dbReplicationManager*     replicationManager;
00130     dbThread                  replicationThread;
00131  
00132     static void thread_proc slaveReplicationProc(void* arg) { 
00133         ((dbReplicatedDatabase*)arg)->slaveReplication();
00134     }
00135 };
00136 
00137 END_GIGABASE_NAMESPACE
00138 
00139 #endif
00140 

Generated on Thu Feb 14 21:46:03 2008 for GigaBASE by doxygen1.2.18