1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
1 |
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
18 |
*
|
19 |
* Original author: Paul McCullagh
|
|
20 |
* Continued development: Barry Leslie
|
|
21 |
*
|
|
22 |
* 2007-07-20
|
|
23 |
*
|
|
24 |
* H&G2JCtL
|
|
25 |
*
|
|
26 |
* Engine interface.
|
|
27 |
*
|
|
28 |
*/
|
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
29 |
#ifdef DRIZZLED
|
30 |
#include "config.h" |
|
31 |
#include <drizzled/common.h> |
|
32 |
#include <drizzled/session.h> |
|
33 |
#endif
|
|
34 |
||
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
35 |
|
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. |
36 |
#include "cslib/CSConfig.h" |
37 |
#include "cslib/CSGlobal.h" |
|
38 |
#include "cslib/CSStrUtil.h" |
|
39 |
#include "cslib/CSThread.h" |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
40 |
|
1644.3.1
by Barry.Leslie at PrimeBase
Merged in changes from PBMS project. |
41 |
#ifndef DRIZZLED
|
42 |
#define PBMS_API pbms_internal
|
|
43 |
#include "pbms.h" |
|
44 |
#endif
|
|
45 |
||
1548.2.10
by Barry.Leslie at PrimeBase
Merge from trunk. |
46 |
#include "engine_ms.h" |
47 |
#include "connection_handler_ms.h" |
|
48 |
#include "open_table_ms.h" |
|
49 |
#include "network_ms.h" |
|
50 |
#include "transaction_ms.h" |
|
51 |
#include "mysql_ms.h" |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
52 |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
53 |
|
54 |
#ifdef new
|
|
55 |
#undef new
|
|
56 |
#endif
|
|
57 |
||
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
58 |
// From ha-pbms.cc:
|
59 |
extern CSThread *pbms_getMySelf(THD *thd); |
|
60 |
extern void pbms_setMySelf(THD *thd, CSThread *self); |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
61 |
|
62 |
#ifndef DRIZZLED
|
|
63 |
||
64 |
/*
|
|
65 |
* ---------------------------------------------------------------
|
|
66 |
* ENGINE CALL-IN INTERFACE
|
|
67 |
*/
|
|
68 |
||
69 |
static PBMS_API *StreamingEngines; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
70 |
// If PBMS support is built directly into the mysql/drizzle handler code
|
71 |
// then calls from all other handlers are ignored.
|
|
72 |
static bool have_handler_support = false; |
|
73 |
||
74 |
/*
|
|
75 |
* ---------------------------------------------------------------
|
|
76 |
* ENGINE CALLBACK INTERFACE
|
|
77 |
*/
|
|
78 |
||
79 |
static void ms_register_engine(PBMSEnginePtr engine) |
|
80 |
{
|
|
81 |
if (engine->ms_internal) |
|
82 |
have_handler_support = true; |
|
83 |
}
|
|
84 |
||
1548.2.28
by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro. |
85 |
static void ms_deregister_engine(PBMSEnginePtr engine) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
86 |
{
|
1548.2.28
by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro. |
87 |
UNUSED(engine); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
88 |
}
|
89 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
90 |
static int ms_create_blob(bool internal, const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url, PBMSResultPtr result) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
91 |
{
|
92 |
if (have_handler_support && !internal) { |
|
1644.3.1
by Barry.Leslie at PrimeBase
Merged in changes from PBMS project. |
93 |
MSEngine::errorResult(CS_CONTEXT, MS_ERR_INVALID_OPERATION, "Invalid ms_create_blob() call", result); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
94 |
return MS_ERR_ENGINE; |
95 |
}
|
|
96 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
97 |
return MSEngine::createBlob(db_name, tab_name, blob, blob_len, blob_url, result); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
98 |
}
|
99 |
||
100 |
/*
|
|
101 |
* ms_use_blob() may or may not alter the blob url depending on the type of URL and if the BLOB is in a
|
|
102 |
* different database or not. It may also add a BLOB reference to the BLOB table log if the BLOB was from
|
|
103 |
* a different table or no table was specified when the BLOB was uploaded.
|
|
104 |
*
|
|
105 |
* There is no need to undo this function because it will be undone automaticly if the BLOB is not retained.
|
|
106 |
*/
|
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
107 |
static int ms_retain_blob(bool internal, const char *db_name, const char *tab_name, PBMSBlobURLPtr ret_blob_url, char *blob_url, unsigned short col_index, PBMSResultPtr result) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
108 |
{
|
109 |
if (have_handler_support && !internal) { |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
110 |
cs_strcpy(PBMS_BLOB_URL_SIZE, ret_blob_url->bu_data, blob_url); // This should have already been converted. |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
111 |
return MS_OK; |
112 |
}
|
|
113 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
114 |
return MSEngine::referenceBlob(db_name, tab_name, ret_blob_url, blob_url, col_index, result); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
115 |
}
|
116 |
||
117 |
static int ms_release_blob(bool internal, const char *db_name, const char *tab_name, char *blob_url, PBMSResultPtr result) |
|
118 |
{
|
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
119 |
|
120 |
if (have_handler_support && !internal) |
|
121 |
return MS_OK; |
|
122 |
||
123 |
return MSEngine::dereferenceBlob(db_name, tab_name, blob_url, result); |
|
124 |
}
|
|
125 |
||
126 |
static int ms_drop_table(bool internal, const char *db_name, const char *tab_name, PBMSResultPtr result) |
|
127 |
{
|
|
128 |
if (have_handler_support && !internal) |
|
129 |
return MS_OK; |
|
130 |
||
131 |
return MSEngine::dropTable(db_name, tab_name, result); |
|
132 |
}
|
|
133 |
||
134 |
static int ms_rename_table(bool internal, const char * db_name, const char *from_table, const char *to_db, const char *to_table, PBMSResultPtr result) |
|
135 |
{
|
|
136 |
if (have_handler_support && !internal) |
|
137 |
return MS_OK; |
|
138 |
||
139 |
return MSEngine::renameTable(db_name, from_table, to_db, to_table, result); |
|
140 |
}
|
|
141 |
||
142 |
static void ms_completed(bool internal, bool ok) |
|
143 |
{
|
|
144 |
if (have_handler_support && !internal) |
|
145 |
return; |
|
146 |
||
147 |
MSEngine::callCompleted(ok); |
|
148 |
}
|
|
149 |
||
150 |
PBMSCallbacksRec engine_callbacks = { |
|
151 |
MS_CALLBACK_VERSION, |
|
152 |
ms_register_engine, |
|
153 |
ms_deregister_engine, |
|
154 |
ms_create_blob, |
|
155 |
ms_retain_blob, |
|
156 |
ms_release_blob, |
|
157 |
ms_drop_table, |
|
158 |
ms_rename_table, |
|
159 |
ms_completed
|
|
160 |
};
|
|
161 |
||
162 |
// =============================
|
|
163 |
int MSEngine::startUp(PBMSResultPtr result) |
|
164 |
{
|
|
165 |
int err = 0; |
|
166 |
||
167 |
StreamingEngines = new PBMS_API(); |
|
168 |
err = StreamingEngines->PBMSStartup(&engine_callbacks, result); |
|
169 |
if (err) |
|
170 |
delete StreamingEngines; |
|
171 |
else { // Register the PBMS enabled engines the startup before PBMS |
|
172 |
PBMSSharedMemoryPtr sh_mem = StreamingEngines->sharedMemory; |
|
173 |
PBMSEnginePtr engine; |
|
174 |
||
175 |
for (int i=0; i<sh_mem->sm_list_len; i++) { |
|
176 |
if ((engine = sh_mem->sm_engine_list[i])) |
|
177 |
ms_register_engine(engine); |
|
178 |
}
|
|
179 |
}
|
|
180 |
return err; |
|
181 |
}
|
|
182 |
||
183 |
void MSEngine::shutDown() |
|
184 |
{
|
|
185 |
StreamingEngines->PBMSShutdown(); |
|
186 |
||
187 |
delete StreamingEngines; |
|
188 |
}
|
|
189 |
||
190 |
const PBMSEnginePtr MSEngine::getEngineInfoAt(int indx) |
|
191 |
{
|
|
192 |
PBMSSharedMemoryPtr sh_mem = StreamingEngines->sharedMemory; |
|
193 |
PBMSEnginePtr engine = NULL; |
|
194 |
||
195 |
if (sh_mem) { |
|
196 |
for (int i=0; i<sh_mem->sm_list_len; i++) { |
|
197 |
if ((engine = sh_mem->sm_engine_list[i])) { |
|
198 |
if (!indx) |
|
199 |
return engine; |
|
200 |
indx--; |
|
201 |
}
|
|
202 |
}
|
|
203 |
}
|
|
204 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
205 |
return (const PBMSEnginePtr)NULL; |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
206 |
}
|
207 |
#endif
|
|
208 |
||
209 |
//---------------
|
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
210 |
bool MSEngine::try_createBlob(CSThread *self, const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url) |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
211 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
212 |
volatile bool rtc = true; |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
213 |
|
214 |
try_(a) { |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
215 |
MSOpenTable *otab; |
216 |
CSInputStream *i_stream = NULL; |
|
217 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
218 |
otab = openTable(db_name, tab_name, true); |
219 |
frompool_(otab); |
|
220 |
||
221 |
if (!otab->getDB()->isRecovering()) { |
|
222 |
i_stream = CSMemoryInputStream::newStream((unsigned char *)blob, blob_len); |
|
223 |
otab->createBlob(blob_url, blob_len, NULL, 0, i_stream); |
|
224 |
} else |
|
225 |
CSException::throwException(CS_CONTEXT, MS_ERR_RECOVERY_IN_PROGRESS, "Cannot create BLOBs during repository recovery."); |
|
226 |
||
227 |
backtopool_(otab); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
228 |
rtc = false; |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
229 |
}
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
230 |
catch_(a); |
231 |
cont_(a); |
|
232 |
return rtc; |
|
233 |
}
|
|
234 |
||
235 |
//---------------
|
|
236 |
int32_t MSEngine::createBlob(const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url, PBMSResultPtr result) |
|
237 |
{
|
|
238 |
||
239 |
CSThread *self; |
|
240 |
int32_t err = MS_OK; |
|
241 |
||
242 |
if ((err = enterConnectionNoThd(&self, result))) |
|
243 |
return err; |
|
244 |
||
245 |
inner_(); |
|
246 |
if (try_createBlob(self, db_name, tab_name, blob, blob_len, blob_url)) |
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
247 |
err = exceptionToResult(&self->myException, result); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
248 |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
249 |
return_(err); |
250 |
}
|
|
251 |
||
252 |
//---------------
|
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
253 |
bool MSEngine::try_referenceBlob(CSThread *self, const char *db_name, const char *tab_name, PBMSBlobURLPtr ret_blob_url, char *blob_url, uint16_t col_index) |
254 |
{
|
|
255 |
volatile bool rtc = true; |
|
256 |
try_(a) { |
|
257 |
MSBlobURLRec blob; |
|
258 |
MSOpenTable *otab; |
|
259 |
||
260 |
if (! PBMSBlobURLTools::couldBeURL(blob_url, &blob)){ |
|
261 |
char buffer[CS_EXC_MESSAGE_SIZE]; |
|
262 |
||
263 |
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Incorrect URL: "); |
|
264 |
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, blob_url); |
|
265 |
CSException::throwException(CS_CONTEXT, MS_ERR_INCORRECT_URL, buffer); |
|
266 |
}
|
|
267 |
||
268 |
otab = openTable(db_name, tab_name, true); |
|
269 |
frompool_(otab); |
|
270 |
||
271 |
otab->useBlob(blob.bu_type, blob.bu_db_id, blob.bu_tab_id, blob.bu_blob_id, blob.bu_auth_code, col_index, blob.bu_blob_size, blob.bu_blob_ref_id, ret_blob_url); |
|
272 |
||
273 |
backtopool_(otab); |
|
274 |
rtc = false; |
|
275 |
}
|
|
276 |
catch_(a); |
|
277 |
cont_(a); |
|
278 |
return rtc; |
|
279 |
}
|
|
280 |
||
281 |
//---------------
|
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
282 |
int32_t MSEngine::referenceBlob(const char *db_name, const char *tab_name, PBMSBlobURLPtr ret_blob_url, char *blob_url, uint16_t col_index, PBMSResultPtr result) |
283 |
{
|
|
284 |
||
285 |
CSThread *self; |
|
286 |
int32_t err = MS_OK; |
|
287 |
||
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
288 |
if ((err = enterConnectionNoThd(&self, result))) |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
289 |
return err; |
290 |
||
291 |
inner_(); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
292 |
if (try_referenceBlob(self, db_name, tab_name, ret_blob_url, blob_url, col_index)) |
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
293 |
err = exceptionToResult(&self->myException, result); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
294 |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
295 |
return_(err); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
296 |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
297 |
}
|
298 |
||
299 |
//---------------
|
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
300 |
bool MSEngine::try_dereferenceBlob(CSThread *self, const char *db_name, const char *tab_name, char *blob_url) |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
301 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
302 |
volatile bool rtc = true; |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
303 |
try_(a) { |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
304 |
MSBlobURLRec blob; |
305 |
MSOpenTable *otab; |
|
306 |
||
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
307 |
if (! PBMSBlobURLTools::couldBeURL(blob_url, &blob)){ |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
308 |
char buffer[CS_EXC_MESSAGE_SIZE]; |
309 |
||
310 |
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Incorrect URL: "); |
|
311 |
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, blob_url); |
|
312 |
CSException::throwException(CS_CONTEXT, MS_ERR_INCORRECT_URL, buffer); |
|
313 |
}
|
|
314 |
||
315 |
otab = openTable(db_name, tab_name, true); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
316 |
frompool_(otab); |
317 |
if (!otab->getDB()->isRecovering()) { |
|
318 |
if (otab->getTableID() == blob.bu_tab_id) |
|
319 |
otab->releaseReference(blob.bu_blob_id, blob.bu_blob_ref_id); |
|
320 |
else { |
|
321 |
char buffer[CS_EXC_MESSAGE_SIZE]; |
|
322 |
||
323 |
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Incorrect table ID: "); |
|
324 |
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, blob_url); |
|
325 |
CSException::throwException(CS_CONTEXT, MS_ERR_INCORRECT_URL, buffer); |
|
326 |
}
|
|
327 |
}
|
|
328 |
else { |
|
329 |
char buffer[CS_EXC_MESSAGE_SIZE]; |
|
330 |
||
331 |
cs_strcpy(CS_EXC_MESSAGE_SIZE, buffer, "Incorrect URL: "); |
|
332 |
cs_strcat(CS_EXC_MESSAGE_SIZE, buffer, blob_url); |
|
333 |
CSException::throwException(CS_CONTEXT, MS_ERR_INCORRECT_URL, buffer); |
|
334 |
}
|
|
335 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
336 |
backtopool_(otab); |
337 |
rtc = false; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
338 |
}
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
339 |
catch_(a); |
340 |
cont_(a); |
|
341 |
return rtc; |
|
342 |
}
|
|
343 |
||
344 |
int32_t MSEngine::dereferenceBlob(const char *db_name, const char *tab_name, char *blob_url, PBMSResultPtr result) |
|
345 |
{
|
|
346 |
CSThread *self; |
|
347 |
int32_t err = MS_OK; |
|
348 |
||
349 |
if ((err = enterConnectionNoThd(&self, result))) |
|
350 |
return err; |
|
351 |
||
352 |
inner_(); |
|
353 |
if (try_dereferenceBlob(self, db_name, tab_name, blob_url)) |
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
354 |
err = exceptionToResult(&self->myException, result); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
355 |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
356 |
return_(err); |
357 |
}
|
|
358 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
359 |
bool MSEngine::try_dropDatabase(CSThread *self, const char *db_name) |
360 |
{
|
|
361 |
volatile bool rtc = true; |
|
362 |
try_(a) { |
|
363 |
MSDatabase::dropDatabase(db_name); |
|
364 |
rtc = false; |
|
365 |
}
|
|
366 |
catch_(a); |
|
367 |
cont_(a); |
|
368 |
||
369 |
return rtc; |
|
370 |
}
|
|
371 |
||
1548.2.6
by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle. |
372 |
int32_t MSEngine::dropDatabase(const char *db_name, PBMSResultPtr result) |
373 |
{
|
|
374 |
CSThread *self; |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
375 |
int err = MS_OK; |
1548.2.6
by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle. |
376 |
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
377 |
if ((err = enterConnectionNoThd(&self, result))) |
1548.2.6
by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle. |
378 |
return err; |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
379 |
|
1548.2.6
by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle. |
380 |
inner_(); |
381 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
382 |
if (try_dropDatabase(self, db_name)) |
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
383 |
err = exceptionToResult(&self->myException, result); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
384 |
|
1548.2.6
by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle. |
385 |
return_(err); |
386 |
}
|
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
387 |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
388 |
//---------------
|
389 |
typedef struct UnDoInfo { |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
390 |
bool udo_WasRename; |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
391 |
CSString *udo_toDatabaseName; |
392 |
CSString *udo_fromDatabaseName; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
393 |
CSString *udo_OldName; |
394 |
CSString *udo_NewName; |
|
395 |
} UnDoInfoRec, *UnDoInfoPtr; |
|
396 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
397 |
//---------------
|
398 |
bool MSEngine::try_dropTable(CSThread *self, const char *db_name, const char *tab_name) |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
399 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
400 |
volatile bool rtc = true; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
401 |
try_(a) { |
402 |
||
403 |
CSPath *new_path; |
|
404 |
CSPath *old_path; |
|
405 |
MSOpenTable *otab; |
|
406 |
MSOpenTablePool *tab_pool; |
|
407 |
MSTable *tab; |
|
408 |
UnDoInfoPtr undo_info = NULL; |
|
409 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
410 |
otab = openTable(db_name, tab_name, false); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
411 |
if (!otab) { |
412 |
goto end_try; |
|
413 |
}
|
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
414 |
|
415 |
// If we are recovering do not delete the table.
|
|
416 |
// It is normal for MySQL recovery scripts to delete any table they aare about to
|
|
417 |
// recover and then recreate it. If this is done after the repository has been recovered
|
|
418 |
// then this would delete all the recovered BLOBs in the table.
|
|
419 |
if (otab->getDB()->isRecovering()) { |
|
420 |
otab->returnToPool(); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
421 |
goto end_try; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
422 |
}
|
423 |
||
424 |
frompool_(otab); |
|
425 |
||
426 |
// Before dropping the table the table ref file is renamed so that
|
|
427 |
// it is out of the way incase a new table is created before the
|
|
428 |
// old one is cleaned up.
|
|
429 |
||
430 |
old_path = otab->getDBTable()->getTableFile(); |
|
431 |
push_(old_path); |
|
432 |
||
433 |
new_path = otab->getDBTable()->getTableFile(tab_name, true); |
|
434 |
||
435 |
// Rearrage the object stack to pop the otab object
|
|
436 |
pop_(old_path); |
|
437 |
pop_(otab); |
|
438 |
||
439 |
push_(new_path); |
|
440 |
push_(old_path); |
|
441 |
frompool_(otab); |
|
442 |
||
443 |
tab = otab->getDBTable(); |
|
444 |
pop_(otab); |
|
445 |
push_(tab); |
|
446 |
||
447 |
tab_pool = MSTableList::lockTablePoolForDeletion(otab); |
|
448 |
frompool_(tab_pool); |
|
449 |
||
450 |
if (old_path->exists()) |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
451 |
old_path->move(RETAIN(new_path)); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
452 |
tab->myDatabase->dropTable(RETAIN(tab)); |
453 |
||
454 |
/* Add the table to the temp delete list if we are not recovering... */
|
|
455 |
tab->prepareToDelete(); |
|
456 |
||
457 |
backtopool_(tab_pool); // The will unlock and close the table pool freeing all tables in it. |
|
458 |
pop_(tab); // Returning the pool will have released this. (YUK!) |
|
459 |
release_(old_path); |
|
460 |
release_(new_path); |
|
461 |
||
462 |
||
463 |
undo_info = (UnDoInfoPtr) cs_malloc(sizeof(UnDoInfoRec)); |
|
464 |
||
465 |
undo_info->udo_WasRename = false; |
|
466 |
self->myInfo = undo_info; |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
467 |
|
468 |
end_try: |
|
469 |
rtc = false; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
470 |
}
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
471 |
catch_(a); |
472 |
cont_(a); |
|
473 |
return rtc; |
|
474 |
}
|
|
475 |
||
476 |
//---------------
|
|
477 |
int32_t MSEngine::dropTable(const char *db_name, const char *tab_name, PBMSResultPtr result) |
|
478 |
{
|
|
479 |
CSThread *self; |
|
480 |
int err = MS_OK; |
|
481 |
||
482 |
if ((err = enterConnectionNoThd(&self, result))) |
|
483 |
return err; |
|
484 |
||
485 |
inner_(); |
|
486 |
if (try_dropTable(self, db_name, tab_name)) |
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
487 |
err = exceptionToResult(&self->myException, result); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
488 |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
489 |
outer_(); |
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
490 |
exitConnection(); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
491 |
return err; |
492 |
}
|
|
493 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
494 |
//---------------
|
1548.2.6
by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle. |
495 |
static void completeDeleteTable(UnDoInfoPtr info, bool ok) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
496 |
{
|
497 |
// TO DO: figure out a way to undo the delete.
|
|
498 |
cs_free(info); |
|
499 |
if (!ok) |
|
500 |
CSException::throwException(CS_CONTEXT, MS_ERR_NOT_IMPLEMENTED, "Cannot undo delete table."); |
|
501 |
}
|
|
502 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
503 |
//---------------
|
504 |
bool MSEngine::renameTable(const char *from_db_name, const char *from_table, const char *to_db_name, const char *to_table) |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
505 |
{
|
506 |
MSOpenTable *otab; |
|
507 |
CSPath *from_path; |
|
508 |
CSPath *to_path; |
|
509 |
MSOpenTablePool *tab_pool; |
|
510 |
MSTable *tab; |
|
511 |
||
512 |
enter_(); |
|
513 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
514 |
if (strcmp(to_db_name, from_db_name) != 0) { |
515 |
CSException::throwException(CS_CONTEXT, MS_ERR_NOT_IMPLEMENTED, "Cannot rename tables containing BLOBs across databases (yet). Sorry!"); |
|
516 |
}
|
|
517 |
||
518 |
otab = openTable(from_db_name, from_table, false); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
519 |
if (!otab) |
520 |
return_(false); |
|
521 |
||
522 |
frompool_(otab); |
|
523 |
||
524 |
if (otab->getDB()->isRecovering()) |
|
525 |
CSException::throwException(CS_CONTEXT, MS_ERR_RECOVERY_IN_PROGRESS, "Cannot rename tables during repository recovery."); |
|
526 |
||
527 |
from_path = otab->getDBTable()->getTableFile(); |
|
528 |
push_(from_path); |
|
529 |
||
530 |
to_path = otab->getDBTable()->getTableFile(to_table, false); |
|
531 |
||
532 |
// Rearrage the object stack to pop the otab object
|
|
533 |
pop_(from_path); |
|
534 |
pop_(otab); |
|
535 |
||
536 |
push_(to_path); |
|
537 |
push_(from_path); |
|
538 |
frompool_(otab); |
|
539 |
||
540 |
otab->openForReading(); |
|
541 |
tab = otab->getDBTable(); |
|
542 |
tab->retain(); |
|
543 |
pop_(otab); |
|
544 |
push_(tab); |
|
545 |
||
546 |
tab_pool = MSTableList::lockTablePoolForDeletion(otab); |
|
547 |
frompool_(tab_pool); |
|
548 |
||
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
549 |
from_path->move(RETAIN(to_path)); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
550 |
tab->myDatabase->renameTable(tab, to_table); |
551 |
||
552 |
backtopool_(tab_pool); // The will unlock and close the table pool freeing all tables in it. |
|
553 |
pop_(tab); // Returning the pool will have released this. (YUK!) |
|
554 |
release_(from_path); |
|
555 |
release_(to_path); |
|
556 |
||
557 |
return_(true); |
|
558 |
}
|
|
559 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
560 |
//---------------
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
561 |
bool MSEngine::try_renameTable(CSThread *self, const char *from_db_name, const char *from_table, const char *to_db_name, const char *to_table) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
562 |
{
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
563 |
volatile bool rtc = true; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
564 |
try_(a) { |
1548.2.18
by Barry.Leslie at PrimeBase
Possible fix for hudson not finding version_ms.h. |
565 |
UnDoInfoPtr undo_info = (UnDoInfoPtr) cs_malloc(sizeof(UnDoInfoRec)); |
1548.2.19
by Barry.Leslie at PrimeBase
Fixes for longjmp clobber problem, (Hopefully) |
566 |
push_ptr_(undo_info); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
567 |
|
568 |
undo_info->udo_WasRename = true; |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
569 |
if (renameTable(from_db_name, from_table, to_db_name, to_table)) { |
570 |
undo_info->udo_fromDatabaseName = CSString::newString(from_db_name); |
|
1548.2.18
by Barry.Leslie at PrimeBase
Possible fix for hudson not finding version_ms.h. |
571 |
push_(undo_info->udo_fromDatabaseName); |
572 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
573 |
undo_info->udo_toDatabaseName = CSString::newString(to_db_name); |
1548.2.18
by Barry.Leslie at PrimeBase
Possible fix for hudson not finding version_ms.h. |
574 |
push_(undo_info->udo_toDatabaseName); |
575 |
||
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
576 |
undo_info->udo_OldName = CSString::newString(from_table); |
1548.2.18
by Barry.Leslie at PrimeBase
Possible fix for hudson not finding version_ms.h. |
577 |
push_(undo_info->udo_OldName); |
578 |
||
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
579 |
undo_info->udo_NewName = CSString::newString(to_table); |
1548.2.18
by Barry.Leslie at PrimeBase
Possible fix for hudson not finding version_ms.h. |
580 |
|
581 |
pop_(undo_info->udo_OldName); |
|
582 |
pop_(undo_info->udo_toDatabaseName); |
|
583 |
pop_(undo_info->udo_fromDatabaseName); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
584 |
} else { |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
585 |
undo_info->udo_fromDatabaseName = undo_info->udo_toDatabaseName = undo_info->udo_OldName = undo_info->udo_NewName = NULL; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
586 |
}
|
587 |
self->myInfo = undo_info; |
|
1548.2.18
by Barry.Leslie at PrimeBase
Possible fix for hudson not finding version_ms.h. |
588 |
pop_(undo_info); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
589 |
rtc = false; |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
590 |
}
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
591 |
catch_(a); |
592 |
cont_(a); |
|
593 |
return rtc; |
|
594 |
}
|
|
595 |
||
596 |
//---------------
|
|
597 |
int32_t MSEngine::renameTable(const char *from_db_name, const char *from_table, const char *to_db_name, const char *to_table, PBMSResultPtr result) |
|
598 |
{
|
|
599 |
CSThread *self; |
|
600 |
int err = MS_OK; |
|
601 |
||
602 |
if ((err = enterConnectionNoThd(&self, result))) |
|
603 |
return err; |
|
604 |
||
605 |
inner_(); |
|
606 |
if (try_renameTable(self, from_db_name, from_table, to_db_name, to_table)) |
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
607 |
err = exceptionToResult(&self->myException, result); |
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
608 |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
609 |
outer_(); |
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
610 |
exitConnection(); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
611 |
return err; |
612 |
}
|
|
613 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
614 |
//---------------
|
615 |
void MSEngine::completeRenameTable(UnDoInfoPtr info, bool ok) |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
616 |
{
|
617 |
// Swap the paths around here to revers the rename.
|
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
618 |
CSString *from_db_name= info->udo_toDatabaseName; |
619 |
CSString *to_db_name= info->udo_fromDatabaseName; |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
620 |
CSString *from_table= info->udo_NewName; |
621 |
CSString *to_table= info->udo_OldName; |
|
622 |
||
623 |
enter_(); |
|
624 |
||
625 |
cs_free(info); |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
626 |
if (from_db_name) { |
627 |
push_(from_db_name); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
628 |
push_(from_table); |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
629 |
push_(to_db_name); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
630 |
push_(to_table); |
631 |
if (!ok) |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
632 |
renameTable(from_db_name->getCString(), from_table->getCString(), to_db_name->getCString(), to_table->getCString()); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
633 |
|
634 |
release_(to_table); |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
635 |
release_(to_db_name); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
636 |
release_(from_table); |
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
637 |
release_(from_db_name); |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
638 |
}
|
639 |
exit_(); |
|
640 |
}
|
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
641 |
|
642 |
//---------------
|
|
643 |
static bool try_CompleteTransaction(CSThread *self, bool ok) |
|
644 |
{
|
|
645 |
volatile bool rtc = true; |
|
646 |
try_(a) { |
|
647 |
if (ok) |
|
648 |
MSTransactionManager::commit(); |
|
649 |
else if (self->myIsAutoCommit) |
|
650 |
MSTransactionManager::rollback(); |
|
651 |
else
|
|
652 |
MSTransactionManager::rollbackToPosition(self->myStartStmt); // Rollback the last logical statement. |
|
653 |
rtc = false; |
|
654 |
}
|
|
655 |
catch_(a) |
|
656 |
cont_(a); |
|
657 |
||
658 |
return rtc; |
|
659 |
}
|
|
660 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
661 |
//---------------
|
662 |
void MSEngine::callCompleted(bool ok) |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
663 |
{
|
664 |
CSThread *self; |
|
665 |
PBMSResultRec result; |
|
666 |
||
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
667 |
if (enterConnectionNoThd(&self, &result)) |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
668 |
return ; |
669 |
||
670 |
if (self->myInfo) { |
|
671 |
UnDoInfoPtr info = (UnDoInfoPtr) self->myInfo; |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
672 |
if (info->udo_WasRename) |
1548.2.6
by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle. |
673 |
completeRenameTable(info, ok); |
674 |
else
|
|
675 |
completeDeleteTable(info, ok); |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
676 |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
677 |
|
678 |
self->myInfo = NULL; |
|
679 |
} else if (self->myTID && (self->myIsAutoCommit || !ok)) { |
|
680 |
inner_(); |
|
1841.1.3
by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger |
681 |
if (try_CompleteTransaction(self, ok)) { |
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
682 |
self->logException(); |
683 |
}
|
|
684 |
outer_(); |
|
685 |
}
|
|
686 |
||
687 |
self->myStartStmt = self->myStmtCount; |
|
688 |
}
|
|
689 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
690 |
//---------------
|
691 |
MSOpenTable *MSEngine::openTable(const char *db_name, const char *tab_name, bool create) |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
692 |
{
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
693 |
MSOpenTable *otab = NULL; |
694 |
uint32_t db_id, tab_id; |
|
695 |
enter_(); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
696 |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
697 |
if ( MSDatabase::convertTableAndDatabaseToIDs(db_name, tab_name, &db_id, &tab_id, create)) |
698 |
otab = MSTableList::getOpenTableByID(db_id, tab_id); |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
699 |
|
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
700 |
return_(otab); |
701 |
}
|
|
702 |
||
703 |
//---------------
|
|
704 |
bool MSEngine::couldBeURL(const char *blob_url, size_t length) |
|
705 |
{
|
|
1548.2.24
by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems. |
706 |
MSBlobURLRec blob; |
707 |
return PBMSBlobURLTools::couldBeURL(blob_url, length, &blob); |
|
708 |
}
|
|
709 |
||
710 |
//---------------
|
|
711 |
int MSEngine::exceptionToResult(CSException *e, PBMSResultPtr result) |
|
712 |
{
|
|
713 |
const char *context, *trace; |
|
714 |
||
715 |
result->mr_code = e->getErrorCode(); |
|
716 |
cs_strcpy(MS_RESULT_MESSAGE_SIZE, result->mr_message, e->getMessage()); |
|
717 |
context = e->getContext(); |
|
718 |
trace = e->getStackTrace(); |
|
719 |
if (context && *context) { |
|
720 |
cs_strcpy(MS_RESULT_STACK_SIZE, result->mr_stack, context); |
|
721 |
if (trace && *trace) |
|
722 |
cs_strcat(MS_RESULT_STACK_SIZE, result->mr_stack, "\n"); |
|
723 |
}
|
|
724 |
else
|
|
725 |
*result->mr_stack = 0; |
|
726 |
if (trace && *trace) |
|
727 |
cs_strcat(MS_RESULT_STACK_SIZE, result->mr_stack, trace); |
|
728 |
return MS_ERR_ENGINE; |
|
729 |
}
|
|
730 |
||
731 |
//---------------
|
|
732 |
int MSEngine::errorResult(const char *func, const char *file, int line, int err, const char *message, PBMSResultPtr result) |
|
733 |
{
|
|
734 |
CSException e; |
|
735 |
||
736 |
e.initException(func, file, line, err, message); |
|
737 |
return exceptionToResult(&e, result); |
|
738 |
}
|
|
739 |
||
740 |
//---------------
|
|
741 |
int MSEngine::osErrorResult(const char *func, const char *file, int line, int err, PBMSResultPtr result) |
|
742 |
{
|
|
743 |
CSException e; |
|
744 |
||
745 |
e.initOSError(func, file, line, err); |
|
746 |
return MSEngine::exceptionToResult(&e, result); |
|
747 |
}
|
|
748 |
||
749 |
//---------------
|
|
750 |
int MSEngine::enterConnection(THD *thd, CSThread **r_self, PBMSResultPtr result, bool doCreate) |
|
751 |
{
|
|
752 |
CSThread *self = NULL; |
|
753 |
||
754 |
#ifndef DRIZZLED
|
|
755 |
// In drizzle there is no 1:1 relationship between pthreads and sessions
|
|
756 |
// so we must always get it from the session handle NOT the current pthread.
|
|
757 |
self = CSThread::getSelf(); |
|
758 |
#endif
|
|
759 |
if (!self) { |
|
760 |
if (thd) { |
|
761 |
if (!(self = pbms_getMySelf(thd))) { |
|
762 |
if (!doCreate) |
|
763 |
return MS_ERR_NOT_FOUND; |
|
764 |
||
765 |
if (!(self = CSThread::newCSThread())) |
|
766 |
return osErrorResult(CS_CONTEXT, ENOMEM, result); |
|
767 |
if (!CSThread::attach(self)) |
|
768 |
return MSEngine::exceptionToResult(&self->myException, result); |
|
769 |
pbms_setMySelf(thd, self); |
|
770 |
} else { |
|
771 |
if (!CSThread::setSelf(self)) |
|
772 |
return MSEngine::exceptionToResult(&self->myException, result); |
|
773 |
}
|
|
774 |
} else { |
|
775 |
if (!doCreate) |
|
776 |
return MS_ERR_NOT_FOUND; |
|
777 |
||
778 |
if (!(self = CSThread::newCSThread())) |
|
779 |
return osErrorResult(CS_CONTEXT, ENOMEM, result); |
|
780 |
if (!CSThread::attach(self)) |
|
781 |
return MSEngine::exceptionToResult(&self->myException, result); |
|
782 |
}
|
|
783 |
}
|
|
784 |
||
785 |
*r_self = self; |
|
786 |
return MS_OK; |
|
787 |
}
|
|
788 |
||
789 |
//---------------
|
|
790 |
int MSEngine::enterConnectionNoThd(CSThread **r_self, PBMSResultPtr result) |
|
791 |
{
|
|
792 |
return enterConnection(current_thd, r_self, result, true); |
|
793 |
}
|
|
794 |
||
795 |
//---------------
|
|
796 |
void MSEngine::exitConnection() |
|
797 |
{
|
|
798 |
THD *thd = (THD *) current_thd; |
|
799 |
CSThread *self; |
|
800 |
||
801 |
self = CSThread::getSelf(); |
|
802 |
if (self && self->pbms_api_owner) |
|
803 |
return; |
|
804 |
||
805 |
||
806 |
if (thd) |
|
807 |
CSThread::setSelf(NULL); |
|
808 |
else { |
|
809 |
self = CSThread::getSelf(); |
|
810 |
CSThread::detach(self); |
|
811 |
}
|
|
812 |
}
|
|
813 |
||
814 |
//---------------
|
|
815 |
void MSEngine::closeConnection(THD* thd) |
|
816 |
{
|
|
817 |
CSThread *self; |
|
818 |
||
819 |
self = CSThread::getSelf(); |
|
820 |
if (self && self->pbms_api_owner) |
|
821 |
return; |
|
822 |
||
823 |
if (thd) { |
|
824 |
if ((self = pbms_getMySelf(thd))) { |
|
825 |
pbms_setMySelf(thd, NULL); |
|
826 |
CSThread::setSelf(self); |
|
827 |
CSThread::detach(self); |
|
828 |
}
|
|
829 |
}
|
|
830 |
else { |
|
831 |
self = CSThread::getSelf(); |
|
832 |
CSThread::detach(self); |
|
833 |
}
|
|
834 |
}
|
|
835 |
||
1548.2.3
by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability. |
836 |
|
1548.2.1
by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin. |
837 |
|
838 |