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