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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <Basics.H>
00042 #include <Table.H>
00043 #include <FP.H>
00044
00045
00046 #include <CacheIntf.H>
00047 #include <Debug.H>
00048 #include <ReadConfig.H>
00049 #include <PKPrefix.H>
00050 #include <CacheState.H>
00051 #include <Model.H>
00052 #include <CacheIndex.H>
00053 #include <FV.H>
00054 #include <VestaVal.H>
00055 #include <NewVal.H>
00056
00057
00058 #include "CacheS.H"
00059 #include "ExpCache.H"
00060
00061 CacheS::CacheS(CacheIntf::DebugLevel debug, bool noHits) throw ()
00062 {
00063 this->debug = CacheIntf::All;
00064 }
00065
00066 FV::Epoch CacheS::FreeVariables(const FP::Tag& pk,
00067 FV::List &names, bool &isEmpty) throw ()
00068 {
00069 FV::Epoch res;
00070 NewVal::NewNames( names);
00071 isEmpty = ((names.len == 0) && (Debug::MyRand(0, 5) > 1));
00072 res = Debug::MyRand(0, 1000);
00073 return(res);
00074 }
00075
00076 CacheIntf::LookupRes
00077 CacheS::Lookup(const FP::Tag &pk, FV::Epoch id, const FP::List &fps,
00078 CacheEntry::Index &ci, const VestaVal::T* &value) throw ()
00079 {
00080 CacheIntf::LookupRes res;
00081 int i = Debug::MyRand(1, 10);
00082 if (i < 6) res = CacheIntf::Hit;
00083 else if (i < 8) res = CacheIntf::Miss;
00084 else res = CacheIntf::FVMismatch;
00085 if (res == CacheIntf::Hit) {
00086 ci = (int)Debug::MyRand(0,9999);
00087 VestaVal::T *newValue = NEW(VestaVal::T);
00088 NewVal::NewValue(*(newValue));
00089 value = (const VestaVal::T *)newValue;
00090 }
00091 return(res);
00092 }
00093
00094 CacheIntf::AddEntryRes
00095 CacheS::AddEntry(FP::Tag *pk, FV::List *names, FP::List *fps,
00096 VestaVal::T *value, Model::T model, CacheEntry::Indices* kids,
00097 CacheEntry::Index& ci) throw ()
00098 {
00099 CacheIntf::AddEntryRes res;
00100 int i = Debug::MyRand(0, 7);
00101 res = (i == 0) ? CacheIntf::NoLease : CacheIntf::EntryAdded;
00102 if (res == CacheIntf::EntryAdded) {
00103 ci = Debug::MyRand(0, 9999);
00104 }
00105 return res;
00106 }
00107
00108 void CacheS::WeederRecovering(bool doneMarking) throw ()
00109 {
00110
00111 }
00112
00113 BitVector* CacheS::StartMark( int &newLogVer) throw ()
00114 {
00115 BitVector *res = NEW(BitVector);
00116 for (int i = 0; i < 10; i++) {
00117 int j = Debug::MyRand(0, 60);
00118 (void) res->Set(j);
00119 }
00120 newLogVer = 0;
00121 return res;
00122 }
00123
00124 void CacheS::SetHitFilter(const BitVector &cis) throw ()
00125 {
00126
00127 }
00128
00129 BitVector* CacheS::GetLeases() throw ()
00130 {
00131 BitVector *res = NEW(BitVector);
00132 for (int i = 0; i < 10; i++) {
00133 int j = Debug::MyRand(0, 60);
00134 (void) res->Set(j);
00135 }
00136 return res;
00137 }
00138
00139 void CacheS::ResumeLeaseExp() throw ()
00140 {
00141
00142 }
00143
00144 int CacheS::EndMark(const BitVector &cis, const PKPrefix::List &pfxs) throw ()
00145 {
00146 return 1;
00147 }
00148
00149 void CacheS::CommitChkpt() throw ()
00150 {
00151
00152 }
00153
00154 void CacheS::Checkpoint(const FP::Tag &pkgVersion, Model::T model,
00155 CacheEntry::Indices *cis, bool done) throw ()
00156 {
00157
00158 }
00159
00160 void CacheS::FlushAll() throw ()
00161 {
00162
00163 }
00164
00165 void CacheS::GetCacheId( CacheId &id) throw ()
00166 {
00167
00168 }
00169
00170 void CacheS::GetCacheState( CacheState &state) throw ()
00171 {
00172
00173 }
00174
00175 bool CacheS::RenewLeases(CacheEntry::Indices *cis) throw ()
00176 {
00177 int i = Debug::MyRand(0,1);
00178 bool res = (i == 0);
00179 return res;
00180 }
00181
00182 void CacheWorker::Start() throw ()
00183 {
00184
00185 }
00186
00187 void ExitServer() throw ()
00188 {
00189 cerr << "SYNTAX: server [ maxRunning [ maxBlocked ] ]" << endl;
00190 exit(1);
00191 }
00192
00193 void HandleFailure(SRPC *srpc, const SRPC::failure &f, void *arg) throw ()
00194 {
00195 cerr << "SRPC failure (code " << f.r << "):" << endl;
00196 cerr << " " << f.msg << endl << endl;
00197 }
00198
00199 void Server(int argc, char *argv[]) throw ()
00200 {
00201 int maxRunning, maxBlocked;
00202
00203
00204 if (argc > 3) {
00205 cerr << "Error: Too many arguments" << endl;
00206 ExitServer();
00207 }
00208 maxRunning = maxBlocked = 10000;
00209 if (argc > 1) sscanf(argv[1], "%d", &maxRunning);
00210 if (argc > 2) sscanf(argv[2], "%d", &maxBlocked);
00211
00212
00213 CacheS cs;
00214 Debug::Lock();
00215 cout << "Starting server:" << endl;
00216 cout << " Config file = " << ReadConfig::Location() << endl;
00217 cout << " Maximum number of running threads = " << maxRunning << endl;
00218 cout << " Maximum number of blocked threads = " << maxBlocked << endl;
00219 cout << endl;
00220 Debug::Unlock();
00221 ExpCache exp(&cs, maxRunning, maxBlocked, HandleFailure);
00222
00223
00224 while (1) {
00225 try {
00226 exp.Run();
00227 }
00228 catch (SRPC::failure f) {
00229 HandleFailure((SRPC *)NULL, f, (void *)NULL);
00230
00231 if (f.r == SRPC::transport_failure) break;
00232 }
00233 }
00234 }
00235
00236 int main(int argc, char *argv[]) throw ()
00237 {
00238 Server(argc, argv);
00239 return(0);
00240 }