~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Mark Atwood
  • Date: 2011-12-20 02:32:53 UTC
  • mfrom: (2469.1.1 drizzle-build)
  • Revision ID: me@mark.atwood.name-20111220023253-bvu0kr14kwsdvz7g
mergeĀ lp:~brianaker/drizzle/deprecate-pbms

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