~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/systab_backup_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:
58
58
 
59
59
DT_FIELD_INFO pbms_backup_info[]=
60
60
{
61
 
        {"Id",                          NULL,   NULL, MYSQL_TYPE_LONG,          NULL,                   NOT_NULL_FLAG,  "The backup reference ID"},
 
61
        {"Id",                          NOVAL,  NULL, MYSQL_TYPE_LONG,          NULL,                   NOT_NULL_FLAG,  "The backup reference ID"},
62
62
        {"Database_Name",       64,             NULL, MYSQL_TYPE_VARCHAR,       &UTF8_CHARSET,  NOT_NULL_FLAG,  "The database name"},
63
 
        {"Database_Id",         NULL,   NULL, MYSQL_TYPE_LONG,          NULL,                   0,      "The database ID"},
 
63
        {"Database_Id",         NOVAL,  NULL, MYSQL_TYPE_LONG,          NULL,                   0,      "The database ID"},
64
64
        {"Started",                     32,             NULL, MYSQL_TYPE_VARCHAR,       &UTF8_CHARSET,  0,      "The start time"},
65
65
        {"Completed",           32,             NULL, MYSQL_TYPE_VARCHAR,       &UTF8_CHARSET,  0,      "The completion time"},
66
66
        {"IsRunning",           3,              NULL, MYSQL_TYPE_VARCHAR,       &UTF8_CHARSET,  0,      "Is the backup still running"},
67
67
        {"IsDump",                      3,              NULL, MYSQL_TYPE_VARCHAR,       &UTF8_CHARSET,  0,      "Is the backup the result of a dump"},
68
68
        {"Location",            1024,   NULL, MYSQL_TYPE_VARCHAR,       &UTF8_CHARSET,  0,      "The backup location"},
69
 
        {"Cloud_Ref",           NULL,   NULL, MYSQL_TYPE_LONG,          NULL,                   0,      "The S3 cloud reference number refering to the pbms.pbms_cloud table."},
70
 
        {"Cloud_Backup_No",     NULL,   NULL, MYSQL_TYPE_LONG,          NULL,                   0,      "The cloud backup number"},
71
 
        {NULL,NULL, NULL, MYSQL_TYPE_STRING,NULL, 0, NULL}
 
69
        {"Cloud_Ref",           NOVAL,  NULL, MYSQL_TYPE_LONG,          NULL,                   0,      "The S3 cloud reference number refering to the pbms.pbms_cloud table."},
 
70
        {"Cloud_Backup_No",     NOVAL,  NULL, MYSQL_TYPE_LONG,          NULL,                   0,      "The cloud backup number"},
 
71
        {NULL,NOVAL, NULL, MYSQL_TYPE_STRING,NULL, 0, NULL}
72
72
};
73
73
 
74
74
DT_KEY_INFO pbms_backup_keys[]=
268
268
 
269
269
        new_(timeVal, CSTime());
270
270
        push_(timeVal);
 
271
#ifdef DRIZZLED
271
272
        memset(buf, 0xFF, table->getNullBytes());
 
273
#else
 
274
        memset(buf, 0xFF, table->s->null_bytes);
 
275
#endif
272
276
        for (Field **field=GET_TABLE_FIELDS(table) ; *field ; field++) {
273
277
                curr_field = *field;
274
278
                save = curr_field->ptr;
275
279
#if MYSQL_VERSION_ID < 50114
276
280
                curr_field->ptr = (byte *) buf + curr_field->offset();
277
281
#else
 
282
#ifdef DRIZZLED
278
283
                curr_field->ptr = (byte *) buf + curr_field->offset(curr_field->getTable()->getInsertRecord());
 
284
#else
 
285
                curr_field->ptr = (byte *) buf + curr_field->offset(curr_field->table->record[0]);
 
286
#endif
279
287
#endif
280
288
                switch (curr_field->field_name[0]) {
281
289
                        case 'I':
458
466
        exit_();
459
467
}
460
468
 
 
469
class InsertRowCleanUp : public CSRefObject {
 
470
        bool do_cleanup;
 
471
        CSThread *myself;
 
472
        
 
473
        uint32_t ref_id;
 
474
 
 
475
        public:
 
476
        
 
477
        InsertRowCleanUp(CSThread *self): CSRefObject(),
 
478
                do_cleanup(true), myself(self){}
 
479
                
 
480
        ~InsertRowCleanUp() 
 
481
        {
 
482
                if (do_cleanup) {
 
483
                        myself->logException();
 
484
                        if (ref_id)
 
485
                                MSBackupInfo::gBackupInfo->remove(ref_id);
 
486
 
 
487
                }
 
488
        }
 
489
        
 
490
        void setCleanUp(uint32_t id)
 
491
        {
 
492
                ref_id = id;
 
493
        }
 
494
        
 
495
        void cancelCleanUp()
 
496
        {
 
497
                do_cleanup = false;
 
498
        }
 
499
        
 
500
};
 
501
 
461
502
void MSBackupTable::insertRow(char *data) 
462
503
{
463
504
        uint32_t ref_id = 0, db_id, cloud_ref, cloud_backup_no;
464
505
        String name, start, end, isRunning, isDump, location;
465
506
        MSBackupInfo *info = NULL;
466
507
        const char *db_name;
467
 
        bool duplicate = true;
 
508
        InsertRowCleanUp *cleanup;
468
509
 
469
510
        enter_();
470
511
 
471
 
        try_(a) {
472
 
                getFieldValue(data, 0, &ref_id);
473
 
                        
474
 
                // The id must be unique.
475
 
                if (ref_id && MSBackupInfo::gBackupInfo->get(ref_id)) {
476
 
                        CSException::throwException(CS_CONTEXT, MS_ERR_DUPLICATE, "Attempt to insert a row with a duplicate key in the "BACKUP_TABLE_NAME" table.");
477
 
                }
478
 
                duplicate = false;
479
 
                
480
 
                // The 'Database_Id', 'Start', 'Completion' and "IsDump" fields are ignored.
481
 
                // I still need to get the fields though to advance the field position pointer.
482
 
                getFieldValue(data, 1, &name);
483
 
                getFieldValue(data, 2, &db_id);
484
 
                getFieldValue(data, 3, &start);
485
 
                getFieldValue(data, 4, &end);
486
 
                getFieldValue(data, 5, &isRunning);
487
 
                getFieldValue(data, 6, &isDump);
488
 
                getFieldValue(data, 7, &location);
489
 
                getFieldValue(data, 8, &cloud_ref);
490
 
                getFieldValue(data, 9, &cloud_backup_no);
491
 
                
492
 
                if (ref_id == 0)
493
 
                        ref_id = MSBackupInfo::gMaxInfoRef++;
494
 
                else if (ref_id >= MSBackupInfo::gMaxInfoRef)
495
 
                        MSBackupInfo::gMaxInfoRef = ref_id +1;
496
 
                
497
 
                db_name = name.c_ptr();
498
 
                db_id = MSDatabase::getDatabaseID(db_name, false);
499
 
                
500
 
                new_(info, MSBackupInfo(ref_id, db_name, db_id, 0, 0, false, location.c_ptr(), cloud_ref, cloud_backup_no));
501
 
                MSBackupInfo::gBackupInfo->set(ref_id, info);
502
 
                
503
 
                // There is no need to call this now, startBackup() will call it
504
 
                // after the backup is started.
505
 
                // saveTable(RETAIN(myShare->mySysDatabase)); 
506
 
                info->startBackup(RETAIN(myShare->mySysDatabase));
 
512
        new_(cleanup, InsertRowCleanUp(self));
 
513
        push_(cleanup);
 
514
        
 
515
        getFieldValue(data, 0, &ref_id);
 
516
                
 
517
        // The id must be unique.
 
518
        if (ref_id && MSBackupInfo::gBackupInfo->get(ref_id)) {
 
519
                CSException::throwException(CS_CONTEXT, MS_ERR_DUPLICATE, "Attempt to insert a row with a duplicate key in the "BACKUP_TABLE_NAME" table.");
507
520
        }
508
521
        
509
 
        catch_(a);
510
 
        // It is good to know the details if the backup could not be started.
511
 
        self->logException();
512
 
        if (ref_id && ! duplicate)
513
 
                MSBackupInfo::gBackupInfo->remove(ref_id);
514
 
        throw_();
515
 
        
516
 
        cont_(a);
 
522
        // The 'Database_Id', 'Start', 'Completion' and "IsDump" fields are ignored.
 
523
        // I still need to get the fields though to advance the field position pointer.
 
524
        getFieldValue(data, 1, &name);
 
525
        getFieldValue(data, 2, &db_id);
 
526
        getFieldValue(data, 3, &start);
 
527
        getFieldValue(data, 4, &end);
 
528
        getFieldValue(data, 5, &isRunning);
 
529
        getFieldValue(data, 6, &isDump);
 
530
        getFieldValue(data, 7, &location);
 
531
        getFieldValue(data, 8, &cloud_ref);
 
532
        getFieldValue(data, 9, &cloud_backup_no);
 
533
        
 
534
        if (ref_id == 0)
 
535
                ref_id = MSBackupInfo::gMaxInfoRef++;
 
536
        else if (ref_id >= MSBackupInfo::gMaxInfoRef)
 
537
                MSBackupInfo::gMaxInfoRef = ref_id +1;
 
538
        
 
539
        db_name = name.c_ptr();
 
540
        db_id = MSDatabase::getDatabaseID(db_name, false);
 
541
        
 
542
        cleanup->setCleanUp(ref_id);
 
543
        new_(info, MSBackupInfo(ref_id, db_name, db_id, 0, 0, false, location.c_ptr(), cloud_ref, cloud_backup_no));
 
544
        MSBackupInfo::gBackupInfo->set(ref_id, info);
 
545
        
 
546
        // There is no need to call this now, startBackup() will call it
 
547
        // after the backup is started.
 
548
        // saveTable(RETAIN(myShare->mySysDatabase)); 
 
549
        info->startBackup(RETAIN(myShare->mySysDatabase));
 
550
 
 
551
        cleanup->cancelCleanUp();
 
552
        release_(cleanup);
 
553
        
517
554
        exit_();
518
555
}
519
556