#include <CheckpointThread.h>
Inheritance diagram for CheckpointThread:
Public Member Functions | |
CheckpointThread (Database &database) | |
Creates a checkpoint thread for the given database (no more than one is ever needed). | |
SXMutex & | getActionMutex () |
Gets the action mutex. | |
virtual void | requestCheckpoint (CheckpointType checkpointType) |
Implements CheckpointProvider by signalling the checkpoint thread, which in response will quiesce the system and carry out a checkpoint. | |
virtual void | start () |
Spawns the OS thread. | |
void | join () |
Waits for the OS thread to terminate. | |
bool | isStarted () const |
| |
bool | isStopped () const |
| |
boost::thread & | getBoostThread () |
Accesses the underlying boost::thread, e.g. | |
std::string | getName () |
void | setName (std::string const &s) |
bool | isClosed () const |
| |
void | close () |
Closes this object, releasing any unallocated resources. | |
Protected Member Functions | |
void | initAndRun () |
virtual void | beforeRun () |
virtual void | afterRun () |
Protected Attributes | |
boost::thread * | pBoostThread |
bool | bRunning |
std::string | name |
StrictMutex | mutex |
LocalCondition | condition |
bool | needsClose |
Private Member Functions | |
void | closeImpl () |
Implements ClosableObject by requesting that the checkpoint thread shut itself down. | |
virtual void | run () |
Private Attributes | |
Database & | database |
SXMutex | actionMutex |
CheckpointType | checkpointType |
bool | quit |
Definition at line 38 of file CheckpointThread.h.
CheckpointThread::CheckpointThread | ( | Database & | database | ) | [explicit] |
Creates a checkpoint thread for the given database (no more than one is ever needed).
This constructor does not start the thread; that must be done explicitly.
database | the Database to checkpoint when requested |
Definition at line 30 of file CheckpointThread.cpp.
References actionMutex, CHECKPOINT_DISCARD, checkpointType, quit, SXMutex::SCHEDULE_FAVOR_EXCLUSIVE, and SXMutex::setSchedulingPolicy().
00031 : database(databaseInit) 00032 { 00033 actionMutex.setSchedulingPolicy(SXMutex::SCHEDULE_FAVOR_EXCLUSIVE); 00034 checkpointType = CHECKPOINT_DISCARD; 00035 quit = false; 00036 }
void CheckpointThread::closeImpl | ( | ) | [private, virtual] |
Implements ClosableObject by requesting that the checkpoint thread shut itself down.
Implements ClosableObject.
Definition at line 68 of file CheckpointThread.cpp.
References SynchMonitoredObject::condition, Thread::isStarted(), Thread::join(), SynchMonitoredObject::mutex, and quit.
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 }
void CheckpointThread::run | ( | ) | [private, virtual] |
Implements Thread.
Definition at line 38 of file CheckpointThread.cpp.
References actionMutex, CHECKPOINT_DISCARD, Database::checkpointImpl(), checkpointType, SynchMonitoredObject::condition, database, SynchMonitoredObject::mutex, quit, and SXMutexGuard< lockMode >::unlock().
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 }
SXMutex & CheckpointThread::getActionMutex | ( | ) |
Gets the action mutex.
The checkpoint thread takes an exclusive lock on this mutex for the duration of each checkpoint, so any thread which needs to carry out an action which must not overlap a checkpoint should take a shared lock on this for the duration of the action.
Definition at line 63 of file CheckpointThread.cpp.
References actionMutex.
00064 { 00065 return actionMutex; 00066 }
void CheckpointThread::requestCheckpoint | ( | CheckpointType | checkpointType | ) | [virtual] |
Implements CheckpointProvider by signalling the checkpoint thread, which in response will quiesce the system and carry out a checkpoint.
checkpointType | type of checkpoint to request |
Implements CheckpointProvider.
Definition at line 83 of file CheckpointThread.cpp.
References CHECKPOINT_DISCARD, CHECKPOINT_FLUSH_ALL, CHECKPOINT_FLUSH_FUZZY, checkpointType, SynchMonitoredObject::condition, and SynchMonitoredObject::mutex.
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 }
void Thread::initAndRun | ( | ) | [protected, inherited] |
Definition at line 66 of file Thread.cpp.
References Thread::afterRun(), Thread::beforeRun(), and Thread::run().
Referenced by Thread::start().
void Thread::beforeRun | ( | ) | [protected, virtual, inherited] |
Definition at line 73 of file Thread.cpp.
References Thread::bRunning.
Referenced by Thread::initAndRun().
00074 { 00075 bRunning = true; 00076 }
void Thread::afterRun | ( | ) | [protected, virtual, inherited] |
Definition at line 78 of file Thread.cpp.
References Thread::bRunning.
Referenced by Thread::initAndRun().
00079 { 00080 bRunning = false; 00081 }
void Thread::start | ( | ) | [virtual, inherited] |
Spawns the OS thread.
Definition at line 50 of file Thread.cpp.
References Thread::initAndRun(), and Thread::pBoostThread.
Referenced by AioLinuxScheduler::AioLinuxScheduler(), AioPollingScheduler::AioPollingScheduler(), StatsTimer::start(), ResourceTest::testConcurrency(), and LocalConditionTest::testNotifyAll().
00051 { 00052 pBoostThread = new boost::thread( 00053 boost::bind(&Thread::initAndRun,this)); 00054 }
void Thread::join | ( | ) | [inherited] |
Waits for the OS thread to terminate.
Definition at line 56 of file Thread.cpp.
References Thread::pBoostThread.
Referenced by closeImpl(), TimerThread::stop(), AioPollingScheduler::stop(), AioLinuxScheduler::stop(), ResourceTest::testConcurrency(), and LocalConditionTest::testNotifyAll().
00057 { 00058 assert(pBoostThread); 00059 boost::thread t; 00060 assert(*pBoostThread != t); 00061 pBoostThread->join(); 00062 delete pBoostThread; 00063 pBoostThread = NULL; 00064 }
bool Thread::isStarted | ( | ) | const [inline, inherited] |
Reimplemented in AioLinuxScheduler.
Definition at line 71 of file Thread.h.
Referenced by closeImpl(), CacheImpl< PageT, VictimPolicyT >::closeImpl(), AioLinuxScheduler::isStarted(), and TimerThread::stop().
00072 { 00073 return pBoostThread ? true : false; 00074 }
bool Thread::isStopped | ( | ) | const [inline, inherited] |
Definition at line 79 of file Thread.h.
00080 { 00081 return !isStarted(); 00082 }
boost::thread& Thread::getBoostThread | ( | ) | [inline, inherited] |
Accesses the underlying boost::thread, e.g.
for use in a boost::thread_group. This thread must already be started.
Definition at line 90 of file Thread.h.
00091 { 00092 assert(isStarted()); 00093 return *pBoostThread; 00094 }
std::string Thread::getName | ( | ) | [inline, inherited] |
void Thread::setName | ( | std::string const & | s | ) | [inline, inherited] |
bool ClosableObject::isClosed | ( | ) | const [inline, inherited] |
Definition at line 58 of file ClosableObject.h.
00059 { 00060 return !needsClose; 00061 }
void ClosableObject::close | ( | ) | [inherited] |
Closes this object, releasing any unallocated resources.
Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.
Definition at line 39 of file ClosableObject.cpp.
References ClosableObject::closeImpl(), and ClosableObject::needsClose.
Referenced by CacheImpl< PageT, VictimPolicyT >::allocatePages(), LcsRowScanBaseExecStream::closeImpl(), ExecStreamGraphImpl::closeImpl(), FlatFileBuffer::open(), ClosableObjectDestructor::operator()(), and Segment::~Segment().
00040 { 00041 if (!needsClose) { 00042 return; 00043 } 00044 needsClose = false; 00045 closeImpl(); 00046 }
Database& CheckpointThread::database [private] |
SXMutex CheckpointThread::actionMutex [private] |
Definition at line 43 of file CheckpointThread.h.
Referenced by CheckpointThread(), getActionMutex(), and run().
Definition at line 44 of file CheckpointThread.h.
Referenced by CheckpointThread(), requestCheckpoint(), and run().
bool CheckpointThread::quit [private] |
Definition at line 45 of file CheckpointThread.h.
Referenced by CheckpointThread(), closeImpl(), and run().
boost::thread* Thread::pBoostThread [protected, inherited] |
Definition at line 44 of file Thread.h.
Referenced by Thread::join(), Thread::start(), Thread::Thread(), and Thread::~Thread().
bool Thread::bRunning [protected, inherited] |
Definition at line 45 of file Thread.h.
Referenced by Thread::afterRun(), Thread::beforeRun(), Thread::Thread(), and Thread::~Thread().
std::string Thread::name [protected, inherited] |
StrictMutex SynchMonitoredObject::mutex [protected, inherited] |
Definition at line 38 of file SynchMonitoredObject.h.
Referenced by ParallelExecStreamScheduler::abort(), LogicalTxnLog::checkpoint(), Database::checkpointImpl(), closeImpl(), LogicalTxnLog::commitTxn(), ParallelExecStreamScheduler::executeManager(), ParallelExecStreamScheduler::executeTask(), LogicalTxnLog::getOldestActiveTxnId(), LogicalTxnLog::newLogicalTxn(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), GroupLock::release(), Database::requestCheckpoint(), requestCheckpoint(), LogicalTxnLog::rollbackTxn(), TimerThread::run(), run(), ThreadPoolBase::runPooledThread(), SXMutex::setSchedulingPolicy(), TimerThread::signalImmediate(), ParallelExecStreamScheduler::signalSentinel(), ThreadPoolBase::start(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::tryUpgrade(), SXMutex::waitFor(), GroupLock::waitFor(), and Database::writeStats().
LocalCondition SynchMonitoredObject::condition [protected, inherited] |
Definition at line 39 of file SynchMonitoredObject.h.
Referenced by ParallelExecStreamScheduler::abort(), Database::checkpointImpl(), closeImpl(), LogicalTxnLog::commitTxnWithGroup(), ParallelExecStreamScheduler::executeTask(), ParallelExecStreamScheduler::readStream(), SXMutex::release(), GroupLock::release(), Database::requestCheckpoint(), requestCheckpoint(), TimerThread::run(), run(), ThreadPoolBase::runPooledThread(), TimerThread::signalImmediate(), TimerThread::stop(), ThreadPoolBase::stop(), ParallelExecStreamScheduler::stop(), ThreadPool< RandomAccessRequest >::submitTask(), ParallelExecStreamScheduler::tryExecuteManager(), ParallelExecStreamScheduler::tryExecuteTask(), SXMutex::waitFor(), and GroupLock::waitFor().
bool ClosableObject::needsClose [protected, inherited] |
Definition at line 44 of file ClosableObject.h.
Referenced by SegStreamAllocation::beginWrite(), ExecStreamGraphImpl::clear(), ClosableObject::ClosableObject(), ClosableObject::close(), FlatFileBuffer::open(), ExecStreamGraphImpl::open(), ExecStream::open(), and ClosableObject::~ClosableObject().