00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <Basics.H>
00023 #include <FS.H>
00024 #include <VestaLog.H>
00025 #include <FP.H>
00026 #include <BitVector.H>
00027 #include <CacheState.H>
00028
00029 #include "CacheConfigServer.H"
00030 #include "EmptyPKLog.H"
00031 #include "VPKFile.H"
00032 #include "SMultiPKFile.H"
00033 #include "VMultiPKFile.H"
00034
00035 using std::ifstream;
00036
00037 bool VMultiPKFile::IsFull() throw ()
00038
00039 {
00040 bool res = (this->numNewEntries >= Config_MPKFileFlushNum)
00041 && (this->numWaiting == 0) && (!(this->autoFlushPending));
00042 if (res) this->autoFlushPending = true;
00043 return res;
00044 }
00045
00046 bool VMultiPKFile::LockForWrite(Basics::mutex &mu, const BitVector *toDelete)
00047 throw()
00048 {
00049
00050 if (this->numNewEntries == 0 && toDelete == (BitVector *)NULL) {
00051 return false;
00052 }
00053
00054
00055 while (this->numRunning > 0) {
00056 assert(this->numRunning == 1);
00057 this->numWaiting++;
00058 this->noneRunning.wait(mu);
00059 this->numWaiting--;
00060 }
00061
00062
00063
00064
00065 if (this->numNewEntries == 0 && toDelete == (BitVector *)NULL) {
00066 return false;
00067 }
00068
00069
00070 assert(this->numRunning == 0);
00071 this->numRunning++;
00072 this->autoFlushPending = false;
00073
00074 return true;
00075 }
00076
00077
00078 bool VMultiPKFile::ChkptForWrite(Basics::mutex &mu, const BitVector *toDelete,
00079 SMultiPKFile::VPKFileMap &toFlush,
00080 SMultiPKFile::ChkPtTbl &vpkChkptTbl)
00081 throw()
00082 {
00083
00084 mu.lock();
00085 toFlush = this->tbl;
00086 this->numNewEntries = 0;
00087 this->freeMPKFileEpoch = -1;
00088 mu.unlock();
00089
00090
00091
00092 bool l_result = SMultiPKFile::ChkptForRewrite(toFlush, toDelete,
00093 vpkChkptTbl);
00094
00095
00096
00097 if(!l_result)
00098 {
00099 this->ReleaseWriteLock(mu);
00100 }
00101
00102
00103 return l_result;
00104 }
00105
00106 void VMultiPKFile::ReleaseWriteLock(Basics::mutex &mu) throw()
00107
00108
00109
00110
00111
00112
00113 {
00114 mu.lock();
00115 this->numRunning--;
00116 assert(this->numRunning == 0);
00117 mu.unlock();
00118 this->noneRunning.signal();
00119 }
00120
00121 void VMultiPKFile::ToSCache(Basics::mutex &mu,
00122
00123
00124 bool mpkFileExists, ifstream &ifs,
00125 SMultiPKFileRep::Header *hdr,
00126
00127
00128 SMultiPKFile::VPKFileMap &toFlush,
00129 SMultiPKFile::ChkPtTbl &vpkChkptTbl,
00130
00131 const BitVector *toDelete,
00132 EmptyPKLog *emptyPKLog,
00133 EntryState &state)
00134 throw (FS::Failure, FS::EndOfFile, VestaLog::Error)
00135
00136 {
00137
00138 assert(this->numRunning == 1);
00139
00140
00141
00142 SMultiPKFile::Rewrite(prefix,
00143 mpkFileExists, ifs, hdr,
00144 toFlush, vpkChkptTbl,
00145 toDelete, emptyPKLog,
00146 state);
00147
00148
00149
00150
00151
00152 this->ReleaseWriteLock(mu);
00153 }
00154
00155 bool VMultiPKFile::IsStale(int latestEpoch) throw ()
00156
00157 {
00158 return (0 <= this->freeMPKFileEpoch
00159 && this->freeMPKFileEpoch <= (latestEpoch -
00160 Config_FlushNewPeriodCnt));
00161 }