Synchronize notmuch mail across machines
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

design.txt 2.0KB

  1. Each replica of maildir has:
  2. * Unique ID
  3. * Current version number
  4. * Sync version vector
  5. * For each message
  6. - id of last replica to modify tags
  7. - current version number of that replica when it modified tags
  8. - Set of tags as of current version number
  9. Before syncing to or from another replica:
  10. * Bump current version number by one
  11. * Set own ID to new version number in sync version vector
  12. * Scan all messages. If tag differs from last seen, set state to:
  13. - modifying replica := current replica's unique id
  14. - version number := current version number
  15. - set of tags := current tags in xapian database
  16. To sync A -> B:
  17. B sends A its "sync version vector"
  18. A sends B its "sync version vector"
  19. A sends B message state messages more recent than A's sync vector
  20. For each such message:
  21. If B's message state is than A's sync vector:
  22. merge flags
  23. set modifying replica to B and version to B's current version
  24. Otherwise: entirely replace B's state with A's state for this message
  25. B sets it's sync version vector to pairwise max of A's and B's.
  26. Keeping local database up to date:
  27. Keep track of ctime of last scan
  28. Scan file system to find all files with more recent ctime
  29. Look up each file in xapian, check all filenames for document
  30. (because this could be a rename, in which case old name is gone)
  31. This handles both new files and renames, but not deletes
  32. Deletes require scanning whole database and calling access on files
  33. Deletes should be kept in database for a while to propagate them
  34. But shouldn't re-appear, old version on other replicas before sync time
  35. * Xapian lets us iterate through:
  36. dirname, dir_docid
  37. docid, message-id
  38. dir_docid, filename, docid
  39. tag, docid
  40. * Resolving a link conflict
  41. Let n_A be the number of links of a file in xxx/new on replica A
  42. Let c_A be the number of links in xxx/cur on replica A
  43. Let n_B and c_B be the same for replica B
  44. Put n links in xxx/new and c links in xxx/cur where
  45. - c = max(c_A, c_B)
  46. - n = max(n_A + c_A, n_B + c_B) - c