1 /* fs.h : interface to Subversion filesystem, private to libsvn_fs
3 * ====================================================================
4 * Copyright (c) 2000-2007 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
18 #ifndef SVN_LIBSVN_FS_FS_H
19 #define SVN_LIBSVN_FS_FS_H
21 #include <apr_pools.h>
24 #include <apr_thread_mutex.h>
25 #include <apr_network_io.h>
28 #include "private/svn_fs_private.h"
32 #endif /* __cplusplus */
35 /*** The filesystem structure. ***/
37 /* Following are defines that specify the textual elements of the
38 native filesystem directories and revision files. */
40 /* Names of special files in the fs_fs filesystem. */
41 #define PATH_FORMAT "format" /* Contains format number */
42 #define PATH_UUID "uuid" /* Contains UUID */
43 #define PATH_CURRENT "current" /* Youngest revision */
44 #define PATH_LOCK_FILE "write-lock" /* Revision lock file */
45 #define PATH_REVS_DIR "revs" /* Directory of revisions */
46 #define PATH_REVPROPS_DIR "revprops" /* Directory of revprops */
47 #define PATH_TXNS_DIR "transactions" /* Directory of transactions */
48 #define PATH_NODE_ORIGINS_DIR "node-origins" /* Lazy node-origin cache */
49 #define PATH_TXN_PROTOS_DIR "txn-protorevs" /* Directory of proto-revs */
50 #define PATH_TXN_CURRENT "txn-current" /* File with next txn key */
51 #define PATH_TXN_CURRENT_LOCK "txn-current-lock" /* Lock for txn-current */
52 #define PATH_LOCKS_DIR "locks" /* Directory of locks */
54 /* Names of special files and file extensions for transactions */
55 #define PATH_CHANGES "changes" /* Records changes made so far */
56 #define PATH_TXN_PROPS "props" /* Transaction properties */
57 #define PATH_NEXT_IDS "next-ids" /* Next temporary ID assignments */
58 #define PATH_TXN_MERGEINFO "mergeinfo" /* Transaction mergeinfo props */
59 #define PATH_PREFIX_NODE "node." /* Prefix for node filename */
60 #define PATH_EXT_TXN ".txn" /* Extension of txn dir */
61 #define PATH_EXT_CHILDREN ".children" /* Extension for dir contents */
62 #define PATH_EXT_PROPS ".props" /* Extension for node props */
63 #define PATH_EXT_REV ".rev" /* Extension of protorev file */
64 #define PATH_EXT_REV_LOCK ".rev-lock" /* Extension of protorev lock file */
65 /* Names of files in legacy FS formats */
66 #define PATH_REV "rev" /* Proto rev file */
67 #define PATH_REV_LOCK "rev-lock" /* Proto rev (write) lock file */
69 /* The format number of this filesystem.
70 This is independent of the repository format number, and
71 independent of any other FS back ends. */
72 #define SVN_FS_FS__FORMAT_NUMBER 3
74 /* The minimum format number that supports svndiff version 1. */
75 #define SVN_FS_FS__MIN_SVNDIFF1_FORMAT 2
77 /* The minimum format number that supports transaction ID generation
78 using a transaction sequence in the txn-current file. */
79 #define SVN_FS_FS__MIN_TXN_CURRENT_FORMAT 3
81 /* The minimum format number that supports the "layout" filesystem
83 #define SVN_FS_FS__MIN_LAYOUT_FORMAT_OPTION_FORMAT 3
85 /* The minimum format number that stores protorevs in a separate directory. */
86 #define SVN_FS_FS__MIN_PROTOREVS_DIR_FORMAT 3
88 /* Maximum number of directories to cache dirents for.
89 This *must* be a power of 2 for DIR_CACHE_ENTRIES_MASK
91 #define NUM_DIR_CACHE_ENTRIES 128
92 #define DIR_CACHE_ENTRIES_MASK(x) ((x) & (NUM_DIR_CACHE_ENTRIES - 1))
94 /* Maximum number of revroot ids to cache dirents for at a time. */
95 #define NUM_RRI_CACHE_ENTRIES 4096
97 /* Private FSFS-specific data shared between all svn_txn_t objects that
98 relate to a particular transaction in a filesystem (as identified
99 by transaction id and filesystem UUID). Objects of this type are
100 allocated in their own subpool of the common pool. */
101 struct fs_fs_shared_txn_data_t
;
102 typedef struct fs_fs_shared_txn_data_t
104 /* The next transaction in the list, or NULL if there is no following
106 struct fs_fs_shared_txn_data_t
*next
;
108 /* This transaction's ID. For repositories whose format is less
109 than SVN_FS_FS__MIN_TXN_CURRENT_FORMAT, the ID is in the form
110 <rev>-<uniqueifier>, where <uniqueifier> runs from 0-99999 (see
111 create_txn_dir_pre_1_5() in fs_fs.c). For newer repositories,
112 the form is <rev>-<200 digit base 36 number> (see
113 create_txn_dir() in fs_fs.c). */
114 char txn_id
[SVN_FS__TXN_MAX_LEN
+1];
116 /* Whether the transaction's prototype revision file is locked for
117 writing by any thread in this process (including the current
118 thread; recursive locks are not permitted). This is effectively
119 a non-recursive mutex. */
120 svn_boolean_t being_written
;
122 /* The pool in which this object has been allocated; a subpool of the
125 } fs_fs_shared_txn_data_t
;
128 /* Private FSFS-specific data shared between all svn_fs_t objects that
129 relate to a particular filesystem, as identified by filesystem UUID.
130 Objects of this type are allocated in the common pool. */
133 /* A list of shared transaction objects for each transaction that is
134 currently active, or NULL if none are. All access to this list,
135 including the contents of the objects stored in it, is synchronised
136 under TXN_LIST_LOCK. */
137 fs_fs_shared_txn_data_t
*txns
;
139 /* A free transaction object, or NULL if there is no free object.
140 Access to this object is synchronised under TXN_LIST_LOCK. */
141 fs_fs_shared_txn_data_t
*free_txn
;
144 /* A lock for intra-process synchronization when accessing the TXNS list. */
145 apr_thread_mutex_t
*txn_list_lock
;
147 /* A lock for intra-process synchronization when grabbing the
148 repository write lock. */
149 apr_thread_mutex_t
*fs_write_lock
;
151 /* A lock for intra-process synchronization when locking the
153 apr_thread_mutex_t
*txn_current_lock
;
156 /* The common pool, under which this object is allocated, subpools
157 of which are used to allocate the transaction objects. */
158 apr_pool_t
*common_pool
;
159 } fs_fs_shared_data_t
;
161 typedef struct dag_node_t dag_node_t
;
163 /* Structure for DAG-node cache. Cache items are arranged in a
164 circular LRU list with a dummy entry, and also indexed with a hash
165 table. Transaction nodes are cached within the individual txn
166 roots; revision nodes are cached together within the FS object. */
167 typedef struct dag_node_cache_t
169 const char *key
; /* Lookup key for cached node: path
170 for txns; rev catenated with path
172 dag_node_t
*node
; /* Cached node */
173 struct dag_node_cache_t
*prev
; /* Next node in LRU list */
174 struct dag_node_cache_t
*next
; /* Previous node in LRU list */
175 apr_pool_t
*pool
; /* Pool in which node is allocated */
179 /* Private (non-shared) FSFS-specific data for each svn_fs_t object. */
182 /* A cache of the last directory opened within the filesystem. */
183 svn_fs_id_t
*dir_cache_id
[NUM_DIR_CACHE_ENTRIES
];
184 apr_hash_t
*dir_cache
[NUM_DIR_CACHE_ENTRIES
];
185 apr_pool_t
*dir_cache_pool
[NUM_DIR_CACHE_ENTRIES
];
187 /* The format number of this FS. */
189 /* The maximum number of files to store per directory (for sharded
190 layouts) or zero (for linear layouts). */
191 int max_files_per_dir
;
193 /* The uuid of this FS. */
196 /* The revision that was youngest, last time we checked. */
197 svn_revnum_t youngest_rev_cache
;
199 /* Caches of immutable data.
201 Both of these could be moved to fs_fs_shared_data_t to make them
202 last longer; on the other hand, this would require adding mutexes
206 /* A cache of revision root IDs, allocated in this subpool. (IDs
207 are so small that one pool per ID would be overkill;
208 unfortunately, this means the only way we expire cache entries is
209 by wiping the whole cache.) */
210 apr_hash_t
*rev_root_id_cache
;
211 apr_pool_t
*rev_root_id_cache_pool
;
213 /* DAG node cache for immutable nodes */
214 dag_node_cache_t rev_node_list
;
215 apr_hash_t
*rev_node_cache
;
217 /* Data shared between all svn_fs_t objects for a given filesystem. */
218 fs_fs_shared_data_t
*shared
;
222 /*** Filesystem Transaction ***/
225 /* property list (const char * name, svn_string_t * value).
226 may be NULL if there are no properties. */
227 apr_hash_t
*proplist
;
229 /* node revision id of the root node. */
230 const svn_fs_id_t
*root_id
;
232 /* node revision id of the node which is the root of the revision
233 upon which this txn is base. (unfinished only) */
234 const svn_fs_id_t
*base_id
;
236 /* copies list (const char * copy_ids), or NULL if there have been
237 no copies in this transaction. */
238 apr_array_header_t
*copies
;
243 /*** Representation ***/
244 /* If you add fields to this, check to see if you need to change
245 * svn_fs_fs__rep_copy. */
248 /* MD5 checksum for the contents produced by this representation.
249 This checksum is for the contents the rep shows to consumers,
250 regardless of how the rep stores the data under the hood. It is
251 independent of the storage (fulltext, delta, whatever).
253 If all the bytes are 0, then for compatibility behave as though
254 this checksum matches the expected checksum. */
255 unsigned char checksum
[APR_MD5_DIGESTSIZE
];
257 /* Revision where this representation is located. */
258 svn_revnum_t revision
;
260 /* Offset into the revision file where it is located. */
263 /* The size of the representation in bytes as seen in the revision
267 /* The size of the fulltext of the representation. */
268 svn_filesize_t expanded_size
;
270 /* Is this representation a transaction? */
276 /*** Node-Revision ***/
277 /* If you add fields to this, check to see if you need to change
278 * copy_node_revision in dag.c. */
282 svn_node_kind_t kind
;
284 /* The node-id for this node-rev. */
285 const svn_fs_id_t
*id
;
287 /* predecessor node revision id, or NULL if there is no predecessor
288 for this node revision */
289 const svn_fs_id_t
*predecessor_id
;
291 /* If this node-rev is a copy, where was it copied from? */
292 const char *copyfrom_path
;
293 svn_revnum_t copyfrom_rev
;
295 /* Helper for history tracing, root of the parent tree from whence
296 this node-rev was copied. */
297 svn_revnum_t copyroot_rev
;
298 const char *copyroot_path
;
300 /* number of predecessors this node revision has (recursively), or
301 -1 if not known (for backward compatibility). */
302 int predecessor_count
;
304 /* representation key for this node's properties. may be NULL if
305 there are no properties. */
306 representation_t
*prop_rep
;
308 /* representation for this node's data. may be NULL if there is
310 representation_t
*data_rep
;
312 /* path at which this node first came into existence. */
313 const char *created_path
;
315 /* is this the unmodified root of a transaction? */
316 svn_boolean_t is_fresh_txn_root
;
318 /* Number of nodes with svn:mergeinfo properties that are
319 descendants of this node (including it itself) */
320 apr_int64_t mergeinfo_count
;
322 /* Does this node itself have svn:mergeinfo? */
323 svn_boolean_t has_mergeinfo
;
331 /* Path of the change. */
334 /* Node revision ID of the change. */
335 const svn_fs_id_t
*noderev_id
;
337 /* The kind of change. */
338 svn_fs_path_change_kind_t kind
;
340 /* Text or property mods? */
341 svn_boolean_t text_mod
;
342 svn_boolean_t prop_mod
;
344 /* Copyfrom revision and path. */
345 svn_revnum_t copyfrom_rev
;
346 const char * copyfrom_path
;
353 #endif /* __cplusplus */
355 #endif /* SVN_LIBSVN_FS_FS_H */