1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
1 |
/* Copyright (c) 2009 PrimeBase Technologies GmbH, Germany
|
2 |
*
|
|
3 |
* PrimeBase Media Stream for MySQL
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
8 |
* (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 |
*
|
|
19 |
* Barry Leslie
|
|
20 |
*
|
|
21 |
* 2009-05-29
|
|
22 |
*
|
|
23 |
* H&G2JCtL
|
|
24 |
*
|
|
25 |
* Repository backup.
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
||
29 |
#ifndef _BACKUP_MS_H_
|
|
30 |
#define _BACKUP_MS_H_
|
|
31 |
||
32 |
#include <inttypes.h> |
|
33 |
||
34 |
class MSDatabase; |
|
35 |
||
36 |
class MSBackupInfo : public CSRefObject { |
|
37 |
private: |
|
38 |
static uint32_t gMaxInfoRef; |
|
39 |
static CSSyncSparseArray *gBackupInfo; |
|
40 |
||
41 |
friend class MSBackupTable; |
|
42 |
friend class MSBackup; |
|
43 |
||
44 |
private: |
|
45 |
uint32_t backupRefId; |
|
46 |
CSString *db_name; |
|
47 |
uint32_t db_id; |
|
48 |
time_t startTime; |
|
49 |
time_t completionTime; |
|
50 |
bool dump; |
|
51 |
bool isRunning; |
|
52 |
CSString *backupLocation; |
|
53 |
uint32_t cloudRef; |
|
54 |
uint32_t cloudBackupNo; |
|
55 |
||
56 |
public: |
|
57 |
||
58 |
static void startUp() |
|
59 |
{
|
|
60 |
new_(gBackupInfo, CSSyncSparseArray(5)); |
|
61 |
gMaxInfoRef = 0; |
|
62 |
}
|
|
63 |
||
64 |
static void shutDown() |
|
65 |
{
|
|
66 |
if (gBackupInfo) { |
|
67 |
gBackupInfo->clear(); |
|
68 |
gBackupInfo->release(); |
|
69 |
gBackupInfo = NULL; |
|
70 |
}
|
|
71 |
}
|
|
72 |
||
73 |
||
74 |
static MSBackupInfo *findBackupInfo(uint32_t backupRefId) |
|
75 |
{
|
|
76 |
MSBackupInfo *info; |
|
77 |
enter_(); |
|
78 |
||
79 |
lock_(gBackupInfo); |
|
80 |
||
81 |
info = (MSBackupInfo *) gBackupInfo->get(backupRefId); |
|
82 |
if (info) |
|
83 |
info->retain(); |
|
84 |
unlock_(gBackupInfo); |
|
85 |
return_(info); |
|
86 |
}
|
|
87 |
||
88 |
static MSBackupInfo *getBackupInfo(uint32_t backupRefId) |
|
89 |
{
|
|
90 |
MSBackupInfo *info = findBackupInfo(backupRefId); |
|
91 |
if (!info) { |
|
92 |
enter_(); |
|
93 |
char msg[80]; |
|
94 |
snprintf(msg, 80, "Backup info with reference ID %"PRIu32" not found", backupRefId); |
|
95 |
CSException::throwException(CS_CONTEXT, CS_ERR_GENERIC_ERROR, msg); |
|
96 |
outer_(); |
|
97 |
}
|
|
98 |
return info; |
|
99 |
}
|
|
100 |
||
101 |
||
102 |
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 ); |
|
103 |
~MSBackupInfo(); |
|
104 |
||
105 |
uint32_t getBackupRefId() { return backupRefId;} |
|
106 |
||
107 |
const char *getName(){ return db_name->getCString(); } |
|
108 |
||
109 |
uint32_t getDatabaseId() { return db_id;} |
|
110 |
||
111 |
time_t getStart(){ return startTime;} |
|
112 |
||
113 |
time_t getEnd(){ return completionTime;} |
|
114 |
||
115 |
bool isDump(){ return dump;} |
|
116 |
||
117 |
bool isBackupRunning(){ return isRunning;} |
|
118 |
||
119 |
const char *getLocation() { return (backupLocation)?backupLocation->getCString():NULL; } |
|
120 |
||
121 |
uint32_t getcloudRef(){ return cloudRef;} |
|
122 |
void setcloudRef(uint32_t no){ cloudRef = no;} |
|
123 |
||
124 |
uint32_t getcloudBackupNo(){ return cloudBackupNo;} |
|
125 |
void setcloudBackupNo(uint32_t no){ cloudBackupNo = no;} |
|
126 |
||
127 |
static MSBackupInfo *startDump(MSDatabase *db, uint32_t cloud_ref, uint32_t backup_no); |
|
128 |
||
129 |
void startBackup(MSDatabase *pbms_db); |
|
130 |
void backupCompleted(MSDatabase *db); |
|
131 |
void backupTerminated(MSDatabase *db); |
|
132 |
};
|
|
133 |
||
134 |
||
135 |
class MSDatabase; |
|
136 |
class MSOpenSystemTable; |
|
137 |
||
138 |
class MSBackup :public CSDaemon { |
|
139 |
||
140 |
public: |
|
141 |
||
142 |
MSBackup(); |
|
1548.2.11
by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser. |
143 |
~MSBackup(){} // Do nothing here because 'self' will no longer be valid, use completeWork(). |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
144 |
|
145 |
virtual bool doWork(); |
|
146 |
||
1548.2.11
by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser. |
147 |
virtual void *completeWork(); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
148 |
|
149 |
void startBackup(MSDatabase *src_db); |
|
150 |
uint64_t getBackupSize() { return bu_size;} |
|
151 |
uint64_t getBackupCompletedSize() { return bu_completed;} |
|
152 |
bool isRunning() { return bu_BackupRunning;} |
|
153 |
int getStatus() { return (bu_BackupRunning)?0:bu_State;} |
|
154 |
uint32_t backupID() { return bu_ID;} |
|
155 |
||
156 |
static MSBackup* newMSBackup(MSBackupInfo *backup_info); |
|
157 |
||
158 |
private: |
|
159 |
void completeBackup(); |
|
160 |
||
161 |
MSBackupInfo *bu_info; |
|
162 |
||
163 |
CSVector *bu_BackupList; |
|
164 |
CSDaemon *bu_Compactor; |
|
165 |
bool bu_BackupRunning; |
|
166 |
enum {BU_RUNNING = -1, BU_COMPLETED = 0, BU_TERMINATED = 1} bu_State; |
|
167 |
||
168 |
MSDatabase *bu_SourceDatabase; // The source database. |
|
169 |
MSDatabase *bu_Database; // The destination database. |
|
170 |
MSOpenSystemTable *bu_dst_dump; // The source database's pbms_dump. |
|
171 |
MSOpenSystemTable *bu_src_dump; // The source database's pbms_dump. |
|
172 |
uint64_t bu_size; // The total size of the data to be backed up. |
|
173 |
uint64_t bu_completed; // The amount of data that has been backed up so far. |
|
174 |
||
175 |
uint32_t bu_ID; |
|
176 |
uint32_t bu_start_time; |
|
177 |
||
178 |
bool bu_TransactionManagerSuspended; |
|
179 |
};
|
|
180 |
||
181 |
#endif // _BACKUP_MS_H_ |