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