Browse Source

Introduce config parameter core.trustfolderstat

JGit's ObjectDirectory implements the optimization that it remembers the
pack folders (.git/objects/pack) lastModified timestamp and doesn't
check for new packfiles in this folder if the lastModified attribute has
not changed.
In environments using NFS this can cause trouble. If multiple JGit
instances from multiple machines work on the same repository and one
instance creates a new ref and a new packfile (e.g. by doing a fetch)
then the other machines may detect the new ref but can't resolve the
referenced object because it doesn't detect that pack folder has a new
packfile. That's because NFS may cache file/folder metadata for quite a
long time and the pack folders modification time is not updated although
a new packfile is there and could be read.

The new config parameter core.trustfolderstat controls this behaviour.
The default is true and jgits behaviours is unchanged. But if this
parameter is set to false then jgit doesn't trust the pack directories
lastmodified anymore. Instead it will always iterate through the content
of that folder to detect new packfiles.

Change-Id: Ie3b4e92933286aa9916070a22422e629b3147f54
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-3.6
Christian Halstrick 10 years ago committed by Matthias Sohn
parent
commit
0fc8b05a71
  1. 15
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
  2. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java

15
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java

@ -72,6 +72,7 @@ import org.eclipse.jgit.internal.storage.pack.PackWriter;
import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectDatabase; import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@ -130,6 +131,14 @@ public class ObjectDirectory extends FileObjectDatabase {
private Set<ObjectId> shallowCommitsIds; private Set<ObjectId> shallowCommitsIds;
// Whether to trust the pack folder's modification time. If set
// to false we will always scan the .git/objects/pack folder to
// check for new pack files. If set to true (default) we use the
// lastmodified attribute of the folder and assume that no new
// pack files can be in this folder if his modification time has
// not changed.
private boolean trustFolderStat = true;
/** /**
* Initialize a reference to an on-disk object directory. * Initialize a reference to an on-disk object directory.
* *
@ -152,6 +161,9 @@ public class ObjectDirectory extends FileObjectDatabase {
File[] alternatePaths, FS fs, File shallowFile) throws IOException { File[] alternatePaths, FS fs, File shallowFile) throws IOException {
config = cfg; config = cfg;
objects = dir; objects = dir;
trustFolderStat = config.getBoolean(
ConfigConstants.CONFIG_CORE_SECTION,
ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, true);
infoDirectory = new File(objects, "info"); //$NON-NLS-1$ infoDirectory = new File(objects, "info"); //$NON-NLS-1$
packDirectory = new File(objects, "pack"); //$NON-NLS-1$ packDirectory = new File(objects, "pack"); //$NON-NLS-1$
alternatesFile = new File(infoDirectory, "alternates"); //$NON-NLS-1$ alternatesFile = new File(infoDirectory, "alternates"); //$NON-NLS-1$
@ -606,7 +618,8 @@ public class ObjectDirectory extends FileObjectDatabase {
} }
private boolean searchPacksAgain(PackList old) { private boolean searchPacksAgain(PackList old) {
return old.snapshot.isModified(packDirectory) && old != scanPacks(old); return ((!trustFolderStat) || old.snapshot.isModified(packDirectory))
&& old != scanPacks(old);
} }
Config getConfig() { Config getConfig() {

6
org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java

@ -257,6 +257,12 @@ public class ConfigConstants {
*/ */
public static final String CONFIG_KEY_RENAMELIMIT = "renamelimit"; public static final String CONFIG_KEY_RENAMELIMIT = "renamelimit";
/**
* The "trustfolderstat" key in the "core section"
* @since 3.6
*/
public static final String CONFIG_KEY_TRUSTFOLDERSTAT = "trustfolderstat";
/** /**
* The "noprefix" key in the "diff section" * The "noprefix" key in the "diff section"
* @since 3.0 * @since 3.0

Loading…
Cancel
Save