Merge lp:~lifeless/bzr/apply-inventory-delta into lp:~bzr/bzr/trunk-old

Proposed by Robert Collins
Status: Merged
Merged at revision: not available
Proposed branch: lp:~lifeless/bzr/apply-inventory-delta
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: None lines
To merge this branch: bzr merge lp:~lifeless/bzr/apply-inventory-delta
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+8118@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

While investigating iter changes based commit I ran into repeated 'what
if' questions relating to the safety of partial deltas. As a result I've
written up a semi-formal model of what we do and how they work.

I'm going to follow this up with tests for the apply delta logic we have
to ensure that they deal correctly with the cases of corruption we know
about. Assuming (and I do) that they currently silently corrupt, this
may be a few days off.

-Rob

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert Collins wrote:
> Robert Collins has proposed merging lp:~lifeless/bzr/apply-inventory-delta into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
> While investigating iter changes based commit I ran into repeated 'what
> if' questions relating to the safety of partial deltas. As a result I've
> written up a semi-formal model of what we do and how they work.
>
> I'm going to follow this up with tests for the apply delta logic we have
> to ensure that they deal correctly with the cases of corruption we know
> about. Assuming (and I do) that they currently silently corrupt, this
> may be a few days off.
>
> -Rob
>
>

 review approve

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpM5oIACgkQJdeBCYSNAAMdeACfXmeOq2V3RFDp002PaomI4eyz
JuMAn1yCJcU6Fkkh/rn7Jn/JJYi6CvzA
=6RHS
-----END PGP SIGNATURE-----

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/inventory.py'
2--- bzrlib/inventory.py 2009-06-18 18:18:36 +0000
3+++ bzrlib/inventory.py 2009-07-02 07:22:27 +0000
4@@ -1090,6 +1090,9 @@
5 def apply_delta(self, delta):
6 """Apply a delta to this inventory.
7
8+ See the inventory developers documentation for the theory behind
9+ inventory deltas.
10+
11 :param delta: A list of changes to apply. After all the changes are
12 applied the final inventory must be internally consistent, but it
13 is ok to supply changes which, if only half-applied would have an
14@@ -1578,6 +1581,9 @@
15 propagate_caches=False):
16 """Create a new CHKInventory by applying inventory_delta to this one.
17
18+ See the inventory developers documentation for the theory behind
19+ inventory deltas.
20+
21 :param inventory_delta: The inventory delta to apply. See
22 Inventory.apply_delta for details.
23 :param new_revision_id: The revision id of the resulting CHKInventory.
24
25=== modified file 'bzrlib/mutabletree.py'
26--- bzrlib/mutabletree.py 2009-06-10 03:56:49 +0000
27+++ bzrlib/mutabletree.py 2009-07-02 07:22:27 +0000
28@@ -523,6 +523,9 @@
29 for commit which is not required to handle situations that do not arise
30 outside of commit.
31
32+ See the inventory developers documentation for the theory behind
33+ inventory deltas.
34+
35 :param new_revid: The new revision id for the trees parent.
36 :param delta: An inventory delta (see apply_inventory_delta) describing
37 the changes from the current left most parent revision to new_revid.
38
39=== modified file 'bzrlib/repository.py'
40--- bzrlib/repository.py 2009-06-26 09:24:34 +0000
41+++ bzrlib/repository.py 2009-07-02 07:22:27 +0000
42@@ -1018,6 +1018,9 @@
43 parents, basis_inv=None, propagate_caches=False):
44 """Add a new inventory expressed as a delta against another revision.
45
46+ See the inventory developers documentation for the theory behind
47+ inventory deltas.
48+
49 :param basis_revision_id: The inventory id the delta was created
50 against. (This does not have to be a direct parent.)
51 :param delta: The inventory delta (see Inventory.apply_delta for
52
53=== modified file 'doc/developers/inventory.txt'
54--- doc/developers/inventory.txt 2009-04-04 02:50:01 +0000
55+++ doc/developers/inventory.txt 2009-07-02 07:22:27 +0000
56@@ -498,3 +498,90 @@
57 delta, the only other valid fields are OLDPATH and 'file-id'. PARENT_ID is ''
58 when a delete has been recorded or when recording a new root entry.
59
60+
61+Delta consistency
62+=================
63+
64+Inventory deltas and more broadly changes between trees are a significant part
65+of bzr's core operations: they are key components in status, diff, commit,
66+and merge (although merge uses tree transform, deltas contain the changes that
67+are applied to the transform). Our ability to perform a given operation depends
68+on us creating consistent deltas between trees. Inconsistent deltas lead to
69+errors and bugs, or even just unexpected conflicts.
70+
71+An inventory delta is a transform to change an inventory A into another
72+inventory B (in patch terms its a perfect patch). Sometimes, for instance in a
73+regular commit, inventory B is known at the time we create the delta. Other
74+times, B is not known because the user is requesting that some parts of the
75+second inventory they have are masked out from consideration. When this happens
76+we create a delta that when applied to A creates a B we haven't seen in total
77+before. In this situation we need to ensure that B will be internally
78+consistent. Deltas are unidirectional, a delta(A, B) creates B from A, but
79+cannot be used to create A from B.
80+
81+Deltas are expressed as a list of (oldpath, newpath, fileid, entry) tuples. The
82+fileid, entry elements are normative; the old and new paths are strong hints
83+but not currently guaranteed to be accurate. (This is a shame and something we
84+should tighten up). Deltas are required to list all removals explicitly -
85+removing the parent of an entry doesn't remove the entry.
86+
87+Applying a delta to an inventory consists of:
88+ - removing all fileids for which entry is None
89+ - adding or replacing all other fileids
90+ - detecting consistency errors
91+
92+An interesting aspect of delta inconsistencies is when we notice them:
93+ - Silent errors which our application logic misses
94+ - Visible errors we catch during application, so bad data isn't stored in
95+ the system.
96+
97+The minimum safe level for our application logic would be to catch all errors
98+during application. Making generation never generate inconsistent deltas is
99+a seperate but necessary condition for robust code.
100+
101+An inconsistent delta is one which:
102+ - after application to an inventory the inventory is an impossible state.
103+ - has the same fileid, or oldpath(not-None), or newpath(not-None) multiple
104+ times.
105+ - has a fileid field different to the entry.fileid in the same item in the
106+ delta.
107+
108+Forms of inventory inconsistency deltas can carry/cause:
109+ - An entry newly introduced to a path without also removing or relocating any
110+ existing entry at that path. (Duplicate paths)
111+ - An entry whose parent id isn't present in the tree. (Missing parent).
112+ - Having oldpath or newpath not be actual original path or resulting path.
113+ (Wrong path)
114+ - An entry whose parent is not a directory. (Under non-directory).
115+ - An entry that is internally inconsistent.
116+
117+Known causes of inconsistency:
118+ - A 'new' entry which the inventory already has - when this is a directory
119+ even arbitrary file ids under the 'new' entry are more likely to collide on
120+ paths.
121+ - Removing a directory without recursively removing its children - causes
122+ Missing parent.
123+ - Recording a change to an entry without including all changed entries found
124+ following its parents up to and includin the root - can cause duplicate
125+ paths, missing parents, wrong path, under non-directory.
126+
127+Avoiding inconsistent deltas
128+----------------------------
129+
130+The simplest thing is to never create partial deltas, as it is trivial to
131+be consistent when all data is examined every time. However users sometimes
132+want to specify a subset of the changes in their tree when they do an operation
133+which needs to create a delta - such as commit.
134+
135+We have a choice about handling user requests that can generate inconsistent
136+deltas. We can alter or interpret the request in such a way that the delta will
137+be consistent, but perhaps larger than the user had intended. Or we can
138+identify problematic situations and abort, specifying to the user why we have
139+aborted and likely things they can do to make their request generate a
140+consistent delta.
141+
142+Currently we attempt to expand/interpret the request so that the user is not
143+required to understand all the internal constraints of the system: if they
144+request 'foo/bar' we automatically include foo. This works to an extent but on
145+review we are creating inconsistent deltas by the way we do this. We need to
146+avoid all the known causes of inconsistency in our delta creation logic.
147