~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/backup_ms.h

Reverted 1103

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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
 
        friend class StartDumpCleanUp;
38
 
        friend class InsertRowCleanUp;
39
 
        
40
 
        private:
41
 
        static uint32_t gMaxInfoRef;
42
 
        static CSSyncSparseArray *gBackupInfo;
43
 
 
44
 
        friend class MSBackupTable;
45
 
        friend class MSBackup;
46
 
        
47
 
        private:        
48
 
        uint32_t                        backupRefId;
49
 
        CSString                *db_name;
50
 
        uint32_t                        db_id;
51
 
        time_t                  startTime;
52
 
        time_t                  completionTime;
53
 
        bool                    dump;
54
 
        bool                    isRunning;
55
 
        CSString                *backupLocation;
56
 
        uint32_t                        cloudRef;
57
 
        uint32_t                        cloudBackupNo;
58
 
        
59
 
public:
60
 
 
61
 
        static void startUp()
62
 
        {
63
 
                new_(gBackupInfo, CSSyncSparseArray(5));
64
 
                gMaxInfoRef = 0;
65
 
        }
66
 
        
67
 
        static void shutDown()
68
 
        {
69
 
                if (gBackupInfo) {
70
 
                        gBackupInfo->clear();
71
 
                        gBackupInfo->release();
72
 
                        gBackupInfo = NULL;
73
 
                }       
74
 
        }
75
 
 
76
 
 
77
 
        static MSBackupInfo *findBackupInfo(uint32_t in_backupRefId)
78
 
        {
79
 
                MSBackupInfo *info;
80
 
                enter_();
81
 
                
82
 
                lock_(gBackupInfo);
83
 
                
84
 
                info = (MSBackupInfo *) gBackupInfo->get(in_backupRefId);
85
 
                if (info) 
86
 
                        info->retain();
87
 
                unlock_(gBackupInfo);
88
 
                return_(info);
89
 
        }
90
 
        
91
 
        static MSBackupInfo *getBackupInfo(uint32_t in_backupRefId)
92
 
        {
93
 
                MSBackupInfo *info = findBackupInfo(in_backupRefId);
94
 
                if (!info) {
95
 
                        enter_();
96
 
                        char msg[80];
97
 
                        snprintf(msg, 80, "Backup info with reference ID %"PRIu32" not found", in_backupRefId);
98
 
                        CSException::throwException(CS_CONTEXT, CS_ERR_GENERIC_ERROR, msg);
99
 
                        outer_();
100
 
                }
101
 
                return info;
102
 
        }
103
 
        
104
 
        
105
 
        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 );
106
 
        ~MSBackupInfo();
107
 
        
108
 
        uint32_t getBackupRefId() { return backupRefId;}
109
 
        
110
 
        const char *getName(){ return db_name->getCString(); }
111
 
        
112
 
        uint32_t getDatabaseId() { return db_id;}
113
 
        
114
 
        time_t getStart(){ return startTime;}
115
 
        
116
 
        time_t getEnd(){ return completionTime;}
117
 
        
118
 
        bool isDump(){ return dump;}
119
 
        
120
 
        bool isBackupRunning(){ return isRunning;}
121
 
 
122
 
        const char *getLocation() { return (backupLocation)?backupLocation->getCString():NULL; }
123
 
                
124
 
        uint32_t getcloudRef(){ return cloudRef;}
125
 
        void setcloudRef(uint32_t no){ cloudRef = no;}
126
 
 
127
 
        uint32_t getcloudBackupNo(){ return cloudBackupNo;}
128
 
        void setcloudBackupNo(uint32_t no){ cloudBackupNo = no;}
129
 
        
130
 
        static MSBackupInfo *startDump(MSDatabase *db, uint32_t cloud_ref, uint32_t backup_no);
131
 
 
132
 
        void startBackup(MSDatabase *pbms_db);
133
 
        void backupCompleted(MSDatabase *db);
134
 
        void backupTerminated(MSDatabase *db);
135
 
};
136
 
 
137
 
 
138
 
class MSDatabase;
139
 
class MSOpenSystemTable;
140
 
 
141
 
class MSBackup :public CSDaemon {
142
 
 
143
 
public:
144
 
 
145
 
        MSBackup();
146
 
        ~MSBackup(){} // Do nothing here because 'self' will no longer be valid, use completeWork().
147
 
        
148
 
        virtual bool doWork();
149
 
 
150
 
        virtual void *completeWork();
151
 
        
152
 
        void startBackup(MSDatabase *src_db);
153
 
        uint64_t getBackupSize() { return bu_size;}
154
 
        uint64_t getBackupCompletedSize() { return bu_completed;}
155
 
        bool    isRunning() { return bu_BackupRunning;}
156
 
        int             getStatus() { return (bu_BackupRunning)?0:bu_State;}
157
 
        uint32_t backupID() { return bu_ID;}
158
 
        
159
 
        static MSBackup* newMSBackup(MSBackupInfo *backup_info);
160
 
 
161
 
        friend class StartBackupCleanUp;
162
 
private:
163
 
        void completeBackup();
164
 
        
165
 
        MSBackupInfo *bu_info;
166
 
 
167
 
        CSVector        *bu_BackupList;
168
 
        CSDaemon        *bu_Compactor;
169
 
        bool            bu_BackupRunning;
170
 
        enum            {BU_RUNNING = -1, BU_COMPLETED = 0, BU_TERMINATED = 1}  bu_State; 
171
 
        
172
 
        MSDatabase      *bu_SourceDatabase;     // The source database.
173
 
        MSDatabase      *bu_Database;           // The destination database.
174
 
        MSOpenSystemTable *bu_dst_dump; // The source database's pbms_dump.
175
 
        MSOpenSystemTable *bu_src_dump; // The source database's pbms_dump.
176
 
        uint64_t                bu_size;                        // The total size of the data to be backed up.
177
 
        uint64_t                bu_completed;           // The amount of data that has been backed up so far.
178
 
        
179
 
        uint32_t                bu_ID;
180
 
        uint32_t                bu_start_time;
181
 
        
182
 
        bool            bu_TransactionManagerSuspended;
183
 
};
184
 
 
185
 
#endif // _BACKUP_MS_H_