~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Lee Bieber
  • Date: 2010-10-22 16:47:38 UTC
  • mfrom: (1841.1.7 drizzle_pbms)
  • Revision ID: kalebral@gmail.com-20101022164738-vv8w22b8towpb307
Merge Barry - fix bug 657830: PBMS build failure in GCC 4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
                }
203
203
        }
204
204
        
205
 
        return NULL;
 
205
        return (const PBMSEnginePtr)NULL;
206
206
}
207
207
#endif  
208
208
 
209
209
//---------------
210
 
int32_t MSEngine::createBlob(const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url, PBMSResultPtr result)
 
210
bool MSEngine::try_createBlob(CSThread *self, const char *db_name, const char *tab_name, char *blob, size_t blob_len, PBMSBlobURLPtr blob_url)
211
211
{
212
 
 
213
 
        CSThread                *self;
214
 
        int32_t                 err = MS_OK;
215
 
        MSOpenTable             *otab;
216
 
        CSInputStream   *i_stream = NULL;
 
212
        volatile bool rtc = true;
217
213
        
218
 
        CLOBBER_PROTECT(err);
219
 
 
220
 
        if ((err = enterConnectionNoThd(&self, result)))
221
 
                return err;
222
 
 
223
 
        inner_();
224
214
        try_(a) {
 
215
                MSOpenTable             *otab;
 
216
                CSInputStream   *i_stream = NULL;
 
217
                
225
218
                otab = openTable(db_name, tab_name, true);
226
219
                frompool_(otab);
227
220
                
232
225
                        CSException::throwException(CS_CONTEXT, MS_ERR_RECOVERY_IN_PROGRESS, "Cannot create BLOBs during repository recovery.");
233
226
 
234
227
                backtopool_(otab);
 
228
                rtc = false;                    
235
229
        }
236
 
        catch_(a) {
 
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))
237
247
                err = exceptionToResult(&self->myException, result);
238
 
        }
239
 
        cont_(a);
 
248
 
240
249
        return_(err);
241
250
}
242
251
 
243
252
//---------------
 
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
//---------------
244
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)
245
283
{
246
284
 
247
285
        CSThread                *self;
248
286
        int32_t                 err = MS_OK;
249
 
        MSBlobURLRec    blob;
250
 
        MSOpenTable             *otab;
251
287
        
252
 
        CLOBBER_PROTECT(err);
253
 
 
254
288
        if ((err = enterConnectionNoThd(&self, result)))
255
289
                return err;
256
290
 
257
291
        inner_();
258
 
        try_(a) {
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
 
        }
275
 
        catch_(a) {
 
292
        if (try_referenceBlob(self, db_name, tab_name, ret_blob_url, blob_url, col_index))
276
293
                err = exceptionToResult(&self->myException, result);
277
 
        }
278
 
        cont_(a);
 
294
 
279
295
        return_(err);
 
296
 
280
297
}
281
298
 
282
299
//---------------
283
 
int32_t MSEngine::dereferenceBlob(const char *db_name, const char *tab_name, char *blob_url, PBMSResultPtr result)
 
300
bool MSEngine::try_dereferenceBlob(CSThread *self, const char *db_name, const char *tab_name, char *blob_url)
284
301
{
285
 
        CSThread                *self;
286
 
        int32_t                 err = MS_OK;
287
 
        MSBlobURLRec    blob;
288
 
        MSOpenTable             *otab;
289
 
 
290
 
        CLOBBER_PROTECT(err);
291
 
 
292
 
        if ((err = enterConnectionNoThd(&self, result)))
293
 
                return err;
294
 
 
295
 
        inner_();
 
302
        volatile bool rtc = true;
296
303
        try_(a) {
 
304
                MSBlobURLRec    blob;
 
305
                MSOpenTable             *otab;
 
306
 
297
307
                if (! PBMSBlobURLTools::couldBeURL(blob_url, &blob)){
298
308
                        char buffer[CS_EXC_MESSAGE_SIZE];
299
309
 
323
333
                        CSException::throwException(CS_CONTEXT, MS_ERR_INCORRECT_URL, buffer);
324
334
                }
325
335
                
326
 
                backtopool_(otab);                              
 
336
                backtopool_(otab);      
 
337
                rtc = false;                    
327
338
        }
328
 
        catch_(a) {
 
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))
329
354
                err = exceptionToResult(&self->myException, result);
330
 
        }
331
 
        cont_(a);
 
355
 
332
356
        return_(err);
333
357
}
334
358
 
 
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
 
335
372
int32_t MSEngine::dropDatabase(const char *db_name, PBMSResultPtr result)
336
373
{
337
374
        CSThread *self;
338
 
        int             err = MS_OK;;
 
375
        int             err = MS_OK;
339
376
        
340
 
        CLOBBER_PROTECT(err);
341
 
 
342
377
        if ((err = enterConnectionNoThd(&self, result)))
343
378
                return err;
 
379
 
344
380
        inner_();
345
381
        
346
 
        try_(a) {
347
 
                MSDatabase::dropDatabase(db_name);
348
 
        }
349
 
        catch_(a) {
 
382
        if (try_dropDatabase(self, db_name))
350
383
                err = exceptionToResult(&self->myException, result);
351
 
        }
352
 
        cont_(a);
 
384
 
353
385
        return_(err);
354
386
}
 
387
 
355
388
//---------------
356
389
typedef struct UnDoInfo {
357
390
        bool udo_WasRename;
361
394
        CSString *udo_NewName;
362
395
} UnDoInfoRec, *UnDoInfoPtr;
363
396
 
364
 
int32_t MSEngine::dropTable(const char *db_name, const char *tab_name, PBMSResultPtr result)
 
397
//---------------
 
398
bool MSEngine::try_dropTable(CSThread *self, const char *db_name, const char *tab_name)
365
399
{
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_();
 
400
        volatile bool rtc = true;
375
401
        try_(a) {
376
402
 
377
403
                CSPath                  *new_path;
382
408
                UnDoInfoPtr             undo_info = NULL;
383
409
 
384
410
                otab = openTable(db_name, tab_name, false);
385
 
                if (!otab)
386
 
                        goto exit;
 
411
                if (!otab) {
 
412
                        goto end_try;
 
413
                }
387
414
                
388
415
                // If we are recovering do not delete the table.
389
416
                // It is normal for MySQL recovery scripts to delete any table they aare about to
391
418
                // then this would delete all the recovered BLOBs in the table.
392
419
                if (otab->getDB()->isRecovering()) {
393
420
                        otab->returnToPool();
394
 
                        goto exit;
 
421
                        goto end_try;
395
422
                }
396
423
 
397
424
                frompool_(otab);
421
448
                frompool_(tab_pool);
422
449
 
423
450
                if (old_path->exists())
424
 
                        old_path->move(new_path);
 
451
                        old_path->move(RETAIN(new_path));
425
452
                tab->myDatabase->dropTable(RETAIN(tab));
426
453
                
427
454
                /* Add the table to the temp delete list if we are not recovering... */
437
464
                
438
465
                undo_info->udo_WasRename = false;
439
466
                self->myInfo = undo_info;
440
 
                
441
 
                
442
 
exit: ;
 
467
                                
 
468
end_try:
 
469
                rtc = false;    
443
470
        }
444
 
        
445
 
        catch_(a) {
 
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))
446
487
                err = exceptionToResult(&self->myException, result);
447
 
        }
448
 
        cont_(a);
 
488
 
449
489
        outer_();
450
490
        exitConnection();
451
491
        return err;
506
546
        tab_pool = MSTableList::lockTablePoolForDeletion(otab);
507
547
        frompool_(tab_pool);
508
548
 
509
 
        from_path->move(to_path);
 
549
        from_path->move(RETAIN(to_path));
510
550
        tab->myDatabase->renameTable(tab, to_table);
511
551
 
512
552
        backtopool_(tab_pool);  // The will unlock and close the table pool freeing all tables in it.
518
558
}
519
559
 
520
560
//---------------
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)
 
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)
522
562
{
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_();
 
563
        volatile bool rtc = true;
532
564
        try_(a) {
533
565
                UnDoInfoPtr undo_info = (UnDoInfoPtr) cs_malloc(sizeof(UnDoInfoRec));
534
566
                push_ptr_(undo_info);
554
586
                }
555
587
                self->myInfo = undo_info;
556
588
                pop_(undo_info);
 
589
                rtc = false;                    
557
590
        }
558
 
        catch_(a) {
 
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))
559
607
                err = exceptionToResult(&self->myException, result);
560
 
        }
561
 
        cont_(a);
 
608
 
562
609
        outer_();
563
610
        exitConnection();
564
611
        return err;
591
638
        }
592
639
        exit_();
593
640
}
 
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
 
594
661
//---------------
595
662
void MSEngine::callCompleted(bool ok)
596
663
{
611
678
                self->myInfo = NULL;
612
679
        } else if (self->myTID && (self->myIsAutoCommit || !ok)) {
613
680
                inner_();
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) {
 
681
                if (try_CompleteTransaction(self, ok)) {
623
682
                        self->logException();
624
683
                }
625
 
                cont_(a);
626
684
                outer_();
627
685
        }
628
686