Main Page | Class Hierarchy | Class List | File List | Class 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 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, // autodetect size of available memory
00080                   size_t dbExtensionQuantum = dbDefaultExtensionQuantum,
00081                   size_t dbInitIndexSize = dbDefaultInitIndexSize,
00082                   int nThreads = 1
00083                   // Do not specify the last parameter - it is only for checking
00084                   // that application and GigaBASE library were built with the
00085                   // same compiler options (-DNO_PTHREADS is critical)
00086                   // Mismached parameters should cause linker error
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, // number of slaves for master or 0 for slave
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 

Generated on Thu Nov 24 23:14:30 2005 for GigaBASE by doxygen 1.3.5