~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/open_table_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) 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-06-04
23
 
 *
24
 
 * H&G2JCtL
25
 
 *
26
 
 * Media Stream Tables.
27
 
 *
28
 
 */
29
 
 
30
 
#pragma once
31
 
#ifndef __OPENTABLE_MS_H__
32
 
#define __OPENTABLE_MS_H__
33
 
 
34
 
#include "cslib/CSDefs.h"
35
 
#include "cslib/CSFile.h"
36
 
 
37
 
#include "engine_ms.h"
38
 
 
39
 
#include "database_ms.h"
40
 
 
41
 
class MSOpenTablePool;
42
 
 
43
 
// Keep the value of MS_OT_BUFFER_SIZE less than 0XFFFF to avoid compiler warnings.
44
 
//
45
 
// From looking at transmition speed using tcpdump it looks like 16K is a goor buffer size.
46
 
// It is very important that it be larger than the TCP frame size of about 1.5K on the 
47
 
// machine I was testing on. There did not eam to be much to gain by having a buffer size
48
 
// larger tham 16K.
49
 
//
50
 
// I wonder if performance could be gained by having 2 buffers and 2 threads per send
51
 
// so that one buffer could be being sent while the other was being filled.
52
 
#ifdef DEBUG
53
 
//#define MS_OT_BUFFER_SIZE             ((uint16_t)(512))
54
 
#define MS_OT_BUFFER_SIZE               ((uint16_t)(16384))
55
 
#else
56
 
//#define MS_OT_BUFFER_SIZE             ((uint16_t)(0XFFF0)) 
57
 
#define MS_OT_BUFFER_SIZE               ((uint16_t)(16384))  
58
 
#endif
59
 
 
60
 
#define MS_UB_SAME_TAB                  0
61
 
#define MS_UB_NEW_HANDLE                1
62
 
#define MS_UB_NEW_BLOB                  2
63
 
#define MS_UB_RETAINED                  3
64
 
#define MS_UB_NEW_RETAINED              4
65
 
 
66
 
/*
67
 
typedef struct MSUsedBlob {
68
 
        int                                     ub_state;
69
 
        uint16_t                                ub_col_index;
70
 
        uint32_t                                ub_repo_id;
71
 
        uint64_t                                ub_repo_offset;
72
 
 
73
 
        uint16_t                                ub_head_size;
74
 
        uint64_t                                ub_blob_size;
75
 
        uint64_t                                ub_blob_ref_id;
76
 
        uint32_t                                ub_blob_id;
77
 
        uint32_t                                ub_auth_code;
78
 
        char                            ub_blob_url[PBMS_BLOB_URL_SIZE];
79
 
} MSUsedBlobRec, *MSUsedBlobPtr;
80
 
*/
81
 
 
82
 
class MSOpenTable : public CSRefObject, public CSPooled {
83
 
public:
84
 
        bool                            inUse;
85
 
        bool                            isNotATable;
86
 
        MSOpenTable                     *nextTable;
87
 
        MSOpenTablePool         *myPool;
88
 
 
89
 
        CSFile                          *myTableFile;
90
 
 
91
 
        MSRepository            *myWriteRepo;
92
 
        MSRepoFile                      *myWriteRepoFile;
93
 
 
94
 
        MSTempLogFile           *myTempLogFile;
95
 
 
96
 
        char                            myOTBuffer[MS_OT_BUFFER_SIZE];
97
 
 
98
 
        MSOpenTable();
99
 
        virtual ~MSOpenTable();
100
 
 
101
 
        virtual void returnToPool();
102
 
 
103
 
        void close();
104
 
 
105
 
        void createBlob(PBMSBlobURLPtr bh, uint64_t size, char *metadata, uint16_t metadata_size, CSInputStream *stream, CloudKeyPtr cloud_key = NULL, Md5Digest *checksum = NULL);
106
 
        void createBlob(PBMSBlobIDPtr blob_id, uint64_t blob_size, char *metadata, uint16_t metadata_size);
107
 
        void sendRepoBlob(uint64_t blob_id, uint64_t req_offset, uint64_t req_size, uint32_t auth_code, bool info_only, CSHTTPOutputStream *stream);
108
 
        void useBlob(int type, uint32_t db_id, uint32_t tab_id, uint64_t blob_id, uint32_t auth_code, uint16_t col_index, uint64_t blob_size, uint64_t blob_ref_id, PBMSBlobURLPtr ret_blob_url);
109
 
 
110
 
        void releaseReference(uint64_t blob_id, uint64_t blob_ref_id);
111
 
        void freeReference(uint64_t blob_id, uint64_t blob_ref_id);
112
 
        void commitReference(uint64_t blob_id, uint64_t blob_ref_id);
113
 
        void checkBlob(CSStringBuffer *buffer, uint64_t blob_id, uint32_t auth_code, uint32_t temp_log_id, uint32_t temp_log_offset);
114
 
        bool deleteReferences(uint32_t temp_log_id, uint32_t temp_log_offset, bool *must_quit);
115
 
 
116
 
        void openForReading();
117
 
        void closeForWriting();
118
 
 
119
 
        bool haveTable() { return (myPool != NULL); }
120
 
        uint32_t getTableID();
121
 
        MSTable *getDBTable();
122
 
        MSDatabase *getDB();
123
 
 
124
 
        void formatBlobURL(PBMSBlobURLPtr blob_url, uint64_t blob_id, uint32_t auth_code, uint64_t blob_size, uint32_t tab_id, uint64_t blob_ref_id);
125
 
        void formatBlobURL(PBMSBlobURLPtr blob_url, uint64_t blob_id, uint32_t auth_code, uint64_t blob_size, uint64_t blob_ref_id);
126
 
        void formatRepoURL(PBMSBlobURLPtr blob_url, uint32_t log_id, uint64_t log_offset, uint32_t auth_code, uint64_t blob_size);
127
 
 
128
 
        /* Make this object linkable: */
129
 
        virtual CSObject *getNextLink() { return iNextLink; }
130
 
        virtual CSObject *getPrevLink() { return iPrevLink; }
131
 
        virtual void setNextLink(CSObject *link) { iNextLink = link; }
132
 
        virtual void setPrevLink(CSObject *link) { iPrevLink = link; }
133
 
 
134
 
private:
135
 
        CSObject                        *iNextLink;
136
 
        CSObject                        *iPrevLink;
137
 
 
138
 
//      uint32_t                                iUseSize;
139
 
//      uint32_t                                iUseCount;
140
 
//      MSUsedBlobPtr           iUsedBlobs;
141
 
        
142
 
 
143
 
        void openForWriting();
144
 
 
145
 
public:
146
 
        static MSOpenTable *newOpenTable(MSOpenTablePool *pool);
147
 
};
148
 
 
149
 
class MSOpenTablePool : public CSRefObject, public CSPooled {
150
 
public:
151
 
        uint32_t                        myPoolTableID;                                          /* Non-zero if in the ID list. */
152
 
        bool                    isRemovingTP;                                           /* Set to true if the table pool is being removed. */
153
 
        MSTable                 *myPoolTable;
154
 
        MSDatabase              *myPoolDB;
155
 
 
156
 
        MSOpenTablePool();
157
 
        virtual ~MSOpenTablePool();
158
 
 
159
 
        MSOpenTable *getPoolTable();                                            /* Returns NULL if there is no table in the pool. */
160
 
        void returnOpenTable(MSOpenTable *otab);
161
 
 
162
 
        void addOpenTable(MSOpenTable *otab);
163
 
        void removeOpenTable(MSOpenTable *otab);
164
 
 
165
 
        void removeOpenTablesNotInUse();
166
 
        
167
 
        virtual void returnToPool();
168
 
 
169
 
#ifdef DEBUG
170
 
        void check();
171
 
#endif
172
 
        
173
 
        uint32_t getSize() { return iPoolTables.getSize(); }
174
 
 
175
 
private:
176
 
        MSOpenTable             *iTablePool;                                            /* A list of tables currently not in use. */
177
 
        CSLinkedList    iPoolTables;                                            /* A list of all tables in this pool */
178
 
 
179
 
public:
180
 
        static MSOpenTablePool *newPool(uint32_t db_id, uint32_t tab_id);
181
 
};
182
 
 
183
 
class MSTableList : public CSObject {
184
 
public:
185
 
        MSTableList();
186
 
        ~MSTableList();
187
 
 
188
 
        static void startUp();
189
 
        static void shutDown();
190
 
 
191
 
        static void debug(MSOpenTable *otab);
192
 
 
193
 
        static MSOpenTable *getOpenTableByID(uint32_t db_id, uint32_t tab_id);
194
 
        static MSOpenTable *getOpenTableForDB(uint32_t db_id);
195
 
        static void releaseTable(MSOpenTable *otab);
196
 
 
197
 
        static bool removeTablePoolIfEmpty(MSOpenTablePool *pool);
198
 
        static void removeTablePool(MSOpenTablePool *pool);
199
 
        static void removeTablePool(MSOpenTable *otab);
200
 
        static void removeDatabaseTables(MSDatabase *database);
201
 
 
202
 
        static MSOpenTablePool *lockTablePoolForDeletion(uint32_t db_id, uint32_t tab_id, CSString *db_name, CSString *tab_name);
203
 
        static MSOpenTablePool *lockTablePoolForDeletion(MSTable *table);
204
 
        static MSOpenTablePool *lockTablePoolForDeletion(CSString *table_url);
205
 
        static MSOpenTablePool *lockTablePoolForDeletion(MSOpenTable *otab);
206
 
        static void unlockTablePool(MSOpenTablePool *pool);
207
 
 
208
 
private:
209
 
        static CSSyncOrderedList        *gPoolListByID;
210
 
 
211
 
};
212
 
 
213
 
#endif