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 Thu Nov 8 12:40:11 EST 2001 by ken@xorian.net 00020 // modified on Thu Feb 10 11:23:34 PST 2000 by heydon 00021 00022 // CacheC -- the evaluator client interface to the Vesta-2 cache server 00023 00024 // The class "CacheC" provides a client connection to one or more running 00025 // instances of the Vesta-2 cache server. It provides operations required by 00026 // the Vesta-2 evaluator. 00027 00028 // Once a new "CacheC" object is initialized, its methods are thread-safe. 00029 // That is, they can safely be called by multiple threads at once. 00030 00031 #ifndef _CACHE_C_H 00032 #define _CACHE_C_H 00033 00034 // from vesta/srpc 00035 #include <SRPC.H> 00036 #include <MultiSRPC.H> 00037 00038 // from vesta/fp 00039 #include <FP.H> 00040 00041 // from vesta/cache-common 00042 #include <CacheIntf.H> 00043 #include <BitVector.H> 00044 #include <FV.H> 00045 #include <CacheIndex.H> 00046 #include <Model.H> 00047 #include <VestaVal.H> 00048 #include <FV2.H> 00049 #include <PKPrefix.H> 00050 #include <CompactFV.H> 00051 00052 class CacheC { 00053 public: 00054 // Constructor: initialize the client 00055 CacheC(CacheIntf::DebugLevel debug = CacheIntf::None) 00056 throw (SRPC::failure); 00057 00058 // Destructor: close and free any open connections to servers 00059 ~CacheC() throw (); 00060 00061 FV::Epoch FreeVariables(const FP::Tag& pk, /*OUT*/ CompactFV::List& names, 00062 /*OUT*/ bool &isEmpty) const throw (SRPC::failure); 00063 /* Set "names" to the list of the union of free variables associated with 00064 cache entries under the primary key "pk". Return the epoch of this set 00065 of names, which should be passed to the "Lookup" method below. If the 00066 cache is guaranteed not to contain any entries for "pk", then "isEmpty" 00067 is set to "true", in which case "names" will be empty and a subsequent 00068 "Lookup" would be pointless. "isEmpty" is set to "false" otherwise. */ 00069 00070 CacheIntf::LookupRes Lookup( 00071 const FP::Tag& pk, const FV::Epoch id, const FP::List& fps, 00072 /*OUT*/ CacheEntry::Index& ci, /*OUT*/ VestaVal::T& value) 00073 const throw (SRPC::failure); 00074 /* Look up the cache entry with primary key "pk", free variables set with 00075 epoch "id", and corresponding value fingerprints "fps". 00076 00077 In the event of a hit, "Hit" is returned, a lease is taken out (or 00078 renewed) on the matching cache entry, "ci" is set to the index of that 00079 entry, and "value" is set to its result value. For all other return 00080 values, "ci" and "value" are unchanged. 00081 00082 In the event of a cache miss, "Miss" is returned. In the event that 00083 "id" is an old epoch for "pk", "FVMismatch" is returned. In this case, 00084 the caller should call the "FreeVariables" method again to get the 00085 latest epoch and names associated with "pk", and then try "Lookup" 00086 again. 00087 00088 If "id" corresponds to the most recent epoch, but the length of "fss" 00089 does not agree with with length of the "names" list returned by the 00090 most recent call to "FreeVariables", then "CacheIntf::BadLookupArgs" 00091 is returned. This return result indicates a programming error on the 00092 part of the client. */ 00093 00094 CacheIntf::AddEntryRes AddEntry( 00095 const FP::Tag& pk, const char *types, const FV2::List& names, 00096 const FP::List& fps, const VestaVal::T& value, const Model::T model, 00097 const CacheEntry::Indices& kids, const Text& sourceFunc, 00098 /*OUT*/ CacheEntry::Index& ci) throw (SRPC::failure); 00099 /* Add a new entry to the cache under the primary key "pk" corresponding 00100 to the evaluation of some function; "types" and "names" together 00101 specify the set of names that are free during the evaluation of the 00102 function, and "fps" are the fingerprints of the values associated with 00103 those names. "types" must be non-NULL. 00104 00105 The "i"th free name is formed by prepending the character "types[i]" 00106 (treated as a text) to the names in the sequence "names[i]". It is an 00107 unchecked run-time error if the "types" array has size less than 00108 "names.len". If "names.len != fps.len", or if "names" contains any 00109 duplicate names, "CacheIntf::BadAddEntryArgs" is immediately returned; 00110 this return result indicates a programming error on the part of the 00111 client. 00112 00113 "value" is the value produced by the evaluation of the function, 00114 "model" is the model in which the function is defined, and "kids" are 00115 the indices of the cache entries corresponding to function evaluations 00116 performed directly on behalf of this evaluation. Finally, "sourceFunc" 00117 is a text denoting the source location of the function definition 00118 for the new cache entry. 00119 00120 In the event of success, "CacheIntf::EntryAdded" is returned, a lease 00121 is taken out on the new cache entry, and "ci" is set to the index of 00122 the new cache entry. 00123 00124 If any of the "kids" lacks a lease, then "CacheIntf::NoLease" is 00125 returned, and the value of "ci" is unchanged. */ 00126 00127 void Checkpoint(const FP::Tag &pkgVersion, Model::T model, 00128 const CacheEntry::Indices& cis, bool done) throw (SRPC::failure); 00129 /* Make stable all cache entries and deriveds reachable from the entries 00130 corresponding to "cis". If the cache entries corresponding to "cis" all 00131 have leases, then also write a "Root" entry to the graph log that 00132 protects them from weeding. The arguments "pkgVersion" and "model" 00133 identify the top-level model on which the evaluator was invoked: 00134 "pkgVersion" is the fingerprint of the immutable directory in which the 00135 model resides, and "model" is the ShortId of the model file itself. The 00136 "done" argument should be true if the checkpoint is for a completed 00137 model evaluation, false if it represents an intermediate checkpoint. 00138 The checkpoint is done synchronously iff "done" is true. */ 00139 00140 bool RenewLeases(const CacheEntry::Indices& cis) 00141 throw (SRPC::failure); 00142 /* Renew the leases on the cache entries with indexes "cis". Returns true 00143 if all the cache entries named by "cis" exist and all currently have 00144 valid leases; false otherwise. Even if false is returned, the leases of 00145 all existing cache entries with valid leases named in "cis" will have 00146 had their leases renewed. */ 00147 00148 protected: 00149 // The client maintains a cache of connections in a "Connections" object 00150 MultiSRPC *conns; 00151 00152 // Read-only after initialization 00153 CacheIntf::DebugLevel debug; 00154 00155 // The cache server instance identifier. Read-only after 00156 // initialization 00157 FP::Tag server_instance; 00158 00159 private: 00160 // hide copy constructor from clients 00161 CacheC(const CacheC&); 00162 00163 // Intialize the server instance fingerprint. Should only called 00164 // by constructors. 00165 void init_server_instance() throw(SRPC::failure); 00166 00167 // Recieve the server instance check response for an SRPC call 00168 // guarded by such a check. Either return to indicate that the 00169 // call should continue, or throw SRPC::failure to indicate that a 00170 // server mismatch. 00171 void recv_server_instance_check(SRPC *srpc, const char *func_name) 00172 const throw(SRPC::failure); 00173 }; 00174 00175 #endif // _CACHE_C_H