CheckpointThread.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/db/CheckpointThread.cpp#12 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/db/CheckpointThread.h"
00026 #include "fennel/db/Database.h"
00027 
00028 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/db/CheckpointThread.cpp#12 $");
00029 
00030 CheckpointThread::CheckpointThread(Database &databaseInit)
00031     : database(databaseInit)
00032 {
00033     actionMutex.setSchedulingPolicy(SXMutex::SCHEDULE_FAVOR_EXCLUSIVE);
00034     checkpointType = CHECKPOINT_DISCARD;
00035     quit = false;
00036 }
00037 
00038 void CheckpointThread::run()
00039 {
00040     for (;;) {
00041         StrictMutexGuard mutexGuard(mutex);
00042         while ((checkpointType == CHECKPOINT_DISCARD) && !quit) {
00043             condition.wait(mutexGuard);
00044         }
00045         if (quit) {
00046             return;
00047         }
00048 
00049         // NOTE jvs 28-Feb-2006:  reset checkpointType here; we used
00050         // to do it after checkpoint completion, but that led to a
00051         // race condition whereby we might miss a new checkpoint request
00052         // by overwriting it.
00053         CheckpointType currentType = checkpointType;
00054         checkpointType = CHECKPOINT_DISCARD;
00055         mutexGuard.unlock();
00056 
00057         SXMutexExclusiveGuard actionMutexGuard(actionMutex);
00058         database.checkpointImpl(currentType);
00059         actionMutexGuard.unlock();
00060     }
00061 }
00062 
00063 SXMutex &CheckpointThread::getActionMutex()
00064 {
00065     return actionMutex;
00066 }
00067 
00068 void CheckpointThread::closeImpl()
00069 {
00070     StrictMutexGuard mutexGuard(mutex);
00071 
00072     if (!isStarted()) {
00073         return;
00074     }
00075 
00076     quit = true;
00077     condition.notify_all();
00078     mutexGuard.unlock();
00079 
00080     join();
00081 }
00082 
00083 void CheckpointThread::requestCheckpoint(CheckpointType request)
00084 {
00085     StrictMutexGuard mutexGuard(mutex);
00086     switch (request) {
00087     case CHECKPOINT_FLUSH_ALL:
00088         checkpointType = request;
00089         break;
00090     case CHECKPOINT_FLUSH_FUZZY:
00091         if (checkpointType == CHECKPOINT_DISCARD) {
00092             checkpointType = request;
00093         }
00094         break;
00095     default:
00096         permAssert(false);
00097     }
00098     condition.notify_all();
00099 }
00100 
00101 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/db/CheckpointThread.cpp#12 $");
00102 
00103 // End CheckpointThread.cpp

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1