~barry-leslie/pbms/with_backup

« back to all changes in this revision

Viewing changes to src/repository/references/table_ms.cc

  • Committer: Barry.Leslie at PrimeBase
  • Date: 2011-04-19 20:30:56 UTC
  • Revision ID: barry.leslie@primebase.com-20110419203056-te9zegmazips45rv
Added dupport for handler records() method and simplified MySQL patch code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        CSDiskValue4                    th_magic_4;                     // Table magic number. 
55
55
        CSDiskValue2                    th_version_2;           //  The header version.
56
56
        CSDiskValue2                    th_head_size_2;         // The size of the header. 
 
57
        
 
58
        // th_free_list_size_8 and th_free_list_8 are always written togeather.
 
59
        CSDiskValue8                    th_free_list_size_8;// The number of free records.
57
60
        CSDiskValue8                    th_free_list_8;         // The file offset of the first free record.
58
61
 
59
62
        CSDiskValue4                    th_del_time_4;          // The time this table was deleted. Zero otherwise.
103
106
dt_database(NULL),
104
107
dt_table_file_size(0),
105
108
dt_table_header_size(0),
 
109
dt_table_record_size(table_record_size),
 
110
dt_free_list_size(0),
106
111
dt_free_list(0),
107
112
dt_is_deleted(0),
108
113
dt_table_delete_time(0)
208
213
                        CS_SET_DISK_4(tab_head.th_magic_4, MS_TABLE_FILE_MAGIC);
209
214
                        CS_SET_DISK_2(tab_head.th_version_2, MS_TABLE_FILE_VERSION);
210
215
                        CS_SET_DISK_2(tab_head.th_head_size_2, MS_TABLE_FILE_HEAD_SIZE);
 
216
                        CS_SET_DISK_8(tab_head.th_free_list_size_8, 0);
211
217
                        CS_SET_DISK_8(tab_head.th_free_list_8, 0);
212
218
                        CS_SET_DISK_4(tab_head.th_del_time_4, 0);
213
219
                        file->write(&tab_head, 0, sizeof(MSTableHeadRec));
220
226
                        CSException::throwFileError(CS_CONTEXT, file->getPathString(), CS_ERR_VERSION_TOO_NEW);
221
227
 
222
228
                /* Load the header details: */
 
229
                dt_free_list_size = CS_GET_DISK_8(tab_head.th_free_list_size_8);
223
230
                dt_free_list = CS_GET_DISK_8(tab_head.th_free_list_8);
224
231
                dt_table_header_size = CS_GET_DISK_2(tab_head.th_head_size_2);
225
232
                dt_table_delete_time = CS_GET_DISK_4(tab_head.th_del_time_4);
236
243
}
237
244
 
238
245
//--------------
 
246
void MSTable::prepTable() 
 
247
{
 
248
        if (!dt_table_header_size) {
 
249
                enter_();
 
250
                CSPooledFile    *file;
 
251
                
 
252
                // Open the file so that it will be loaded.
 
253
                file = getFileFromPool();
 
254
                frompool_(file);
 
255
                backtopool_(file);
 
256
                
 
257
                outer_();
 
258
        }
 
259
        
 
260
}
 
261
 
 
262
//--------------
 
263
uint64_t MSTable::getReferenceCount() 
 
264
{
 
265
        prepTable();
 
266
        return (dt_table_file_size - dt_table_header_size)/dt_table_record_size - dt_free_list_size;
 
267
}
 
268
 
 
269
//--------------
239
270
// Mark the file as being deleted
240
271
void MSTable::dropTable()
241
272
{
288
319
        exit_();
289
320
}
290
321
 
 
322
//--------------------------
 
323
void MSTable::updateDiskFreeList(CSPooledFile *file)
 
324
{
 
325
        MSTableHeadRec  tab_head;
 
326
        
 
327
        CS_SET_DISK_8(tab_head.th_free_list_size_8, dt_free_list_size);
 
328
        CS_SET_DISK_8(tab_head.th_free_list_8, dt_free_list);
 
329
        file->write(&tab_head.th_free_list_size_8, offsetof(MSTableHeadRec, th_free_list_size_8), 16);
 
330
}
 
331
 
291
332
//--------------------
292
333
void MSTable::createBlobReference(BlobRefUrl *blob_url)
293
334
{
311
352
        frompool_(file);
312
353
        
313
354
        lock_(this);
314
 
        if (dt_free_list) {
 
355
        if (dt_free_list_size) {
315
356
                MSTableFreeBlobRec      freeb;
316
 
                MSTableHeadRec          tab_head;
317
357
                CSDiskValue2            ref_id_2;
318
358
 
319
359
                // Take the the location of the first free record in the list
321
361
                record_offset = dt_free_list;
322
362
                file->read(&freeb, dt_free_list, sizeof(MSTableFreeBlobRec), sizeof(MSTableFreeBlobRec));
323
363
                dt_free_list = CS_GET_DISK_8(freeb.tf_next_8);
324
 
                CS_SET_DISK_8(tab_head.th_free_list_8, dt_free_list);
325
 
                file->write(&tab_head.th_free_list_8, offsetof(MSTableHeadRec, th_free_list_8), 8);
 
364
                dt_free_list_size--;
326
365
                
 
366
                updateDiskFreeList(file);
 
367
                                
327
368
                // Read in the old reference id:
328
369
                file->read(ref_id_2, record_offset + offsetof(MSTableBlobRec,tb_reference_id_2) , 2, 2);
329
370
                ref_id = CS_GET_DISK_2(ref_id_2);
365
406
{
366
407
        MSTableBlobRec          blob;
367
408
        MSTableFreeBlobPtr      fblob = (MSTableFreeBlobPtr) &blob;
368
 
        MSTableHeadRec          tab_head;
369
409
        CSPooledFile            *file;
370
410
        uint32_t                        check_code;
371
411
        uint64_t                        blob_index;
394
434
                memset(&blob, 0, offsetof(MSTableBlobRec,tb_reference_id_2)); // Do not wipe tb_reference_id_2
395
435
                CS_SET_DISK_8(fblob->tf_next_8, dt_free_list);
396
436
                dt_free_list = blob_ref.file_offset;
397
 
                CS_SET_DISK_8(tab_head.th_free_list_8, dt_free_list);
 
437
                dt_free_list_size++;
 
438
                
 
439
                updateDiskFreeList(file);
398
440
                
399
441
                file->write(&blob, blob_ref.file_offset, table_record_size);
400
 
                file->write(&tab_head.th_free_list_8, offsetof(MSTableHeadRec, th_free_list_8), 8);
401
442
                unlock_(this);
402
443
        }
403
444
        
583
624
        old_path = getTableFile();
584
625
        push_(old_path);
585
626
        
 
627
        // Call getTableFile() to get the correct file name for the new table.
586
628
        new_path = getTableFile(new_name, false);
587
629
        push_(new_path);
588
630
        
589
 
        old_path->rename(new_path->getCString());
 
631
        old_path->rename(new_path->getNameCString());
590
632
        release_(new_path);
591
633
        release_(old_path);
592
634
        
 
635
        dt_table_name->release();
 
636
        dt_table_name = CSString::newString(new_name);
 
637
        
593
638
        exit_();
594
639
}
595
640