00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <Basics.H>
00025 #include <FS.H>
00026 #include "VestaLog.H"
00027 #include "Recovery.H"
00028 #include "VestaLogSeq.H"
00029
00030 using std::fstream;
00031
00032 void VestaLogSeq::Open(int ver, bool readonly) throw (VestaLog::Error)
00033 {
00034 assert(!this->opened);
00035 this->vlog.open(this->dir, ver, readonly);
00036 this->opened = true;
00037 this->readChkpt = false;
00038 this->chkptFS = (fstream *)NULL;
00039 this->rr = (RecoveryReader *)NULL;
00040 }
00041
00042 RecoveryReader* VestaLogSeq::Next(int endVer)
00043 throw (VestaLog::Error, FS::Failure)
00044 {
00045 assert(this->opened);
00046
00047
00048 if (!this->readChkpt) {
00049
00050 this->readChkpt = true;
00051 if ((this->chkptFS = this->vlog.openCheckpoint()) != (fstream *)NULL) {
00052 return NEW_CONSTR(RecoveryReader, (this->chkptFS));
00053 }
00054 } else if (this->chkptFS != (fstream *)NULL) {
00055
00056 FS::Close(*(this->chkptFS));
00057 this->chkptFS = (fstream *)NULL;
00058 }
00059
00060
00061 if (this->rr == (RecoveryReader *)NULL) {
00062
00063 if (endVer < 0 || this->vlog.logVersion() < endVer) {
00064 this->rr = NEW_CONSTR(RecoveryReader, (&(this->vlog)));
00065 return this->rr;
00066 }
00067 } else {
00068
00069 if (this->vlog.nextLog() &&
00070 (endVer < 0 || this->vlog.logVersion() < endVer)) {
00071 return this->rr;
00072 }
00073 }
00074
00075
00076 return (RecoveryReader *)NULL;
00077 }
00078
00079 void VestaLogSeq::Close() throw ()
00080 {
00081 assert(this->opened);
00082
00083
00084 if (this->chkptFS != (fstream *)NULL) {
00085 FS::Close(*(this->chkptFS));
00086 this->chkptFS = (fstream *)NULL;
00087 }
00088
00089
00090 this->vlog.close();
00091
00092
00093 this->opened = false;
00094 this->rr = (RecoveryReader *)NULL;
00095 }