(file) Return to InstanceDataFile.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Repository

  1 karl  1.7 //%2004////////////////////////////////////////////////////////////////////////
  2 mike  1.1 //
  3 karl  1.7 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.6 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 mike  1.1 //
 10           // Permission is hereby granted, free of charge, to any person obtaining a copy
 11           // of this software and associated documentation files (the "Software"), to
 12           // deal in the Software without restriction, including without limitation the
 13           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14           // sell copies of the Software, and to permit persons to whom the Software is
 15           // furnished to do so, subject to the following conditions:
 16 kumpf 1.3 // 
 17 mike  1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25           //
 26           //==============================================================================
 27           //
 28           // Author: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
 29           //
 30           // Modified By: Michael E. Brasher (mbrasher@bmc.com)
 31 david.dillard 1.8 //              David Dillard, VERITAS Software Corp.
 32                   //                  (david.dillard@veritas.com)
 33 mike          1.1 //
 34                   //%/////////////////////////////////////////////////////////////////////////////
 35                   
 36                   #ifndef Pegasus_InstanceDataFile_h
 37                   #define Pegasus_InstanceDataFile_h
 38                   
 39                   #include <fstream>
 40                   #include <Pegasus/Common/Config.h>
 41                   #include <Pegasus/Common/String.h>
 42 kumpf         1.5 #include <Pegasus/Common/InternalException.h>
 43 kumpf         1.2 #include <Pegasus/Common/CIMObjectPath.h>
 44 kumpf         1.4 #include <Pegasus/Repository/Linkage.h>
 45 mike          1.1 
 46                   PEGASUS_NAMESPACE_BEGIN
 47                   
 48                   /** This class manages access to an instance data file which contains all
 49                       instances of a particular class.
 50                   
 51                       The instances are stored in ASCII XML format one after another. A separate
 52                       instance index file is maintained (see InstanceIndexFile) which contains
 53                       an index entry for each instance in the data file. This index ties the key
 54                       of the instance to an offset and size within the instance file.
 55                   
 56                       The index file and data file are named according to the class whose
 57                       instances they contain information about. The index file and data file for
 58                       a class named "Zebra" would be:
 59                   
 60                       <pre>
 61                           Zebra (index file).
 62                           Zebra.instances (instance-file).
 63                       </pre>
 64                     
 65                       When an instance is created, it is appended to the end of the instance 
 66 mike          1.1     file. When one is deleted, it is marked as free in the index file. When
 67                       an instance is modified, the old one is marked as deleted and the new
 68                       modified instance is appended to the end of the data file. Note that 
 69                       deletion and modification may leave unused gaps in the data file. These
 70                       gaps are reclaimed during compaction (performed when the data file has
 71                       N gaps where N is some arbitrarily chosen number for now). Performing
 72                       compaction during each modify and delete would be extremely inefficient.
 73                       By postponing it until N such operations have been performed, we 
 74                       improve performance considerably.
 75                   
 76                       Note the three operations which may be performed on an instance and there
 77                       associated effect on the data file.
 78                   
 79                       <ul>
 80                       <li>Create - appends an instance to the end of the file.</li>
 81                       <li>Modify - appends an instance to the end of the file.</li>
 82                       <li>Delete - has no effect on the data file</li>
 83                       </ul>
 84                   
 85                       To avoid corruption of the data file we provide a rollback scheme. A
 86                       rollback file is created (the name is formed by appending ".rollback" to
 87 mike          1.1     the name of the data file) which contains the original size of the data
 88                       file. After the modification of the data file is complete, the rollback
 89                       file is removed. If we discover a rollback file when we start an operation,
 90                       this means that the last operation did not succeed. We then rollback the
 91                       operation by truncating the file to its old size.
 92                   */
 93                   class PEGASUS_REPOSITORY_LINKAGE InstanceDataFile
 94                   {
 95                   public:
 96                       
 97                       /** loads an instance from the data file into memory.
 98                   
 99                           @param path the file path of the instance file
100                           @param index the byte positon of the instance record
101                           @param size the size of the instance record 
102                           @param data the buffer to hold the instance data 
103                           @return true on success.
104                       */
105                       static Boolean loadInstance(
106                   	const String& path, 
107                   	Uint32 index,
108 mike          1.1 	Uint32 size,  
109 david.dillard 1.8         Array<char>& data);
110 mike          1.1     
111                       /** loads all the instances from the data file into memory. 
112                   
113                           @param path the file path of the instance file
114                           @param data the buffer to hold the data 
115                           @return true on success.
116                       */
117                       static Boolean loadAllInstances(
118                   	const String& path, 
119 david.dillard 1.8         Array<char>& data);
120 mike          1.1     
121                       /** Appends a new instance to the end of the file.
122                        
123                           @param out the buffer containing the CIM/XML encoding of the 
124                           @param path the file path of the instance file
125                           @param index the byte positon of the instance record
126                           @return true on success
127                       */
128                       static Boolean appendInstance(
129                   	const String& path, 
130 david.dillard 1.8         const Array<char>& data,
131 mike          1.1 	Uint32& index);
132                   
133                       /** Begin a transaction to modify this file. The effect of subsequent
134                   	modifications can be rolled back by calling rollbackTransaction().
135                       */
136                       static Boolean beginTransaction(const String& path);
137                   
138                       /** Roll back any changes to the file since the last time 
139                           beginTransaction() was called.
140                       */
141                       static Boolean rollbackTransaction(const String& path);
142                   
143                       /** Commit changes made after beginTransaction() was called.
144                       */
145                       static Boolean commitTransaction(const String& path);
146                   
147                       /** Reorganizes the data file to reclaim free space. This is done by
148                   	copying over all non-free instances to a temporary file and then
149                   	deleting the original file and renaming the temporary file to the
150                   	same name as the original.
151                       */
152 mike          1.1     static Boolean compact(
153                   	const String& path,
154                           const Array<Uint32>& freeFlags,
155                           const Array<Uint32>& indices,
156                           const Array<Uint32>& sizes);
157                   
158                   private:
159                   
160                       static Boolean _openFile(
161                   	PEGASUS_STD(fstream)& fs,
162                   	const String& path,
163                   	int mode);
164                   };
165                   
166                   PEGASUS_NAMESPACE_END
167                   
168                   #endif /* Pegasus_InstanceDataFile_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2