We observe in Gerrit 2.12 that useCnt can become negative in rare cases. Log this to help finding the bug. Change-Id: Ie91c7f9d190a5d7cf4733d4bf84124d119ca20f7 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>tags/v4.4.1.201607150455-r
corruptObjectTruncatedInName=truncated in name | corruptObjectTruncatedInName=truncated in name | ||||
corruptObjectTruncatedInObjectId=truncated in object id | corruptObjectTruncatedInObjectId=truncated in object id | ||||
corruptObjectZeroId=entry points to null SHA-1 | corruptObjectZeroId=entry points to null SHA-1 | ||||
corruptUseCnt=close() called when useCnt is already zero | |||||
couldNotCheckOutBecauseOfConflicts=Could not check out because of conflicts | couldNotCheckOutBecauseOfConflicts=Could not check out because of conflicts | ||||
couldNotDeleteLockFileShouldNotHappen=Could not delete lock file. Should not happen | couldNotDeleteLockFileShouldNotHappen=Could not delete lock file. Should not happen | ||||
couldNotDeleteTemporaryIndexFileShouldNotHappen=Could not delete temporary index file. Should not happen | couldNotDeleteTemporaryIndexFileShouldNotHappen=Could not delete temporary index file. Should not happen |
/***/ public String corruptObjectTruncatedInObjectId; | /***/ public String corruptObjectTruncatedInObjectId; | ||||
/***/ public String corruptObjectZeroId; | /***/ public String corruptObjectZeroId; | ||||
/***/ public String corruptPack; | /***/ public String corruptPack; | ||||
/***/ public String corruptUseCnt; | |||||
/***/ public String couldNotCheckOutBecauseOfConflicts; | /***/ public String couldNotCheckOutBecauseOfConflicts; | ||||
/***/ public String couldNotDeleteLockFileShouldNotHappen; | /***/ public String couldNotDeleteLockFileShouldNotHappen; | ||||
/***/ public String couldNotDeleteTemporaryIndexFileShouldNotHappen; | /***/ public String couldNotDeleteTemporaryIndexFileShouldNotHappen; |
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
import org.eclipse.jgit.util.SystemReader; | import org.eclipse.jgit.util.SystemReader; | ||||
import org.eclipse.jgit.util.io.SafeBufferedOutputStream; | import org.eclipse.jgit.util.io.SafeBufferedOutputStream; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
/** | /** | ||||
* Represents a Git repository. | * Represents a Git repository. | ||||
* This class is thread-safe. | * This class is thread-safe. | ||||
*/ | */ | ||||
public abstract class Repository implements AutoCloseable { | public abstract class Repository implements AutoCloseable { | ||||
private static Logger LOG = LoggerFactory.getLogger(Repository.class); | |||||
private static final ListenerList globalListeners = new ListenerList(); | private static final ListenerList globalListeners = new ListenerList(); | ||||
/** @return the global listener list observing all events in this JVM. */ | /** @return the global listener list observing all events in this JVM. */ | ||||
/** Decrement the use count, and maybe close resources. */ | /** Decrement the use count, and maybe close resources. */ | ||||
public void close() { | public void close() { | ||||
if (useCnt.decrementAndGet() == 0) { | |||||
int newCount = useCnt.decrementAndGet(); | |||||
if (newCount == 0) { | |||||
if (RepositoryCache.isCached(this)) { | if (RepositoryCache.isCached(this)) { | ||||
closedAt.set(System.currentTimeMillis()); | closedAt.set(System.currentTimeMillis()); | ||||
} else { | } else { | ||||
doClose(); | doClose(); | ||||
} | } | ||||
} else if (newCount == -1) { | |||||
// should not happen, only log when useCnt became negative to | |||||
// minimize number of log entries | |||||
LOG.warn(JGitText.get().corruptUseCnt); | |||||
if (LOG.isDebugEnabled()) { | |||||
IllegalStateException e = new IllegalStateException(); | |||||
LOG.debug("", e); //$NON-NLS-1$ | |||||
} | |||||
if (RepositoryCache.isCached(this)) { | |||||
closedAt.set(System.currentTimeMillis()); | |||||
} | |||||
} | } | ||||
} | } | ||||