Browse Source

Merge branch 'stable-4.8' into stable-4.9

* stable-4.8:
  Prepare 4.7.10-SNAPSHOT builds
  JGit v4.7.9.201904161809-r
  Prepare 4.5.8-SNAPSHOT builds
  JGit v4.5.7.201904151645-r
  Remember the cause for invalidating a packfile
  Fix API problem filters
  Fix pack files scan when filesnapshot isn't modified

Change-Id: Idaa789e699f1ef568ea957184d0641355d9e3181
stable-4.9
Matthias Sohn 6 years ago
parent
commit
d5ec15c8d0
  1. 16
      org.eclipse.jgit/.settings/.api_filters
  2. 34
      org.eclipse.jgit/src/org/eclipse/jgit/errors/PackInvalidException.java
  3. 8
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/BlockBasedFile.java
  4. 11
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
  5. 18
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
  6. 20
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

16
org.eclipse.jgit/.settings/.api_filters

@ -3,11 +3,25 @@
<resource path="META-INF/MANIFEST.MF"> <resource path="META-INF/MANIFEST.MF">
<filter id="924844039"> <filter id="924844039">
<message_arguments> <message_arguments>
<message_argument value="4.9.8"/> <message_argument value="4.9.10"/>
<message_argument value="4.9.0"/> <message_argument value="4.9.0"/>
</message_arguments> </message_arguments>
</filter> </filter>
</resource> </resource>
<resource path="src/org/eclipse/jgit/errors/PackInvalidException.java" type="org.eclipse.jgit.errors.PackInvalidException">
<filter id="1142947843">
<message_arguments>
<message_argument value="4.5.7"/>
<message_argument value="PackInvalidException(File, Throwable)"/>
</message_arguments>
</filter>
<filter id="1142947843">
<message_arguments>
<message_argument value="4.5.7"/>
<message_argument value="PackInvalidException(String, Throwable)"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants"> <resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants">
<filter id="336658481"> <filter id="336658481">
<message_arguments> <message_arguments>

34
org.eclipse.jgit/src/org/eclipse/jgit/errors/PackInvalidException.java

@ -58,9 +58,24 @@ public class PackInvalidException extends IOException {
* *
* @param path * @param path
* path of the invalid pack file. * path of the invalid pack file.
* @deprecated Use {@link #PackInvalidException(File, Throwable)}.
*/ */
@Deprecated
public PackInvalidException(final File path) { public PackInvalidException(final File path) {
this(path.getAbsolutePath()); this(path, null);
}
/**
* Construct a pack invalid error with cause.
*
* @param path
* path of the invalid pack file.
* @param cause
* cause of the pack file becoming invalid.
* @since 4.5.7
*/
public PackInvalidException(final File path, Throwable cause) {
this(path.getAbsolutePath(), cause);
} }
/** /**
@ -68,8 +83,23 @@ public class PackInvalidException extends IOException {
* *
* @param path * @param path
* path of the invalid pack file. * path of the invalid pack file.
* @deprecated Use {@link #PackInvalidException(String, Throwable)}.
*/ */
@Deprecated
public PackInvalidException(final String path) { public PackInvalidException(final String path) {
super(MessageFormat.format(JGitText.get().packFileInvalid, path)); this(path, null);
}
/**
* Construct a pack invalid error with cause.
*
* @param path
* path of the invalid pack file.
* @param cause
* cause of the pack file becoming invalid.
* @since 4.5.7
*/
public PackInvalidException(final String path, Throwable cause) {
super(MessageFormat.format(JGitText.get().packFileInvalid, path), cause);
} }
} }

8
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/BlockBasedFile.java

@ -84,6 +84,9 @@ abstract class BlockBasedFile {
/** True once corruption has been detected that cannot be worked around. */ /** True once corruption has been detected that cannot be worked around. */
volatile boolean invalid; volatile boolean invalid;
/** Exception that caused the packfile to be flagged as invalid */
protected volatile Exception invalidatingCause;
BlockBasedFile(DfsBlockCache cache, DfsPackDescription desc, PackExt ext) { BlockBasedFile(DfsBlockCache cache, DfsPackDescription desc, PackExt ext) {
this.cache = cache; this.cache = cache;
this.key = desc.getStreamKey(ext); this.key = desc.getStreamKey(ext);
@ -135,8 +138,9 @@ abstract class BlockBasedFile {
DfsBlock readOneBlock(long pos, DfsReader ctx, DfsBlock readOneBlock(long pos, DfsReader ctx,
@Nullable ReadableChannel fileChannel) throws IOException { @Nullable ReadableChannel fileChannel) throws IOException {
if (invalid) if (invalid) {
throw new PackInvalidException(getFileName()); throw new PackInvalidException(getFileName(), invalidatingCause);
}
ctx.stats.readBlock++; ctx.stats.readBlock++;
long start = System.nanoTime(); long start = System.nanoTime();

11
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java

@ -175,8 +175,9 @@ public final class DfsPackFile extends BlockBasedFile {
return idx; return idx;
} }
if (invalid) if (invalid) {
throw new PackInvalidException(getFileName()); throw new PackInvalidException(getFileName(), invalidatingCause);
}
Repository.getGlobalListenerList() Repository.getGlobalListenerList()
.dispatch(new BeforeDfsPackIndexLoadedEvent(this)); .dispatch(new BeforeDfsPackIndexLoadedEvent(this));
@ -220,11 +221,13 @@ public final class DfsPackFile extends BlockBasedFile {
} }
} catch (EOFException e) { } catch (EOFException e) {
invalid = true; invalid = true;
invalidatingCause = e;
throw new IOException(MessageFormat.format( throw new IOException(MessageFormat.format(
DfsText.get().shortReadOfIndex, DfsText.get().shortReadOfIndex,
desc.getFileName(INDEX)), e); desc.getFileName(INDEX)), e);
} catch (IOException e) { } catch (IOException e) {
invalid = true; invalid = true;
invalidatingCause = e;
throw new IOException(MessageFormat.format( throw new IOException(MessageFormat.format(
DfsText.get().cannotReadIndex, DfsText.get().cannotReadIndex,
desc.getFileName(INDEX)), e); desc.getFileName(INDEX)), e);
@ -723,8 +726,10 @@ public final class DfsPackFile extends BlockBasedFile {
private IOException packfileIsTruncated() { private IOException packfileIsTruncated() {
invalid = true; invalid = true;
return new IOException(MessageFormat.format( IOException exc = new IOException(MessageFormat.format(
JGitText.get().packfileIsTruncated, getFileName())); JGitText.get().packfileIsTruncated, getFileName()));
invalidatingCause = exc;
return exc;
} }
private void readFully(long position, byte[] dstbuf, int dstoff, int cnt, private void readFully(long position, byte[] dstbuf, int dstoff, int cnt,

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

@ -132,8 +132,6 @@ public class ObjectDirectory extends FileObjectDatabase {
private final File alternatesFile; private final File alternatesFile;
private final AtomicReference<PackList> packList;
private final FS fs; private final FS fs;
private final AtomicReference<AlternateHandle[]> alternates; private final AtomicReference<AlternateHandle[]> alternates;
@ -146,6 +144,8 @@ public class ObjectDirectory extends FileObjectDatabase {
private Set<ObjectId> shallowCommitsIds; private Set<ObjectId> shallowCommitsIds;
final AtomicReference<PackList> packList;
/** /**
* Initialize a reference to an on-disk object directory. * Initialize a reference to an on-disk object directory.
* *
@ -669,13 +669,8 @@ public class ObjectDirectory extends FileObjectDatabase {
transientErrorCount = p.incrementTransientErrorCount(); transientErrorCount = p.incrementTransientErrorCount();
} }
if (warnTmpl != null) { if (warnTmpl != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(warnTmpl,
p.getPackFile().getAbsolutePath()), e);
} else {
LOG.warn(MessageFormat.format(warnTmpl, LOG.warn(MessageFormat.format(warnTmpl,
p.getPackFile().getAbsolutePath())); p.getPackFile().getAbsolutePath()), e);
}
} else { } else {
if (doLogExponentialBackoff(transientErrorCount)) { if (doLogExponentialBackoff(transientErrorCount)) {
// Don't remove the pack from the list, as the error may be // Don't remove the pack from the list, as the error may be
@ -762,7 +757,7 @@ public class ObjectDirectory extends FileObjectDatabase {
return InsertLooseObjectResult.FAILURE; return InsertLooseObjectResult.FAILURE;
} }
private boolean searchPacksAgain(PackList old) { boolean searchPacksAgain(PackList old) {
// Whether to trust the pack folder's modification time. If set // Whether to trust the pack folder's modification time. If set
// to false we will always scan the .git/objects/pack folder to // 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 // check for new pack files. If set to true (default) we use the
@ -915,7 +910,8 @@ public class ObjectDirectory extends FileObjectDatabase {
final String packName = base + PACK.getExtension(); final String packName = base + PACK.getExtension();
final File packFile = new File(packDirectory, packName); final File packFile = new File(packDirectory, packName);
final PackFile oldPack = forReuse.remove(packName); final PackFile oldPack = forReuse.remove(packName);
if (oldPack != null && oldPack.getFileSnapshot().isModified(packFile)) { if (oldPack != null
&& !oldPack.getFileSnapshot().isModified(packFile)) {
list.add(oldPack); list.add(oldPack);
continue; continue;
} }
@ -1077,7 +1073,7 @@ public class ObjectDirectory extends FileObjectDatabase {
return new File(new File(getDirectory(), d), f); return new File(new File(getDirectory(), d), f);
} }
private static final class PackList { static final class PackList {
/** State just before reading the pack directory. */ /** State just before reading the pack directory. */
final FileSnapshot snapshot; final FileSnapshot snapshot;

20
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

@ -135,6 +135,8 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
private volatile boolean invalid; private volatile boolean invalid;
private volatile Exception invalidatingCause;
private boolean invalidBitmap; private boolean invalidBitmap;
private AtomicInteger transientErrorCount = new AtomicInteger(); private AtomicInteger transientErrorCount = new AtomicInteger();
@ -184,7 +186,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
idx = loadedIdx; idx = loadedIdx;
if (idx == null) { if (idx == null) {
if (invalid) { if (invalid) {
throw new PackInvalidException(packFile); throw new PackInvalidException(packFile, invalidatingCause);
} }
try { try {
idx = PackIndex.open(extFile(INDEX)); idx = PackIndex.open(extFile(INDEX));
@ -208,6 +210,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
throw e; throw e;
} catch (IOException e) { } catch (IOException e) {
invalid = true; invalid = true;
invalidatingCause = e;
throw e; throw e;
} }
} }
@ -658,7 +661,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
private void doOpen() throws IOException { private void doOpen() throws IOException {
if (invalid) { if (invalid) {
throw new PackInvalidException(packFile); throw new PackInvalidException(packFile, invalidatingCause);
} }
try { try {
synchronized (readLock) { synchronized (readLock) {
@ -668,13 +671,13 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
} }
} catch (InterruptedIOException e) { } catch (InterruptedIOException e) {
// don't invalidate the pack, we are interrupted from another thread // don't invalidate the pack, we are interrupted from another thread
openFail(false); openFail(false, e);
throw e; throw e;
} catch (FileNotFoundException fn) { } catch (FileNotFoundException fn) {
// don't invalidate the pack if opening an existing file failed // don't invalidate the pack if opening an existing file failed
// since it may be related to a temporary lack of resources (e.g. // since it may be related to a temporary lack of resources (e.g.
// max open files) // max open files)
openFail(!packFile.exists()); openFail(!packFile.exists(), fn);
throw fn; throw fn;
} catch (EOFException | AccessDeniedException | NoSuchFileException } catch (EOFException | AccessDeniedException | NoSuchFileException
| CorruptObjectException | NoPackSignatureException | CorruptObjectException | NoPackSignatureException
@ -682,20 +685,21 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
| UnsupportedPackIndexVersionException | UnsupportedPackIndexVersionException
| UnsupportedPackVersionException pe) { | UnsupportedPackVersionException pe) {
// exceptions signaling permanent problems with a pack // exceptions signaling permanent problems with a pack
openFail(true); openFail(true, pe);
throw pe; throw pe;
} catch (IOException | RuntimeException ge) { } catch (IOException | RuntimeException ge) {
// generic exceptions could be transient so we should not mark the // generic exceptions could be transient so we should not mark the
// pack invalid to avoid false MissingObjectExceptions // pack invalid to avoid false MissingObjectExceptions
openFail(false); openFail(false, ge);
throw ge; throw ge;
} }
} }
private void openFail(boolean invalidate) { private void openFail(boolean invalidate, Exception cause) {
activeWindows = 0; activeWindows = 0;
activeCopyRawData = 0; activeCopyRawData = 0;
invalid = invalidate; invalid = invalidate;
invalidatingCause = cause;
doClose(); doClose();
} }
@ -722,7 +726,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
// Detect the situation and throw a proper exception so that can be properly // Detect the situation and throw a proper exception so that can be properly
// managed by the main packfile search loop and the Git client won't receive // managed by the main packfile search loop and the Git client won't receive
// any failures. // any failures.
throw new PackInvalidException(packFile); throw new PackInvalidException(packFile, invalidatingCause);
} }
if (length < pos + size) if (length < pos + size)
size = (int) (length - pos); size = (int) (length - pos);

Loading…
Cancel
Save