00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <Basics.H>
00026 #include <VestaLog.H>
00027 #include <Recovery.H>
00028 #include <FP.H>
00029 #include <CacheArgs.H>
00030 #include <CacheIntf.H>
00031 #include <CacheConfig.H>
00032 #include <EmptyPKLog.H>
00033 #include <CacheLog.H>
00034
00035 using std::fstream;
00036 using std::cout;
00037 using std::cerr;
00038 using std::endl;
00039
00040
00041
00042
00043 void PrintEmptyPKLogEntries(EmptyPKLog &log)
00044 throw (VestaLog::Error, VestaLog::Eof)
00045 {
00046 bool empty = true;
00047 int num = 0;
00048 cout << ">>>>> EmptyPKLog <<<<<" << endl << endl;
00049 while (!log.EndOfFile()) {
00050 FP::Tag pk; PKFile::Epoch logPKEpoch;
00051 log.Read( pk, logPKEpoch);
00052 cout << ++num << ". " << "pk = " << pk;
00053 cout << ", pkEpoch = " << logPKEpoch << endl;
00054 empty = false;
00055 }
00056 if (empty) cout << "<<Empty>>" << endl;
00057 cout << endl;
00058 }
00059
00060 void PrintEmptyPKLog() throw (VestaLog::Error, VestaLog::Eof)
00061
00062
00063 {
00064 Basics::mutex mu;
00065 EmptyPKLog emptyPKLog(&mu, CacheIntf::None, true);
00066 do {
00067 PrintEmptyPKLogEntries(emptyPKLog);
00068 } while (emptyPKLog.NextLog());
00069 }
00070
00071 void PrintCacheLogEntries(RecoveryReader &rd, bool verbose, int &num)
00072 throw (VestaLog::Error, VestaLog::Eof)
00073 {
00074 while (!rd.eof()) {
00075 CacheLog::Entry *entry = NEW_CONSTR(CacheLog::Entry, (rd));
00076 if (verbose) {
00077 cout << "*** Entry " << ++num << " ***" << endl;
00078 entry->DebugFull(cout);
00079 cout << endl;
00080 } else {
00081 cout << ++num << ". ";
00082 entry->Debug(cout, 0);
00083 }
00084 cout.flush();
00085 delete entry;
00086 }
00087 }
00088
00089 void PrintCacheLog(bool verbose) throw (VestaLog::Error, VestaLog::Eof)
00090 {
00091 int num = 0;
00092 VestaLog cacheLog;
00093 cacheLog.open(Config_CacheLogPath.chars(), -1, true);
00094 cout << ">>>>>> CacheLog <<<<<<" << endl << endl;
00095
00096 fstream *chkpt = cacheLog.openCheckpoint();
00097 if (chkpt != (fstream *)NULL) {
00098 RecoveryReader rd(chkpt);
00099 PrintCacheLogEntries(rd, verbose, num);
00100 chkpt->close();
00101 }
00102 do {
00103 RecoveryReader rd(&cacheLog);
00104 PrintCacheLogEntries(rd, verbose, num);
00105 } while (cacheLog.nextLog());
00106 if (num == 0) cout << "<<Empty>>" << endl;
00107 }
00108
00109 void ExitProgram(char *msg) throw ()
00110 {
00111 cerr << "Fatal error: " << msg << endl;
00112 cerr << "Syntax: PrintCacheLog [ -verbose ]" << endl;
00113 exit(1);
00114 }
00115
00116 int main(int argc, char *argv[])
00117 {
00118 bool verbose = false;
00119
00120
00121 if (argc > 2) ExitProgram("too many command-line arguments");
00122 if (argc == 2) {
00123 if (CacheArgs::StartsWith(argv[1], "-verbose")) {
00124 verbose = true;
00125 } else {
00126 ExitProgram("unrecognized command-line option");
00127 }
00128 }
00129
00130
00131 try {
00132 PrintEmptyPKLog();
00133 PrintCacheLog(verbose);
00134 }
00135 catch (VestaLog::Error) {
00136 cerr << "VestaLog fatal error: ";
00137 cerr << "failed reading cache log; exiting..." << endl;
00138 exit(1);
00139 }
00140 catch (VestaLog::Eof) {
00141 cerr << "VestaLog fatal error: ";
00142 cerr << "unexpected EOF while reading cache log; exiting..." << endl;
00143 exit(1);
00144 }
00145 return 0;
00146 }