Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

PrintCacheLog.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Mon May 23 22:54:20 EDT 2005 by ken@xorian.net  
00020 //      modified on Sat Feb 12 13:12:48 PST 2000 by mann  
00021 //      modified on Sun Aug 23 11:35:45 PDT 1998 by heydon
00022 
00023 // Read the cache log and print its complete contents
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 /* Note: This is a single-threaded program, so it doesn't respect
00041    the locking level requirements of the log files. */
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(/*OUT*/ pk, /*OUT*/ 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 /* Open the emptyPKLog, and loop over the checkpoint and all subsequent
00062    log files. */
00063 {
00064     Basics::mutex mu; // dummy lock
00065     EmptyPKLog emptyPKLog(&mu, CacheIntf::None, /*readonly=*/ true);
00066     do {
00067         PrintEmptyPKLogEntries(emptyPKLog);
00068     } while (emptyPKLog.NextLog());
00069 }
00070 
00071 void PrintCacheLogEntries(RecoveryReader &rd, bool verbose, /*INOUT*/ 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, /*indent=*/ 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, /*readonly=*/ 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, /*INOUT*/ num);
00100         chkpt->close();
00101     }
00102     do {
00103         RecoveryReader rd(&cacheLog);
00104         PrintCacheLogEntries(rd, verbose, /*INOUT*/ 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     // process command-line
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     // print logs
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 }

Generated on Mon May 8 00:48:35 2006 for Vesta by  doxygen 1.4.2