Skip to content

Commit 00f6873

Browse files
hanwengitster
authored andcommitted
doc/reftable: document how to handle windows
On Windows we can't delete or overwrite files opened by other processes. Here we sketch how to handle this situation. We propose to use a random element in the filename. It's possible to design an alternate solution based on counters, but that would assign semantics to the filenames that complicates implementation. Signed-off-by: Han-Wen Nienhuys <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 966e671 commit 00f6873

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

Documentation/technical/reftable.txt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -872,17 +872,11 @@ A repository must set its `$GIT_DIR/config` to configure reftable:
872872
Layout
873873
^^^^^^
874874

875-
A collection of reftable files are stored in the `$GIT_DIR/reftable/`
876-
directory:
877-
878-
....
879-
00000001-00000001.log
880-
00000002-00000002.ref
881-
00000003-00000003.ref
882-
....
883-
884-
where reftable files are named by a unique name such as produced by the
885-
function `${min_update_index}-${max_update_index}.ref`.
875+
A collection of reftable files are stored in the `$GIT_DIR/reftable/` directory.
876+
Their names should have a random element, such that each filename is globally
877+
unique; this helps avoid spurious failures on Windows, where open files cannot
878+
be removed or overwritten. It suggested to use
879+
`${min_update_index}-${max_update_index}-${random}.ref` as a naming convention.
886880

887881
Log-only files use the `.log` extension, while ref-only and mixed ref
888882
and log files use `.ref`. extension.
@@ -893,9 +887,9 @@ current files, one per line, in order, from oldest (base) to newest
893887

894888
....
895889
$ cat .git/reftable/tables.list
896-
00000001-00000001.log
897-
00000002-00000002.ref
898-
00000003-00000003.ref
890+
00000001-00000001-RANDOM1.log
891+
00000002-00000002-RANDOM2.ref
892+
00000003-00000003-RANDOM3.ref
899893
....
900894

901895
Readers must read `$GIT_DIR/reftable/tables.list` to determine which
@@ -940,7 +934,7 @@ new reftable and atomically appending it to the stack:
940934
3. Select `update_index` to be most recent file's
941935
`max_update_index + 1`.
942936
4. Prepare temp reftable `tmp_XXXXXX`, including log entries.
943-
5. Rename `tmp_XXXXXX` to `${update_index}-${update_index}.ref`.
937+
5. Rename `tmp_XXXXXX` to `${update_index}-${update_index}-${random}.ref`.
944938
6. Copy `tables.list` to `tables.list.lock`, appending file from (5).
945939
7. Rename `tables.list.lock` to `tables.list`.
946940

@@ -993,7 +987,7 @@ prevents other processes from trying to compact these files.
993987
should always be the case, assuming that other processes are adhering to
994988
the locking protocol.
995989
7. Rename `${min_update_index}-${max_update_index}_XXXXXX` to
996-
`${min_update_index}-${max_update_index}.ref`.
990+
`${min_update_index}-${max_update_index}-${random}.ref`.
997991
8. Write the new stack to `tables.list.lock`, replacing `B` and `C`
998992
with the file from (4).
999993
9. Rename `tables.list.lock` to `tables.list`.
@@ -1005,6 +999,22 @@ This strategy permits compactions to proceed independently of updates.
1005999
Each reftable (compacted or not) is uniquely identified by its name, so
10061000
open reftables can be cached by their name.
10071001

1002+
Windows
1003+
^^^^^^^
1004+
1005+
On windows, and other systems that do not allow deleting or renaming to open
1006+
files, compaction may succeed, but other readers may prevent obsolete tables
1007+
from being deleted.
1008+
1009+
On these platforms, the following strategy can be followed: on closing a
1010+
reftable stack, reload `tables.list`, and delete any tables no longer mentioned
1011+
in `tables.list`.
1012+
1013+
Irregular program exit may still leave about unused files. In this case, a
1014+
cleanup operation can read `tables.list`, note its modification timestamp, and
1015+
delete any unreferenced `*.ref` files that are older.
1016+
1017+
10081018
Alternatives considered
10091019
~~~~~~~~~~~~~~~~~~~~~~~
10101020

0 commit comments

Comments
 (0)