Drizzled Public API Documentation

backup_ms.h
00001 /* Copyright (C) 2009 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Barry Leslie
00020  *
00021  * 2009-05-29
00022  *
00023  * H&G2JCtL
00024  *
00025  * Repository backup.
00026  *
00027  */
00028 
00029 #pragma once
00030 #ifndef _BACKUP_MS_H_
00031 #define _BACKUP_MS_H_
00032 
00033 #include <inttypes.h>
00034 
00035 class MSDatabase;
00036 
00037 class MSBackupInfo : public CSRefObject {
00038   friend class StartDumpCleanUp;
00039   friend class InsertRowCleanUp;
00040   
00041   private:
00042   static uint32_t gMaxInfoRef;
00043   static CSSyncSparseArray *gBackupInfo;
00044 
00045   friend class MSBackupTable;
00046   friend class MSBackup;
00047   
00048   private:  
00049   uint32_t      backupRefId;
00050   CSString    *db_name;
00051   uint32_t      db_id;
00052   time_t      startTime;
00053   time_t      completionTime;
00054   bool      dump;
00055   bool      isRunning;
00056   CSString    *backupLocation;
00057   uint32_t      cloudRef;
00058   uint32_t      cloudBackupNo;
00059   
00060 public:
00061 
00062   static void startUp()
00063   {
00064     new_(gBackupInfo, CSSyncSparseArray(5));
00065     gMaxInfoRef = 0;
00066   }
00067   
00068   static void shutDown()
00069   {
00070     if (gBackupInfo) {
00071       gBackupInfo->clear();
00072       gBackupInfo->release();
00073       gBackupInfo = NULL;
00074     } 
00075   }
00076 
00077 
00078   static MSBackupInfo *findBackupInfo(uint32_t in_backupRefId)
00079   {
00080     MSBackupInfo *info;
00081     enter_();
00082     
00083     lock_(gBackupInfo);
00084     
00085     info = (MSBackupInfo *) gBackupInfo->get(in_backupRefId);
00086     if (info) 
00087       info->retain();
00088     unlock_(gBackupInfo);
00089     return_(info);
00090   }
00091   
00092   static MSBackupInfo *getBackupInfo(uint32_t in_backupRefId)
00093   {
00094     MSBackupInfo *info = findBackupInfo(in_backupRefId);
00095     if (!info) {
00096       enter_();
00097       char msg[80];
00098       snprintf(msg, 80, "Backup info with reference ID %"PRIu32" not found", in_backupRefId);
00099       CSException::throwException(CS_CONTEXT, CS_ERR_GENERIC_ERROR, msg);
00100       outer_();
00101     }
00102     return info;
00103   }
00104   
00105   
00106   MSBackupInfo(uint32_t id, const char *name, uint32_t db_id, time_t start, time_t end, bool isDump, const char *location, uint32_t cloudRef_arg, uint32_t cloudBackupNo_arg );
00107   ~MSBackupInfo();
00108   
00109   uint32_t getBackupRefId() { return backupRefId;}
00110   
00111   const char *getName(){ return db_name->getCString(); }
00112   
00113   uint32_t getDatabaseId() { return db_id;}
00114   
00115   time_t getStart(){ return startTime;}
00116   
00117   time_t getEnd(){ return completionTime;}
00118   
00119   bool isDump(){ return dump;}
00120   
00121   bool isBackupRunning(){ return isRunning;}
00122 
00123   const char *getLocation() { return (backupLocation)?backupLocation->getCString():NULL; }
00124     
00125   uint32_t getcloudRef(){ return cloudRef;}
00126   void setcloudRef(uint32_t no){ cloudRef = no;}
00127 
00128   uint32_t getcloudBackupNo(){ return cloudBackupNo;}
00129   void setcloudBackupNo(uint32_t no){ cloudBackupNo = no;}
00130   
00131   static MSBackupInfo *startDump(MSDatabase *db, uint32_t cloud_ref, uint32_t backup_no);
00132 
00133   void startBackup(MSDatabase *pbms_db);
00134   void backupCompleted(MSDatabase *db);
00135   void backupTerminated(MSDatabase *db);
00136 };
00137 
00138 
00139 class MSDatabase;
00140 class MSOpenSystemTable;
00141 
00142 class MSBackup :public CSDaemon {
00143 
00144 public:
00145 
00146   MSBackup();
00147   ~MSBackup(){} // Do nothing here because 'self' will no longer be valid, use completeWork().
00148   
00149   virtual bool doWork();
00150 
00151   virtual void *completeWork();
00152   
00153   void startBackup(MSDatabase *src_db);
00154   uint64_t getBackupSize() { return bu_size;}
00155   uint64_t getBackupCompletedSize() { return bu_completed;}
00156   bool  isRunning() { return bu_BackupRunning;}
00157   int   getStatus() { return (bu_BackupRunning)?0:bu_State;}
00158   uint32_t backupID() { return bu_ID;}
00159   
00160   static MSBackup* newMSBackup(MSBackupInfo *backup_info);
00161 
00162   friend class StartBackupCleanUp;
00163 private:
00164   void completeBackup();
00165   
00166   MSBackupInfo *bu_info;
00167 
00168   CSVector  *bu_BackupList;
00169   CSDaemon  *bu_Compactor;
00170   bool    bu_BackupRunning;
00171   enum    {BU_RUNNING = -1, BU_COMPLETED = 0, BU_TERMINATED = 1}  bu_State; 
00172   
00173   MSDatabase  *bu_SourceDatabase; // The source database.
00174   MSDatabase  *bu_Database;   // The destination database.
00175   MSOpenSystemTable *bu_dst_dump; // The source database's pbms_dump.
00176   MSOpenSystemTable *bu_src_dump; // The source database's pbms_dump.
00177   uint64_t    bu_size;      // The total size of the data to be backed up.
00178   uint64_t    bu_completed;   // The amount of data that has been backed up so far.
00179   
00180   uint32_t    bu_ID;
00181   uint32_t    bu_start_time;
00182   
00183   bool    bu_TransactionManagerSuspended;
00184 };
00185 
00186 #endif // _BACKUP_MS_H_