]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - docs/proposed/magic-folder/filesystem-integration.rst
Copyediting.
[tahoe-lafs/tahoe-lafs.git] / docs / proposed / magic-folder / filesystem-integration.rst
1 Magic Folder local filesystem integration design
2 ================================================
3
4 *Scope*
5
6 This document describes how to integrate the local filesystem with Magic
7 Folder in an efficient and reliable manner. For now we ignore Remote to
8 Local synchronization; the design and implementation of this is scheduled
9 for a later time. We also ignore multiple writers for the same Magic
10 Folder, which may or may not be supported in future. The design here will
11 be updated to account for those features in later Objectives. Objective 3
12 may require modifying the database schema or operation, and Objective 5
13 may modify the User interface.
14
15
16 *Local scanning and database*
17
18 When a Magic-Folder-enabled node starts up, it scans all directories
19 under the local directory and adds every file to a first-in first-out
20 "scan queue". When processing the scan queue, redundant uploads are
21 avoided by using the same mechanism the Tahoe backup command uses: we
22 keep track of previous uploads by recording each file's metadata such as
23 size, ``ctime`` and ``mtime``. This information is stored in a database,
24 referred to from now on as the magic folder db. Using this recorded
25 state, we ensure that when Magic Folder is subsequently started, the
26 local directory tree can be scanned quickly by comparing current
27 filesystem metadata with the previously recorded metadata. Each file
28 referenced in the scan queue is uploaded only if its metadata differs at
29 the time it is processed. If a change event is detected for a file that
30 is already queued (and therefore will be processed later), the redundant
31 event is ignored.
32
33 To implement the magic folder db, we will use an SQLite schema that
34 initially is the existing Tahoe-LAFS backup schema. This schema may
35 change in later objectives; this will cause no backward compatibility
36 problems, because this new feature will be developed on a branch that
37 makes no compatibility guarantees. However we will have a separate SQLite
38 database file and separate mutex lock just for Magic Folder. This avoids
39 usability problems related to mutual exclusion. (If a single file and
40 lock were used, a backup would block Magic Folder updates for a long
41 time, and a user would not be able to tell when backups are possible
42 because Magic Folder would acquire a lock at arbitrary times.)
43
44
45 *Eventual consistency property*
46
47 During the process of reading a file in order to upload it, it is not
48 possible to prevent further local writes. Such writes will result in
49 temporary inconsistency (that is, the uploaded file will not reflect
50 what the contents of the local file were at any specific time). Eventual
51 consistency is reached when the queue of pending uploads is empty. That
52 is, a consistent snapshot will be achieved eventually when local writes
53 to the target folder cease for a sufficiently long period of time.
54
55
56 *Detecting filesystem changes*
57
58 For the Linux implementation, we will use the inotify Linux kernel
59 subsystem to gather events on the local Magic Folder directory tree. This
60 implementation was already present in Tahoe-LAFS 1.9.0, but needs to be
61 changed to gather directory creation and move events, in addition to the
62 events indicating that a file has been written that are gathered by the
63 current code.
64
65 For the Windows implementation, we will use the ``ReadDirectoryChangesW``
66 Win32 API. The prototype implementation simulates a Python interface to
67 the inotify API in terms of ``ReadDirectoryChangesW``, allowing most of
68 the code to be shared across platforms.
69
70 When we detect the creation of a new directory below the local Magic
71 Folder directory, we create it in the Tahoe-LAFS filesystem, and also
72 scan the new local directory for new files. This scan is necessary to
73 avoid missing events for creation of files in a new directory before it
74 can be watched, and to correctly handle cases where an existing directory
75 is moved to be under the local Magic Folder directory.
76
77
78 *User interface*
79
80 The Magic Folder local filesystem integration will initially have a
81 provisional configuration file-based interface that may not be ideal from
82 a usability perspective. Creating our local filesystem integration in
83 this manner will allow us to use and test it independently of the rest of
84 the Magic Folder software components. We will focus greater attention on
85 user interface design as a later milestone in our development roadmap.
86
87 The configuration file, ``tahoe.cfg``, must define a target local
88 directory to be synchronized. Provisionally, this configuration will
89 replace the current ``[drop_upload]`` section::
90
91  [magic_folder]
92  enabled = true
93  local.directory = "/home/human"
94
95 When a filesystem directory is first configured for Magic Folder, the user
96 needs to create the remote Tahoe-LAFS directory using ``tahoe mkdir``,
97 and configure the Magic-Folder-enabled node with its URI (e.g. by putting
98 it in a file ``private/magic_folder_dircap``). If there are existing
99 files in the local directory, they will be uploaded as a result of the
100 initial scan described earlier.
101