00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CLASSAD_COLLECTION_BASE_H__
00022 #define __CLASSAD_COLLECTION_BASE_H__
00023
00024 #include "classad/collection.h"
00025 #include "classad/indexfile.h"
00026
00027 #ifndef WIN32
00028 #include <sys/time.h>
00029 #include <unistd.h>
00030 #endif
00031
00032 #define MaxCacheSize 5
00033
00034 BEGIN_NAMESPACE( classad )
00035
00036 class ServerTransaction;
00037
00038 class ClassAdProxy {
00039 public:
00040 ClassAdProxy( ){ ad=NULL; };
00041 ~ClassAdProxy( ){ };
00042
00043 ClassAd *ad;
00044 };
00045
00046 typedef classad_map<std::string,View*> ViewRegistry;
00047 typedef classad_map<std::string,ClassAdProxy> ClassAdTable;
00048 typedef classad_map<std::string,ServerTransaction*> XactionTable;
00049
00052 class ClassAdCollection : public ClassAdCollectionInterface {
00053 public:
00065 ClassAdCollection( );
00066
00070 ClassAdCollection(bool cacheOn);
00071
00073 virtual ~ClassAdCollection( );
00075
00093 virtual bool InitializeFromLog( const std::string &logfile,
00094 const std::string storagefile="",
00095 const std::string checkpointfile="" );
00096
00102 virtual bool TruncateLog(void);
00104
00123 virtual bool AddClassAd( const std::string &key, ClassAd *newAd );
00124 virtual bool UpdateClassAd( const std::string &key, ClassAd *updateAd );
00125
00126
00127 virtual bool ModifyClassAd( const std::string &key, ClassAd *modifyAd );
00128 virtual bool RemoveClassAd( const std::string &key );
00129
00130
00131 virtual ClassAd *GetClassAd(const std::string &key );
00133
00134
00135 virtual bool CreateSubView( const ViewName &viewName,
00136 const ViewName &parentViewName,
00137 const std::string &constraint, const std::string &rank,
00138 const std::string &partitionExprs );
00139 virtual bool CreatePartition( const ViewName &viewName,
00140 const ViewName &parentViewName,
00141 const std::string &constraint, const std::string &rank,
00142 const std::string &partitionExprs, ClassAd *rep );
00143 virtual bool DeleteView( const ViewName &viewName );
00144 virtual bool SetViewInfo( const ViewName &viewName,
00145 const std::string &constraint, const std::string &rank,
00146 const std::string &partitionAttrs );
00147 virtual bool GetViewInfo( const ViewName &viewName, ClassAd *&viewInfo );
00148 virtual const View *GetView( const ViewName &viewName );
00149 virtual bool ViewExists( const ViewName &viewName);
00150
00151 virtual bool GetSubordinateViewNames( const ViewName &viewName,
00152 std::vector<std::string>& views );
00153 virtual bool GetPartitionedViewNames( const ViewName &viewName,
00154 std::vector<std::string>& views );
00155 virtual bool FindPartitionName( const ViewName &viewName, ClassAd *rep,
00156 ViewName &partition );
00157
00158
00159 virtual bool OpenTransaction( const std::string &transactionName );
00160 virtual bool CloseTransaction(const std::string &transactionName,bool commit,
00161 int &outcome);
00162
00163 virtual bool IsMyActiveTransaction( const std::string &transactionName );
00164 virtual void GetMyActiveTransactions( std::vector<std::string>& );
00165 virtual bool IsActiveTransaction( const std::string &transactionName );
00166 virtual bool GetAllActiveTransactions( std::vector<std::string>& );
00167 virtual bool IsCommittedTransaction( const std::string &transactionName );
00168 virtual bool GetAllCommittedTransactions( std::vector<std::string>& );
00169
00170
00171 bool DisplayView( const ViewName &viewName, FILE * );
00172
00173 bool dump_collection();
00174 IndexFile ClassAdStorage;
00175 int WriteCheckPoint();
00176 bool TruncateStorageFile();
00177
00178 protected:
00179 virtual bool OperateInRecoveryMode( ClassAd * );
00180 virtual bool LogState( FILE * );
00181
00182 friend class View;
00183 friend class ServerTransaction;
00184 friend class ClassAd;
00185 friend class LocalCollectionQuery;
00186
00187
00188
00189 bool PlayClassAdOp ( int, ClassAd * );
00190 bool PlayXactionOp ( int, const std::string &, ClassAd *, ServerTransaction *& );
00191 bool PlayViewOp ( int, ClassAd * );
00192
00193
00194 bool RegisterView( const ViewName &viewName, View * );
00195 bool UnregisterView( const ViewName &viewName );
00196
00197
00198 ViewRegistry viewRegistry;
00199 ClassAdTable classadTable;
00200 View viewTree;
00201 XactionTable xactionTable;
00202
00203 bool LogViews( FILE *log, View *view, bool subView );
00204 void Setup(bool CacheOn);
00205 bool Cache;
00206 bool SelectClassadToReplace(std::string &key);
00207 bool SetDirty(std::string key);
00208 bool ClearDirty(std::string key);
00209 bool CheckDirty(std::string key);
00210 bool GetStringClassAd(std::string key,std::string &WriteBackClassad);
00211 bool SwitchInClassAd(std::string key);
00212 int ReadStorageEntry(int sfiled, int &offset,std::string &ckey);
00213 bool ReadCheckPointFile();
00214 void MaybeSwapOutClassAd(void);
00215
00216 int Max_Classad;
00217 int CheckPoint;
00218 std::map<std::string,int> DirtyClassad;
00219 timeval LatestCheckpoint;
00220 std::string CheckFileName;
00221 int test_checkpoint;
00222
00223 private:
00224 ClassAdCollection(const ClassAdCollection &) : ClassAdCollectionInterface(), viewTree(NULL) { return; }
00225 ClassAdCollection &operator=(const ClassAdCollection &) { return *this; }
00226
00227 bool AddClassAd_Transaction(const std::string &key, ClassAd *newAd);
00228 bool AddClassAd_NoTransaction(const std::string &key, ClassAd *newAd);
00229
00230 };
00231
00232 END_NAMESPACE
00233
00234 #endif