~drizzle-trunk/drizzle/development

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