index-helper/watchman
Subsystems (2)
v9 cover index-helper/watchman
Formatting and patch naming fixes from Junio. No substantive changes.
David Turner (8):
index-helper: log warnings
unpack-trees: preserve index extensions
watchman: add a config option to enable the extension
index-helper: kill mode
index-helper: don't run if already running
index-helper: autorun mode
index-helper: optionally automatically run
untracked-cache: config option
Nguyễn Thái Ngọc Duy (11):
read-cache.c: fix constness of verify_hdr()
read-cache: allow to keep mmap'd memory after reading
index-helper: new daemon for caching index and related stuff
index-helper: add --strict
daemonize(): set a flag before exiting the main process
index-helper: add --detach
read-cache: add watchman 'WAMA' extension
watchman: support watchman to reduce index refresh cost
index-helper: use watchman to avoid refreshing index with lstat()
update-index: enable/disable watchman support
trace: measure where the time is spent in the index-heavy operations
.gitignore | 2 + Documentation/config.txt | 12 + Documentation/git-index-helper.txt | 81 +++++ Documentation/git-update-index.txt | 6 + Documentation/technical/index-format.txt | 22 ++ Makefile | 18 ++ builtin/gc.c | 2 +- builtin/update-index.c | 16 + cache.h | 25 +- config.c | 5 + configure.ac | 8 + daemon.c | 2 +- diff-lib.c | 4 + dir.c | 25 +- dir.h | 6 + environment.c | 3 + git-compat-util.h | 1 + index-helper.c | 506 +++++++++++++++++++++++++++++ name-hash.c | 2 + preload-index.c | 2 + read-cache.c | 534 ++++++++++++++++++++++++++++++- refs/files-backend.c | 2 + setup.c | 4 +- t/t1701-watchman-extension.sh | 37 +++ t/t7063-status-untracked-cache.sh | 22 ++ t/t7900-index-helper.sh | 69 ++++ t/test-lib-functions.sh | 4 + test-dump-watchman.c | 16 + unpack-trees.c | 1 + watchman-support.c | 135 ++++++++ watchman-support.h | 7 + 31 files changed, 1558 insertions(+), 21 deletions(-) create mode 100644 Documentation/git-index-helper.txt create mode 100644 index-helper.c create mode 100755 t/t1701-watchman-extension.sh create mode 100755 t/t7900-index-helper.sh create mode 100644 test-dump-watchman.c create mode 100644 watchman-support.c create mode 100644 watchman-support.h
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 1/19 read-cache.c: fix constness of verify_hdr()
From: Nguyễn Thái Ngọc Duy <[email protected]>
--- read-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
read-cache.c +1 -1
@@ -1345,7 +1345,7 @@ struct ondisk_cache_entry_extended { ondisk_cache_entry_extended_size(ce_namelen(ce)) : \ ondisk_cache_entry_size(ce_namelen(ce))) -static int verify_hdr (struct cache_header *hdr,unsigned long size) +static int verify_hdr (const struct cache_header *hdr,unsigned long size) {git_SHA_CTX c;unsigned char sha1[20 ];
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 2/19 read-cache: allow to keep mmap'd memory after reading
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
Later, we will introduce git index-helper to share this memory with other git processes.
We only unmap it when we discard the index (although the kernel may of course choose to page it out).
--- cache.h | 3 +++ read-cache.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
cache.h +3 -0
@@ -333,11 +333,14 @@ struct index_state {struct split_index *split_index;struct cache_time timestamp; unsigned name_hash_initialized : 1, + keep_mmap : 1, initialized : 1;struct hashmap name_hash;struct hashmap dir_hash;unsigned char sha1[20 ];struct untracked_cache *untracked; +void *mmap; +size_t mmap_size; };extern struct index_state the_index;
read-cache.c +12 -1
@@ -1574,6 +1574,10 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) mmap =xmmap (NULL , mmap_size,PROT_READ ,MAP_PRIVATE , fd,0 );if (mmap ==MAP_FAILED )die_errno ("unable to map index file" ); +if (istate->keep_mmap) { + istate->mmap = mmap; + istate->mmap_size = mmap_size; + }close (fd); hdr = mmap;
@@ -1626,11 +1630,13 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) src_offset +=8 ; src_offset += extsize; } -munmap (mmap, mmap_size); +if (!istate->keep_mmap) +munmap (mmap, mmap_size);return istate->cache_nr; unmap:munmap (mmap, mmap_size); + istate->mmap =NULL ;die ("index file corrupt" ); }
@@ -1655,6 +1661,7 @@ int read_index_from(struct index_state *istate, const char *path)discard_index (split_index->base); else split_index->base = xcalloc(1, sizeof(*split_index->base)); + split_index->base->keep_mmap = istate->keep_mmap; ret =do_read_index (split_index->base,git_path ("sharedindex.%s" ,sha1_to_hex (split_index->base_sha1)),1 );
@@ -1698,6 +1705,10 @@ int discard_index(struct index_state *istate)free (istate->cache); istate->cache =NULL ; istate->cache_alloc =0 ; +if (istate->keep_mmap && istate->mmap) { +munmap (istate->mmap, istate->mmap_size); + istate->mmap =NULL ; + }discard_split_index (istate);free_untracked_cache (istate->untracked); istate->untracked =NULL ;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 3/19 index-helper: new daemon for caching index and related stuff
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
Instead of reading the index from disk and worrying about disk corruption, the index is cached in memory (memory bit-flips happen too, but hopefully less often). The result is faster read. Read time is reduced by 70%.
The biggest gain is not having to verify the trailing SHA-1, which takes lots of time especially on large index files. But this also opens doors for further optimizations:
- we could create an in-memory format that's essentially the memory dump of the index to eliminate most of parsing/allocation overhead. The mmap'd memory can be used straight away. Experiment
[1] shows we could reduce read time by 88%.
- we could cache non-index info such as name hash
Shared memory is done by storing files in a per-repository temporary directory. This is more portable than shm (which requires posix-realtime and has various quirks on OS X). It might even work on Windows, although this has not been tested. The shared memory file's name follows the template "shm-<object>-<SHA1>" where <SHA1> is the trailing SHA-1 of the index file. <object> is "index" for cached index files (and might later be "name-hash" for name-hash cache). If such shared memory exists, it contains the same index content as on disk. The content is already validated by the daemon and git won't validate it again (except comparing the trailing SHA-1s).
We also add some bits to the index (to_shm and from_shm) to track when an index came from shared memory or is going to shared memory.
We keep this daemon's logic as thin as possible. The "brain" stays in git. So the daemon can read and validate stuff, but that's all it's allowed to do. It does not add/create new information. It doesn't even accept direct updates from git.
Git can poke the daemon via unix domain sockets to tell it to refresh the index cache, or to keep it alive some more minutes. It can't give any real index data directly to the daemon. Real data goes to disk first, then the daemon reads and verifies it from there. The daemon only handles $GIT_DIR/index, not temporary index files; it only gets poked for the former.
$GIT_DIR/index-helper.sock is the socket for the daemon process. The daemon reads from the socket and executes commands.
Named pipes were considered for portability reasons, but then commands that need replies from the daemon would have to open their own pipes, since a named pipe should only have one reader. Unix domain sockets don't have this problem.
On webkit.git with index format v2, duplicating 8 times to 1.5m entries and 236MB in size:
(vanilla) 0.50 s: read_index_from .git/index
(index-helper) 0.18 s: read_index_from .git/index
Interestingly with index v4, we get less out of index-helper. It makes sense as v4 requires more processing after loading the index:
(vanilla) 0.37 s: read_index_from .git/index
(index-helper) 0.22 s: read_index_from .git/index
[1] http://thread.gmane.org/gmane.comp.version-control.git/247268/focus=248771
--- .gitignore | 1 + Documentation/git-index-helper.txt | 50 +++++++ Makefile | 5 + cache.h | 11 ++ git-compat-util.h | 1 + index-helper.c | 277 +++++++++++++++++++++++++++++++++++++ read-cache.c | 125 +++++++++++++++-- t/t7900-index-helper.sh | 23 +++ 8 files changed, 484 insertions(+), 9 deletions(-) create mode 100644 Documentation/git-index-helper.txt create mode 100644 index-helper.c create mode 100755 t/t7900-index-helper.sh
.gitignore +1 -0
@@ -71,6 +71,7 @@ /git-http-fetch /git-http-push /git-imap-send +/git-index-helper /git-index-pack /git-init /git-init-db
Documentation/git-index-helper.txt new file +50 -0
50 lines not on this page · raw message
Makefile +5 -0
@@ -1433,6 +1433,10 @@ ifdef HAVE_DEV_TTY BASIC_CFLAGS += -DHAVE_DEV_TTY endif +ifndef NO_MMAP + PROGRAM_OBJS += index-helper.o +endif + ifdef DIR_HAS_BSD_GROUP_SEMANTICS COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS endif
@@ -2159,6 +2163,7 @@ GIT-BUILD-OPTIONS: FORCE @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@+ @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+ @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+ + @echo NO_MMAP=\''$(subst ','\'',$(subst ','\'',$(NO_MMAP)))'\' >>$@+ ifdef TEST_OUTPUT_DIRECTORY @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+ endif
cache.h +11 -0
@@ -334,6 +334,17 @@ struct index_state {struct cache_time timestamp; unsigned name_hash_initialized : 1, keep_mmap : 1, + +/* +* This index came from index-helper originally. +*/ + from_shm : 1, +/* +* We're moving this index to shared memory, so we +* don't need to poke the daemon to request updates +* on it. +*/ + to_shm : 1, initialized : 1;struct hashmap name_hash;struct hashmap dir_hash;
git-compat-util.h +1 -0
@@ -513,6 +513,7 @@ static inline int ends_with(const char *str, const char *suffix)#define PROT_READ 1#define PROT_WRITE 2#define MAP_PRIVATE 1 +#define MAP_SHARED 2#endif #define mmap git_mmap
index-helper.c new file +277 -0
277 lines not on this page · raw message
read-cache.c +116 -9
170 lines not on this page · raw message
t/t7900-index-helper.sh new file +23 -0
@@ -0,0 +1,23 @@ +#!/bin/sh +# +# Copyright (c) 2016, Twitter, Inc +# + +test_description='git-index-helper + +Testing git index-helper +' + +. ./test-lib.sh + +test -n "$NO_MMAP" && { + skip_all='skipping index-helper tests: no mmap' + test_done +} + +test_expect_success 'index-helper smoke test' ' + git index-helper --exit-after 1 && + test_path_is_missing .git/index-helper.sock +' + +test_done
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 4/19 index-helper: add --strict
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
There are "holes" in the index-helper approach because the shared memory is not verified again by git. If $USER is compromised, shared memory could be modified. But anyone who could do this could already modify $GIT_DIR/index. A more realistic risk is some bugs in index-helper that produce corrupt shared memory. --strict is added to avoid that.
Strictly speaking there's still a very small gap where corrupt shared memory could still be read by git: after we write the trailing SHA-1 in the shared memory (thus signaling "this shm is ready") and before verify_shm() detects an error.
--- Documentation/git-index-helper.txt | 9 +++++++ cache.h | 1 + index-helper.c | 48 ++++++++++++++++++++++++++++++++++++++ read-cache.c | 9 ++++--- 4 files changed, 64 insertions(+), 3 deletions(-)
Documentation/git-index-helper.txt +9 -0
@@ -25,6 +25,15 @@ OPTIONS Exit if the cached index is not accessed for `<n>` seconds. Specify 0 to wait forever. Default is 600. +--strict:: +--no-strict:: + Strict mode makes index-helper verify the shared memory after + it's created. If the result does not match what's read from + $GIT_DIR/index, the shared memory is destroyed. This makes + index-helper take more than double the amount of time required + for reading an index, but because it will happen in the + background, it's not noticable. `--strict` is enabled by default. + NOTES -----
cache.h +1 -0
@@ -345,6 +345,7 @@ struct index_state {* on it. */ to_shm : 1, + always_verify_trailing_sha1 : 1, initialized : 1;struct hashmap name_hash;struct hashmap dir_hash;
index-helper.c +48 -0
71 lines not on this page · raw message
read-cache.c +6 -3
@@ -1674,9 +1674,12 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) istate->mmap = mmap; istate->mmap_size = mmap_size; -if (try_shm (istate) && -verify_hdr (istate->mmap, istate->mmap_size) <0 ) - goto unmap; +if (try_shm (istate)) { +if (verify_hdr (istate->mmap, istate->mmap_size) <0 ) + goto unmap; + }else if (istate->always_verify_trailing_sha1 && +verify_hdr (istate->mmap, istate->mmap_size) <0 ) + goto unmap; hdr = mmap = istate->mmap; mmap_size = istate->mmap_size;if (!istate->keep_mmap)
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 5/19 index-helper: log warnings
In reply to David TurnerInstead of writing warnings to stderr, write them to a log. Later, we'll probably be daemonized, so writing to stderr will be pointless.
--- Documentation/git-index-helper.txt | 3 +++ index-helper.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-)
Documentation/git-index-helper.txt +3 -0
@@ -54,6 +54,9 @@ command. The following commands are used to control the daemon: All commands and replies are terminated by a NUL byte. +In the event of an error, messages may be written to +$GIT_DIR/index-helper.log. + GIT --- Part of the linkgit:git[1] suite
index-helper.c +28 -4
@@ -19,6 +19,29 @@ static struct shm shm_index;static struct shm shm_base_index;static int to_verify =1 ; +static void log_warning (const char *warning, ...) +{ +va_list ap; +FILE *fp; + + fp =fopen (git_path ("index-helper.log" ),"a" ); +if (!fp) +/* +* Probably nobody will see this, but it's the best +* we can do. +*/ +die ("Failed to open log for warnings" ); + +fprintf (fp,"%" PRIuMAX"\t" , (uintmax_t )time (NULL )); + +va_start (ap, warning); +vfprintf (fp, warning, ap); +va_end (ap); + +fputc ('\n' , fp); +fclose (fp); +} +static void release_index_shm (struct shm *is) {if (!is->shm)
@@ -93,7 +116,8 @@ static void share_index(struct index_state *istate, struct shm *is)if (shared_mmap_create (istate->mmap_size, &new_mmap,git_path ("shm-index-%s" ,sha1_to_hex (istate->sha1))) <0 ) { -die ("Failed to create shm-index file" ); +log_warning ("Failed to create shm-index file" ); +exit (1 ); }
@@ -135,7 +159,7 @@ static int verify_shm(void) ce = istate.cache[i];if (ce->ce_namelen != base->ce_namelen ||strcmp (ce->name, base->name)) { -warning ("mismatch at entry %d" , i); +log_warning ("mismatch at entry %d" , i);break ; } ce_flags = ce->ce_flags;
@@ -149,7 +173,7 @@ static int verify_shm(void) ce->ce_flags = ce_flags; base->ce_flags = base_flags;if (ret) { -warning ("mismatch at entry %d" , i); +log_warning ("mismatch at entry %d" , i);break ; } }
@@ -255,7 +279,7 @@ static void loop(int fd, int idle_in_seconds)* alive, nothing to do. */ }else { -warning ("BUG: Bogus command %s" , buf); +log_warning ("BUG: Bogus command %s" , buf); } }else {/*
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 6/19 daemonize(): set a flag before exiting the main process
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
This allows signal handlers and atexit functions to realize this situation and not clean up.
--- builtin/gc.c | 2 +- cache.h | 2 +- daemon.c | 2 +- setup.c | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-)
builtin/gc.c +1 -1
@@ -385,7 +385,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)* failure to daemonize is ok, we'll continue * in foreground */ - daemonized = !daemonize (); + daemonized = !daemonize (NULL ); } }else add_repack_all_option ();
cache.h +1 -1
@@ -539,7 +539,7 @@ extern int set_git_dir_init(const char *git_dir, const char *real_git_dir, int);extern int init_db (const char *template_dir,unsigned int flags);extern void sanitize_stdfds (void ); -extern int daemonize (void ); +extern int daemonize (int *);#define alloc_nr (x) (((x)+16)*3/2)
daemon.c +1 -1
@@ -1365,7 +1365,7 @@ int main(int argc, char **argv)return execute ();if (detach) { -if (daemonize ()) +if (daemonize (NULL ))die ("--detach not supported on this platform" ); }else sanitize_stdfds ();
setup.c +3 -1
@@ -1017,7 +1017,7 @@ void sanitize_stdfds(void)close (fd); } -int daemonize (void ) +int daemonize (int *daemonized) {#ifdef NO_POSIX_GOODIES errno =ENOSYS ;
@@ -1029,6 +1029,8 @@ int daemonize(void)case -1 :die_errno ("fork failed" );default : +if (daemonized) + *daemonized =1 ;exit (0 ); }if (setsid () ==-1 )
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 7/19 index-helper: add --detach
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
We detach after creating and opening the socket, because otherwise we might return control to the shell before index-helper is ready to accept commands. This might lead to flaky tests.
--- Documentation/git-index-helper.txt | 3 +++ index-helper.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
Documentation/git-index-helper.txt +3 -0
@@ -34,6 +34,9 @@ OPTIONS for reading an index, but because it will happen in the background, it's not noticable. `--strict` is enabled by default. +--detach:: + Detach from the shell. + NOTES -----
index-helper.c +13 -2
@@ -17,7 +17,7 @@ struct shm {static struct shm shm_index;static struct shm shm_base_index; -static int to_verify =1 ; +static int daemonized, to_verify =1 ;static void log_warning (const char *warning, ...) {
@@ -59,6 +59,8 @@ static void cleanup_shm(void)static void cleanup (void ) { +if (daemonized) +return ;unlink (git_path ("index-helper.sock" ));cleanup_shm (); }
@@ -311,7 +313,7 @@ static const char * const usage_text[] = {int main (int argc,char **argv) {const char *prefix; -int idle_in_seconds =600 ; +int idle_in_seconds =600 , detach =0 ;int fd;struct strbuf socket_path =STRBUF_INIT ;struct option options[] = {
@@ -319,6 +321,7 @@ int main(int argc, char **argv) N_("exit if not used after some seconds")),OPT_BOOL (0 ,"strict" , &to_verify,"verify shared memory after creating" ), +OPT_BOOL (0 ,"detach" , &detach,"detach the process" ), OPT_END() };
@@ -342,6 +345,14 @@ int main(int argc, char **argv)if (fd <0 )die_errno (_ ("could not set up index-helper socket" )); +if (!freopen ("/dev/null" ,"w" , stderr)) +die_errno ("failed to redirect stderr to /dev/null" ); + +if (!freopen ("/dev/null" ,"w" , stdout)) +die_errno ("failed to redirect stdout to /dev/null" ); + +if (detach &&daemonize (&daemonized)) +die_errno (_ ("unable to detach" ));loop (fd, idle_in_seconds);close (fd);
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 8/19 read-cache: add watchman 'WAMA' extension
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
The extension contains a bitmap, one bit for each entry in the index. If the n-th bit is zero, the n-th entry is considered unchanged, we can ce_mark_uptodate() it without refreshing. If the bit is non-zero and we found out the corresponding file is clean after refresh, we can clear the bit.
In addition, there's a list of directories in the untracked-cache to invalidate (because they have new or modified entries).
The 'skipping refresh' bit is not in this patch yet as we would need watchman. More details in later patches.
--- Documentation/technical/index-format.txt | 22 ++++++ cache.h | 4 ++ dir.h | 3 + read-cache.c | 117 ++++++++++++++++++++++++++++++- 4 files changed, 144 insertions(+), 2 deletions(-)
Documentation/technical/index-format.txt +22 -0
@@ -295,3 +295,25 @@ The remaining data of each directory block is grouped by type: in the previous ewah bitmap. - One NUL. + +== Watchman cache + + The watchman cache tracks files for which watchman has told us about + changes. The signature for this extension is { 'W', 'A', 'M', 'A' }. + + The extension starts with + + - A NUL-terminated string: the watchman vector clock at the last + time we heard from watchman. + + - 32-bit bitmap size: the size of the CE_WATCHMAN_DIRTY bitmap + + - 32-bit untracked cache entry count: the number of dirty untracked + cache entries + + - An ewah bitmap, the n-th bit indicates whether the n-th index entry + is CE_WATCHMAN_DIRTY. + + - a list of N NUL-terminated strings. Each is a directory that should + be marked dirty in the untracked cache because watchman has told us + about an update to a file in it.
cache.h +4 -0
@@ -182,6 +182,8 @@ struct cache_entry {#define CE_VALID (0x8000)#define CE_STAGESHIFT 12 +#define CE_WATCHMAN_DIRTY (0x0001) +/* * Range 0xFFFF0FFF in ce_flags is divided into * two parts: in-memory flags and on-disk ones.
@@ -320,6 +322,7 @@ static inline unsigned int canon_mode(unsigned int mode)#define CACHE_TREE_CHANGED (1 << 5)#define SPLIT_INDEX_ORDERED (1 << 6)#define UNTRACKED_CHANGED (1 << 7) +#define WATCHMAN_CHANGED (1 << 8)struct split_index ;struct untracked_cache ;
@@ -353,6 +356,7 @@ struct index_state {struct untracked_cache *untracked;void *mmap;size_t mmap_size; +char *last_update; };extern struct index_state the_index;
dir.h +3 -0
@@ -142,6 +142,9 @@ struct untracked_cache {int gitignore_invalidated;int dir_invalidated;int dir_opened; +/* watchman invalidation data */ + unsigned int use_watchman : 1; +struct string_list invalid_untracked; };struct dir_struct {
read-cache.c +115 -2
164 lines not on this page · raw message
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 9/19 watchman: support watchman to reduce index refresh cost
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
The previous patch has the logic to clear bits in 'WAMA' bitmap. This patch has logic to set bits as told by watchman. The missing bit, _using_ these bits, are not here yet.
A lot of this code is written by David Turner originally, mostly from [1]. I'm just copying and polishing it a bit.
[1] http://article.gmane.org/gmane.comp.version-control.git/248006
--- Makefile | 12 +++++ cache.h | 1 + config.c | 5 ++ configure.ac | 8 ++++ environment.c | 3 ++ watchman-support.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ watchman-support.h | 7 +++ 7 files changed, 171 insertions(+) create mode 100644 watchman-support.c create mode 100644 watchman-support.h
Makefile +12 -0
@@ -451,6 +451,7 @@ MSGFMT = msgfmt CURL_CONFIG = curl-config PTHREAD_LIBS = -lpthread PTHREAD_CFLAGS = +WATCHMAN_LIBS = GCOV = gcov export TCL_PATH TCLTK_PATH
@@ -1416,6 +1417,13 @@ else LIB_OBJS += thread-utils.o endif +ifdef USE_WATCHMAN + LIB_H += watchman-support.h + LIB_OBJS += watchman-support.o + WATCHMAN_LIBS = -lwatchman + BASIC_CFLAGS += -DUSE_WATCHMAN +endif + ifdef HAVE_PATHS_H BASIC_CFLAGS += -DHAVE_PATHS_H endif
@@ -2025,6 +2033,9 @@ git-remote-testsvn$X: remote-testsvn.o GIT-LDFLAGS $(GITLIBS) $(VCSSVN_LIB) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) \ $(VCSSVN_LIB) +git-index-helper$X: index-helper.o GIT-LDFLAGS $(GITLIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(WATCHMAN_LIBS) + $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY) $(QUIET_LNCP)$(RM) $@ && \ ln $< $@ 2>/dev/null || \
@@ -2164,6 +2175,7 @@ GIT-BUILD-OPTIONS: FORCE @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+ @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+ @echo NO_MMAP=\''$(subst ','\'',$(subst ','\'',$(NO_MMAP)))'\' >>$@+ + @echo USE_WATCHMAN=\''$(subst ','\'',$(subst ','\'',$(USE_WATCHMAN)))'\' >>$@+ ifdef TEST_OUTPUT_DIRECTORY @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+ endif
cache.h +1 -0
@@ -696,6 +696,7 @@ extern char *git_replace_ref_base;extern int fsync_object_files;extern int core_preload_index; +extern int core_watchman_sync_timeout;extern int core_apply_sparse_checkout;extern int precomposed_unicode;extern int protect_hfs;
config.c +5 -0
@@ -882,6 +882,11 @@ static int git_default_core_config(const char *var, const char *value)return 0 ; } +if (!strcmp (var,"core.watchmansynctimeout" )) { + core_watchman_sync_timeout =git_config_int (var, value); +return 0 ; + } +if (!strcmp (var,"core.createobject" )) {if (!strcmp (value,"rename" )) object_creation_mode =OBJECT_CREATION_USES_RENAMES ;
configure.ac +8 -0
@@ -1099,6 +1099,14 @@ AC_COMPILE_IFELSE([BSD_SYSCTL_SRC], HAVE_BSD_SYSCTL=]) GIT_CONF_SUBST([HAVE_BSD_SYSCTL]) +# +# Check for watchman client library + +AC_CHECK_LIB([watchman], [watchman_connect], + [USE_WATCHMAN=YesPlease], + [USE_WATCHMAN=]) +GIT_CONF_SUBST([USE_WATCHMAN]) + ## Other checks. # Define USE_PIC if you need the main git objects to be built with -fPIC # in order to build and link perl/Git.so. x86-64 seems to need this.
environment.c +3 -0
@@ -94,6 +94,9 @@ int core_preload_index = 1;*/ int ignore_untracked_cache_config; +int core_watchman_sync_timeout =300 ; + +/* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg;static char *work_tree;
watchman-support.c new file +135 -0
135 lines not on this page · raw message
watchman-support.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef WATCHMAN_SUPPORT_H +#define WATCHMAN_SUPPORT_H + +struct index_state ; +int check_watchman (struct index_state *index); + +#endif /* WATCHMAN_SUPPORT_H */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 10/19 index-helper: use watchman to avoid refreshing index with lstat()
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
Watchman is hidden behind index-helper. Before git tries to read the index from shm, it notifies index-helper through the socket and waits for index-helper to prepare a file for sharing memory (with MAP_SHARED). index-helper then contacts watchman, updates 'WAMA' extension and put it in a separate file and wakes git up with a reply to git's socket.
Git uses this extension to not lstat unchanged entries. Git only trusts the 'WAMA' extension when it's received from the separate file, not from disk. Unmarked entries are "clean". Marked entries are dirty from watchman point of view. If it finds out some entries are 'watchman-dirty', but are really unchanged (e.g. the file was changed, then reverted back), then Git will clear the marking in 'WAMA' before writing it down.
Hiding watchman behind index-helper means you need both daemons. You can't run watchman alone. Not so good. But on the other hand, 'git' binary is not linked to watchman/json libraries, which is good for packaging. Core git package will run fine without watchman-related packages. If they need watchman, they can install git-index-helper and dependencies.
This also lets us trust anything in the untracked cache that we haven't marked invalid, saving those stat() calls.
Another reason for tying watchman to index-helper is, when used with untracked cache, we need to keep track of $GIT_WORK_TREE file listing. That kind of list can be kept in index-helper.
--- Documentation/git-index-helper.txt | 6 + cache.h | 2 + dir.c | 23 +++- dir.h | 3 + index-helper.c | 107 ++++++++++++++-- read-cache.c | 243 ++++++++++++++++++++++++++++++++++--- 6 files changed, 357 insertions(+), 27 deletions(-)
Documentation/git-index-helper.txt +6 -0
@@ -55,6 +55,12 @@ command. The following commands are used to control the daemon: Let the daemon know the index is to be read. It keeps the daemon alive longer, unless `--exit-after=0` is used. +"poke <path>": + Like "poke", but replies with "OK". If the index has the + watchman extension, index-helper queries watchman, then + prepares a shared memory object with the watchman index + extension before replying. + All commands and replies are terminated by a NUL byte. In the event of an error, messages may be written to
cache.h +2 -0
@@ -567,6 +567,7 @@ extern int daemonize(int *);/* Initialize and use the cache information */ struct lock_file ; +extern int verify_index (const struct index_state *);extern int read_index (struct index_state *);extern int read_index_preload (struct index_state *,const struct pathspec *pathspec); extern int do_read_index(struct index_state *istate, const char *path,
@@ -574,6 +575,7 @@ extern int do_read_index(struct index_state *istate, const char *path,extern int read_index_from (struct index_state *,const char *path);extern int is_index_unborn (struct index_state *);extern int read_index_unmerged (struct index_state *); +extern void write_watchman_ext (struct strbuf *sb,struct index_state *istate);#define COMMIT_LOCK (1 << 0)#define CLOSE_LOCK (1 << 1)extern int write_locked_index (struct index_state *,struct lock_file *lock,unsigned flags);
dir.c +19 -4
@@ -597,9 +597,9 @@ static void trim_trailing_spaces(char *buf)* * If "name" has the trailing slash, it'll be excluded in the search. */ -static struct untracked_cache_dir *lookup_untracked (struct untracked_cache *uc, -struct untracked_cache_dir *dir, -const char *name,int len) +struct untracked_cache_dir *lookup_untracked (struct untracked_cache *uc, +struct untracked_cache_dir *dir, +const char *name,int len) {int first, last;struct untracked_cache_dir *d;
@@ -1726,6 +1726,17 @@ static int valid_cached_dir(struct dir_struct *dir,if (!untracked)return 0 ; +if (dir->untracked->use_watchman) { +/* +* With watchman, we can trust the untracked cache's +* valid field. +*/ +if (untracked->valid) + goto skip_stat; +else +invalidate_directory (dir->untracked, untracked); + } +if (stat (path->len ? path->buf :"." , &st)) {invalidate_directory (dir->untracked, untracked);memset (&untracked->stat_data,0 ,sizeof (untracked->stat_data));
@@ -1739,6 +1750,7 @@ static int valid_cached_dir(struct dir_struct *dir,return 0 ; } +skip_stat:if (untracked->check_only != !!check_only) {invalidate_directory (dir->untracked, untracked);return 0 ;
@@ -2625,8 +2637,10 @@ static void free_untracked(struct untracked_cache_dir *ucd)void free_untracked_cache (struct untracked_cache *uc) { -if (uc) +if (uc) {free_untracked (uc->root); +string_list_clear (&uc->invalid_untracked,0 ); + }free (uc); }
@@ -2775,6 +2789,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned longreturn NULL ; uc =xcalloc (1 ,sizeof (*uc)); +string_list_init (&uc->invalid_untracked,1 );strbuf_init (&uc->ident, ident_len);strbuf_add (&uc->ident, ident, ident_len); load_sha1_stat(&uc->ss_info_exclude, &ouc->info_exclude_stat,
dir.h +3 -0
@@ -315,4 +315,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned longvoid write_untracked_extension (struct strbuf *out,struct untracked_cache *untracked);void add_untracked_cache (struct index_state *istate);void remove_untracked_cache (struct index_state *istate); +struct untracked_cache_dir *lookup_untracked (struct untracked_cache *uc, +struct untracked_cache_dir *dir, +const char *name,int len);#endif
index-helper.c +100 -7
151 lines not on this page · raw message
read-cache.c +227 -16
310 lines not on this page · raw message
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 11/19 update-index: enable/disable watchman support
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
--- Documentation/git-index-helper.txt | 3 +++ Documentation/git-update-index.txt | 6 ++++++ builtin/update-index.c | 16 ++++++++++++++++ 3 files changed, 25 insertions(+)
Documentation/git-index-helper.txt +3 -0
@@ -18,6 +18,9 @@ each with a submodule, you might need four index-helpers. (In practice, this is only worthwhile for large indexes, so only use it if you notice that git status is slow). +If you want the index-helper to accelerate untracked file checking, +run git update-index --watchman before using it. + OPTIONS -------
Documentation/git-update-index.txt +6 -0
@@ -19,6 +19,7 @@ SYNOPSIS [--ignore-submodules] [--[no-]split-index] [--[no-|test-|force-]untracked-cache] + [--[no-]watchman] [--really-refresh] [--unresolve] [--again | -g] [--info-only] [--index-info] [-z] [--stdin] [--index-version <n>]
@@ -176,6 +177,11 @@ may not support it yet. --no-untracked-cache:: Enable or disable untracked cache feature. Please use `--test-untracked-cache` before enabling it. + +--watchman:: +--no-watchman:: + Enable or disable watchman support. This is, at present, + only useful with git index-helper. + These options take effect whatever the value of the `core.untrackedCache` configuration variable (see linkgit:git-config[1]). But a warning is
builtin/update-index.c +16 -0
@@ -914,6 +914,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) {int newfd, entries, has_errors =0 , nul_term_line =0 ;enum uc_mode untracked_cache =UC_UNSPECIFIED ; +int use_watchman =-1 ;int read_from_stdin =0 ;int prefix_length = prefix ?strlen (prefix) :0 ;int preferred_index_format =0 ;
@@ -1012,6 +1013,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) N_("test if the filesystem supports untracked cache"), UC_TEST),OPT_SET_INT (0 ,"force-untracked-cache" , &untracked_cache,N_ ("enable untracked cache without testing the filesystem" ),UC_FORCE ), +OPT_BOOL (0 ,"watchman" , &use_watchman, +N_ ("use or not use watchman to reduce refresh cost" )), OPT_END() };
@@ -1149,6 +1152,19 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)die ("Bug: bad untracked_cache value: %d" , untracked_cache); } +if (use_watchman >0 ) { + the_index.last_update =xstrdup ("" ); + the_index.cache_changed |=WATCHMAN_CHANGED ; +#ifndef USE_WATCHMAN +warning ("git was built without watchman support -- I'm " +"adding the extension here, but it probably won't " +"do you any good." ); +#endif + }else if (!use_watchman) { + the_index.last_update =NULL ; + the_index.cache_changed |=WATCHMAN_CHANGED ; + } +if (active_cache_changed) {if (newfd <0 ) {if (refresh_args.flags &REFRESH_QUIET )
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 12/19 unpack-trees: preserve index extensions
In reply to David TurnerMake git checkout (and other unpack_tree operations) preserve the untracked cache and watchman status. This is valuable for two reasons:
1. Often, an unpack_tree operation will not touch large parts of the working tree, and thus most of the untracked cache will continue to be valid.
2. Even if the untracked cache were entirely invalidated by such an operation, the user has signaled their intention to have such a cache, and we don't want to throw it away.
The same logic applies to the watchman state.
--- cache.h | 1 + read-cache.c | 8 ++++++++ t/t7063-status-untracked-cache.sh | 22 ++++++++++++++++++++++ t/test-lib-functions.sh | 4 ++++ unpack-trees.c | 1 + 5 files changed, 36 insertions(+)
cache.h +1 -0
@@ -580,6 +580,7 @@ extern void write_watchman_ext(struct strbuf *sb, struct index_state *istate);#define CLOSE_LOCK (1 << 1)extern int write_locked_index (struct index_state *,struct lock_file *lock,unsigned flags);extern int discard_index (struct index_state *); +extern void move_index_extensions (struct index_state *dst,struct index_state *src);extern int unmerged_index (const struct index_state *);extern int verify_path (const char *path);extern int index_dir_exists (struct index_state *istate,const char *name,int namelen);
read-cache.c +8 -0
@@ -2769,3 +2769,11 @@ void stat_validity_update(struct stat_validity *sv, int fd)fill_stat_data (sv->sd, &st); } } + +void move_index_extensions (struct index_state *dst,struct index_state *src) +{ + dst->untracked = src->untracked; + src->untracked =NULL ; + dst->last_update = src->last_update; + src->last_update =NULL ; +}
t/t7063-status-untracked-cache.sh +22 -0
@@ -646,4 +646,26 @@ test_expect_success 'test ident field is working' ' test_cmp ../expect ../err ' +test_expect_success 'untracked cache survives a checkout' ' + git commit --allow-empty -m empty && + test-dump-untracked-cache >../before && + test_when_finished "git checkout master" && + git checkout -b other_branch && + test-dump-untracked-cache >../after && + test_cmp ../before ../after && + test_commit test && + test-dump-untracked-cache >../before && + git checkout master && + test-dump-untracked-cache >../after && + test_cmp ../before ../after +' + +test_expect_success 'untracked cache survives a commit' ' + test-dump-untracked-cache >../before && + git add done/two && + git commit -m commit && + test-dump-untracked-cache >../after && + test_cmp ../before ../after +' + test_done
t/test-lib-functions.sh +4 -0
@@ -186,6 +186,10 @@ test_commit () { test_tick fi && git commit $signoff -m "$1" && + if [ "$(git config core.bare)" = false ] + then + git update-index --force-untracked-cache + fi git tag "${4:-$1}" }
unpack-trees.c +1 -0
@@ -1215,6 +1215,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_optionsWRITE_TREE_SILENT | WRITE_TREE_REPAIR); } +move_index_extensions (&o->result, o->dst_index);discard_index (o->dst_index); *o->dst_index = o->result; }else {
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 13/19 watchman: add a config option to enable the extension
In reply to David TurnerFor installations that have centrally-managed configuration, it's easier to set a config once than to run update-index on every repository.
--- .gitignore | 1 + Documentation/config.txt | 4 ++++ Makefile | 1 + read-cache.c | 6 ++++++ t/t1701-watchman-extension.sh | 37 +++++++++++++++++++++++++++++++++++++ test-dump-watchman.c | 16 ++++++++++++++++ 6 files changed, 65 insertions(+) create mode 100755 t/t1701-watchman-extension.sh create mode 100644 test-dump-watchman.c
.gitignore +1 -0
@@ -188,6 +188,7 @@ /test-dump-cache-tree /test-dump-split-index /test-dump-untracked-cache +/test-dump-watchman /test-fake-ssh /test-scrap-cache-tree /test-genrandom
Documentation/config.txt +4 -0
@@ -1848,6 +1848,10 @@ imap:: The configuration variables in the 'imap' section are described in linkgit:git-imap-send[1]. +index.addwatchmanextension:: + Automatically add the watchman extension to the index whenever + it is written. + index.version:: Specify the version with which new index files should be initialized. This does not affect existing repositories.
Makefile +1 -0
@@ -599,6 +599,7 @@ TEST_PROGRAMS_NEED_X += test-delta TEST_PROGRAMS_NEED_X += test-dump-cache-tree TEST_PROGRAMS_NEED_X += test-dump-split-index TEST_PROGRAMS_NEED_X += test-dump-untracked-cache +TEST_PROGRAMS_NEED_X += test-dump-watchman TEST_PROGRAMS_NEED_X += test-fake-ssh TEST_PROGRAMS_NEED_X += test-genrandom TEST_PROGRAMS_NEED_X += test-hashmap
read-cache.c +6 -0
@@ -2428,6 +2428,7 @@ static int do_write_index(struct index_state *istate, int newfd,int entries = istate->cache_nr;struct stat st;struct strbuf previous_name_buf =STRBUF_INIT , *previous_name; +int watchman =0 ;for (i = removed = extended =0 ; i < entries; i++) {if (cache[i]->ce_flags &CE_REMOVE )
@@ -2451,6 +2452,11 @@ static int do_write_index(struct index_state *istate, int newfd,if (istate->version ==3 || istate->version ==2 ) istate->version = extended ?3 :2 ; +if (!git_config_get_bool ("index.addwatchmanextension" , &watchman) && + watchman && + !the_index.last_update) + the_index.last_update =xstrdup ("" ); + hdr_version = istate->version; hdr.hdr_signature =htonl (CACHE_SIGNATURE );
t/t1701-watchman-extension.sh new file +37 -0
@@ -0,0 +1,37 @@ +#!/bin/sh + +test_description='watchman extension smoke tests' + +# These don't actually test watchman interaction -- just the +# index extension + +. ./test-lib.sh + +test_expect_success 'enable watchman' ' + test_commit a && + test-dump-watchman .git/index >actual && + echo "last_update: (null)" >expect && + test_cmp expect actual && + git update-index --watchman && + test-dump-watchman .git/index >actual && + echo "last_update: " >expect && + test_cmp expect actual +' + +test_expect_success 'disable watchman' ' + git update-index --no-watchman && + test-dump-watchman .git/index >actual && + echo "last_update: (null)" >expect && + test_cmp expect actual +' + +test_expect_success 'auto-enable watchman' ' + test_config index.addwatchmanextension true && + test_commit c && + test-dump-watchman .git/index >actual && + echo "last_update: " >expect && + test_cmp expect actual +' + + +test_done
test-dump-watchman.c new file +16 -0
@@ -0,0 +1,16 @@ +#include "cache.h" +#include "ewah/ewok.h" + +int main (int argc,char **argv) +{ +do_read_index (&the_index, argv[1 ],1 ); +printf ("last_update: %s\n" , the_index.last_update ? + the_index.last_update :"(null)" ); + +/* +* For now, we just dump last_update, since it is not reasonable +* to populate the extension itself in tests. +*/ + +return 0 ; +}
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 14/19 index-helper: kill mode
In reply to David TurnerAdd a new command (and command-line arg) to allow index-helpers to exit cleanly.
This is mainly useful for tests.
--- Documentation/git-index-helper.txt | 3 +++ index-helper.c | 31 ++++++++++++++++++++++++++++++- t/t7900-index-helper.sh | 9 +++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
Documentation/git-index-helper.txt +3 -0
@@ -40,6 +40,9 @@ OPTIONS --detach:: Detach from the shell. +--kill:: + Kill any running index-helper and clean up the socket + NOTES -----
index-helper.c +30 -1
@@ -373,6 +373,8 @@ static void loop(int fd, int idle_in_seconds)* alive, nothing to do. */ } + }else if (!strcmp (buf,"die" )) { +break ; }else {log_warning ("BUG: Bogus command %s" , buf); }
@@ -403,10 +405,29 @@ static const char * const usage_text[] = {NULL }; +static void request_kill (void ) +{ +int fd =unix_stream_connect (git_path ("index-helper.sock" )); + +if (fd >=0 ) { +write_in_full (fd,"die" ,4 ); +close (fd); + } + +/* +* The child will try to do this anyway, but we want to be +* ready to launch a new daemon immediately after this command +* returns. +*/ + +unlink (git_path ("index-helper.sock" )); +return ; +} +int main (int argc,char **argv) {const char *prefix; -int idle_in_seconds =600 , detach =0 ; +int idle_in_seconds =600 , detach =0 , kill =0 ;int fd;struct strbuf socket_path =STRBUF_INIT ;struct option options[] = {
@@ -415,6 +436,7 @@ int main(int argc, char **argv)OPT_BOOL (0 ,"strict" , &to_verify,"verify shared memory after creating" ),OPT_BOOL (0 ,"detach" , &detach,"detach the process" ), +OPT_BOOL (0 ,"kill" , &kill,"request that existing index helper processes exit" ), OPT_END() };
@@ -429,6 +451,13 @@ int main(int argc, char **argv) options, usage_text, 0))die (_ ("too many arguments" )); +if (kill) { +if (detach) +die (_ ("--kill doesn't want any other options" )); +request_kill (); +return 0 ; + } +atexit (cleanup);sigchain_push_common (cleanup_on_signal);
t/t7900-index-helper.sh +9 -0
@@ -20,4 +20,13 @@ test_expect_success 'index-helper smoke test' ' test_path_is_missing .git/index-helper.sock ' +test_expect_success 'index-helper creates usable path file and can be killed' ' + test_when_finished "git index-helper --kill" && + test_path_is_missing .git/index-helper.sock && + git index-helper --detach && + test -S .git/index-helper.sock && + git index-helper --kill && + test_path_is_missing .git/index-helper.sock +' + test_done
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 15/19 index-helper: don't run if already running
In reply to David Turner--- index-helper.c | 7 +++++++ t/t7900-index-helper.sh | 9 +++++++++ 2 files changed, 16 insertions(+)
index-helper.c +7 -0
@@ -458,6 +458,13 @@ int main(int argc, char **argv)return 0 ; } +/* check that no other copy is running */ + fd =unix_stream_connect (git_path ("index-helper.sock" )); +if (fd >0 ) +die (_ ("Already running" )); +if (errno !=ECONNREFUSED && errno !=ENOENT ) +die_errno (_ ("Unexpected error checking socket" )); +atexit (cleanup);sigchain_push_common (cleanup_on_signal);
t/t7900-index-helper.sh +9 -0
@@ -29,4 +29,13 @@ test_expect_success 'index-helper creates usable path file and can be killed' ' test_path_is_missing .git/index-helper.sock ' +test_expect_success 'index-helper will not start if already running' ' + test_when_finished "git index-helper --kill" && + git index-helper --detach && + test -S .git/index-helper.sock && + test_must_fail git index-helper 2>err && + test -S .git/index-helper.sock && + grep "Already running" err +' + test_done
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 16/19 index-helper: autorun mode
In reply to David TurnerSoon, we'll want to automatically start index-helper, so we need a mode that silently exits if it can't start up (either because it's not in a git dir, or because another one is already running).
--- Documentation/git-index-helper.txt | 4 ++++ index-helper.c | 29 +++++++++++++++++++++++------ t/t7900-index-helper.sh | 8 ++++++++ 3 files changed, 35 insertions(+), 6 deletions(-)
Documentation/git-index-helper.txt +4 -0
@@ -43,6 +43,10 @@ OPTIONS --kill:: Kill any running index-helper and clean up the socket +--autorun:: + If index-helper is not already running, start it. Else, do + nothing. + NOTES -----
index-helper.c +23 -6
@@ -427,8 +427,9 @@ static void request_kill(void) int main(int argc, char **argv) { const char *prefix; - int idle_in_seconds = 600, detach = 0, kill = 0; + int idle_in_seconds = 600, detach = 0, kill = 0, autorun = 0; int fd; + int nongit; struct strbuf socket_path = STRBUF_INIT; struct option options[] = { OPT_INTEGER(0, "exit-after", &idle_in_seconds,
@@ -437,6 +438,7 @@ int main(int argc, char **argv) "verify shared memory after creating"),OPT_BOOL (0 ,"detach" , &detach,"detach the process" ),OPT_BOOL (0 ,"kill" , &kill,"request that existing index helper processes exit" ), +OPT_BOOL (0 ,"autorun" , &autorun,"this is an automatic run of git index-helper, so certain errors can be solved by silently exiting" ), OPT_END() };
@@ -446,7 +448,14 @@ int main(int argc, char **argv)if (argc ==2 && !strcmp (argv[1 ],"-h" ))usage_with_options (usage_text, options); - prefix =setup_git_directory (); + prefix =setup_git_directory_gently (&nongit); +if (nongit) { +if (autorun) +exit (0 ); +else +die (_ ("not a git repository" )); + } +if (parse_options (argc, (const char **)argv, prefix, options, usage_text,0 ))die (_ ("too many arguments" ));
@@ -460,10 +469,18 @@ int main(int argc, char **argv)/* check that no other copy is running */ fd =unix_stream_connect (git_path ("index-helper.sock" )); -if (fd >0 ) -die (_ ("Already running" )); -if (errno !=ECONNREFUSED && errno !=ENOENT ) -die_errno (_ ("Unexpected error checking socket" )); +if (fd >0 ) { +if (autorun) +exit (0 ); +else +die (_ ("Already running" )); + } +if (errno !=ECONNREFUSED && errno !=ENOENT ) { +if (autorun) +return 0 ; +else +die_errno (_ ("Unexpected error checking socket" )); + }atexit (cleanup);sigchain_push_common (cleanup_on_signal);
t/t7900-index-helper.sh +8 -0
@@ -38,4 +38,12 @@ test_expect_success 'index-helper will not start if already running' ' grep "Already running" err ' +test_expect_success 'index-helper is quiet with --autorun' ' + test_when_finished "git index-helper --kill" && + git index-helper --kill && + git index-helper --detach && + test -S .git/index-helper.sock && + git index-helper --autorun +' + test_done
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 17/19 index-helper: optionally automatically run
In reply to David TurnerIntroduce a new config option, indexhelper.autorun, to automatically run git index-helper before starting up a builtin git command. This enables users to keep index-helper running without manual intervention.
--- Documentation/config.txt | 4 ++++ read-cache.c | 37 +++++++++++++++++++++++++++++++++++-- t/t7900-index-helper.sh | 20 ++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-)
Documentation/config.txt +4 -0
@@ -1856,6 +1856,10 @@ index.version:: Specify the version with which new index files should be initialized. This does not affect existing repositories. +indexhelper.autorun:: + Automatically run git index-helper when any builtin git + command is run inside a repository. + init.templateDir:: Specify the directory from which templates will be copied. (See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)
read-cache.c +35 -2
@@ -22,6 +22,7 @@#include "pkt-line.h" #include "sigchain.h" #include "ewah/ewok.h" +#include "run-command.h" static struct cache_entry *refresh_cache_entry (struct cache_entry *ce,unsigned int options);
@@ -1723,6 +1724,33 @@ static void post_read_index_from(struct index_state *istate)tweak_untracked_cache (istate); } +static int want_auto_index_helper (void ) +{ +int want =-1 ; +const char *value =NULL ; +const char *key ="indexhelper.autorun" ; + +if (git_config_key_is_valid (key) && + !git_config_get_value (key, &value)) { +int b =git_config_maybe_bool (key, value); + want = b >=0 ? b :0 ; + } +return want; +} + +static void autorun_index_helper (void ) +{ +const char *argv[] = {"git-index-helper" ,"--detach" ,"--autorun" ,NULL }; +if (want_auto_index_helper () <=0 ) +return ; + +trace_argv_printf (argv,"trace: auto index-helper:" ); + +if (run_command_v_opt (argv, +RUN_SILENT_EXEC_FAILURE |RUN_CLEAN_ON_EXIT )) +warning (_ ("You specified indexhelper.autorun, but running git-index-helper failed." )); +} +/* in ms */ #define WATCHMAN_TIMEOUT 1000
@@ -1796,6 +1824,7 @@ static int poke_daemon(struct index_state *istate,if (fd <0 ) {warning ("Failed to connect to index-helper socket" );unlink (git_path ("index-helper.sock" )); +autorun_index_helper ();return -1 ; }sigchain_push (SIGPIPE ,SIG_IGN );
@@ -1835,9 +1864,13 @@ static int try_shm(struct index_state *istate)int fd =-1 ;if (!is_main_index (istate) || - old_size <=20 || -stat (git_path ("index-helper.sock" ), &st)) + old_size <=20 )return -1 ; + +if (stat (git_path ("index-helper.sock" ), &st)) { +autorun_index_helper (); +return -1 ; + }if (poke_daemon (istate, &st,0 ))return -1 ; sha1 = (unsigned char *)istate->mmap + old_size -20 ;
t/t7900-index-helper.sh +20 -0
@@ -16,6 +16,9 @@ test -n "$NO_MMAP" && { } test_expect_success 'index-helper smoke test' ' + # We need an existing commit so that the index exists (otherwise, + # the index-helper will not be autostarted) + test_commit x && git index-helper --exit-after 1 && test_path_is_missing .git/index-helper.sock '
@@ -46,4 +49,21 @@ test_expect_success 'index-helper is quiet with --autorun' ' git index-helper --autorun ' +test_expect_success 'index-helper autorun works' ' + test_when_finished "git index-helper --kill" && + rm -f .git/index-helper.sock && + git status && + test_path_is_missing .git/index-helper.sock && + test_config indexhelper.autorun true && + git status && + test -S .git/index-helper.sock && + git status 2>err && + test -S .git/index-helper.sock && + test_must_be_empty err && + git index-helper --kill && + test_config indexhelper.autorun false && + git status && + test_path_is_missing .git/index-helper.sock +' + test_done
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 18/19 trace: measure where the time is spent in the index-heavy operations
In reply to David TurnerFrom: Nguyễn Thái Ngọc Duy <[email protected]>
All the known heavy code blocks are measured (except object database access). This should help identify if an optimization is effective or not. An unoptimized git-status would give something like below (92% of time is accounted). To sum up the effort of making git scale better:
- read cache line is being addressed by index-helper
- preload/refresh index by watchman
- read packed refs by lmdb backend
- diff-index by rebuilding cache-tree
- read directory by untracked cache and watchman
- write index by split index
- name hash potientially by index-helper
read-cache.c:2075 performance: 0.004058570 s: read cache .../index preload-index.c:104 performance: 0.004419864 s: preload index read-cache.c:1265 performance: 0.000185224 s: refresh index refs/files-backend.c:1100 performance: 0.001935788 s: read packed refs diff-lib.c:240 performance: 0.000144132 s: diff-files diff-lib.c:506 performance: 0.013592000 s: diff-index name-hash.c:128 performance: 0.000614177 s: initialize name hash dir.c:2030 performance: 0.015814103 s: read directory read-cache.c:2565 performance: 0.004052343 s: write index, changed mask = 2 trace.c:420 performance: 0.048365509 s: git command: './git' 'status'
--- diff-lib.c | 4 ++++ dir.c | 2 ++ name-hash.c | 2 ++ preload-index.c | 2 ++ read-cache.c | 11 +++++++++++ refs/files-backend.c | 2 ++ 6 files changed, 23 insertions(+)
diff-lib.c +4 -0
@@ -90,6 +90,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)int diff_unmerged_stage = revs->max_count;unsigned ce_option = ((option &DIFF_RACY_IS_MODIFIED ) ?CE_MATCH_RACY_IS_DIRTY :0 ); +uint64_t start =getnanotime ();diff_set_mnemonic_prefix (&revs->diffopt,"i/" ,"w/" );
@@ -236,6 +237,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) }diffcore_std (&revs->diffopt);diff_flush (&revs->diffopt); +trace_performance_since (start,"diff-files" );return 0 ; }
@@ -491,6 +493,7 @@ static int diff_cache(struct rev_info *revs,int run_diff_index (struct rev_info *revs,int cached) {struct object_array_entry *ent; +uint64_t start =getnanotime (); ent = revs->pending.objects;if (diff_cache (revs, ent->item->oid.hash, ent->name, cached))
@@ -500,6 +503,7 @@ int run_diff_index(struct rev_info *revs, int cached)diffcore_fix_diff_index (&revs->diffopt);diffcore_std (&revs->diffopt);diff_flush (&revs->diffopt); +trace_performance_since (start,"diff-index" );return 0 ; }
dir.c +2 -0
@@ -2183,6 +2183,7 @@ int read_directory(struct dir_struct *dir, const char *path, int len, const stru {struct path_simplify *simplify;struct untracked_cache_dir *untracked; +uint64_t start =getnanotime ();/* * Check out create_simplify()
@@ -2224,6 +2225,7 @@ int read_directory(struct dir_struct *dir, const char *path, int len, const strufree_simplify (simplify);qsort (dir->entries, dir->nr,sizeof (struct dir_entry *), cmp_name);qsort (dir->ignored, dir->ignored_nr,sizeof (struct dir_entry *), cmp_name); +trace_performance_since (start,"read directory %.*s" , len, path);if (dir->untracked) {static struct trace_key trace_untracked_stats =TRACE_KEY_INIT (UNTRACKED_STATS ); trace_printf_key(&trace_untracked_stats,
name-hash.c +2 -0
@@ -115,6 +115,7 @@ static int cache_entry_cmp(const struct cache_entry *ce1,static void lazy_init_name_hash (struct index_state *istate) {int nr; +uint64_t start =getnanotime ();if (istate->name_hash_initialized)return ;
@@ -124,6 +125,7 @@ static void lazy_init_name_hash(struct index_state *istate)for (nr =0 ; nr < istate->cache_nr; nr++)hash_index_entry (istate, istate->cache[nr]); istate->name_hash_initialized =1 ; +trace_performance_since (start,"initialize name hash" ); }void add_name_hash (struct index_state *istate,struct cache_entry *ce)
preload-index.c +2 -0
@@ -72,6 +72,7 @@ static void preload_index(struct index_state *index, {int threads, i, work, offset;struct thread_data data[MAX_PARALLEL ]; +uint64_t start =getnanotime ();if (!core_preload_index)return ;
@@ -100,6 +101,7 @@ static void preload_index(struct index_state *index,if (pthread_join (p->pthread,NULL )) die("unable to join threaded lstat"); } +trace_performance_since (start,"preload index" ); }#endif
read-cache.c +11 -0
@@ -1189,6 +1189,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,const char *typechange_fmt;const char *added_fmt;const char *unmerged_fmt; +uint64_t start =getnanotime (); modified_fmt = (in_porcelain ?"M\t%s\n" :"%s: needs update\n" ); deleted_fmt = (in_porcelain ?"D\t%s\n" :"%s: needs update\n" );
@@ -1263,6 +1264,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,replace_index_entry (istate, i, new); } +trace_performance_since (start,"refresh index" );return has_errors; }
@@ -2086,12 +2088,15 @@ int read_index_from(struct index_state *istate, const char *path) {struct split_index *split_index;int ret; +uint64_t start;/* istate->initialized covers both .git/index and .git/sharedindex.xxx */ if (istate->initialized)return istate->cache_nr; + start =getnanotime (); ret =do_read_index (istate, path,0 ); +trace_performance_since (start,"read cache %s" , path); split_index = istate->split_index;if (!split_index ||is_null_sha1 (split_index->base_sha1)) {
@@ -2106,6 +2111,7 @@ int read_index_from(struct index_state *istate, const char *path) split_index->base->keep_mmap = istate->keep_mmap; split_index->base->to_shm = istate->to_shm; split_index->base->from_shm = istate->from_shm; + start =getnanotime (); ret =do_read_index (split_index->base,git_path ("sharedindex.%s" ,sha1_to_hex (split_index->base_sha1)),1 );
@@ -2117,6 +2123,9 @@ int read_index_from(struct index_state *istate, const char *path) sha1_to_hex(split_index->base->sha1));merge_base_index (istate);post_read_index_from (istate); +trace_performance_since (start,"read cache %s" , +git_path ("sharedindex.%s" , +sha1_to_hex (split_index->base_sha1))); done:if (ret >0 && istate->from_shm && istate->last_update)
@@ -2462,6 +2471,7 @@ static int do_write_index(struct index_state *istate, int newfd,struct stat st;struct strbuf previous_name_buf =STRBUF_INIT , *previous_name;int watchman =0 ; +uint64_t start =getnanotime ();for (i = removed = extended =0 ; i < entries; i++) {if (cache[i]->ce_flags &CE_REMOVE )
@@ -2582,6 +2592,7 @@ static int do_write_index(struct index_state *istate, int newfd,return -1 ; istate->timestamp.sec = (unsigned int )st.st_mtime; istate->timestamp.nsec =ST_MTIME_NSEC (st); +trace_performance_since (start,"write index, changed mask = %x" , istate->cache_changed);return 0 ; }
refs/files-backend.c +2 -0
@@ -1048,6 +1048,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)struct ref_entry *last =NULL ;struct strbuf line =STRBUF_INIT ;enum {PEELED_NONE ,PEELED_TAGS ,PEELED_FULLY } peeled =PEELED_NONE ; +uint64_t start =getnanotime ();while (strbuf_getwholeline (&line, f,'\n' ) !=EOF ) {unsigned char sha1[20 ];
@@ -1096,6 +1097,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir) }strbuf_release (&line); +trace_performance_since (start,"read packed refs" ); }/*
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v9 19/19 untracked-cache: config option
In reply to David TurnerAdd a config option to populate the untracked cache.
For installations that have centrally-managed configuration, it's easier to set a config once than to run update-index on every repository.
--- Documentation/config.txt | 4 ++++ read-cache.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
Documentation/config.txt +4 -0
@@ -1848,6 +1848,10 @@ imap:: The configuration variables in the 'imap' section are described in linkgit:git-imap-send[1]. +index.adduntrackedcache:: + Automatically populate the untracked cache whenever the index + is written. + index.addwatchmanextension:: Automatically add the watchman extension to the index whenever it is written.
read-cache.c +6 -1
@@ -2470,7 +2470,7 @@ static int do_write_index(struct index_state *istate, int newfd,int entries = istate->cache_nr;struct stat st;struct strbuf previous_name_buf =STRBUF_INIT , *previous_name; -int watchman =0 ; +int watchman =0 , untracked =0 ;uint64_t start =getnanotime ();for (i = removed = extended =0 ; i < entries; i++) {
@@ -2500,6 +2500,11 @@ static int do_write_index(struct index_state *istate, int newfd, !the_index.last_update) the_index.last_update =xstrdup ("" ); +if (!git_config_get_bool ("index.adduntrackedcache" , &untracked) && + untracked && + !istate->untracked) +add_untracked_cache (&the_index); + hdr_version = istate->version; hdr.hdr_signature =htonl (CACHE_SIGNATURE );
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
Hmmm, I seem to be getting
$ cat t/trash*7900*/err
fatal: Already runningafter running t7900 and it fails at #5, after applying "index-helper: optionally automatically run".
Quoted 7 lines · Junio C Hamano
Hmmm, I seem to be getting
$ cat t/trash*7900*/err fatal: Already runningafter running t7900 and it fails at #5, after applying "index-helper: optionally automatically run"
It still passes for me (with or without USE_WATCHMAN set). I'm testing on Ubuntu 15.10 with "Linux ubuntu 4.2.0-35-generic", on an ext4 filesystem.
Does it fail before or after git status 2>err ? (If before, then those "err" contents are from the previous test).
Is index-helper in fact running after the test fails?
Can you tell me a little about your system? I'm not even sure what would be useful here, but if I could set up a similarly-configured vm, I could try to repro.
Thanks, and sorry for the failures.
Quoted 6 lines · David Turner
Quoted 5 lines · Junio C Hamano
Hmmm, I seem to be getting
$ cat t/trash*7900*/err fatal: Already running
Quoted 6 lines
Quoted 2 lines
after running t7900 and it fails at #5, after applying "index-helper: optionally automatically run"
It still passes for me (with or without
USE_WATCHMANset). I'm testing on Ubuntu 15.10 with "Linux ubuntu 4.2.0-35-generic", on an ext4 filesystem.
It passes on one box and fails on another. They both run the same Ubuntu 14.04 derivative, with same ext3 filesystem. The failing one is on a VM.
Quoted 2 lines
Does it fail before or after git status 2>err ? (If before, then those "err" contents are from the previous test).
I didn't dig and I do not know (yet).
Quoted 1 line
Is index-helper in fact running after the test fails?
"ps ax | grep index-helper" showed a process, which I had to "kill" manually.
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · David Turner
Quoted 7 lines · Junio C Hamano
Hmmm, I seem to be getting
$ cat t/trash*7900*/err fatal: Already runningafter running t7900 and it fails at #5, after applying "index-helper: optionally automatically run"
The symptom looks pretty similar to $gmane/293461 reported earlier. Here is how "t7900-index-helper.sh -i -v -x -d" ends.
expecting success:
test_when_finished "git index-helper --kill" &&
rm -f .git/index-helper.sock &&
git status &&
test_path_is_missing .git/index-helper.sock &&
test_config indexhelper.autorun true &&
git status &&
test -S .git/index-helper.sock &&
git status 2>err &&
test -S .git/index-helper.sock &&
test_must_be_empty err &&
git index-helper --kill &&
test_config indexhelper.autorun false &&
git status &&
test_path_is_missing .git/index-helper.sock+ test_when_finished git index-helper --kill
+ test 0 = 0
+ test_cleanup={ git index-helper --kill
} && (exit "$eval_ret"); eval_ret=$?; :
+ rm -f .git/index-helper.sock
+ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
err
nothing added to commit but untracked files present (use "git add" to track)
+ test_path_is_missing .git/index-helper.sock
+ test -e .git/index-helper.sock
+ test_config indexhelper.autorun true
+ config_dir=
+ test indexhelper.autorun = -C
+ test_when_finished test_unconfig 'indexhelper.autorun'
+ test 0 = 0
+ test_cleanup={ test_unconfig 'indexhelper.autorun'
} && (exit "$eval_ret"); eval_ret=$?; { git index-helper --kill
} && (exit "$eval_ret"); eval_ret=$?; :+ git config indexhelper.autorun true
+ git status
error: last command exited with $?=141
not ok 5 - index-helper autorun works
#
# test_when_finished "git index-helper --kill" && # rm -f .git/index-helper.sock && # git status && # test_path_is_missing .git/index-helper.sock && # test_config indexhelper.autorun true && # git status && # test -S .git/index-helper.sock && # git status 2>err && # test -S .git/index-helper.sock && # test_must_be_empty err && # git index-helper --kill && # test_config indexhelper.autorun false && # git status && # test_path_is_missing .git/index-helper.sock
#
:
Quoted 55 lines · Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · David Turner
Quoted 7 lines · Junio C Hamano
Hmmm, I seem to be getting
$ cat t/trash*7900*/err fatal: Already runningafter running t7900 and it fails at #5, after applying "index-helper: optionally automatically run"
The symptom looks pretty similar to $gmane/293461 reported earlier. Here is how "
t7900-index-helper.sh-i -v -x -d" ends.expecting success:
test_when_finished "git index-helper --kill" && rm -f .git/index-helper.sock && git status && test_path_is_missing .git/index-helper.sock && test_config indexhelper.autorun true && git status && test -S .git/index-helper.sock && git status 2>err && test -S .git/index-helper.sock && test_must_be_empty err && git index-helper --kill && test_config indexhelper.autorun false && git status && test_path_is_missing .git/index-helper.sock+
test_when_finishedgit index-helper --kill
+ test 0 = 0
+ test_cleanup={ git index-helper --kill} && (exit "$eval_ret"); eval_ret=$?; :+ rm -f .git/index-helper.sock
+ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)err
nothing added to commit but untracked files present (use "git add" to track)
+test_path_is_missing.git/index-helper.sock
+ test -e .git/index-helper.sock
+test_configindexhelper.autorun true
+ config_dir=
+ test indexhelper.autorun = -C
+test_when_finishedtest_unconfig'indexhelper.autorun'
+ test 0 = 0
+ test_cleanup={test_unconfig'indexhelper.autorun'
Quoted 6 lines
} && (exit "$eval_ret"); eval_ret=$?; { git index -helper --kill } && (exit "$eval_ret"); eval_ret=$?; :+ git config indexhelper.autorun true
+ git status
error: last command exited with $?=141
I think that's a SIGPIPE on the first git status. Weird, since I just added sigpipe-avoidance code (in v8). Does anyone have any idea why the sigchain stuff isn't doing what I think it is?
Quoted 63 lines · David Turner
Quoted 55 lines · Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · David Turner
Quoted 7 lines · Junio C Hamano
Hmmm, I seem to be getting
$ cat t/trash*7900*/err fatal: Already runningafter running t7900 and it fails at #5, after applying "index-helper: optionally automatically run"
The symptom looks pretty similar to $gmane/293461 reported earlier. Here is how "
t7900-index-helper.sh-i -v -x -d" ends.expecting success:
test_when_finished "git index-helper --kill" && rm -f .git/index-helper.sock && git status && test_path_is_missing .git/index-helper.sock && test_config indexhelper.autorun true && git status && test -S .git/index-helper.sock && git status 2>err && test -S .git/index-helper.sock && test_must_be_empty err && git index-helper --kill && test_config indexhelper.autorun false && git status && test_path_is_missing .git/index-helper.sock+
test_when_finishedgit index-helper --kill
+ test 0 = 0
+ test_cleanup={ git index-helper --kill} && (exit "$eval_ret"); eval_ret=$?; :+ rm -f .git/index-helper.sock
+ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)err
nothing added to commit but untracked files present (use "git add" to track)
+test_path_is_missing.git/index-helper.sock
+ test -e .git/index-helper.sock
+test_configindexhelper.autorun true
+ config_dir=
+ test indexhelper.autorun = -C
+test_when_finishedtest_unconfig'indexhelper.autorun'
+ test 0 = 0
+ test_cleanup={test_unconfig'indexhelper.autorun'Quoted 6 lines
} && (exit "$eval_ret"); eval_ret=$?; { git index -helper --kill } && (exit "$eval_ret"); eval_ret=$?; :+ git config indexhelper.autorun true
+ git status
error: last command exited with $?=141
Quoted 3 lines
I think that's a SIGPIPE on the first git status. Weird, since I just added sigpipe-avoidance code (in v8). Does anyone have any idea why the sigchain stuff isn't doing what I think it is?
Sorry for a late report (I've been a bit busy last couple of days), but I've been seeing exactly the same on v8 of this series.
Note that the above 'git status' is actually the second git-status in the test.
I haven't been able to debug it too much, but I can tell you that it is not failing at exactly the same place every time (so it may be time sensitive). However, it often fails in poke_and_wait_for_reply() at the first packet_flush() (which in turn calls write_or_die() which calls check_pipe() with an EPIPE(32)). At other times it fails when issuing a flush after a refresh packet. For example, on one run with packet tracing enabled, I got this for the trace:
trace: built-in: git 'status'
packet: git> poke 3221 packet: git> 0000 packet: git< OK packet: git> refresh packet: git> 0000
So, its getting the EPIPE for the refresh in this case, even though the index-helper is still running, the unix socket is in .git/ (and so is a shm-* file BTW).
I didn't get any further than that I'm afraid.
ATB,
Ramsay Jones
Re: [PATCH v9 03/19] index-helper: new daemon for caching index and related stuff
In reply to David TurnerThis patch adds a new plumbing command, which then will show up in completion after 'git <TAB>'. Could you please squash in this oneliner to exclude index-helper from porcelain commands in the completion script?
--- contrib/completion/git-completion.bash | 1 + 1 file changed, 1 insertion(+)
contrib/completion/git-completion.bash +1 -0
@@ -684,6 +684,7 @@ __git_list_porcelain_commands () for-each-ref) : plumbing;; hash-object) : plumbing;; http-*) : transport;; + index-helper) : plumbing;; index-pack) : plumbing;; init-db) : deprecated;; local-fetch) : plumbing;;
Signature · 1 line
2.8.2.356.ge684b1d
Re: [PATCH v9 03/19] index-helper: new daemon for caching index and related stuff
Will do, thanks.
Quoted 23 lines · SZEDER Gábor
This patch adds a new plumbing command, which then will show up in completion after 'git <TAB>'. Could you please squash in this oneliner to exclude index-helper from porcelain commands in the completion script?
--- contrib/completion/git-completion.bash | 1 + 1 file changed, 1 insertion(+)contrib/completion/git-completion.bash +1
-0@@ -684,6 +684,7 @@ __git_list_porcelain_commands () for-each-ref) : plumbing;; hash-object) : plumbing;; http-*) : transport;; + index-helper) : plumbing;; index-pack) : plumbing;; init-db) : deprecated;; local-fetch) : plumbing;;
Re: [PATCH v9 03/19] index-helper: new daemon for caching index and related stuff
In reply to SZEDER GáborThis reminds me, we need to update command-list.txt as well. I guess it belongs to purehelpers? Back to the patch..
Quoted 4 lines · SZEDER Gábor
This patch adds a new plumbing command, which then will show up in completion after 'git <TAB>'. Could you please squash in this oneliner to exclude index-helper from porcelain commands in the completion script?
I don't think the user should run this command explicitly a lot. Usually it should be run automatically (with config key indexhelper.autorun) and die when idle for some time. You just don't care about it (until performance degrades and you have to investigate). Occasionally you may have to "git index-helper --kill". Is there any other reason it should be run often enough to justify this change?
Quoted 21 lines
--- contrib/completion/git-completion.bash | 1 + 1 file changed, 1 insertion(+)contrib/completion/git-completion.bash +1
-1@@ -684,6 +684,7 @@ __git_list_porcelain_commands () for-each-ref) : plumbing;; hash-object) : plumbing;; http-*) : transport;; + index-helper) : plumbing;; index-pack) : plumbing;; init-db) : deprecated;; local-fetch) : plumbing;; --2.8.2.356.ge684b1d
Signature · 1 line
Duy
Re: [PATCH v9 03/19] index-helper: new daemon for caching index and related stuff
Quoting Duy Nguyen <[email protected]>:
Quoted 9 lines
This reminds me, we need to update command-list.txt as well. I guess it belongs to purehelpers? Back to the patch..
Quoted 4 lines · SZEDER Gábor
This patch adds a new plumbing command, which then will show up in completion after 'git <TAB>'. Could you please squash in this oneliner to exclude index-helper from porcelain commands in the completion script?
Quoted 7 lines
I don't think the user should run this command explicitly a lot. Usually it should be run automatically (with config key indexhelper.autorun) and die when idle for some time. You just don't care about it (until performance degrades and you have to investigate). Occasionally you may have to "git index-helper --kill". Is there any other reason it should be run often enough to justify this change?
I think you misunderstood this change, it _excludes_ 'index-helper' from the list of porcelain commands.
Quoted 22 lines
Quoted 18 lines
--- contrib/completion/git-completion.bash | 1 + 1 file changed, 1 insertion(+)contrib/completion/git-completion.bash +1
-1@@ -684,6 +684,7 @@ __git_list_porcelain_commands () for-each-ref) : plumbing;; hash-object) : plumbing;; http-*) : transport;; + index-helper) : plumbing;; index-pack) : plumbing;; init-db) : deprecated;; local-fetch) : plumbing;; --Quoted 2 lines
2.8.2.356.ge684b1d
--
Duy
Re: [PATCH v9 03/19] index-helper: new daemon for caching index and related stuff
Quoted 23 lines · SZEDER Gábor
Quoting Duy Nguyen <[email protected]>:
Quoted 11 lines
This reminds me, we need to update command-list.txt as well. I guess it belongs to purehelpers? Back to the patch..
Quoted 5 lines · SZEDER Gábor
This patch adds a new plumbing command, which then will show up in completion after 'git <TAB>'. Could you please squash in this oneliner to exclude index-helper from porcelain commands in the completion script?
Quoted 7 lines
I don't think the user should run this command explicitly a lot. Usually it should be run automatically (with config key indexhelper.autorun) and die when idle for some time. You just don't care about it (until performance degrades and you have to investigate). Occasionally you may have to "git index-helper --kill". Is there any other reason it should be run often enough to justify this change?
Quoted 2 lines
I think you misunderstood this change, it _excludes_ 'index-helper' from the list of porcelain commands.
Oops, right it excludes it.
Signature · 1 line
Duy
Quoted 3 lines · David Turner
I think that's a SIGPIPE on the first git status. Weird, since I just added sigpipe-avoidance code (in v8). Does anyone have any idea why the sigchain stuff isn't doing what I think it is?
SIGPIPE code works. I tested with and without --detach (suspecting fork causing problems). I even logged all sigchain_push() calls to see if anybody else is interfering (none did, at least without watchman). Problem is elsewhere.
There are two problems with logging code in index-helper though. The redirecting std{out,err} to /dev/null should only be done when --detach is given (and I' m quite sure daemonize() already takes care of that). If --detach is used, log_warning() can't cover die(), warning() or error(), most importantly die() for example because of bugs. I think you can call set_die_routine() and similar, just be careful not lead to recursive calls (die() is protected, but I dont think error and warning are).
Signature · 1 line
Duy
Quoted 3 lines · Duy Nguyen
If --detach is used,
log_warning()can't coverdie(),warning()orerror(), most importantlydie()for example because of bugs.
A case for redirecting warning() is because watchman-support.c uses it. But because this file is only used by index-helper, you have another option, simply convert it to using log_warning().
Signature · 1 line
Duy
Quoted 72 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · David Turner
Quoted 1 line · Junio C Hamano
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Hmmm, I seem to be getting
$ cat t/trash*7900*/err fatal: Already runningafter running t7900 and it fails at #5, after applying "index-helper: optionally automatically run"
The symptom looks pretty similar to $gmane/293461 reported earlier. Here is how "
t7900-index-helper.sh-i -v -x -d" ends.expecting success:
test_when_finished "git index-helper --kill" && rm -f .git/index-helper.sock &&
git status &&
test_path_is_missing .git/index-helper.sock &&test_configindexhelper.autorun true && git status &&
test -S .git/index-helper.sock &&
git status 2>err &&
test -S .git/index-helper.sock &&test_must_be_emptyerr &&
git index-helper --kill &&
test_config indexhelper.autorun false && git status &&
test_path_is_missing .git/index-helper.sock+
test_when_finishedgit index-helper --kill
+ test 0 = 0
+ test_cleanup={ git index-helper --kill
} && (exit "$eval_ret"); eval_ret=$?; :
+ rm -f .git/index-helper.sock
+ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)err
nothing added to commit but untracked files present (use "git add" to track)
+test_path_is_missing.git/index-helper.sock
+ test -e .git/index-helper.sock
+test_configindexhelper.autorun true
+ config_dir=
+ test indexhelper.autorun = -C
+test_when_finishedtest_unconfig 'indexhelper.autorun'
+ test 0 = 0
+ test_cleanup={ test_unconfig 'indexhelper.autorun'
} && (exit "$eval_ret"); eval_ret=$?; { git index- helper --kill
} && (exit "$eval_ret"); eval_ret=$?; :
+ git config indexhelper.autorun true
+ git status
error: last command exited with $?=141
not ok 5 - index-helper autorun works
#
# test_when_finished "git index-helper --kill" && # rm -f .git/index-helper.sock &&
# git status &&
# test_path_is_missing .git/index-helper.sock && # test_config indexhelper.autorun true &&
# git status &&
# test -S .git/index-helper.sock &&
Quoted 8 lines
# git status 2>err &&
# test -S .git/index-helper.sock && # test_must_be_empty err &&
# git index-helper --kill &&
# test_config indexhelper.autorun false && # git status &&
# test_path_is_missing .git/index-helper.sock #
Here are the relevant bits of a strace, pid 22200 is the second git status, 222197 is the index helper. 22122 is the test script
22200 socket(PF_LOCAL, SOCK_STREAM, 0) = 7
22200 connect(7, {sa_family=AF_LOCAL, sun_path=".git/index-helper.sock"}, 110 <unfinished ...>
22197 <... poll resumed> ) = 1
22197 accept(7, 0, NULL) = 8
22197 fcntl(8, F_GETFL) = 0x2 (flags O_RDWR)
22197 fcntl(8, F_SETFL, O_RDWR) = 0
22197 read(8, <unfinished ...>
22200 <... connect resumed> ) = 0
22200 rt_sigaction(SIGPIPE, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART, 0x7fcc463fdd40}, {SIG_DFL, [PIPE], SA_RESTORER|SA_RESTART, 0x7fcc463fdd40}, 8) = 0 22200 write(7, "000fpoke 22200 ", 15 <unfinished ...>
22197 <... read resumed> 0x7ffc4e4b9b20, 4) = 4
22197 read(8, 0x7ffc4e4b9c70, 11) = 11
22197 write(8, 0x18b08b0, 6) = 6
22197 close(8) = 0
22197 poll([?] 0x7ffc4e4b9b80, 1, 600000 <unfinished ...>
22200 <... write resumed> ) = 15
22200 write(7, "0000", 4) = -1 EPIPE (Broken pipe)
22200 --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=22200, si_uid=1000} ---
22200 rt_sigaction(SIGPIPE, {SIG_DFL, [PIPE], SA_RESTORER|SA_RESTART, 0x7fcc463fdd40}, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART, 0x7fcc463fdd40}, 8) = 0 22200 tgkill(22200, 22200, SIGPIPE) = 0
22200 --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_TKILL, si_pid=22200, si_uid=1000} ---
22200 +++ killed by SIGPIPE +++
22122 <... wait4 resumed> [{WIFSIGNALED(s) && WTERMSIG(s) == SIGPIPE}], 0, NULL) = 22200
22122 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=22200, si_status=SIGPIPE, si_utime=0, si_stime=0} ---
Looks like the index helper closes the socket, but git status still wants to write to it. The index-helper also doesn't seem to read all data from the socket.
Signature · 2 lines
Dennis Kaarsemaker www.kaarsemaker.net
Quoted 123 lines · Dennis Kaarsemaker
Quoted 77 lines · Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · David Turner
Quoted 2 lines · Junio C Hamano
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Hmmm, I seem to be getting
$ cat t/trash*7900*/err fatal: Already runningafter running t7900 and it fails at #5, after applying "index-helper: optionally automatically run"
The symptom looks pretty similar to $gmane/293461 reported earlier. Here is how "
t7900-index-helper.sh-i -v -x -d" ends.expecting success:
test_when_finished "git index-helper --kill" && rm -f .git/index-helper.sock &&
git status &&
test_path_is_missing .git/index-helper.sock &&test_configindexhelper.autorun true && git status &&
test -S .git/index-helper.sock &&
git status 2>err &&
test -S .git/index-helper.sock &&test_must_be_emptyerr &&
git index-helper --kill &&
test_config indexhelper.autorun false && git status &&
test_path_is_missing .git/index-helper.sock+
test_when_finishedgit index-helper --kill
+ test 0 = 0
+ test_cleanup={ git index-helper --kill
} && (exit "$eval_ret"); eval_ret=$?; :
+ rm -f .git/index-helper.sock
+ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)err
nothing added to commit but untracked files present (use "git add" to
track)
+test_path_is_missing.git/index-helper.sock
+ test -e .git/index-helper.sock
+test_configindexhelper.autorun true
+ config_dir=
+ test indexhelper.autorun = -C
+test_when_finishedtest_unconfig 'indexhelper.autorun'
+ test 0 = 0
+ test_cleanup={ test_unconfig 'indexhelper.autorun'
} && (exit "$eval_ret"); eval_ret=$?; { git index- helper --kill
} && (exit "$eval_ret"); eval_ret=$?; :
+ git config indexhelper.autorun true
+ git status
error: last command exited with $?=141
not ok 5 - index-helper autorun works
#
# test_when_finished "git index-helper --kill" && # rm -f .git/index-helper.sock &&
# git status &&
# test_path_is_missing .git/index-helper.sock && # test_config indexhelper.autorun true && # git status &&
# test -S .git/index-helper.sock &&Quoted 8 lines
# git status 2>err &&
# test -S .git/index-helper.sock && # test_must_be_empty err &&
# git index-helper --kill &&
# test_config indexhelper.autorun false && # git status &&
# test_path_is_missing .git/index-helper.sock #Here are the relevant bits of a strace, pid 22200 is the second git status, 222197 is the index helper. 22122 is the test script
22200
socket(PF_LOCAL, SOCK_STREAM, 0)= 7
22200 connect(7, {sa_family=AF_LOCAL, sun_path=".git/index- helper.sock"}, 110 <unfinished ...>
22197 <... poll resumed> ) = 1
22197accept(7, 0, NULL)= 8
22197fcntl(8, F_GETFL)=0x2(flagsO_RDWR) 22197fcntl(8, F_SETFL, O_RDWR)= 0
22197 read(8, <unfinished ...>
22200 <... connect resumed> ) = 0
22200 rt_sigaction(SIGPIPE, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART,0x7fcc463fdd40}, {SIG_DFL, [PIPE], SA_RESTORER|SA_RESTART,0x7fcc463fdd40}, 8) = 0
22200 write(7, "000fpoke 22200 ", 15 <unfinished ...> 22197 <... read resumed>0x7ffc4e4b9b20, 4) = 4
22197read(8, 0x7ffc4e4b9c70, 11)= 11
22197write(8, 0x18b08b0, 6)= 6
22197 close(8) = 0
22197 poll([?]0x7ffc4e4b9b80, 1, 600000 <unfinished ...> 22200 <... write resumed> ) = 15
22200write(7, "0000", 4)= -1 EPIPE (Broken pipe) 22200 --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=22200, si_uid=1000} ---
22200 rt_sigaction(SIGPIPE, {SIG_DFL, [PIPE], SA_RESTORER|SA_RESTART,0x7fcc463fdd40}, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART,0x7fcc463fdd40}, 8) = 0
22200tgkill(22200, 22200, SIGPIPE)= 0
22200 --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_TKILL, si_pid=22200, si_uid=1000} ---
22200 +++ killed by SIGPIPE +++
22122 <... wait4 resumed> [{WIFSIGNALED(s) && WTERMSIG(s) == SIGPIPE}], 0, NULL) = 22200
22122 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=22200, si_status=SIGPIPE, si_utime=0, si_stime=0} ---
Quoted 3 lines
Looks like the index helper closes the socket, but git status still wants to write to it. The index-helper also doesn't seem to read all data from the socket.
This dodgy hack to make the index helper read that empty pkt-line before closing the socket seems to work around the issue enough to make the test pass
index-helper.c +0 -0
@@ -385,6 +385,8 @@ static void loop(int fd, int idle_in_seconds)
* close up.
*/
}
+ bytes_read = packet_read(client_fd, NULL, NULL, buf, + sizeof(buf), flags); close(client_fd);
}
And this even dodgier hack breaks the race on a physical machine, so the test reliably fails everywher:
read-cache.c +0 -0
@@ -1836,6 +1836,7 @@ static int poke_and_wait_for_reply(int fd)
strbuf_addf(&buf, "poke %d %s", getpid(), requested_capabilities); packet_write(fd, buf.buf, buf.len);
+ sleep(5);
packet_flush(fd);
/* Now wait for a reply */
But at this point I'll have to claim ignorance on whether reading the empty pkt-line is a fix or just hiding the problem.
Signature · 2 lines
Dennis Kaarsemaker www.kaarsemaker.net
Quoted 3 lines · Junio C Hamano
It passes on one box and fails on another. They both run the same Ubuntu 14.04 derivative, with same ext3 filesystem. The failing one is on a VM.
Same here, except ext4 instead of ext3. Failing on a virtual machine, not failing on a physical one.
Signature · 2 lines
Dennis Kaarsemaker http://www.kaarsemaker.net
Quoted 7 lines · Dennis Kaarsemaker
Quoted 3 lines · Junio C Hamano
It passes on one box and fails on another. They both run the same Ubuntu 14.04 derivative, with same ext3 filesystem. The failing one is on a VM.
Same here, except ext4 instead of ext3. Failing on a virtual machine, not failing on a physical one.
I can confirm the trend:
Linux Mint 17.3, ext4 - bare-metal pass, (Virtual Box) VM fail.
ATB,
Ramsay Jones
Quoted 9 lines · Ramsay Jones
Quoted 7 lines · Dennis Kaarsemaker
Quoted 3 lines · Junio C Hamano
It passes on one box and fails on another. They both run the same Ubuntu 14.04 derivative, with same ext3 filesystem. The failing one is on a VM.
Same here, except ext4 instead of ext3. Failing on a virtual machine, not failing on a physical one.
Quoted 6 lines
I can confirm the trend:
Linux Mint 17.3, ext4 - bare-metal pass, (Virtual Box) VM fail.
ATB,
Ramsay Jones
I do not think there is anything VM specific, though. If it is SIGPIPE, it is very much understandable it is timing dependent, and VMness may be a cause of timing differences, nothing more.
I seem to getting the failure on my physical box today, by the way.
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Ramsay Jones
Quoted 7 lines · Dennis Kaarsemaker
Quoted 3 lines · Junio C Hamano
It passes on one box and fails on another. They both run the same Ubuntu 14.04 derivative, with same ext3 filesystem. The failing one is on a VM.
Same here, except ext4 instead of ext3. Failing on a virtual machine, not failing on a physical one.
Quoted 7 lines
Quoted 4 lines
I can confirm the trend:
Linux Mint 17.3, ext4 - bare-metal pass, (Virtual Box) VM fail.
I do not think there is anything VM specific, though. If it is SIGPIPE, it is very much understandable it is timing dependent, and VMness may be a cause of timing differences, nothing more.
Yeah, I had previously noted that this was probably a timing related issue - this was only meant as confirmation that David could probably reproduce the issue if he tested in a VM. ;-)
However, it appears Dennis has found a way to force a failure, even on bare-metal (at least on v8, I think).
Quoted 1 line
I seem to getting the failure on my physical box today, by the way.
Ah, interesting.
ATB,
Ramsay Jones