Merge lp:~thisfred/u1db/doc-fixes into lp:u1db

Proposed by Eric Casteleijn
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 394
Merged at revision: 391
Proposed branch: lp:~thisfred/u1db/doc-fixes
Merge into: lp:u1db
Diff against target: 139 lines (+43/-27)
2 files modified
html-docs/conflicts.rst (+41/-27)
html-docs/high-level-api.rst (+2/-0)
To merge this branch: bzr merge lp:~thisfred/u1db/doc-fixes
Reviewer Review Type Date Requested Status
Stuart Langridge (community) Approve
Review via email: mp+120825@code.launchpad.net

Commit message

-fixed and clarified documentation

Description of the change

-fixed and clarified documentation

To post a comment you must log in.
lp:~thisfred/u1db/doc-fixes updated
392. By Eric Casteleijn

moar fixes

393. By Eric Casteleijn

s/can/should/

Revision history for this message
Stuart Langridge (sil) :
review: Approve
lp:~thisfred/u1db/doc-fixes updated
394. By Eric Casteleijn

footnotes sections

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'html-docs/conflicts.rst'
--- html-docs/conflicts.rst 2012-08-22 12:50:24 +0000
+++ html-docs/conflicts.rst 2012-08-22 17:05:21 +0000
@@ -87,8 +87,8 @@
87Synchronisation between two u1db replicas consists of the following steps:87Synchronisation between two u1db replicas consists of the following steps:
8888
89 1. The source replica asks the target replica for the information it has89 1. The source replica asks the target replica for the information it has
90 stored about the last time these two replicas were synchronised (If90 stored about the last time these two replicas were synchronised (if
91 ever.)91 ever).
9292
93 2. The source replica validates that its information regarding the last93 2. The source replica validates that its information regarding the last
94 synchronisation is consistent with the target's information, and94 synchronisation is consistent with the target's information, and
@@ -131,15 +131,19 @@
131 * The generation and transaction id of *this* replica at the time of the131 * The generation and transaction id of *this* replica at the time of the
132 most recent succesfully completed synchronisation with the other replica.132 most recent succesfully completed synchronisation with the other replica.
133133
134The generation is a counter that increases with each change to the database.134Any change to any document in a database constitutes a transaction. Each
135The transaction id is a unique random string that is paired with a particular135transaction increases the database generation by 1, and u1db implementations
136generation to identify cases where one of the replicas has been copied or136should [#]_ assign a transaction id, which is meant to be a unique random string
137reverted to an earlier state by a restore from backup, and then diverged from137paired with each generation, that can be used to detect the case where replica
138the known state on the other side of the synchronisation.138A and replica B have previously synchronised at generation N, and subsequently
139replica B is somehow reverted to an earlier generation (say, a restore from
140backup, or somebody made a copy of the database file of replica B at generation
141< N, and tries to synchronise that), and then new changes are made to it. It
142could end up at generation N again, but with completely different data. Having
143random unique transaction ids will allow replica A to detect this situation,
144and refuse to synchronise to prevent data loss. (Lesson to be learned from
145this: do not copy databases around, that is what synchronisation is for.)
139146
140Implementations are not required to use transaction ids. If they don't they
141should return an empty string when asked for a transaction id. All
142implementations should accept an empty string as a valid transaction id.
143147
144Synchronisation Over HTTP148Synchronisation Over HTTP
145-------------------------149-------------------------
@@ -193,8 +197,9 @@
193 {"last_known_generation": 12, "last_known_trans_id": "T-39299sdsfla8"},\r\n197 {"last_known_generation": 12, "last_known_trans_id": "T-39299sdsfla8"},\r\n
194198
195 and then for each document that it has changes for that are more recent199 and then for each document that it has changes for that are more recent
196 than generation 23, it sends, on a single line, followed by a comma and200 than generation 23, ordered by generation in ascending order, it sends,
197 a newline character, the following JSON object::201 on a single line, followed by a comma and a newline character, the
202 following JSON object::
198203
199 {"id": "mydocid", "rev": "my_replica_uid:4", "content": "{}", "generation": 48, "trans_id": "T-88djlahhhd"},\r\n204 {"id": "mydocid", "rev": "my_replica_uid:4", "content": "{}", "generation": 48, "trans_id": "T-88djlahhhd"},\r\n
200205
@@ -217,8 +222,8 @@
217 which tells the source what the target's new generation and transaction222 which tells the source what the target's new generation and transaction
218 id are, now that it processed the changes it received from the source.223 id are, now that it processed the changes it received from the source.
219 Then it starts streaming *its* changes since its last generation that224 Then it starts streaming *its* changes since its last generation that
220 was synced (12 in this case,) in exactly the same format as the source225 was synced (12 in this case), in exactly the same format (and order) as
221 did in step 3.226 the source did in step 3.
222227
223 5. When the source has processed all the changes it received from the228 5. When the source has processed all the changes it received from the
224 target, *and* it detects that there have been no changes to its database229 target, *and* it detects that there have been no changes to its database
@@ -245,34 +250,34 @@
245If you are writing a new u1db implementation, understanding revisions is250If you are writing a new u1db implementation, understanding revisions is
246important, and this is where you find out about them.251important, and this is where you find out about them.
247252
248To keep track of document revisions u1db uses vector versions. Each253To keep track of document revisions u1db uses vector clocks. Each
249synchronised instance of the same database is called a replica and has a unique254synchronised instance of the same database is called a replica and has a unique
250identifier (``replica uid``) assigned to it (currently the reference255identifier (``replica uid``) assigned to it (currently the reference
251implementation by default uses UUID4s for that); a revision is a mapping256implementation by default uses UUID4s for that); a revision is a mapping
252between ``replica uids`` and ``generations``, as follows: ``rev257between ``replica uids`` and ``revisions``, as follows: ``rev
253= <replica_uid:generation...>``, or using a functional notation258= <replica_uid:revision...>``, or using a functional notation
254``rev(replica_uid) = generation``. The current concrete format is a string259``rev(replica_uid) = revision``. The current concrete format is a string
255built out of each ``replica_uid`` concatenated with ``':'`` and with its260built out of each ``replica_uid`` concatenated with ``':'`` and with its
256generation in decimal, sorted lexicographically by ``replica_uid`` and then all261revision in decimal, sorted lexicographically by ``replica_uid`` and then all
257joined with ``'|'``, for example: ``'replicaA:1|replicaB:3'`` . Absent262joined with ``'|'``, for example: ``'replicaA:1|replicaB:3'`` . Absent
258``replica uids`` in a revision mapping are implicitly mapped to generation 0.263``replica uids`` in a revision mapping are implicitly mapped to revison 0.
259264
260The new revision of a document modified locally in a replica, is the265The new revision of a document modified locally in a replica, is the
261modification of the old revision where the generation mapped to the editing266modification of the old revision where the revision mapped to the editing
262``replica uid`` is increased by 1.267``replica uid`` is increased by 1.
263268
264When syncing one needs to establish whether an incoming revision is newer than269When syncing one needs to establish whether an incoming revision is newer than
265the current one or in conflict. A revision270the current one or in conflict. A revision
266271
267``rev1 = <replica_1i:generation1i|i=1..n>``272``rev1 = <replica_1i:revision1i|i=1..n>``
268273
269is newer than a different274is newer than a different
270275
271``rev2 = <replica_2j:generation2j|j=1..m>``276``rev2 = <replica_2j:revision2j|j=1..m>``
272277
273if for all ``i=1..n``, ``rev2(replica_1i) <= generation1i``278if for all ``i=1..n``, ``rev2(replica_1i) <= revision1i``
274279
275and for all ``j=1..m``, ``rev1(replica_2j) >= generation2j``.280and for all ``j=1..m``, ``rev1(replica_2j) >= revision2j``.
276281
277Two revisions which are not equal nor one newer than the other are in conflict.282Two revisions which are not equal nor one newer than the other are in conflict.
278283
@@ -285,3 +290,12 @@
285 ``rev_resol(r) = max(rev1(r)...revN(r))`` for all ``r`` in ``R``, with ``r != rev_resol``290 ``rev_resol(r) = max(rev1(r)...revN(r))`` for all ``r`` in ``R``, with ``r != rev_resol``
286291
287 ``rev_resol(replica_resol) = max(rev1(replica_resol)...revN(replica_resol))+1``292 ``rev_resol(replica_resol) = max(rev1(replica_resol)...revN(replica_resol))+1``
293
294.. rubric:: footnotes
295
296.. [#] Implementations are not required to use transaction ids. If they don't
297 they should return an empty string when asked for a transaction id. All
298 implementations should accept an empty string as a valid transaction id.
299 We suggest to implement transaction ids where possible though, since
300 omitting them can lead to data loss in scenarios like the ones described
301 above.
288302
=== modified file 'html-docs/high-level-api.rst'
--- html-docs/high-level-api.rst 2012-08-21 18:46:01 +0000
+++ html-docs/high-level-api.rst 2012-08-22 17:05:21 +0000
@@ -381,6 +381,8 @@
381 * :py:meth:`~u1db.Database.get_doc_conflicts`381 * :py:meth:`~u1db.Database.get_doc_conflicts`
382 * :py:meth:`~u1db.Database.resolve_doc`382 * :py:meth:`~u1db.Database.resolve_doc`
383383
384.. rubric:: footnotes
385
384.. [#] Alternatively if a factory function was passed into386.. [#] Alternatively if a factory function was passed into
385 :py:func:`u1db.open`, :py:meth:`~u1db.Database.get_doc` will return387 :py:func:`u1db.open`, :py:meth:`~u1db.Database.get_doc` will return
386 whatever type of object the factory function returns.388 whatever type of object the factory function returns.

Subscribers

People subscribed via source and target branches