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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2