##// END OF EJS Templates
internals: minor rewriting of revlogs documentation...
Gregory Szorc -
r41235:d8fe67db default
parent child Browse files
Show More
@@ -1,229 +1,235 b''
1 Revision logs - or *revlogs* - are an append only data structure for
1 Revision logs - or *revlogs* - are an append only data structure for
2 storing discrete entries, or *revisions*. They are the primary storage
2 storing discrete entries, or *revisions*. They are the primary storage
3 mechanism of repository data.
3 mechanism of repository data.
4
4
5 Revlogs effectively model a directed acyclic graph (DAG). Each node
5 Revlogs effectively model a directed acyclic graph (DAG). Each node
6 has edges to 1 or 2 *parent* nodes. Each node contains metadata and
6 has edges to 1 or 2 *parent* nodes. Each node contains metadata and
7 the raw value for that node.
7 the raw value for that node.
8
8
9 Revlogs consist of entries which have metadata and revision data.
9 Revlogs consist of entries which have metadata and revision data.
10 Metadata includes the hash of the revision's content, sizes, and
10 Metadata includes the hash of the revision's content, sizes, and
11 links to its *parent* entries. The collective metadata is referred
11 links to its *parent* entries. The collective metadata is referred
12 to as the *index* and the revision data is the *data*.
12 to as the *index* and the revision data is the *data*.
13
13
14 Revision data is stored as a series of compressed deltas against previous
14 Revision data is stored as a series of compressed deltas against
15 revisions.
15 ancestor revisions.
16
16
17 Revlogs are written in an append-only fashion. We never need to rewrite
17 Revlogs are written in an append-only fashion. We never need to rewrite
18 a file to insert nor do we need to remove data. Rolling back in-progress
18 a file to insert nor do we need to remove data. Rolling back in-progress
19 writes can be performed by truncating files. Read locks can be avoided
19 writes can be performed by truncating files. Read locks can be avoided
20 using simple techniques. This means that references to other data in
20 using simple techniques. This means that references to other data in
21 the same revlog *always* refer to a previous entry.
21 the same revlog *always* refer to a previous entry.
22
22
23 Revlogs can be modeled as 0-indexed arrays. The first revision is
23 Revlogs can be modeled as 0-indexed arrays. The first revision is
24 revision #0 and the second is revision #1. The revision -1 is typically
24 revision #0 and the second is revision #1. The revision -1 is typically
25 used to mean *does not exist* or *not defined*.
25 used to mean *does not exist* or *not defined*.
26
26
27 File Format
27 File Format
28 ===========
28 ===========
29
29
30 A revlog begins with a 32-bit big endian integer holding version info
30 A revlog begins with a 32-bit big endian integer holding version info
31 and feature flags. This integer is shared with the first revision
31 and feature flags. This integer is shared with the first revision
32 entry.
32 entry.
33
33
34 This integer is logically divided into 2 16-bit shorts. The least
34 This integer is logically divided into 2 16-bit shorts. The least
35 significant half of the integer is the format/version short. The other
35 significant half of the integer is the format/version short. The other
36 short holds feature flags that dictate behavior of the revlog.
36 short holds feature flags that dictate behavior of the revlog.
37
37
38 Only 1 bit of the format/version short is currently used. Remaining
39 bits are reserved for future use.
40
41 The following values for the format/version short are defined:
38 The following values for the format/version short are defined:
42
39
43 0
40 0
44 The original revlog version.
41 The original revlog version.
45 1
42 1
46 RevlogNG (*next generation*). It replaced version 0 when it was
43 RevlogNG (*next generation*). It replaced version 0 when it was
47 implemented in 2006.
44 implemented in 2006.
48 2
45 2
49 In-development version incorporating accumulated knowledge and
46 In-development version incorporating accumulated knowledge and
50 missing features from 10+ years of revlog version 1.
47 missing features from 10+ years of revlog version 1.
51 57005 (0xdead)
48 57005 (0xdead)
52 Reserved for internal testing of new versions. No defined format
49 Reserved for internal testing of new versions. No defined format
53 beyond 32-bit header.
50 beyond 32-bit header.
54
51
55 The feature flags short consists of bit flags. Where 0 is the least
52 The feature flags short consists of bit flags. Where 0 is the least
56 significant bit, the following bit offsets define flags:
53 significant bit. The bit flags vary by revlog version.
54
55 Version 0 revlogs have no defined flags and the presence of a flag
56 is considered an error.
57
58 Version 1 revlogs have the following flags at the specified bit offsets:
57
59
58 0
60 0
59 Store revision data inline.
61 Store revision data inline.
60 1
62 1
61 Generaldelta encoding.
63 Generaldelta encoding.
62
64
63 2-15
65 Version 2 revlogs have the following flags at the specified bit offsets:
64 Reserved for future use.
66
67 0
68 Store revision data inline.
69 1
70 Generaldelta encoding.
65
71
66 The following header values are common:
72 The following header values are common:
67
73
68 00 00 00 01
74 00 00 00 01
69 v1
75 v1
70 00 01 00 01
76 00 01 00 01
71 v1 + inline
77 v1 + inline
72 00 02 00 01
78 00 02 00 01
73 v1 + generaldelta
79 v1 + generaldelta
74 00 03 00 01
80 00 03 00 01
75 v1 + inline + generaldelta
81 v1 + inline + generaldelta
76
82
77 Following the 32-bit header is the remainder of the first index entry.
83 Following the 32-bit header is the remainder of the first index entry.
78 Following that are remaining *index* data. Inlined revision data is
84 Following that are remaining *index* data. Inlined revision data is
79 possibly located between index entries. More on this layout is described
85 possibly located between index entries. More on this layout is described
80 below.
86 below.
81
87
82 Version 1 Format
88 Version 1 Format
83 ================
89 ================
84
90
85 Version 1 (RevlogNG) begins with an index describing the revisions in
91 Version 1 (RevlogNG) begins with an index describing the revisions in
86 the revlog. If the ``inline`` flag is set, revision data is stored inline,
92 the revlog. If the ``inline`` flag is set, revision data is stored inline,
87 or between index entries (as opposed to in a separate container).
93 or between index entries (as opposed to in a separate container).
88
94
89 Each index entry is 64 bytes. The byte layout of each entry is as
95 Each index entry is 64 bytes. The byte layout of each entry is as
90 follows, with byte 0 being the first byte (all data stored as big endian):
96 follows, with byte 0 being the first byte (all data stored as big endian):
91
97
92 0-3 (4 bytes) (rev 0 only)
98 0-3 (4 bytes) (rev 0 only)
93 Revlog header
99 Revlog header
94
100
95 0-5 (6 bytes)
101 0-5 (6 bytes)
96 Absolute offset of revision data from beginning of revlog.
102 Absolute offset of revision data from beginning of revlog.
97
103
98 6-7 (2 bytes)
104 6-7 (2 bytes)
99 Bit flags impacting revision behavior. The following bit offsets define:
105 Bit flags impacting revision behavior. The following bit offsets define:
100
106
101 0: REVIDX_ISCENSORED revision has censor metadata, must be verified.
107 0: REVIDX_ISCENSORED revision has censor metadata, must be verified.
102
108
103 1: REVIDX_ELLIPSIS revision hash does not match its data. Used by
109 1: REVIDX_ELLIPSIS revision hash does not match its data. Used by
104 narrowhg
110 narrowhg
105
111
106 2: REVIDX_EXTSTORED revision data is stored externally.
112 2: REVIDX_EXTSTORED revision data is stored externally.
107
113
108 8-11 (4 bytes)
114 8-11 (4 bytes)
109 Compressed length of revision data / chunk as stored in revlog.
115 Compressed length of revision data / chunk as stored in revlog.
110
116
111 12-15 (4 bytes)
117 12-15 (4 bytes)
112 Uncompressed length of revision data. This is the size of the full
118 Uncompressed length of revision data. This is the size of the full
113 revision data, not the size of the chunk post decompression.
119 revision data, not the size of the chunk post decompression.
114
120
115 16-19 (4 bytes)
121 16-19 (4 bytes)
116 Base or previous revision this revision's delta was produced against.
122 Base or previous revision this revision's delta was produced against.
117 This revision holds full text (as opposed to a delta) if it points to
123 This revision holds full text (as opposed to a delta) if it points to
118 itself. For generaldelta repos, this is the previous revision in the
124 itself. For generaldelta repos, this is the previous revision in the
119 delta chain. For non-generaldelta repos, this is the base or first
125 delta chain. For non-generaldelta repos, this is the base or first
120 revision in the delta chain.
126 revision in the delta chain.
121
127
122 20-23 (4 bytes)
128 20-23 (4 bytes)
123 A revision this revision is *linked* to. This allows a revision in
129 A revision this revision is *linked* to. This allows a revision in
124 one revlog to be forever associated with a revision in another
130 one revlog to be forever associated with a revision in another
125 revlog. For example, a file's revlog may point to the changelog
131 revlog. For example, a file's revlog may point to the changelog
126 revision that introduced it.
132 revision that introduced it.
127
133
128 24-27 (4 bytes)
134 24-27 (4 bytes)
129 Revision of 1st parent. -1 indicates no parent.
135 Revision of 1st parent. -1 indicates no parent.
130
136
131 28-31 (4 bytes)
137 28-31 (4 bytes)
132 Revision of 2nd parent. -1 indicates no 2nd parent.
138 Revision of 2nd parent. -1 indicates no 2nd parent.
133
139
134 32-63 (32 bytes)
140 32-63 (32 bytes)
135 Hash of revision's full text. Currently, SHA-1 is used and only
141 Hash of revision's full text. Currently, SHA-1 is used and only
136 the first 20 bytes of this field are used. The rest of the bytes
142 the first 20 bytes of this field are used. The rest of the bytes
137 are ignored and should be stored as \0.
143 are ignored and should be stored as \0.
138
144
139 If inline revision data is being stored, the compressed revision data
145 If inline revision data is being stored, the compressed revision data
140 (of length from bytes offset 8-11 from the index entry) immediately
146 (of length from bytes offset 8-11 from the index entry) immediately
141 follows the index entry. There is no header on the revision data. There
147 follows the index entry. There is no header on the revision data. There
142 is no padding between it and the index entries before and after.
148 is no padding between it and the index entries before and after.
143
149
144 If revision data is not inline, then raw revision data is stored in a
150 If revision data is not inline, then raw revision data is stored in a
145 separate byte container. The offsets from bytes 0-5 and the compressed
151 separate byte container. The offsets from bytes 0-5 and the compressed
146 length from bytes 8-11 define how to access this data.
152 length from bytes 8-11 define how to access this data.
147
153
148 The first 4 bytes of the revlog are shared between the revlog header
154 The first 4 bytes of the revlog are shared between the revlog header
149 and the 6 byte absolute offset field from the first revlog entry.
155 and the 6 byte absolute offset field from the first revlog entry.
150
156
151 Version 2 Format
157 Version 2 Format
152 ================
158 ================
153
159
154 (In development. Format not finalized or stable.)
160 (In development. Format not finalized or stable.)
155
161
156 Version 2 is currently identical to version 1. This will obviously
162 Version 2 is currently identical to version 1. This will obviously
157 change.
163 change.
158
164
159 Delta Chains
165 Delta Chains
160 ============
166 ============
161
167
162 Revision data is encoded as a chain of *chunks*. Each chain begins with
168 Revision data is encoded as a chain of *chunks*. Each chain begins with
163 the compressed original full text for that revision. Each subsequent
169 the compressed original full text for that revision. Each subsequent
164 *chunk* is a *delta* against the previous revision. We therefore call
170 *chunk* is a *delta* against the previous revision. We therefore call
165 these chains of chunks/deltas *delta chains*.
171 these chains of chunks/deltas *delta chains*.
166
172
167 The full text for a revision is reconstructed by loading the original
173 The full text for a revision is reconstructed by loading the original
168 full text for the base revision of a *delta chain* and then applying
174 full text for the base revision of a *delta chain* and then applying
169 *deltas* until the target revision is reconstructed.
175 *deltas* until the target revision is reconstructed.
170
176
171 *Delta chains* are limited in length so lookup time is bound. They are
177 *Delta chains* are limited in length so lookup time is bound. They are
172 limited to ~2x the length of the revision's data. The linear distance
178 limited to ~2x the length of the revision's data. The linear distance
173 between the base chunk and the final chunk is also limited so the
179 between the base chunk and the final chunk is also limited so the
174 amount of read I/O to load all chunks in the delta chain is bound.
180 amount of read I/O to load all chunks in the delta chain is bound.
175
181
176 Deltas and delta chains are either computed against the previous
182 Deltas and delta chains are either computed against the previous
177 revision in the revlog or another revision (almost certainly one of
183 revision in the revlog or another revision (almost certainly one of
178 the parents of the revision). Historically, deltas were computed against
184 the parents of the revision). Historically, deltas were computed against
179 the previous revision. The *generaldelta* revlog feature flag (enabled
185 the previous revision. The *generaldelta* revlog feature flag (enabled
180 by default in Mercurial 3.7) activates the mode where deltas are
186 by default in Mercurial 3.7) activates the mode where deltas are
181 computed against an arbitrary revision (almost certainly a parent revision).
187 computed against an arbitrary revision (almost certainly a parent revision).
182
188
183 File Storage
189 File Storage
184 ============
190 ============
185
191
186 Revlogs logically consist of an index (metadata of entries) and
192 Revlogs logically consist of an index (metadata of entries) and
187 revision data. This data may be stored together in a single file or in
193 revision data. This data may be stored together in a single file or in
188 separate files. The mechanism used is indicated by the ``inline`` feature
194 separate files. The mechanism used is indicated by the ``inline`` feature
189 flag on the revlog.
195 flag on the revlog.
190
196
191 Mercurial's behavior is to use inline storage until a revlog reaches a
197 Mercurial's behavior is to use inline storage until a revlog reaches a
192 certain size, at which point it will be converted to non-inline. The
198 certain size, at which point it will be converted to non-inline. The
193 reason there is a size limit on inline storage is to establish an upper
199 reason there is a size limit on inline storage is to establish an upper
194 bound on how much data must be read to load the index. It would be a waste
200 bound on how much data must be read to load the index. It would be a waste
195 to read tens or hundreds of extra megabytes of data just to access the
201 to read tens or hundreds of extra megabytes of data just to access the
196 index data.
202 index data.
197
203
198 The actual layout of revlog files on disk is governed by the repository's
204 The actual layout of revlog files on disk is governed by the repository's
199 *store format*. Typically, a ``.i`` file represents the index revlog
205 *store format*. Typically, a ``.i`` file represents the index revlog
200 (possibly containing inline data) and a ``.d`` file holds the revision data.
206 (possibly containing inline data) and a ``.d`` file holds the revision data.
201
207
202 Revision Entries
208 Revision Entries
203 ================
209 ================
204
210
205 Revision entries consist of an optional 1 byte header followed by an
211 Revision entries consist of an optional 1 byte header followed by an
206 encoding of the revision data. The headers are as follows:
212 encoding of the revision data. The headers are as follows:
207
213
208 \0 (0x00)
214 \0 (0x00)
209 Revision data is the entirety of the entry, including this header.
215 Revision data is the entirety of the entry, including this header.
210 u (0x75)
216 u (0x75)
211 Raw revision data follows.
217 Raw revision data follows.
212 x (0x78)
218 x (0x78)
213 zlib (RFC 1950) data.
219 zlib (RFC 1950) data.
214
220
215 The 0x78 value is actually the first byte of the zlib header (CMF byte).
221 The 0x78 value is actually the first byte of the zlib header (CMF byte).
216
222
217 Hash Computation
223 Hash Computation
218 ================
224 ================
219
225
220 The hash of the revision is stored in the index and is used both as a primary
226 The hash of the revision is stored in the index and is used both as a primary
221 key and for data integrity verification.
227 key and for data integrity verification.
222
228
223 Currently, SHA-1 is the only supported hashing algorithm. To obtain the SHA-1
229 Currently, SHA-1 is the only supported hashing algorithm. To obtain the SHA-1
224 hash of a revision:
230 hash of a revision:
225
231
226 1. Hash the parent nodes
232 1. Hash the parent nodes
227 2. Hash the fulltext of the revision
233 2. Hash the fulltext of the revision
228
234
229 The 20 byte node ids of the parents are fed into the hasher in ascending order.
235 The 20 byte node ids of the parents are fed into the hasher in ascending order.
General Comments 0
You need to be logged in to leave comments. Login now