aboutsummaryrefslogtreecommitdiffstats
path: root/subversion/include/private/svn_fs_fs_private.h
blob: d2573d447c9d02dce5533f59ec8f65b8a48396e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/**
 * @copyright
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 * @endcopyright
 *
 * @file svn_fs_fs_private.h
 * @brief Private API for tools that access FSFS internals and can't use
 *        the svn_fs_t API for that.
 */


#ifndef SVN_FS_FS_PRIVATE_H
#define SVN_FS_FS_PRIVATE_H

#include <apr_pools.h>
#include <apr_hash.h>

#include "svn_types.h"
#include "svn_error.h"
#include "svn_fs.h"
#include "svn_iter.h"
#include "svn_config.h"
#include "svn_string.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */



/* Description of one large representation.  It's content will be reused /
 * overwritten when it gets replaced by an even larger representation.
 */
typedef struct svn_fs_fs__large_change_info_t
{
  /* size of the (deltified) representation */
  apr_uint64_t size;

  /* Revision of the representation. SVN_INVALID_REVNUM for unused entries.
   */
  svn_revnum_t revision;

  /* node path. "" for unused instances */
  svn_stringbuf_t *path;
} svn_fs_fs__large_change_info_t;

/* Container for the largest representations found so far.  The capacity
 * is fixed and entries will be inserted by reusing the last one and
 * reshuffling the entry pointers.
 */
typedef struct svn_fs_fs__largest_changes_t
{
  /* number of entries allocated in CHANGES */
  apr_size_t count;

  /* size of the smallest change */
  apr_uint64_t min_size;

  /* changes kept in this struct */
  svn_fs_fs__large_change_info_t **changes;
} svn_fs_fs__largest_changes_t;

/* Information we gather per size bracket.
 */
typedef struct svn_fs_fs__histogram_line_t
{
  /* number of item that fall into this bracket */
  apr_uint64_t count;

  /* sum of values in this bracket */
  apr_uint64_t sum;
} svn_fs_fs__histogram_line_t;

/* A histogram of 64 bit integer values.
 */
typedef struct svn_fs_fs__histogram_t
{
  /* total sum over all brackets */
  svn_fs_fs__histogram_line_t total;

  /* one bracket per binary step.
   * line[i] is the 2^(i-1) <= x < 2^i bracket */
  svn_fs_fs__histogram_line_t lines[64];
} svn_fs_fs__histogram_t;

/* Information we collect per file ending.
 */
typedef struct svn_fs_fs__extension_info_t
{
  /* file extension, including leading "."
   * "(none)" in the container for files w/o extension. */
  const char *extension;

  /* histogram of representation sizes */
  svn_fs_fs__histogram_t rep_histogram;

  /* histogram of sizes of changed files */
  svn_fs_fs__histogram_t node_histogram;
} svn_fs_fs__extension_info_t;

/* Compression statistics we collect over a given set of representations.
 */
typedef struct svn_fs_fs__rep_pack_stats_t
{
  /* number of representations */
  apr_uint64_t count;

  /* total size after deltification (i.e. on disk size) */
  apr_uint64_t packed_size;

  /* total size after de-deltification (i.e. plain text size) */
  apr_uint64_t expanded_size;

  /* total on-disk header size */
  apr_uint64_t overhead_size;
} svn_fs_fs__rep_pack_stats_t;

/* Statistics we collect over a given set of representations.
 * We group them into shared and non-shared ("unique") reps.
 */
typedef struct svn_fs_fs__representation_stats_t
{
  /* stats over all representations */
  svn_fs_fs__rep_pack_stats_t total;

  /* stats over those representations with ref_count == 1 */
  svn_fs_fs__rep_pack_stats_t uniques;

  /* stats over those representations with ref_count > 1 */
  svn_fs_fs__rep_pack_stats_t shared;

  /* sum of all ref_counts */
  apr_uint64_t references;

  /* sum of ref_count * expanded_size,
   * i.e. total plaintext content if there was no rep sharing */
  apr_uint64_t expanded_size;

  /* sum of all representation delta chain lengths */
  apr_uint64_t chain_len;
} svn_fs_fs__representation_stats_t;

/* Basic statistics we collect over a given set of noderevs.
 */
typedef struct svn_fs_fs__node_stats_t
{
  /* number of noderev structs */
  apr_uint64_t count;

  /* their total size on disk (structs only) */
  apr_uint64_t size;
} svn_fs_fs__node_stats_t;

/* Comprises all the information needed to create the output of the
 * 'svnfsfs stats' command.
 */
typedef struct svn_fs_fs__stats_t
{
  /* sum total of all rev / pack file sizes in bytes */
  apr_uint64_t total_size;

  /* number of revisions in the repository */
  apr_uint64_t revision_count;

  /* total number of changed paths */
  apr_uint64_t change_count;

  /* sum of all changed path list sizes on disk in bytes */
  apr_uint64_t change_len;

  /* stats on all representations */
  svn_fs_fs__representation_stats_t total_rep_stats;

  /* stats on all file text representations */
  svn_fs_fs__representation_stats_t file_rep_stats;

  /* stats on all directory text representations */
  svn_fs_fs__representation_stats_t dir_rep_stats;

  /* stats on all file prop representations */
  svn_fs_fs__representation_stats_t file_prop_rep_stats;

  /* stats on all directory prop representations */
  svn_fs_fs__representation_stats_t dir_prop_rep_stats;

  /* size and count summary over all noderevs */
  svn_fs_fs__node_stats_t total_node_stats;

  /* size and count summary over all file noderevs */
  svn_fs_fs__node_stats_t file_node_stats;

  /* size and count summary over all directory noderevs */
  svn_fs_fs__node_stats_t dir_node_stats;

  /* the biggest single contributors to repo size */
  svn_fs_fs__largest_changes_t *largest_changes;

  /* histogram of representation sizes */
  svn_fs_fs__histogram_t rep_size_histogram;

  /* histogram of sizes of changed nodes */
  svn_fs_fs__histogram_t node_size_histogram;

  /* histogram of representation sizes */
  svn_fs_fs__histogram_t added_rep_size_histogram;

  /* histogram of sizes of changed nodes */
  svn_fs_fs__histogram_t added_node_size_histogram;

  /* histogram of unused representations */
  svn_fs_fs__histogram_t unused_rep_histogram;

  /* histogram of sizes of changed files */
  svn_fs_fs__histogram_t file_histogram;

  /* histogram of sizes of file representations */
  svn_fs_fs__histogram_t file_rep_histogram;

  /* histogram of sizes of changed file property sets */
  svn_fs_fs__histogram_t file_prop_histogram;

  /* histogram of sizes of file property representations */
  svn_fs_fs__histogram_t file_prop_rep_histogram;

  /* histogram of sizes of changed directories (in bytes) */
  svn_fs_fs__histogram_t dir_histogram;

  /* histogram of sizes of directories representations */
  svn_fs_fs__histogram_t dir_rep_histogram;

  /* histogram of sizes of changed directories property sets */
  svn_fs_fs__histogram_t dir_prop_histogram;

  /* histogram of sizes of directories property representations */
  svn_fs_fs__histogram_t dir_prop_rep_histogram;

  /* extension -> svn_fs_fs__extension_info_t* map */
  apr_hash_t *by_extension;
} svn_fs_fs__stats_t;


/* Scan all contents of the repository FS and return statistics in *STATS,
 * allocated in RESULT_POOL.  Report progress through PROGRESS_FUNC with
 * PROGRESS_BATON, if PROGRESS_FUNC is not NULL.
 * Use SCRATCH_POOL for temporary allocations.
 */
svn_error_t *
svn_fs_fs__get_stats(svn_fs_fs__stats_t **stats,
                     svn_fs_t *fs,
                     svn_fs_progress_notify_func_t progress_func,
                     void *progress_baton,
                     svn_cancel_func_t cancel_func,
                     void *cancel_baton,
                     apr_pool_t *result_pool,
                     apr_pool_t *scratch_pool);

/* A node-revision ID in FSFS consists of 3 sub-IDs ("parts") that consist
 * of a creation REVISION number and some revision- / transaction-local
 * counter value (NUMBER).  Old-style ID parts use global counter values.
 *
 * The parts are: node_id, copy_id and txn_id for in-txn IDs as well as
 * node_id, copy_id and rev_item for in-revision IDs.  This struct is the
 * data structure used for each of those parts.
 */
typedef struct svn_fs_fs__id_part_t
{
  /* SVN_INVALID_REVNUM for txn_id part -> not a txn, NUMBER must be 0.
     SVN_INVALID_REVNUM for other parts -> not assigned to a revision, yet.
     0                  for other parts -> old-style ID or the root in rev 0.
   */
  svn_revnum_t revision;

  /* sub-id value relative to REVISION.  Its interpretation depends on
     the part itself.  In rev_item, it is the index_index value, in others
     it represents a unique counter value. */
  apr_uint64_t number;
} svn_fs_fs__id_part_t;

/* (user visible) entry in the phys-to-log index.  It describes a section
 * of some packed / non-packed rev file as containing a specific item.
 * There must be no overlapping / conflicting entries.
 */
typedef struct svn_fs_fs__p2l_entry_t
{
  /* offset of the first byte that belongs to the item */
  apr_off_t offset;

  /* length of the item in bytes */
  apr_off_t size;

  /* type of the item (see SVN_FS_FS__ITEM_TYPE_*) defines */
  apr_uint32_t type;

  /* modified FNV-1a checksum.  0 if unknown checksum */
  apr_uint32_t fnv1_checksum;

  /* item in that block */
  svn_fs_fs__id_part_t item;
} svn_fs_fs__p2l_entry_t;


/* Callback function type receiving a single P2L index ENTRY, a user
 * provided BATON and a SCRATCH_POOL for temporary allocations.
 * ENTRY's lifetime may end when the callback returns.
 */
typedef svn_error_t *
(*svn_fs_fs__dump_index_func_t)(const svn_fs_fs__p2l_entry_t *entry,
                                void *baton,
                                apr_pool_t *scratch_pool);

/* Read the P2L index for the rev / pack file containing REVISION in FS.
 * For each index entry, invoke CALLBACK_FUNC with CALLBACK_BATON.
 * If not NULL, call CANCEL_FUNC with CANCEL_BATON from time to time.
 * Use SCRATCH_POOL for temporary allocations.
 */
svn_error_t *
svn_fs_fs__dump_index(svn_fs_t *fs,
                      svn_revnum_t revision,
                      svn_fs_fs__dump_index_func_t callback_func,
                      void *callback_baton,
                      svn_cancel_func_t cancel_func,
                      void *cancel_baton,
                      apr_pool_t *scratch_pool);


/* Rewrite the respective index information of the rev / pack file in FS
 * containing REVISION and use the svn_fs_fs__p2l_entry_t * array ENTRIES
 * as the new index contents.  Allocate temporaries from SCRATCH_POOL.
 *
 * Note that this becomes a no-op if ENTRIES is empty.  You may use a zero-
 * sized empty entry instead.
 */
svn_error_t *
svn_fs_fs__load_index(svn_fs_t *fs,
                      svn_revnum_t revision,
                      apr_array_header_t *entries,
                      apr_pool_t *scratch_pool);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* SVN_FS_FS_PRIVATE_H */