~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/temp_log_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:
31
31
 
32
32
#include <stddef.h>
33
33
 
 
34
#include "defs_ms.h"
 
35
 
 
36
#include "cslib/CSGlobal.h"
 
37
#include "cslib/CSStrUtil.h"
 
38
#include "cslib/CSStorage.h"
 
39
 
34
40
#include "temp_log_ms.h"
35
41
#include "open_table_ms.h"
36
42
#include "trans_log_ms.h"
37
43
#include "transaction_ms.h"
38
44
#include "parameters_ms.h"
39
45
 
40
 
#include "cslib/CSGlobal.h"
41
 
#include "cslib/CSStrUtil.h"
42
 
#include "cslib/CSStorage.h"
43
 
 
44
46
 
45
47
// Search the transaction log for a MS_ReferenceTxn record for the given BLOB.
46
48
// Just search the log file and not the cache. Seaching the cache may be faster but
111
113
MSTempLogFile *MSTempLogFile::newTempLogFile(uint32_t id, MSTempLog *temp_log, CSFile *file)
112
114
{
113
115
        MSTempLogFile *f;
114
 
        
115
 
        if (!(f = new MSTempLogFile())) {
116
 
                temp_log->release();
117
 
                file->release();
 
116
        enter_();
 
117
        
 
118
        push_(temp_log);
 
119
        push_(file);
 
120
        
 
121
        if (!(f = new MSTempLogFile())) 
118
122
                CSException::throwOSError(CS_CONTEXT, ENOMEM);
119
 
        }
 
123
 
120
124
        f->myTempLogID = id;
 
125
        
 
126
        pop_(file);
 
127
        f->setFile(file);
 
128
        
 
129
        pop_(temp_log);
121
130
        f->myTempLog = temp_log;
122
 
        f->myFile = file;
123
 
        f->myFilePath = file->myFilePath;
124
 
        f->myFilePath->retain();
125
 
        return f;
 
131
        return_(f);
126
132
}
127
133
 
128
134
MSTempLog::MSTempLog(uint32_t id, MSDatabase *db, off64_t file_size):
261
267
        }
262
268
}
263
269
 
 
270
bool MSTempLogThread::try_ReleaseBLOBReference(CSThread *self, CSStringBuffer *buffer, uint32_t tab_id, int type, uint64_t blob_id, uint32_t auth_code)
 
271
{
 
272
        volatile bool rtc = true;
 
273
        try_(a) {
 
274
                /* Release the BLOB reference. */
 
275
                MSOpenTable *otab;
 
276
 
 
277
                if (type == MS_TL_REPO_REF) {
 
278
                        MSRepoFile      *repo_file;
 
279
 
 
280
                        if ((repo_file = iTempLogDatabase->getRepoFileFromPool(tab_id, true))) {
 
281
                                frompool_(repo_file);
 
282
                                repo_file->checkBlob(buffer, blob_id, auth_code, iTempLogFile->myTempLogID, iLogOffset);
 
283
                                backtopool_(repo_file);
 
284
                        }
 
285
                }
 
286
                else {
 
287
                        if ((otab = MSTableList::getOpenTableByID(iTempLogDatabase->myDatabaseID, tab_id))) {
 
288
                                frompool_(otab);
 
289
                                if (type == MS_TL_BLOB_REF) {
 
290
                                        otab->checkBlob(buffer, blob_id, auth_code, iTempLogFile->myTempLogID, iLogOffset);
 
291
                                        backtopool_(otab);
 
292
                                }
 
293
                                else {
 
294
                                        ASSERT(type == MS_TL_TABLE_REF);
 
295
                                        if ((type == MS_TL_TABLE_REF) && otab->deleteReferences(iTempLogFile->myTempLogID, iLogOffset, &myMustQuit)) {
 
296
                                                /* Delete the file now... */
 
297
                                                MSTable                 *tab;
 
298
                                                CSPath                  *from_path;
 
299
                                                MSOpenTablePool *tab_pool;
 
300
 
 
301
                                                tab = otab->getDBTable();
 
302
                                                from_path = otab->getDBTable()->getTableFile();
 
303
 
 
304
                                                pop_(otab);
 
305
 
 
306
                                                push_(from_path);
 
307
                                                tab->retain();
 
308
                                                push_(tab);
 
309
 
 
310
                                                tab_pool = MSTableList::lockTablePoolForDeletion(otab); // This returns otab to the pool.
 
311
                                                frompool_(tab_pool);
 
312
 
 
313
                                                from_path->removeFile();
 
314
                                                tab->myDatabase->removeTable(tab);
 
315
 
 
316
                                                backtopool_(tab_pool); // The will unlock and close the table pool freeing all tables in it.
 
317
                                                pop_(tab);                              // Returning the pool will have released this. (YUK!)
 
318
                                                release_(from_path);
 
319
                                        }
 
320
                                        else 
 
321
                                                backtopool_(otab);
 
322
                                }
 
323
                        }
 
324
                }
 
325
                
 
326
                rtc = false;
 
327
        }
 
328
        
 
329
        catch_(a);
 
330
        cont_(a);
 
331
        return rtc;
 
332
}
 
333
 
264
334
bool MSTempLogThread::doWork()
265
335
{
266
336
        size_t                          tfer;
308
378
                        uint32_t then;
309
379
                        time_t  now;
310
380
 
311
 
                        CLOBBER_PROTECT(blob_id);
312
381
                        /*
313
382
                         * Items in the temp log are never updated.
314
383
                         * If a temp operation is canceled then the object 
330
399
                                myWaitTime = MSTempLog::adjustWaitTime(then, now);
331
400
                                break;
332
401
                        }
333
 
 
334
 
                        try_(a) {
335
 
                                /* Release the BLOB reference. */
336
 
                                MSOpenTable *otab;
337
 
 
338
 
                                if (type == MS_TL_REPO_REF) {
339
 
                                        MSRepoFile      *repo_file;
340
 
 
341
 
                                        if ((repo_file = iTempLogDatabase->getRepoFileFromPool(tab_id, true))) {
342
 
                                                frompool_(repo_file);
343
 
                                                repo_file->checkBlob(buffer, blob_id, auth_code, iTempLogFile->myTempLogID, iLogOffset);
344
 
                                                backtopool_(repo_file);
345
 
                                        }
346
 
                                }
347
 
                                else {
348
 
                                        if ((otab = MSTableList::getOpenTableByID(iTempLogDatabase->myDatabaseID, tab_id))) {
349
 
                                                frompool_(otab);
350
 
                                                if (type == MS_TL_BLOB_REF) {
351
 
                                                        otab->checkBlob(buffer, blob_id, auth_code, iTempLogFile->myTempLogID, iLogOffset);
352
 
                                                        backtopool_(otab);
353
 
                                                }
354
 
                                                else {
355
 
                                                        ASSERT(type == MS_TL_TABLE_REF);
356
 
                                                        if ((type == MS_TL_TABLE_REF) && otab->deleteReferences(iTempLogFile->myTempLogID, iLogOffset, &myMustQuit)) {
357
 
                                                                /* Delete the file now... */
358
 
                                                                MSTable                 *tab;
359
 
                                                                CSPath                  *from_path;
360
 
                                                                MSOpenTablePool *tab_pool;
361
 
 
362
 
                                                                tab = otab->getDBTable();
363
 
                                                                from_path = otab->getDBTable()->getTableFile();
364
 
 
365
 
                                                                pop_(otab);
366
 
 
367
 
                                                                push_(from_path);
368
 
                                                                tab->retain();
369
 
                                                                push_(tab);
370
 
 
371
 
                                                                tab_pool = MSTableList::lockTablePoolForDeletion(otab); // This returns otab to the pool.
372
 
                                                                frompool_(tab_pool);
373
 
 
374
 
                                                                from_path->removeFile();
375
 
                                                                tab->myDatabase->removeTable(tab);
376
 
 
377
 
                                                                backtopool_(tab_pool); // The will unlock and close the table pool freeing all tables in it.
378
 
                                                                pop_(tab);                              // Returning the pool will have released this. (YUK!)
379
 
                                                                release_(from_path);
380
 
                                                        }
381
 
                                                        else 
382
 
                                                                backtopool_(otab);
383
 
                                                }
384
 
                                        }
385
 
                                }
386
 
                        }
387
 
                        catch_(a) {
 
402
                
 
403
                        if (try_ReleaseBLOBReference(self, buffer, tab_id, type, blob_id, auth_code)) {
388
404
                                int err = self->myException.getErrorCode();
389
405
                                
390
406
                                if (err == MS_ERR_TABLE_LOCKED) {
401
417
                                else
402
418
                                        self->myException.log(NULL);
403
419
                        }
404
 
                        cont_(a);
 
420
 
405
421
                }
406
422
                else {
407
423
                        // Only part of the data read, don't wait very long to try again: