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 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef Pegasus_InstanceDataFile_h
35 #define Pegasus_InstanceDataFile_h
36
37 #include <fstream>
38 #include <Pegasus/Common/Config.h>
39 #include <Pegasus/Common/String.h>
|
40 kumpf 1.5 #include <Pegasus/Common/InternalException.h>
|
41 kumpf 1.2 #include <Pegasus/Common/CIMObjectPath.h>
|
42 kumpf 1.4 #include <Pegasus/Repository/Linkage.h>
|
43 mike 1.10 #include <Pegasus/Common/Buffer.h>
|
44 mike 1.1
45 PEGASUS_NAMESPACE_BEGIN
46
47 /** This class manages access to an instance data file which contains all
48 instances of a particular class.
49
50 The instances are stored in ASCII XML format one after another. A separate
51 instance index file is maintained (see InstanceIndexFile) which contains
52 an index entry for each instance in the data file. This index ties the key
53 of the instance to an offset and size within the instance file.
54
55 The index file and data file are named according to the class whose
56 instances they contain information about. The index file and data file for
57 a class named "Zebra" would be:
58
59 <pre>
60 Zebra (index file).
61 Zebra.instances (instance-file).
62 </pre>
|
63 kumpf 1.12
64 When an instance is created, it is appended to the end of the instance
|
65 mike 1.1 file. When one is deleted, it is marked as free in the index file. When
66 an instance is modified, the old one is marked as deleted and the new
|
67 kumpf 1.12 modified instance is appended to the end of the data file. Note that
|
68 mike 1.1 deletion and modification may leave unused gaps in the data file. These
69 gaps are reclaimed during compaction (performed when the data file has
70 N gaps where N is some arbitrarily chosen number for now). Performing
71 compaction during each modify and delete would be extremely inefficient.
|
72 kumpf 1.12 By postponing it until N such operations have been performed, we
|
73 mike 1.1 improve performance considerably.
74
75 Note the three operations which may be performed on an instance and there
76 associated effect on the data file.
77
78 <ul>
79 <li>Create - appends an instance to the end of the file.</li>
80 <li>Modify - appends an instance to the end of the file.</li>
81 <li>Delete - has no effect on the data file</li>
82 </ul>
83
84 To avoid corruption of the data file we provide a rollback scheme. A
85 rollback file is created (the name is formed by appending ".rollback" to
86 the name of the data file) which contains the original size of the data
87 file. After the modification of the data file is complete, the rollback
88 file is removed. If we discover a rollback file when we start an operation,
89 this means that the last operation did not succeed. We then rollback the
90 operation by truncating the file to its old size.
91 */
92 class PEGASUS_REPOSITORY_LINKAGE InstanceDataFile
93 {
94 mike 1.1 public:
|
95 kumpf 1.12
|
96 mike 1.1 /** loads an instance from the data file into memory.
97
98 @param path the file path of the instance file
99 @param index the byte positon of the instance record
|
100 kumpf 1.12 @param size the size of the instance record
101 @param data the buffer to hold the instance data
|
102 mike 1.1 @return true on success.
103 */
104 static Boolean loadInstance(
|
105 kumpf 1.12 const String& path,
106 Uint32 index,
107 Uint32 size,
|
108 mike 1.10 Buffer& data);
|
109 kumpf 1.12
110 /** loads all the instances from the data file into memory.
|
111 mike 1.1
112 @param path the file path of the instance file
|
113 kumpf 1.12 @param data the buffer to hold the data
|
114 mike 1.1 @return true on success.
115 */
116 static Boolean loadAllInstances(
|
117 kumpf 1.12 const String& path,
|
118 mike 1.10 Buffer& data);
|
119 kumpf 1.12
|
120 mike 1.1 /** Appends a new instance to the end of the file.
|
121 kumpf 1.12
122 @param out the buffer containing the CIM/XML encoding of the
|
123 mike 1.1 @param path the file path of the instance file
124 @param index the byte positon of the instance record
125 @return true on success
126 */
127 static Boolean appendInstance(
|
128 kumpf 1.12 const String& path,
|
129 mike 1.10 const Buffer& data,
|
130 kumpf 1.12 Uint32& index);
|
131 mike 1.1
132 /** Begin a transaction to modify this file. The effect of subsequent
|
133 kumpf 1.12 modifications can be rolled back by calling rollbackTransaction().
|
134 mike 1.1 */
135 static Boolean beginTransaction(const String& path);
136
|
137 kumpf 1.12 /** Roll back any changes to the file since the last time
|
138 mike 1.1 beginTransaction() was called.
139 */
140 static Boolean rollbackTransaction(const String& path);
141
142 /** Commit changes made after beginTransaction() was called.
143 */
144 static Boolean commitTransaction(const String& path);
145
146 /** Reorganizes the data file to reclaim free space. This is done by
|
147 kumpf 1.12 copying over all non-free instances to a temporary file and then
148 deleting the original file and renaming the temporary file to the
149 same name as the original.
|
150 mike 1.1 */
151 static Boolean compact(
|
152 kumpf 1.12 const String& path,
|
153 mike 1.1 const Array<Uint32>& freeFlags,
154 const Array<Uint32>& indices,
155 const Array<Uint32>& sizes);
156
157 private:
158
159 static Boolean _openFile(
|
160 kumpf 1.12 PEGASUS_STD(fstream)& fs,
161 const String& path,
162 int mode);
|
163 mike 1.1 };
164
165 PEGASUS_NAMESPACE_END
166
167 #endif /* Pegasus_InstanceDataFile_h */
|