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

collectionBase.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
00021  *
00022  *********************************************************************/
00023 
00024 #ifndef __COLLECTION_BASE_H__
00025 #define __COLLECTION_BASE_H__
00026 
00027 #include "collection.h"
00028 
00029 //#ifdef ADDCACHE
00030   #include "indexfile.h"
00031   #include <string>
00032 #ifndef WIN32
00033   #include <sys/time.h>
00034   #include <unistd.h>
00035 #endif
00036 //#endif
00037 #define MaxCacheSize 5
00038 
00039 BEGIN_NAMESPACE( classad )
00040 
00041 class ServerTransaction;
00042 
00043 class ClassAdProxy {
00044 public:
00045         ClassAdProxy( ){ ad=NULL; };
00046         ~ClassAdProxy( ){ };
00047 
00048         ClassAd *ad;
00049 };
00050 
00051 
00052 typedef classad_hash_map<std::string,View*,StringHash> ViewRegistry;
00053 typedef classad_hash_map<std::string,ClassAdProxy,StringHash> ClassAdTable;
00054 typedef classad_hash_map<std::string,ServerTransaction*,StringHash> XactionTable;
00055 
00056 class ClassAdCollection : public ClassAdCollectionInterface {
00057 public:
00058         ClassAdCollection( );
00059         virtual ~ClassAdCollection( );
00060         ClassAdCollection(bool CacheOn);
00061         // Logfile control
00062         virtual bool InitializeFromLog( const std::string &filename,
00063                                                                         const std::string storagefile="", 
00064                                                                         const std::string checkpointfile=""  );
00065 
00066 
00067         // View creation/deletion/interrogation
00068         virtual bool CreateSubView( const ViewName &viewName,
00069                                 const ViewName &parentViewName,
00070                                 const std::string &constraint, const std::string &rank,
00071                                 const std::string &partitionExprs );
00072         virtual bool CreatePartition( const ViewName &viewName,
00073                                 const ViewName &parentViewName,
00074                                 const std::string &constraint, const std::string &rank,
00075                                 const std::string &partitionExprs, ClassAd *rep );
00076         virtual bool DeleteView( const ViewName &viewName );
00077         virtual bool SetViewInfo( const ViewName &viewName,
00078                                 const std::string &constraint, const std::string &rank,
00079                                 const std::string &partitionAttrs );
00080         virtual bool GetViewInfo( const ViewName &viewName, ClassAd *&viewInfo );
00081         virtual bool ViewExists( const ViewName &viewName);
00082         // Child view interrogation
00083         virtual bool GetSubordinateViewNames( const ViewName &viewName,
00084                                 std::vector<std::string>& views );
00085         virtual bool GetPartitionedViewNames( const ViewName &viewName,
00086                                 std::vector<std::string>& views );
00087         virtual bool FindPartitionName( const ViewName &viewName, ClassAd *rep, 
00088                                 ViewName &partition );
00089 
00090 
00091         // ClassAd manipulation 
00092         virtual bool AddClassAd( const std::string &key, ClassAd *newAd );
00093         virtual bool UpdateClassAd( const std::string &key, ClassAd *updateAd );
00094         virtual bool ModifyClassAd( const std::string &key, ClassAd *modifyAd );
00095         virtual bool RemoveClassAd( const std::string &key );
00096 
00097         // ClassAd interrogation
00098         virtual ClassAd *GetClassAd(const std::string &key );
00099 
00100                  
00101         // Transaction management
00102         virtual bool OpenTransaction( const std::string &transactionName );
00103         virtual bool CloseTransaction(const std::string &transactionName,bool commit,
00104                                 int &outcome);
00105 
00106         virtual bool IsMyActiveTransaction( const std::string &transactionName );
00107         virtual void GetMyActiveTransactions( std::vector<std::string>& );
00108         virtual bool IsActiveTransaction( const std::string &transactionName );
00109         virtual bool GetAllActiveTransactions( std::vector<std::string>& );
00110         virtual bool IsCommittedTransaction( const std::string &transactionName );
00111         virtual bool GetAllCommittedTransactions( std::vector<std::string>& );
00112                                                                 
00113         // Debugging function
00114         bool DisplayView( const ViewName &viewName, FILE * );
00115 
00116 //#ifdef  ADDCACHE
00117         bool dump_collection();
00118         IndexFile ClassAdStorage;
00119         int  WriteCheckPoint();
00120         bool TruncateStorageFile();
00121 //#endif
00122 
00123 
00124 protected:
00125         virtual bool OperateInRecoveryMode( ClassAd * );
00126         virtual bool LogState( FILE * );
00127 
00128         friend class View;
00129         friend class ServerTransaction;
00130         friend class ClassAd;
00131         friend class LocalCollectionQuery;
00132 
00133 
00134         // low level execution modules
00135         bool PlayClassAdOp ( int, ClassAd * );
00136         bool PlayXactionOp ( int, const std::string &, ClassAd *, ServerTransaction *& );
00137         bool PlayViewOp ( int, ClassAd * );
00138 
00139         // View registry interface
00140         bool RegisterView( const ViewName &viewName, View * );
00141         bool UnregisterView( const ViewName &viewName );
00142 
00143         // Internal tables and associated state
00144         ViewRegistry    viewRegistry;
00145         ClassAdTable    classadTable;
00146         View                    viewTree;
00147         XactionTable    xactionTable;
00148 
00149         bool LogViews( FILE *log, View *view, bool subView );
00150         void Setup(bool CacheOn);
00151         bool Cache;
00152 //#ifdef  ADDCACHE
00153         bool ReplaceClassad(std::string &key);
00154         bool SetDirty(std::string key);
00155         bool ClearDirty(std::string key);
00156         bool CheckDirty(std::string key);
00157         bool GetStringClassAd(std::string key,std::string &WriteBackClassad);       
00158         bool SwitchInClassAd(std::string key);
00159         int  ReadStorageEntry(int sfiled, int &offset,std::string &ckey);        
00160         bool ReadCheckPointFile();
00161         int Max_Classad;
00162         int CheckPoint;      
00163         std::map<std::string,int> DirtyClassad;
00164         timeval LatestCheckpoint;
00165         std::string CheckFileName;
00166         int test_checkpoint;
00167 //#endif
00168 
00169 private:
00170         ClassAdCollection(const ClassAdCollection &collection) : viewTree(NULL) { return;       }
00171         ClassAdCollection &operator=(const ClassAdCollection &collection) { return *this; }
00172 };
00173 
00174 END_NAMESPACE
00175 
00176 #endif