1 /**
2  * @copyright
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file svn_fs_fs_private.h
24  * @brief Private API for tools that access FSFS internals and can't use
25  *        the svn_fs_t API for that.
26  */
27 
28 
29 #ifndef SVN_FS_FS_PRIVATE_H
30 #define SVN_FS_FS_PRIVATE_H
31 
32 #include <apr_pools.h>
33 #include <apr_hash.h>
34 
35 #include "svn_types.h"
36 #include "svn_error.h"
37 #include "svn_fs.h"
38 #include "svn_iter.h"
39 #include "svn_config.h"
40 #include "svn_string.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif /* __cplusplus */
45 
46 
47 
48 /* Description of one large representation.  It's content will be reused /
49  * overwritten when it gets replaced by an even larger representation.
50  */
51 typedef struct svn_fs_fs__large_change_info_t
52 {
53   /* size of the (deltified) representation */
54   apr_uint64_t size;
55 
56   /* Revision of the representation. SVN_INVALID_REVNUM for unused entries.
57    */
58   svn_revnum_t revision;
59 
60   /* node path. "" for unused instances */
61   svn_stringbuf_t *path;
62 } svn_fs_fs__large_change_info_t;
63 
64 /* Container for the largest representations found so far.  The capacity
65  * is fixed and entries will be inserted by reusing the last one and
66  * reshuffling the entry pointers.
67  */
68 typedef struct svn_fs_fs__largest_changes_t
69 {
70   /* number of entries allocated in CHANGES */
71   apr_size_t count;
72 
73   /* size of the smallest change */
74   apr_uint64_t min_size;
75 
76   /* changes kept in this struct */
77   svn_fs_fs__large_change_info_t **changes;
78 } svn_fs_fs__largest_changes_t;
79 
80 /* Information we gather per size bracket.
81  */
82 typedef struct svn_fs_fs__histogram_line_t
83 {
84   /* number of item that fall into this bracket */
85   apr_uint64_t count;
86 
87   /* sum of values in this bracket */
88   apr_uint64_t sum;
89 } svn_fs_fs__histogram_line_t;
90 
91 /* A histogram of 64 bit integer values.
92  */
93 typedef struct svn_fs_fs__histogram_t
94 {
95   /* total sum over all brackets */
96   svn_fs_fs__histogram_line_t total;
97 
98   /* one bracket per binary step.
99    * line[i] is the 2^(i-1) <= x < 2^i bracket */
100   svn_fs_fs__histogram_line_t lines[64];
101 } svn_fs_fs__histogram_t;
102 
103 /* Information we collect per file ending.
104  */
105 typedef struct svn_fs_fs__extension_info_t
106 {
107   /* file extension, including leading "."
108    * "(none)" in the container for files w/o extension. */
109   const char *extension;
110 
111   /* histogram of representation sizes */
112   svn_fs_fs__histogram_t rep_histogram;
113 
114   /* histogram of sizes of changed files */
115   svn_fs_fs__histogram_t node_histogram;
116 } svn_fs_fs__extension_info_t;
117 
118 /* Compression statistics we collect over a given set of representations.
119  */
120 typedef struct svn_fs_fs__rep_pack_stats_t
121 {
122   /* number of representations */
123   apr_uint64_t count;
124 
125   /* total size after deltification (i.e. on disk size) */
126   apr_uint64_t packed_size;
127 
128   /* total size after de-deltification (i.e. plain text size) */
129   apr_uint64_t expanded_size;
130 
131   /* total on-disk header size */
132   apr_uint64_t overhead_size;
133 } svn_fs_fs__rep_pack_stats_t;
134 
135 /* Statistics we collect over a given set of representations.
136  * We group them into shared and non-shared ("unique") reps.
137  */
138 typedef struct svn_fs_fs__representation_stats_t
139 {
140   /* stats over all representations */
141   svn_fs_fs__rep_pack_stats_t total;
142 
143   /* stats over those representations with ref_count == 1 */
144   svn_fs_fs__rep_pack_stats_t uniques;
145 
146   /* stats over those representations with ref_count > 1 */
147   svn_fs_fs__rep_pack_stats_t shared;
148 
149   /* sum of all ref_counts */
150   apr_uint64_t references;
151 
152   /* sum of ref_count * expanded_size,
153    * i.e. total plaintext content if there was no rep sharing */
154   apr_uint64_t expanded_size;
155 
156   /* sum of all representation delta chain lengths */
157   apr_uint64_t chain_len;
158 } svn_fs_fs__representation_stats_t;
159 
160 /* Basic statistics we collect over a given set of noderevs.
161  */
162 typedef struct svn_fs_fs__node_stats_t
163 {
164   /* number of noderev structs */
165   apr_uint64_t count;
166 
167   /* their total size on disk (structs only) */
168   apr_uint64_t size;
169 } svn_fs_fs__node_stats_t;
170 
171 /* Comprises all the information needed to create the output of the
172  * 'svnfsfs stats' command.
173  */
174 typedef struct svn_fs_fs__stats_t
175 {
176   /* sum total of all rev / pack file sizes in bytes */
177   apr_uint64_t total_size;
178 
179   /* number of revisions in the repository */
180   apr_uint64_t revision_count;
181 
182   /* total number of changed paths */
183   apr_uint64_t change_count;
184 
185   /* sum of all changed path list sizes on disk in bytes */
186   apr_uint64_t change_len;
187 
188   /* stats on all representations */
189   svn_fs_fs__representation_stats_t total_rep_stats;
190 
191   /* stats on all file text representations */
192   svn_fs_fs__representation_stats_t file_rep_stats;
193 
194   /* stats on all directory text representations */
195   svn_fs_fs__representation_stats_t dir_rep_stats;
196 
197   /* stats on all file prop representations */
198   svn_fs_fs__representation_stats_t file_prop_rep_stats;
199 
200   /* stats on all directory prop representations */
201   svn_fs_fs__representation_stats_t dir_prop_rep_stats;
202 
203   /* size and count summary over all noderevs */
204   svn_fs_fs__node_stats_t total_node_stats;
205 
206   /* size and count summary over all file noderevs */
207   svn_fs_fs__node_stats_t file_node_stats;
208 
209   /* size and count summary over all directory noderevs */
210   svn_fs_fs__node_stats_t dir_node_stats;
211 
212   /* the biggest single contributors to repo size */
213   svn_fs_fs__largest_changes_t *largest_changes;
214 
215   /* histogram of representation sizes */
216   svn_fs_fs__histogram_t rep_size_histogram;
217 
218   /* histogram of sizes of changed nodes */
219   svn_fs_fs__histogram_t node_size_histogram;
220 
221   /* histogram of representation sizes */
222   svn_fs_fs__histogram_t added_rep_size_histogram;
223 
224   /* histogram of sizes of changed nodes */
225   svn_fs_fs__histogram_t added_node_size_histogram;
226 
227   /* histogram of unused representations */
228   svn_fs_fs__histogram_t unused_rep_histogram;
229 
230   /* histogram of sizes of changed files */
231   svn_fs_fs__histogram_t file_histogram;
232 
233   /* histogram of sizes of file representations */
234   svn_fs_fs__histogram_t file_rep_histogram;
235 
236   /* histogram of sizes of changed file property sets */
237   svn_fs_fs__histogram_t file_prop_histogram;
238 
239   /* histogram of sizes of file property representations */
240   svn_fs_fs__histogram_t file_prop_rep_histogram;
241 
242   /* histogram of sizes of changed directories (in bytes) */
243   svn_fs_fs__histogram_t dir_histogram;
244 
245   /* histogram of sizes of directories representations */
246   svn_fs_fs__histogram_t dir_rep_histogram;
247 
248   /* histogram of sizes of changed directories property sets */
249   svn_fs_fs__histogram_t dir_prop_histogram;
250 
251   /* histogram of sizes of directories property representations */
252   svn_fs_fs__histogram_t dir_prop_rep_histogram;
253 
254   /* extension -> svn_fs_fs__extension_info_t* map */
255   apr_hash_t *by_extension;
256 } svn_fs_fs__stats_t;
257 
258 /* A node-revision ID in FSFS consists of 3 sub-IDs ("parts") that consist
259  * of a creation REVISION number and some revision- / transaction-local
260  * counter value (NUMBER).  Old-style ID parts use global counter values.
261  *
262  * The parts are: node_id, copy_id and txn_id for in-txn IDs as well as
263  * node_id, copy_id and rev_item for in-revision IDs.  This struct is the
264  * data structure used for each of those parts.
265  */
266 typedef struct svn_fs_fs__id_part_t
267 {
268   /* SVN_INVALID_REVNUM for txn_id part -> not a txn, NUMBER must be 0.
269      SVN_INVALID_REVNUM for other parts -> not assigned to a revision, yet.
270      0                  for other parts -> old-style ID or the root in rev 0.
271    */
272   svn_revnum_t revision;
273 
274   /* sub-id value relative to REVISION.  Its interpretation depends on
275      the part itself.  In rev_item, it is the index_index value, in others
276      it represents a unique counter value. */
277   apr_uint64_t number;
278 } svn_fs_fs__id_part_t;
279 
280 /* (user visible) entry in the phys-to-log index.  It describes a section
281  * of some packed / non-packed rev file as containing a specific item.
282  * There must be no overlapping / conflicting entries.
283  */
284 typedef struct svn_fs_fs__p2l_entry_t
285 {
286   /* offset of the first byte that belongs to the item */
287   apr_off_t offset;
288 
289   /* length of the item in bytes */
290   apr_off_t size;
291 
292   /* type of the item (see SVN_FS_FS__ITEM_TYPE_*) defines */
293   apr_uint32_t type;
294 
295   /* modified FNV-1a checksum.  0 if unknown checksum */
296   apr_uint32_t fnv1_checksum;
297 
298   /* item in that block */
299   svn_fs_fs__id_part_t item;
300 } svn_fs_fs__p2l_entry_t;
301 
302 
303 /* Callback function type receiving a single P2L index ENTRY, a user
304  * provided BATON and a SCRATCH_POOL for temporary allocations.
305  * ENTRY's lifetime may end when the callback returns.
306  */
307 typedef svn_error_t *
308 (*svn_fs_fs__dump_index_func_t)(const svn_fs_fs__p2l_entry_t *entry,
309                                 void *baton,
310                                 apr_pool_t *scratch_pool);
311 
312 typedef struct svn_fs_fs__ioctl_get_stats_input_t
313 {
314   svn_fs_progress_notify_func_t progress_func;
315   void *progress_baton;
316 } svn_fs_fs__ioctl_get_stats_input_t;
317 
318 typedef struct svn_fs_fs__ioctl_get_stats_output_t
319 {
320   svn_fs_fs__stats_t *stats;
321 } svn_fs_fs__ioctl_get_stats_output_t;
322 
323 SVN_FS_DECLARE_IOCTL_CODE(SVN_FS_FS__IOCTL_GET_STATS, SVN_FS_TYPE_FSFS, 1000);
324 
325 typedef struct svn_fs_fs__ioctl_dump_index_input_t
326 {
327   svn_revnum_t revision;
328   svn_fs_fs__dump_index_func_t callback_func;
329   void *callback_baton;
330 } svn_fs_fs__ioctl_dump_index_input_t;
331 
332 SVN_FS_DECLARE_IOCTL_CODE(SVN_FS_FS__IOCTL_DUMP_INDEX, SVN_FS_TYPE_FSFS, 1001);
333 
334 typedef struct svn_fs_fs__ioctl_load_index_input_t
335 {
336   svn_revnum_t revision;
337   /* Array of svn_fs_fs__p2l_entry_t * entries. */
338   apr_array_header_t *entries;
339 } svn_fs_fs__ioctl_load_index_input_t;
340 
341 SVN_FS_DECLARE_IOCTL_CODE(SVN_FS_FS__IOCTL_LOAD_INDEX, SVN_FS_TYPE_FSFS, 1002);
342 
343 typedef struct svn_fs_fs__ioctl_revision_size_input_t
344 {
345   svn_revnum_t revision;
346 } svn_fs_fs__ioctl_revision_size_input_t;
347 
348 typedef struct svn_fs_fs__ioctl_revision_size_output_t
349 {
350   apr_off_t rev_size;
351 } svn_fs_fs__ioctl_revision_size_output_t;
352 
353 /* See svn_fs_fs__revision_size(). */
354 SVN_FS_DECLARE_IOCTL_CODE(SVN_FS_FS__IOCTL_REVISION_SIZE, SVN_FS_TYPE_FSFS, 1003);
355 
356 typedef struct svn_fs_fs__ioctl_build_rep_cache_input_t
357 {
358   svn_revnum_t start_rev;
359   svn_revnum_t end_rev;
360   svn_fs_progress_notify_func_t progress_func;
361   void *progress_baton;
362 } svn_fs_fs__ioctl_build_rep_cache_input_t;
363 
364 /* See svn_fs_fs__build_rep_cache(). */
365 SVN_FS_DECLARE_IOCTL_CODE(SVN_FS_FS__IOCTL_BUILD_REP_CACHE, SVN_FS_TYPE_FSFS, 1004);
366 
367 #ifdef __cplusplus
368 }
369 #endif /* __cplusplus */
370 
371 #endif /* SVN_FS_FS_PRIVATE_H */
372