Automatically check for refs/meta/config changes

Periodically check a project's refs/meta/config for modifications
made outside of Gerrit Code Review.  This ensures slave servers will
eventually pick up new access controls or project settings without
requiring administrators to flush the "projects" cache over SSH.

Checks are done only every cache.projects.checkFrequency period, as a
local disk check requires at least one stat() call to examine the
loose reference's last modified time. This is relatively inexpensive
for a single project request like git clone, but not feasible for
multiple project lookups like a query results page or user dashboard.

To prevent many calls to System.currentTimeMillis() a background
thread (managed by Executors.newScheduledThreadPool) is used to update
a generation flag every checkFrequency period. During a cache get the
ProjectState rechecks its refs/meta/config if the generation does not
match, and gets replaced if there were changes.

Bug: issue 962
Change-Id: I9ad4db27329968e2993b4dd142d1325446190065
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 09b3f50..e5bc703 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -485,6 +485,21 @@
 +
 Default is true, enabled.
 
+cache.projects.checkFrequency::
++
+How often project configuration should be checked for update from Git.
+Gerrit Code Review caches project access rules and configuration in
+memory, checking the refs/meta/config branch every checkFrequency
+minutes to see if a new revision should be loaded and used for future
+access. Values can be specified using standard time unit abbreviations
+('ms', 'sec', 'min', etc.).
++
+If set to 0, checks occur every time, which may slow down operations.
+Administrators may force the cache to flush with
+link:cmd-flush-caches.html[gerrit flush-caches].
++
+Default is 5 minutes.
+
 
 [[commentlink]]Section commentlink
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~