~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/engine_ms.cc

  • Committer: Monty Taylor
  • Date: 2010-10-21 23:10:12 UTC
  • mto: (1879.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1880.
  • Revision ID: mordred@inaugust.com-20101021231012-uhsebiqo23xi0ygy
Updated AUTHORS list with everyone from bzr logs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
2
 *
3
3
 * PrimeBase Media Stream for MySQL
4
4
 *
27
27
 *
28
28
 */
29
29
#ifdef DRIZZLED
30
 
#include <config.h>
31
 
 
 
30
#include "config.h"
32
31
#include <drizzled/common.h>
33
 
#include <drizzled/current_session.h>
34
32
#include <drizzled/session.h>
35
33
#endif
36
34
 
204
202
                }
205
203
        }
206
204
        
207
 
        return (const PBMSEnginePtr)NULL;
 
205
        return NULL;
208
206
}
209
207
#endif  
210
208
 
211
209
//---------------
212
 
bool MSEngine::try_createBlob(CSThread *self, const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url)
 
210
int32_t MSEngine::createBlob(const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url, PBMSResultPtr result)
213
211
{
214
 
        volatile bool rtc = true;
 
212
 
 
213
        CSThread                *self;
 
214
        int32_t                 err = MS_OK;
 
215
        MSOpenTable             *otab;
 
216
        CSInputStream   *i_stream = NULL;
215
217
        
 
218
        CLOBBER_PROTECT(err);
 
219
 
 
220
        if ((err = enterConnectionNoThd(&self, result)))
 
221
                return err;
 
222
 
 
223
        inner_();
216
224
        try_(a) {
217
 
                MSOpenTable             *otab;
218
 
                CSInputStream   *i_stream = NULL;
219
 
                
220
225
                otab = openTable(db_name, tab_name, true);
221
226
                frompool_(otab);
222
227
                
227
232
                        CSException::throwException(CS_CONTEXT, MS_ERR_RECOVERY_IN_PROGRESS, "Cannot create BLOBs during repository recovery.");
228
233
 
229
234
                backtopool_(otab);
230
 
                rtc = false;                    
231
 
        }
232
 
        catch_(a);
 
235
        }
 
236
        catch_(a) {
 
237
                err = exceptionToResult(&self->myException, result);
 
238
        }
233
239
        cont_(a);
234
 
        return rtc;
 
240
        return_(err);
235
241
}
236
242
 
237
243
//---------------
238
 
int32_t MSEngine::createBlob(const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url, PBMSResultPtr result)
 
244
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)
239
245
{
240
246
 
241
247
        CSThread                *self;
242
248
        int32_t                 err = MS_OK;
 
249
        MSBlobURLRec    blob;
 
250
        MSOpenTable             *otab;
243
251
        
 
252
        CLOBBER_PROTECT(err);
 
253
 
244
254
        if ((err = enterConnectionNoThd(&self, result)))
245
255
                return err;
246
256
 
247
257
        inner_();
248
 
        if (try_createBlob(self, db_name, tab_name, blob, blob_len, blob_url))
249
 
                err = exceptionToResult(&self->myException, result);
250
 
 
251
 
        return_(err);
252
 
}
253
 
 
254
 
//---------------
255
 
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)
256
 
{
257
 
        volatile bool rtc = true;
258
258
        try_(a) {
259
 
                MSBlobURLRec    blob;
260
 
                MSOpenTable             *otab;
261
259
                
262
260
                if (! PBMSBlobURLTools::couldBeURL(blob_url, &blob)){
263
261
                        char buffer[CS_EXC_MESSAGE_SIZE];
273
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);
274
272
 
275
273
                backtopool_(otab);
276
 
                rtc = false;                    
277
 
        }
278
 
        catch_(a);
 
274
        }
 
275
        catch_(a) {
 
276
                err = exceptionToResult(&self->myException, result);
 
277
        }
279
278
        cont_(a);
280
 
        return rtc;
 
279
        return_(err);
281
280
}
282
281
 
283
282
//---------------
284
 
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
int32_t MSEngine::dereferenceBlob(const char *db_name, const char *tab_name, char *blob_url, PBMSResultPtr result)
285
284
{
286
 
 
287
285
        CSThread                *self;
288
286
        int32_t                 err = MS_OK;
289
 
        
 
287
        MSBlobURLRec    blob;
 
288
        MSOpenTable             *otab;
 
289
 
 
290
        CLOBBER_PROTECT(err);
 
291
 
290
292
        if ((err = enterConnectionNoThd(&self, result)))
291
293
                return err;
292
294
 
293
295
        inner_();
294
 
        if (try_referenceBlob(self, db_name, tab_name, ret_blob_url, blob_url, col_index))
295
 
                err = exceptionToResult(&self->myException, result);
296
 
 
297
 
        return_(err);
298
 
 
299
 
}
300
 
 
301
 
//---------------
302
 
bool MSEngine::try_dereferenceBlob(CSThread *self, const char *db_name, const char *tab_name, char *blob_url)
303
 
{
304
 
        volatile bool rtc = true;
305
296
        try_(a) {
306
 
                MSBlobURLRec    blob;
307
 
                MSOpenTable             *otab;
308
 
 
309
297
                if (! PBMSBlobURLTools::couldBeURL(blob_url, &blob)){
310
298
                        char buffer[CS_EXC_MESSAGE_SIZE];
311
299
 
335
323
                        CSException::throwException(CS_CONTEXT, MS_ERR_INCORRECT_URL, buffer);
336
324
                }
337
325
                
338
 
                backtopool_(otab);      
339
 
                rtc = false;                    
 
326
                backtopool_(otab);                              
340
327
        }
341
 
        catch_(a);
342
 
        cont_(a);
343
 
        return rtc;
344
 
}
345
 
 
346
 
int32_t MSEngine::dereferenceBlob(const char *db_name, const char *tab_name, char *blob_url, PBMSResultPtr result)
347
 
{
348
 
        CSThread                *self;
349
 
        int32_t                 err = MS_OK;
350
 
 
351
 
        if ((err = enterConnectionNoThd(&self, result)))
352
 
                return err;
353
 
 
354
 
        inner_();
355
 
        if (try_dereferenceBlob(self, db_name, tab_name, blob_url))
 
328
        catch_(a) {
356
329
                err = exceptionToResult(&self->myException, result);
357
 
 
 
330
        }
 
331
        cont_(a);
358
332
        return_(err);
359
333
}
360
334
 
361
 
bool MSEngine::try_dropDatabase(CSThread *self, const char *db_name)
362
 
{
363
 
        volatile bool rtc = true;
364
 
        try_(a) {
365
 
                MSDatabase::dropDatabase(db_name);
366
 
                rtc = false;
367
 
        }
368
 
        catch_(a);
369
 
        cont_(a);
370
 
        
371
 
        return rtc;
372
 
}
373
 
 
374
335
int32_t MSEngine::dropDatabase(const char *db_name, PBMSResultPtr result)
375
336
{
376
337
        CSThread *self;
377
 
        int             err = MS_OK;
 
338
        int             err = MS_OK;;
378
339
        
 
340
        CLOBBER_PROTECT(err);
 
341
 
379
342
        if ((err = enterConnectionNoThd(&self, result)))
380
343
                return err;
381
 
 
382
344
        inner_();
383
345
        
384
 
        if (try_dropDatabase(self, db_name))
 
346
        try_(a) {
 
347
                MSDatabase::dropDatabase(db_name);
 
348
        }
 
349
        catch_(a) {
385
350
                err = exceptionToResult(&self->myException, result);
386
 
 
 
351
        }
 
352
        cont_(a);
387
353
        return_(err);
388
354
}
389
 
 
390
355
//---------------
391
356
typedef struct UnDoInfo {
392
357
        bool udo_WasRename;
396
361
        CSString *udo_NewName;
397
362
} UnDoInfoRec, *UnDoInfoPtr;
398
363
 
399
 
//---------------
400
 
bool MSEngine::try_dropTable(CSThread *self, const char *db_name, const char *tab_name)
 
364
int32_t MSEngine::dropTable(const char *db_name, const char *tab_name, PBMSResultPtr result)
401
365
{
402
 
        volatile bool rtc = true;
 
366
        CSThread        *self;
 
367
        int                     err = MS_OK;
 
368
 
 
369
        CLOBBER_PROTECT(err);
 
370
 
 
371
        if ((err = enterConnectionNoThd(&self, result)))
 
372
                return err;
 
373
 
 
374
        inner_();
403
375
        try_(a) {
404
376
 
405
377
                CSPath                  *new_path;
410
382
                UnDoInfoPtr             undo_info = NULL;
411
383
 
412
384
                otab = openTable(db_name, tab_name, false);
413
 
                if (!otab) {
414
 
                        goto end_try;
415
 
                }
 
385
                if (!otab)
 
386
                        goto exit;
416
387
                
417
388
                // If we are recovering do not delete the table.
418
389
                // It is normal for MySQL recovery scripts to delete any table they aare about to
420
391
                // then this would delete all the recovered BLOBs in the table.
421
392
                if (otab->getDB()->isRecovering()) {
422
393
                        otab->returnToPool();
423
 
                        goto end_try;
 
394
                        goto exit;
424
395
                }
425
396
 
426
397
                frompool_(otab);
450
421
                frompool_(tab_pool);
451
422
 
452
423
                if (old_path->exists())
453
 
                        old_path->move(RETAIN(new_path));
 
424
                        old_path->move(new_path);
454
425
                tab->myDatabase->dropTable(RETAIN(tab));
455
426
                
456
427
                /* Add the table to the temp delete list if we are not recovering... */
466
437
                
467
438
                undo_info->udo_WasRename = false;
468
439
                self->myInfo = undo_info;
469
 
                                
470
 
end_try:
471
 
                rtc = false;    
472
 
        }
473
 
        catch_(a);
 
440
                
 
441
                
 
442
exit: ;
 
443
        }
 
444
        
 
445
        catch_(a) {
 
446
                err = exceptionToResult(&self->myException, result);
 
447
        }
474
448
        cont_(a);
475
 
        return rtc;
476
 
}
477
 
 
478
 
//---------------
479
 
int32_t MSEngine::dropTable(const char *db_name, const char *tab_name, PBMSResultPtr result)
480
 
{
481
 
        CSThread        *self;
482
 
        int                     err = MS_OK;
483
 
 
484
 
        if ((err = enterConnectionNoThd(&self, result)))
485
 
                return err;
486
 
 
487
 
        inner_();
488
 
        if (try_dropTable(self, db_name, tab_name))
489
 
                err = exceptionToResult(&self->myException, result);
490
 
 
491
449
        outer_();
492
450
        exitConnection();
493
451
        return err;
548
506
        tab_pool = MSTableList::lockTablePoolForDeletion(otab);
549
507
        frompool_(tab_pool);
550
508
 
551
 
        from_path->move(RETAIN(to_path));
 
509
        from_path->move(to_path);
552
510
        tab->myDatabase->renameTable(tab, to_table);
553
511
 
554
512
        backtopool_(tab_pool);  // The will unlock and close the table pool freeing all tables in it.
560
518
}
561
519
 
562
520
//---------------
563
 
bool MSEngine::try_renameTable(CSThread *self, const char *from_db_name, const char *from_table, const char *to_db_name, const char *to_table)
 
521
int32_t MSEngine::renameTable(const char *from_db_name, const char *from_table, const char *to_db_name, const char *to_table, PBMSResultPtr result)
564
522
{
565
 
        volatile bool rtc = true;
 
523
        CSThread        *self;
 
524
        int err = MS_OK;
 
525
 
 
526
        CLOBBER_PROTECT(err);
 
527
 
 
528
        if ((err = enterConnectionNoThd(&self, result)))
 
529
                return err;
 
530
 
 
531
        inner_();
566
532
        try_(a) {
567
533
                UnDoInfoPtr undo_info = (UnDoInfoPtr) cs_malloc(sizeof(UnDoInfoRec));
568
534
                push_ptr_(undo_info);
588
554
                }
589
555
                self->myInfo = undo_info;
590
556
                pop_(undo_info);
591
 
                rtc = false;                    
592
 
        }
593
 
        catch_(a);
 
557
        }
 
558
        catch_(a) {
 
559
                err = exceptionToResult(&self->myException, result);
 
560
        }
594
561
        cont_(a);
595
 
        return rtc;
596
 
}
597
 
 
598
 
//---------------
599
 
int32_t MSEngine::renameTable(const char *from_db_name, const char *from_table, const char *to_db_name, const char *to_table, PBMSResultPtr result)
600
 
{
601
 
        CSThread        *self;
602
 
        int err = MS_OK;
603
 
 
604
 
        if ((err = enterConnectionNoThd(&self, result)))
605
 
                return err;
606
 
 
607
 
        inner_();
608
 
        if (try_renameTable(self, from_db_name, from_table, to_db_name, to_table))
609
 
                err = exceptionToResult(&self->myException, result);
610
 
 
611
562
        outer_();
612
563
        exitConnection();
613
564
        return err;
640
591
        }
641
592
        exit_();
642
593
}
643
 
 
644
 
//---------------
645
 
static bool try_CompleteTransaction(CSThread *self, bool ok)
646
 
{
647
 
        volatile bool rtc = true;
648
 
        try_(a) {
649
 
                if (ok)
650
 
                        MSTransactionManager::commit();
651
 
                else if (self->myIsAutoCommit)
652
 
                        MSTransactionManager::rollback();
653
 
                else
654
 
                        MSTransactionManager::rollbackToPosition(self->myStartStmt); // Rollback the last logical statement.
655
 
                rtc = false;
656
 
        }
657
 
        catch_(a)
658
 
        cont_(a);
659
 
        
660
 
        return rtc;
661
 
}
662
 
 
663
594
//---------------
664
595
void MSEngine::callCompleted(bool ok)
665
596
{
680
611
                self->myInfo = NULL;
681
612
        } else if (self->myTID && (self->myIsAutoCommit || !ok)) {
682
613
                inner_();
683
 
                if (try_CompleteTransaction(self, ok)) {
 
614
                try_(a) {
 
615
                        if (ok)
 
616
                                MSTransactionManager::commit();
 
617
                        else if (self->myIsAutoCommit)
 
618
                                MSTransactionManager::rollback();
 
619
                        else
 
620
                                MSTransactionManager::rollbackToPosition(self->myStartStmt); // Rollback the last logical statement.
 
621
                }
 
622
                catch_(a) {
684
623
                        self->logException();
685
624
                }
 
625
                cont_(a);
686
626
                outer_();
687
627
        }
688
628