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 Wed Aug 4 23:59:34 EDT 2004 by ken@xorian.net 00020 // modified on Thu Feb 10 11:54:03 PST 2000 by heydon 00021 00022 #ifndef _CACHE_LOG_H 00023 #define _CACHE_LOG_H 00024 00025 #include <Basics.H> 00026 #include <VestaLog.H> 00027 #include <Recovery.H> 00028 #include <FP.H> 00029 #include <PKEpoch.H> 00030 #include <FV.H> 00031 00032 #include "CacheEntry.H" 00033 00034 /* The "cacheLog" is a linked list of "CacheLog::Entry" structures. Each 00035 structure contains: 00036 00037 "pk": a primary key 00038 "pkEpoch": the epoch of the entry's PKFile at the time it was 00039 added 00040 "sourceFunc": the source location annotation from the client 00041 "ci": the cache index of the entry 00042 "value": the stored result value 00043 "model": model (ShortId) for the entry 00044 "kids": a list of the child cache entry indecies 00045 "names": the free variables (on which the functions result 00046 depends) 00047 "fps": the fingerprints corresponding to the free 00048 variables 00049 00050 Conceptually, this is the arguments from the client's AddEntry 00051 call, plus the pkEpoch and ci. 00052 */ 00053 00054 class CacheLog { 00055 public: 00056 // Once initialized, all data fields (except the "next" field) of a 00057 // "CacheLog::Entry" are read-only 00058 class Entry { 00059 public: 00060 // Constructors 00061 Entry() throw () 00062 : pk((FP::Tag *)NULL), value(NULL), kids(NULL), 00063 names(NULL), fps(NULL), 00064 next((Entry *)NULL) { /*SKIP*/ } 00065 Entry(const Text& sourceFunc, FP::Tag *pk, PKFile::Epoch pkEpoch, 00066 CacheEntry::Index ci, VestaVal::T *value, 00067 Model::T model, CacheEntry::Indices *kids, 00068 FV::List *names, FP::List *fps) throw () 00069 : sourceFunc(sourceFunc), pk(pk), pkEpoch(pkEpoch), 00070 ci(ci), value(value), model(model), kids(kids), 00071 names(names), fps(fps), 00072 next((Entry *)NULL) 00073 { /*SKIP*/ } 00074 Entry(RecoveryReader &rd) throw (VestaLog::Error, VestaLog::Eof) 00075 /* REQUIRES Sup(LL) = CacheS.cacheLogMu */ 00076 { Recover(rd); } 00077 00078 void Init(const Text& sourceFunc, FP::Tag *pk, PKFile::Epoch pkEpoch, 00079 CacheEntry::Index ci, VestaVal::T *value, 00080 Model::T model, CacheEntry::Indices *kids, 00081 FV::List *names, FP::List *fps) throw (); 00082 /* Initialize this cache log entry to the tuple "(sourceFunc, 00083 pk, pkEpoch, ci, value, model, kids, names, fps)". */ 00084 00085 // Destructors 00086 ~Entry() throw () { this->Reset(); } 00087 void Reset() throw () 00088 { 00089 this->pk = NULL; this->value = NULL; this->kids = NULL; 00090 this->names = NULL; this->fps = NULL; 00091 } 00092 /* Drop memory reachable from this cache entry. */ 00093 00094 void Log(VestaLog &log) const throw (VestaLog::Error); 00095 /* REQUIRES Sup(LL) = CacheS.cacheLogMu */ 00096 /* Append this cache entry to "log"; requires "log" to be 00097 in the "logging" state. */ 00098 00099 void Recover(RecoveryReader &rd) 00100 throw (VestaLog::Error, VestaLog::Eof); 00101 /* REQUIRES Sup(LL) = CacheS.cacheLogMu */ 00102 /* Recover a previously-logged CacheLogEntry from "rd". */ 00103 00104 void Write(std::ostream &ofs) const throw (FS::Failure); 00105 /* Write this cache log entry to "ofs". */ 00106 00107 void Debug(std::ostream &s, int indent = 2) const throw (); 00108 /* Write a one-line summary of this entry to "s". The output is 00109 indented by "indent" spaces, and ends with a newline. */ 00110 00111 void DebugFull(std::ostream &s) const throw (); 00112 /* Write full debugging information for this entry to "s" consisting 00113 of serveral lines. The output is indented; it is not followed by a 00114 blank line. */ 00115 00116 // All data fields of a CacheLog::Entry are read-only after init. 00117 /* The "pk", "values", "kids", "names", and "fps" fields are 00118 pointers to structures that also reside in the cache. */ 00119 Entry *next; 00120 Text sourceFunc; // source location of function definition 00121 FP::Tag *pk; // primary key 00122 PKFile::Epoch pkEpoch; // current PKFile epoch 00123 00124 CacheEntry::Index ci; // cache index 00125 VestaVal::T *value; // value stored in this cache entry 00126 CacheEntry::Indices *kids; // child cache indecies 00127 Model::T model; // model (ShortId) for this entry 00128 00129 FV::List *names; // free variables of this entry... 00130 FP::List *fps; // ...and associated fingerprints 00131 00132 private: 00133 // hide copy constructor from clients 00134 Entry(const Entry &); 00135 }; 00136 }; 00137 00138 #endif // _CACHE_LOG_H