~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 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
 
 * Original author: Paul McCullagh
20
 
 * Continued development: Barry Leslie
21
 
 *
22
 
 * 2007-07-18
23
 
 *
24
 
 * H&G2JCtL
25
 
 *
26
 
 * System tables.
27
 
 *
28
 
 */
29
 
 
30
 
/*
31
 
 
32
 
DROP TABLE IF EXISTS pbms_repository;
33
 
CREATE TABLE pbms_repository (
34
 
        Repository_id     INT COMMENT 'The reppository file number',
35
 
        Repo_blob_offset  BIGINT COMMENT 'The offset of the BLOB in the repository file',
36
 
        Blob_size         BIGINT COMMENT 'The size of the BLOB in bytes',
37
 
        Head_size         SMALLINT UNSIGNED COMMENT 'The size of the BLOB header - preceeds the BLOB data',
38
 
        Access_code       INT COMMENT 'The 4-byte authorisation code required to access the BLOB - part of the BLOB URL',
39
 
        Creation_time     TIMESTAMP COMMENT 'The time the BLOB was created',
40
 
        Last_ref_time     TIMESTAMP COMMENT 'The last time the BLOB was referenced',
41
 
        Last_access_time  TIMESTAMP COMMENT 'The last time the BLOB was accessed (read)',
42
 
        Content_type      CHAR(128) COMMENT 'The content type of the BLOB - returned by HTTP GET calls',
43
 
        Blob_data         LONGBLOB COMMENT 'The data of this BLOB'
44
 
) ENGINE=PBMS;
45
 
 
46
 
        PRIMARY KEY (Repository_id, Repo_blob_offset)
47
 
 
48
 
DROP TABLE IF EXISTS pbms_reference;
49
 
CREATE TABLE pbms_reference (
50
 
        Table_name        CHAR(64) COMMENT 'The name of the referencing table',
51
 
        Blob_id           BIGINT COMMENT 'The BLOB reference number - part of the BLOB URL',
52
 
        Column_name       CHAR(64) COMMENT 'The column name of the referencing field',
53
 
        Row_condition     VARCHAR(255) COMMENT 'This condition identifies the row in the table',
54
 
        Blob_url          VARCHAR(200) COMMENT 'The BLOB URL for HTTP GET access',
55
 
        Repository_id     INT COMMENT 'The repository file number of the BLOB',
56
 
        Repo_blob_offset  BIGINT COMMENT 'The offset in the repository file',
57
 
        Blob_size         BIGINT COMMENT 'The size of the BLOB in bytes',
58
 
        Deletion_time     TIMESTAMP COMMENT 'The time the BLOB was deleted',
59
 
        Remove_in         INT COMMENT 'The number of seconds before the reference/BLOB is removed perminently',
60
 
        Temp_log_id       INT COMMENT 'Temporary log number of the referencing deletion entry',
61
 
        Temp_log_offset   BIGINT COMMENT 'Temporary log offset of the referencing deletion entry'
62
 
) ENGINE=PBMS;
63
 
 
64
 
        PRIMARY KEY (Table_name, Blob_id, Column_name, Condition)
65
 
*/
66
 
 
67
 
#pragma once
68
 
#ifndef __SYSTEMTABLE_MS_H__
69
 
#define __SYSTEMTABLE_MS_H__
70
 
 
71
 
#include "cslib/CSMutex.h"
72
 
 
73
 
#include "defs_ms.h"
74
 
#include "repository_ms.h"
75
 
#include "cloud_ms.h"
76
 
 
77
 
#ifdef DRIZZLED
78
 
using namespace drizzled;
79
 
#else
80
 
int pbms_discover_system_tables(handlerton *hton, THD* thd, const char *db, const char *name, uchar **frmblob, size_t *frmlen);
81
 
#endif
82
 
 
83
 
class PBMSSystemTables
84
 
{
85
 
        public:
86
 
        
87
 
        #ifdef DRIZZLED
88
 
        static int getSystemTableInfo(const char *name, drizzled::message::Table &table);
89
 
        static void getSystemTableNames(bool isPBMS, std::set<std::string> &set_of_names);
90
 
        #endif
91
 
 
92
 
        static bool isSystemTable(bool isPBMS, const char *name);
93
 
 
94
 
        static void transferSystemTables(MSDatabase *dst_db, MSDatabase *src_db);
95
 
        static void loadSystemTables(MSDatabase *db);
96
 
        static void removeSystemTables(CSString *path);
97
 
 
98
 
        static CSStringBuffer *dumpSystemTables(MSDatabase *db);
99
 
        static void restoreSystemTables(MSDatabase *db, const char *data, size_t size);
100
 
 
101
 
        static void systemTablesStartUp();
102
 
        static void systemTableShutDown();
103
 
 
104
 
        private:
105
 
        static bool try_loadSystemTables(CSThread *self, int i, MSDatabase *db);
106
 
};
107
 
 
108
 
class MSSystemTableShare;
109
 
class MSDatabase;
110
 
class CSDaemon;
111
 
class MSTempLogFile;
112
 
 
113
 
#ifdef DRIZZLED
114
 
#define GET_FIELD(table, column_index) table->getField(column_index)
115
 
#define GET_TABLE_FIELDS(table) table->getFields()
116
 
#else
117
 
#define GET_FIELD(table, column_index) table->field[column_index]
118
 
#define GET_TABLE_FIELDS(table) table->field
119
 
#endif
120
 
 
121
 
 
122
 
class MSOpenSystemTable : public CSRefObject {
123
 
public:
124
 
        MSSystemTableShare              *myShare;
125
 
        TABLE                                   *mySQLTable;
126
 
 
127
 
        MSOpenSystemTable(MSSystemTableShare *share, TABLE *table);
128
 
        virtual ~MSOpenSystemTable();
129
 
 
130
 
        /*
131
 
         * The getFieldValue() methods access fields in a server record.
132
 
         * They assumes the caller knows what it is doing and does no error checking.
133
 
         */
134
 
        inline void getFieldValue(const char *row, uint16_t column_index, String *value)
135
 
        {
136
 
                Field *assumed_str_field = GET_FIELD(mySQLTable, column_index);
137
 
                unsigned char *old_ptr = assumed_str_field->ptr;
138
 
                
139
 
 
140
 
#ifdef DRIZZLED
141
 
                assumed_str_field->ptr = (unsigned char *)row + assumed_str_field->offset(mySQLTable->getInsertRecord());
142
 
                assumed_str_field->setReadSet();
143
 
#else
144
 
                assumed_str_field->ptr = (unsigned char *)row + assumed_str_field->offset(mySQLTable->record[0]);
145
 
                assumed_str_field->table->use_all_columns();
146
 
#endif
147
 
                value = assumed_str_field->val_str_internal(value);
148
 
                
149
 
                assumed_str_field->ptr = old_ptr;
150
 
        }
151
 
 
152
 
        inline void getFieldValue(const char *row, uint16_t column_index, uint64_t *value)
153
 
        {
154
 
                Field *assumed_int_field = GET_FIELD(mySQLTable, column_index);
155
 
                unsigned char *old_ptr = assumed_int_field->ptr;
156
 
 
157
 
 
158
 
#ifdef DRIZZLED
159
 
                assumed_int_field->ptr = (unsigned char *)row + assumed_int_field->offset(mySQLTable->getInsertRecord());
160
 
                assumed_int_field->setReadSet();
161
 
#else
162
 
                assumed_int_field->ptr = (unsigned char *)row + assumed_int_field->offset(mySQLTable->record[0]);
163
 
                assumed_int_field->table->use_all_columns();
164
 
#endif
165
 
                *value = assumed_int_field->val_int();
166
 
                
167
 
                assumed_int_field->ptr = old_ptr;
168
 
        }
169
 
 
170
 
        inline void getFieldValue(const char *row, uint16_t column_index, uint32_t *value)
171
 
        {
172
 
                uint64_t v64;
173
 
                getFieldValue(row, column_index, &v64);
174
 
                *value = (uint32_t) v64;
175
 
        }
176
 
 
177
 
        virtual void use() { }
178
 
        virtual void unuse() { }
179
 
        virtual void backupSeqScanInit() { }
180
 
        virtual void seqScanInit() { }
181
 
        virtual bool seqScanNext(char *buf) { UNUSED(buf); return false; }
182
 
        virtual int     getRefLen() { return 0; }
183
 
        virtual void seqScanPos(unsigned char *pos) { UNUSED(pos);}
184
 
        virtual void seqScanRead(unsigned char *pos , char *buf) {UNUSED(pos);UNUSED(buf); }
185
 
        virtual void insertRow(char *buf) {UNUSED(buf); }
186
 
        virtual void deleteRow(char *buf) {UNUSED(buf);  }
187
 
        virtual void updateRow(char *old_data, char *new_data) {UNUSED(old_data);UNUSED(new_data); }
188
 
/*      
189
 
        virtual void index_init(uint8_t idx) { }
190
 
        virtual void index_end() { }
191
 
        virtual bool index_read(char *buf, const char *key,
192
 
                                                                 uint key_len, enum ha_rkey_function find_flag){ return false;}
193
 
        virtual bool index_read_idx(char *buf, uint idx, const char *key,
194
 
                                                                                 uint key_len, enum ha_rkey_function find_flag){ return false;}
195
 
        virtual bool index_next(char *buf){ return false;}
196
 
        virtual bool index_prev(char *buf){ return false;}
197
 
        virtual bool index_first(char *buf){ return false;}
198
 
        virtual bool index_last(char *buf){ return false;}
199
 
        virtual bool index_read_last(char *buf, const char *key, uint key_len){ return false;}
200
 
*/
201
 
        
202
 
        static void setNotNullInRecord(Field *field, char *record);
203
 
        static void setNullInRecord(Field *field, char *record);
204
 
 
205
 
private:
206
 
};
207
 
 
208
 
typedef struct MSRefData {
209
 
        uint32_t                                rd_ref_count;
210
 
        uint32_t                                rd_tab_id;
211
 
        uint64_t                                rd_blob_id;
212
 
        uint64_t                                rd_blob_ref_id;
213
 
        uint32_t                                rd_temp_log_id;
214
 
        uint32_t                                rd_temp_log_offset;
215
 
        uint16_t                                rd_col_index;
216
 
} MSRefDataRec, *MSRefDataPtr;
217
 
 
218
 
class MSRepositoryTable : public MSOpenSystemTable {
219
 
public:
220
 
        MSRepositoryTable(MSSystemTableShare *share, TABLE *table);
221
 
        virtual ~MSRepositoryTable();
222
 
 
223
 
        virtual void use();
224
 
        virtual void unuse();
225
 
        virtual void seqScanInit();
226
 
        virtual bool seqScanNext(char *buf);
227
 
        virtual int     getRefLen();
228
 
        virtual void seqScanPos(unsigned char *pos);
229
 
        virtual void seqScanRead(uint32_t repo, uint64_t offset, char *buf);
230
 
        virtual void seqScanRead(unsigned char *pos, char *buf);
231
 
 
232
 
        friend class MSReferenceTable;
233
 
        friend class MSBlobDataTable;
234
 
        friend class MSMetaDataTable;
235
 
        friend class MSBlobAliasTable;
236
 
        friend class MSDumpTable;
237
 
 
238
 
private:
239
 
        uint32_t                        iRepoIndex;
240
 
        uint64_t                        iRepoCurrentOffset;
241
 
        uint64_t                        iRepoOffset;
242
 
        uint64_t                        iRepoFileSize;
243
 
        CSDaemon                *iCompactor;
244
 
        MSRepoFile              *iRepoFile;
245
 
        CSStringBuffer  *iBlobBuffer;
246
 
 
247
 
        virtual bool returnRecord(char *buf);
248
 
        virtual bool returnSubRecord(char *buf);
249
 
        virtual bool returnRow(MSBlobHeadPtr blob, char *buf);
250
 
        virtual bool resetScan(bool positioned, uint32_t iRepoIndex = 0);
251
 
};
252
 
 
253
 
class MSBlobDataTable : public MSRepositoryTable {
254
 
public:
255
 
        MSBlobDataTable(MSSystemTableShare *share, TABLE *table);
256
 
        ~MSBlobDataTable();
257
 
        
258
 
private:
259
 
        virtual bool returnRow(MSBlobHeadPtr blob, char *buf);
260
 
};
261
 
 
262
 
// The main purpose of this class if for internal use when
263
 
// building the alias index.
264
 
class MSBlobAliasTable : public MSRepositoryTable {
265
 
public:
266
 
        MSBlobAliasTable(MSSystemTableShare *share, TABLE *table):MSRepositoryTable(share, table){}     
267
 
private:
268
 
        
269
 
        virtual bool returnRow(MSBlobHeadPtr blob, char *buf);
270
 
};
271
 
 
272
 
 
273
 
class MSReferenceTable : public MSRepositoryTable {
274
 
public:
275
 
        MSReferenceTable(MSSystemTableShare *share, TABLE *table);
276
 
        virtual ~MSReferenceTable();
277
 
 
278
 
        void unuse();
279
 
        void seqScanInit();
280
 
        int     getRefLen();
281
 
        void seqScanPos(unsigned char *pos);
282
 
        virtual void seqScanRead(uint32_t repo, uint64_t offset, char *buf) { return MSRepositoryTable::seqScanRead(repo, offset, buf);}
283
 
        void seqScanRead(unsigned char *pos, char *buf);
284
 
        bool seqScanNext(char *buf);
285
 
 
286
 
private:
287
 
        MSRefDataPtr    iRefDataList;
288
 
        /* 
289
 
         * I need my own copy of the current repository index and offset
290
 
         * to ensure it referess to the same blob as the reference data position.
291
 
        */
292
 
        uint32_t                        iRefCurrentIndex;               
293
 
        uint64_t                        iRefCurrentOffset;              
294
 
        uint32_t                        iRefCurrentDataUsed;
295
 
        uint32_t                        iRefCurrentDataPos;
296
 
        uint32_t                        iRefDataSize;
297
 
        uint32_t                        iRefDataUsed;
298
 
        uint32_t                        iRefDataPos;
299
 
        uint32_t                        iRefAuthCode;
300
 
        uint64_t                        iRefBlobSize;
301
 
        uint32_t                        iRefBlobRepo;
302
 
        uint64_t                        iRefBlobOffset;
303
 
        MSOpenTable             *iRefOpenTable;
304
 
        MSTempLogFile   *iRefTempLog;
305
 
 
306
 
        virtual bool returnRecord(char *buf);
307
 
        virtual bool returnSubRecord(char *buf);
308
 
        virtual bool returnRow(MSBlobHeadPtr blob, char *buf) { return MSRepositoryTable::returnRow(blob, buf);}
309
 
        virtual void returnRow(MSRefDataPtr ref_data, char *buf);
310
 
        virtual bool resetScan(bool positioned, uint32_t iRepoIndex = 0);
311
 
};
312
 
 
313
 
class MSMetaDataTable : public MSRepositoryTable {
314
 
public:
315
 
        MSMetaDataTable(MSSystemTableShare *share, TABLE *table);
316
 
        virtual ~MSMetaDataTable();
317
 
 
318
 
        void use();
319
 
        void unuse();
320
 
        void seqScanInit();
321
 
        int     getRefLen();
322
 
        void seqScanPos(unsigned char *pos);
323
 
        virtual void seqScanRead(uint32_t repo, uint64_t offset, char *buf) { return MSRepositoryTable::seqScanRead(repo, offset, buf);}
324
 
        void seqScanRead(unsigned char *pos, char *buf);
325
 
        bool seqScanNext(char *buf);
326
 
        void insertRow(char *buf);
327
 
        void deleteRow(char *buf);
328
 
        void updateRow(char *old_data, char *new_data);
329
 
 
330
 
#ifdef HAVE_ALIAS_SUPPORT
331
 
        bool matchAlias(uint32_t repo_id, uint64_t offset, const char *alias);
332
 
#endif
333
 
 
334
 
        friend class MSSysMeta;
335
 
 
336
 
private:
337
 
        CSStringBuffer  *iMetData;
338
 
        uint32_t                iMetCurrentBlobRepo;            
339
 
        uint64_t                iMetCurrentBlobOffset;          
340
 
        uint32_t                        iMetCurrentDataPos;
341
 
        uint32_t                        iMetCurrentDataSize;
342
 
        uint32_t                        iMetDataPos;
343
 
        uint32_t                        iMetDataSize;
344
 
        uint32_t                iMetBlobRepo;
345
 
        uint64_t                iMetBlobOffset;
346
 
        uint8_t                 iMetState[20];
347
 
        bool                    iMetStateSaved;
348
 
        
349
 
        bool nextRecord(char **name, char **value);
350
 
        void seqScanReset();
351
 
        
352
 
        virtual bool returnRecord(char *buf);
353
 
        virtual bool returnSubRecord(char *buf);
354
 
        virtual bool returnRow(MSBlobHeadPtr blob, char *buf) { return MSRepositoryTable::returnRow(blob, buf);}
355
 
        virtual void returnRow(char *name, char *value, char *buf);
356
 
        virtual bool resetScan(bool positioned, uint32_t index = 0) {bool have_data= false; return resetScan(positioned, &have_data, index);}
357
 
        virtual bool resetScan(bool positioned, bool *have_data, uint32_t iRepoIndex = 0);
358
 
        
359
 
        static MSMetaDataTable *newMSMetaDataTable(MSDatabase *db);
360
 
};
361
 
 
362
 
class MSSystemTableShare : public CSRefObject {
363
 
public:
364
 
        CSString                                *myTablePath;
365
 
        THR_LOCK                                myThrLock;
366
 
        MSDatabase                              *mySysDatabase;
367
 
 
368
 
        MSSystemTableShare();
369
 
        ~MSSystemTableShare();
370
 
 
371
 
        /* Make this object sortable: */
372
 
        virtual CSObject *getKey();
373
 
        virtual int compareKey(CSObject *);
374
 
 
375
 
private:
376
 
        uint32_t                                        iOpenCount;
377
 
 
378
 
public:
379
 
        static CSSyncSortedList *gSystemTableList;
380
 
 
381
 
        // Close all open system tables for the database being dropped.
382
 
        static void removeDatabaseSystemTables(MSDatabase *doomed_db); 
383
 
        static void startUp();
384
 
        static void shutDown();
385
 
 
386
 
        static MSOpenSystemTable *openSystemTable(const char *table_path, TABLE *table);
387
 
        static void releaseSystemTable(MSOpenSystemTable *tab);
388
 
 
389
 
        static MSSystemTableShare *newTableShare(CSString *table_path);
390
 
};
391
 
 
392
 
#endif