Browse Source

Merge branch 'stable-5.6'

* stable-5.6:
  Fix API problem filters
  Fix unclosed resource warning in SmartOutputStream
  JschConfigSessionFactory: fix boxing warning
  SshSupport#runSshCommand: don't throw exception in finally block
  Don't override already managed maven-compiler-plugin version
  Remove unused import from CreateFileSnapshotBenchmark
  Remove duplicate ignore_optional_problems entry in .classpath
  Update maven-site-plugin used by benchmark module to 3.8.2
  Add dependency to enable site generation for benchmark module
  Ignore warnings for generated source code in
org.eclipse.jgit.benchmark
  Fix MBean registration
  Enhance WindowCache statistics

Change-Id: I4a77c602bfffed60535d0b8fc251a552b128068d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.7
Matthias Sohn 5 years ago
parent
commit
db019c473e
  1. 11
      org.eclipse.jgit.benchmarks/.classpath
  2. 27
      org.eclipse.jgit.benchmarks/pom.xml
  3. 17
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
  4. 2
      org.eclipse.jgit.packaging/pom.xml
  5. 43
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
  6. 25
      org.eclipse.jgit/.settings/.api_filters
  7. 250
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java
  8. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
  9. 176
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheStats.java
  10. 89
      org.eclipse.jgit/src/org/eclipse/jgit/util/Monitoring.java
  11. 11
      org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java
  12. 2
      pom.xml

11
org.eclipse.jgit.benchmarks/.classpath

@ -19,6 +19,17 @@
<classpathentry kind="src" path=".apt_generated"> <classpathentry kind="src" path=".apt_generated">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>

27
org.eclipse.jgit.benchmarks/pom.xml

@ -157,6 +157,33 @@
</lifecycleMappingMetadata> </lifecycleMappingMetadata>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.8.2</version>
<dependencies>
<dependency><!-- add support for ssh/scp -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>3.3.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>

17
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java

@ -72,18 +72,16 @@ class SmartOutputStream extends TemporaryBuffer {
// If output hasn't started yet, the entire thing fit into our // If output hasn't started yet, the entire thing fit into our
// buffer. Try to use a proper Content-Length header, and also // buffer. Try to use a proper Content-Length header, and also
// deflate the response with gzip if it will be smaller. // deflate the response with gzip if it will be smaller.
@SuppressWarnings("resource") if (256 < this.length() && acceptsGzipEncoding(req)) {
TemporaryBuffer out = this;
if (256 < out.length() && acceptsGzipEncoding(req)) {
TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT); TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT);
try { try {
try (GZIPOutputStream gzip = new GZIPOutputStream(gzbuf)) { try (GZIPOutputStream gzip = new GZIPOutputStream(gzbuf)) {
out.writeTo(gzip, null); this.writeTo(gzip, null);
} }
if (gzbuf.length() < out.length()) { if (gzbuf.length() < this.length()) {
out = gzbuf;
rsp.setHeader(HDR_CONTENT_ENCODING, ENCODING_GZIP); rsp.setHeader(HDR_CONTENT_ENCODING, ENCODING_GZIP);
writeResponse(gzbuf);
return;
} }
} catch (IOException err) { } catch (IOException err) {
// Most likely caused by overflowing the buffer, meaning // Most likely caused by overflowing the buffer, meaning
@ -91,7 +89,11 @@ class SmartOutputStream extends TemporaryBuffer {
// copy and use the original. // copy and use the original.
} }
} }
writeResponse(this);
}
}
private void writeResponse(TemporaryBuffer out) throws IOException {
// The Content-Length cannot overflow when cast to an int, our // The Content-Length cannot overflow when cast to an int, our
// hardcoded LIMIT constant above assures us we wouldn't store // hardcoded LIMIT constant above assures us we wouldn't store
// more than 2 GiB of content in memory. // more than 2 GiB of content in memory.
@ -102,4 +104,3 @@ class SmartOutputStream extends TemporaryBuffer {
} }
} }
} }
}

2
org.eclipse.jgit.packaging/pom.xml

@ -304,7 +304,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId> <artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version> <version>3.8.2</version>
</plugin> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>

43
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java

@ -28,6 +28,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.storage.file.WindowCacheConfig; import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.storage.file.WindowCacheStats;
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.MutableInteger;
import org.junit.Before; import org.junit.Before;
@ -69,8 +70,21 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
checkLimits(cfg); checkLimits(cfg);
final WindowCache cache = WindowCache.getInstance(); final WindowCache cache = WindowCache.getInstance();
assertEquals(6, cache.getOpenFiles()); WindowCacheStats s = cache.getStats();
assertEquals(17346, cache.getOpenBytes()); assertEquals(6, s.getOpenFileCount());
assertEquals(17346, s.getOpenByteCount());
assertEquals(0, s.getEvictionCount());
assertEquals(90, s.getHitCount());
assertTrue(s.getHitRatio() > 0.0 && s.getHitRatio() < 1.0);
assertEquals(6, s.getLoadCount());
assertEquals(0, s.getLoadFailureCount());
assertEquals(0, s.getLoadFailureRatio(), 0.001);
assertEquals(6, s.getLoadSuccessCount());
assertEquals(6, s.getMissCount());
assertTrue(s.getMissRatio() > 0.0 && s.getMissRatio() < 1.0);
assertEquals(96, s.getRequestCount());
assertTrue(s.getAverageLoadTime() > 0.0);
assertTrue(s.getTotalLoadTime() > 0.0);
} }
@Test @Test
@ -94,10 +108,27 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
private static void checkLimits(WindowCacheConfig cfg) { private static void checkLimits(WindowCacheConfig cfg) {
final WindowCache cache = WindowCache.getInstance(); final WindowCache cache = WindowCache.getInstance();
assertTrue(cache.getOpenFiles() <= cfg.getPackedGitOpenFiles()); WindowCacheStats s = cache.getStats();
assertTrue(cache.getOpenBytes() <= cfg.getPackedGitLimit()); assertTrue(0 < s.getAverageLoadTime());
assertTrue(0 < cache.getOpenFiles()); assertTrue(0 < s.getOpenByteCount());
assertTrue(0 < cache.getOpenBytes()); assertTrue(0 < s.getOpenByteCount());
assertTrue(0.0 < s.getAverageLoadTime());
assertTrue(0 <= s.getEvictionCount());
assertTrue(0 < s.getHitCount());
assertTrue(0 < s.getHitRatio());
assertTrue(1 > s.getHitRatio());
assertTrue(0 < s.getLoadCount());
assertTrue(0 <= s.getLoadFailureCount());
assertTrue(0.0 <= s.getLoadFailureRatio());
assertTrue(1 > s.getLoadFailureRatio());
assertTrue(0 < s.getLoadSuccessCount());
assertTrue(s.getOpenByteCount() <= cfg.getPackedGitLimit());
assertTrue(s.getOpenFileCount() <= cfg.getPackedGitOpenFiles());
assertTrue(0 <= s.getMissCount());
assertTrue(0 <= s.getMissRatio());
assertTrue(1 > s.getMissRatio());
assertTrue(0 < s.getRequestCount());
assertTrue(0 < s.getTotalLoadTime());
} }
private void doCacheTests() throws IOException { private void doCacheTests() throws IOException {

25
org.eclipse.jgit/.settings/.api_filters

@ -1,5 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.jgit" version="2"> <component id="org.eclipse.jgit" version="2">
<resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants">
<filter id="1142947843">
<message_arguments>
<message_argument value="5.1.13"/>
<message_argument value="CONFIG_JMX_SECTION"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/jgit/storage/file/WindowCacheStats.java" type="org.eclipse.jgit.storage.file.WindowCacheStats">
<filter id="337809484">
<message_arguments>
<message_argument value="org.eclipse.jgit.storage.file.WindowCacheStats"/>
<message_argument value="4"/>
<message_argument value="8"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/jgit/transport/ReceivePack.java" type="org.eclipse.jgit.transport.ReceivePack"> <resource path="src/org/eclipse/jgit/transport/ReceivePack.java" type="org.eclipse.jgit.transport.ReceivePack">
<filter id="336658481"> <filter id="336658481">
<message_arguments> <message_arguments>
@ -8,4 +25,12 @@
</message_arguments> </message_arguments>
</filter> </filter>
</resource> </resource>
<resource path="src/org/eclipse/jgit/util/Monitoring.java" type="org.eclipse.jgit.util.Monitoring">
<filter id="1109393411">
<message_arguments>
<message_argument value="5.1.13"/>
<message_argument value="org.eclipse.jgit.util.Monitoring"/>
</message_arguments>
</filter>
</resource>
</component> </component>

250
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java

@ -15,13 +15,16 @@ import java.io.IOException;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.storage.file.WindowCacheConfig; import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.storage.file.WindowCacheStats;
import org.eclipse.jgit.util.Monitoring;
/** /**
* Caches slices of a {@link org.eclipse.jgit.internal.storage.file.PackFile} in * Caches slices of a {@link org.eclipse.jgit.internal.storage.file.PackFile} in
@ -91,6 +94,196 @@ import org.eclipse.jgit.storage.file.WindowCacheConfig;
* other threads. * other threads.
*/ */
public class WindowCache { public class WindowCache {
/**
* Record statistics for a cache
*/
static interface StatsRecorder {
/**
* Record cache hits. Called when cache returns a cached entry.
*
* @param count
* number of cache hits to record
*/
void recordHits(int count);
/**
* Record cache misses. Called when the cache returns an entry which had
* to be loaded.
*
* @param count
* number of cache misses to record
*/
void recordMisses(int count);
/**
* Record a successful load of a cache entry
*
* @param loadTimeNanos
* time to load a cache entry
*/
void recordLoadSuccess(long loadTimeNanos);
/**
* Record a failed load of a cache entry
*
* @param loadTimeNanos
* time used trying to load a cache entry
*/
void recordLoadFailure(long loadTimeNanos);
/**
* Record cache evictions due to the cache evictions strategy
*
* @param count
* number of evictions to record
*/
void recordEvictions(int count);
/**
* Record files opened by cache
*
* @param count
* delta of number of files opened by cache
*/
void recordOpenFiles(int count);
/**
* Record cached bytes
*
* @param count
* delta of cached bytes
*/
void recordOpenBytes(int count);
/**
* Returns a snapshot of this recorder's stats. Note that this may be an
* inconsistent view, as it may be interleaved with update operations.
*
* @return a snapshot of this recorder's stats
*/
@NonNull
WindowCacheStats getStats();
}
static class StatsRecorderImpl
implements StatsRecorder, WindowCacheStats {
private final LongAdder hitCount;
private final LongAdder missCount;
private final LongAdder loadSuccessCount;
private final LongAdder loadFailureCount;
private final LongAdder totalLoadTime;
private final LongAdder evictionCount;
private final LongAdder openFileCount;
private final LongAdder openByteCount;
/**
* Constructs an instance with all counts initialized to zero.
*/
public StatsRecorderImpl() {
hitCount = new LongAdder();
missCount = new LongAdder();
loadSuccessCount = new LongAdder();
loadFailureCount = new LongAdder();
totalLoadTime = new LongAdder();
evictionCount = new LongAdder();
openFileCount = new LongAdder();
openByteCount = new LongAdder();
}
@Override
public void recordHits(int count) {
hitCount.add(count);
}
@Override
public void recordMisses(int count) {
missCount.add(count);
}
@Override
public void recordLoadSuccess(long loadTimeNanos) {
loadSuccessCount.increment();
totalLoadTime.add(loadTimeNanos);
}
@Override
public void recordLoadFailure(long loadTimeNanos) {
loadFailureCount.increment();
totalLoadTime.add(loadTimeNanos);
}
@Override
public void recordEvictions(int count) {
evictionCount.add(count);
}
@Override
public void recordOpenFiles(int count) {
openFileCount.add(count);
}
@Override
public void recordOpenBytes(int count) {
openByteCount.add(count);
}
@Override
public WindowCacheStats getStats() {
return this;
}
@Override
public long getHitCount() {
return hitCount.sum();
}
@Override
public long getMissCount() {
return missCount.sum();
}
@Override
public long getLoadSuccessCount() {
return loadSuccessCount.sum();
}
@Override
public long getLoadFailureCount() {
return loadFailureCount.sum();
}
@Override
public long getEvictionCount() {
return evictionCount.sum();
}
@Override
public long getTotalLoadTime() {
return totalLoadTime.sum();
}
@Override
public long getOpenFileCount() {
return openFileCount.sum();
}
@Override
public long getOpenByteCount() {
return openByteCount.sum();
}
@Override
public void resetCounters() {
hitCount.reset();
missCount.reset();
loadSuccessCount.reset();
loadFailureCount.reset();
totalLoadTime.reset();
evictionCount.reset();
}
}
private static final int bits(int newSize) { private static final int bits(int newSize) {
if (newSize < 4096) if (newSize < 4096)
throw new IllegalArgumentException(JGitText.get().invalidWindowSize); throw new IllegalArgumentException(JGitText.get().invalidWindowSize);
@ -195,9 +388,9 @@ public class WindowCache {
private final int windowSize; private final int windowSize;
private final AtomicInteger openFiles; private final StatsRecorder statsRecorder;
private final AtomicLong openBytes; private final StatsRecorderImpl mbean;
private WindowCache(WindowCacheConfig cfg) { private WindowCache(WindowCacheConfig cfg) {
tableSize = tableSize(cfg); tableSize = tableSize(cfg);
@ -230,8 +423,9 @@ public class WindowCache {
windowSizeShift = bits(cfg.getPackedGitWindowSize()); windowSizeShift = bits(cfg.getPackedGitWindowSize());
windowSize = 1 << windowSizeShift; windowSize = 1 << windowSizeShift;
openFiles = new AtomicInteger(); mbean = new StatsRecorderImpl();
openBytes = new AtomicLong(); statsRecorder = mbean;
Monitoring.registerMBean(mbean, "block_cache"); //$NON-NLS-1$
if (maxFiles < 1) if (maxFiles < 1)
throw new IllegalArgumentException(JGitText.get().openFilesMustBeAtLeast1); throw new IllegalArgumentException(JGitText.get().openFilesMustBeAtLeast1);
@ -240,55 +434,63 @@ public class WindowCache {
} }
/** /**
* @return the number of open files. * @return cache statistics for the WindowCache
*/ */
public int getOpenFiles() { public WindowCacheStats getStats() {
return openFiles.get(); return statsRecorder.getStats();
} }
/** /**
* @return the number of open bytes. * Reset stats. Does not reset open bytes and open files stats.
*/ */
public long getOpenBytes() { public void resetStats() {
return openBytes.get(); mbean.resetCounters();
} }
private int hash(int packHash, long off) { private int hash(int packHash, long off) {
return packHash + (int) (off >>> windowSizeShift); return packHash + (int) (off >>> windowSizeShift);
} }
private ByteWindow load(PackFile pack, long offset) private ByteWindow load(PackFile pack, long offset) throws IOException {
throws IOException { long startTime = System.nanoTime();
if (pack.beginWindowCache()) if (pack.beginWindowCache())
openFiles.incrementAndGet(); statsRecorder.recordOpenFiles(1);
try { try {
if (mmap) if (mmap)
return pack.mmap(offset, windowSize); return pack.mmap(offset, windowSize);
return pack.read(offset, windowSize); ByteArrayWindow w = pack.read(offset, windowSize);
statsRecorder.recordLoadSuccess(System.nanoTime() - startTime);
return w;
} catch (IOException | RuntimeException | Error e) { } catch (IOException | RuntimeException | Error e) {
close(pack); close(pack);
statsRecorder.recordLoadFailure(System.nanoTime() - startTime);
throw e; throw e;
} finally {
statsRecorder.recordMisses(1);
} }
} }
private Ref createRef(PackFile p, long o, ByteWindow v) { private Ref createRef(PackFile p, long o, ByteWindow v) {
final Ref ref = new Ref(p, o, v, queue); final Ref ref = new Ref(p, o, v, queue);
openBytes.addAndGet(ref.size); statsRecorder.recordOpenBytes(ref.size);
return ref; return ref;
} }
private void clear(Ref ref) { private void clear(Ref ref) {
openBytes.addAndGet(-ref.size); statsRecorder.recordOpenBytes(-ref.size);
statsRecorder.recordEvictions(1);
close(ref.pack); close(ref.pack);
} }
private void close(PackFile pack) { private void close(PackFile pack) {
if (pack.endWindowCache()) if (pack.endWindowCache()) {
openFiles.decrementAndGet(); statsRecorder.recordOpenFiles(-1);
}
} }
private boolean isFull() { private boolean isFull() {
return maxFiles < openFiles.get() || maxBytes < openBytes.get(); return maxFiles < mbean.getOpenFileCount()
|| maxBytes < mbean.getOpenByteCount();
} }
private long toStart(long offset) { private long toStart(long offset) {
@ -326,16 +528,20 @@ public class WindowCache {
final int slot = slot(pack, position); final int slot = slot(pack, position);
final Entry e1 = table.get(slot); final Entry e1 = table.get(slot);
ByteWindow v = scan(e1, pack, position); ByteWindow v = scan(e1, pack, position);
if (v != null) if (v != null) {
statsRecorder.recordHits(1);
return v; return v;
}
synchronized (lock(pack, position)) { synchronized (lock(pack, position)) {
Entry e2 = table.get(slot); Entry e2 = table.get(slot);
if (e2 != e1) { if (e2 != e1) {
v = scan(e2, pack, position); v = scan(e2, pack, position);
if (v != null) if (v != null) {
statsRecorder.recordHits(1);
return v; return v;
} }
}
v = load(pack, position); v = load(pack, position);
final Ref ref = createRef(pack, position, v); final Ref ref = createRef(pack, position, v);

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

@ -497,4 +497,10 @@ public final class ConfigConstants {
* @since 5.7 * @since 5.7
*/ */
public static final String CONFIG_REFSTORAGE_REFTREE = "reftree"; public static final String CONFIG_REFSTORAGE_REFTREE = "reftree";
/**
* The "jmx" section
* @since 5.1.13
*/
public static final String CONFIG_JMX_SECTION = "jmx";
} }

176
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheStats.java

@ -7,29 +7,193 @@
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
package org.eclipse.jgit.storage.file; package org.eclipse.jgit.storage.file;
import javax.management.MXBean;
import org.eclipse.jgit.internal.storage.file.WindowCache; import org.eclipse.jgit.internal.storage.file.WindowCache;
/** /**
* Accessor for stats about {@link WindowCache}. * Cache statistics for {@link WindowCache}.
* *
* @since 4.11 * @since 4.11
*
*/ */
public class WindowCacheStats { @MXBean
public interface WindowCacheStats {
/** /**
* @return the number of open files. * @return the number of open files.
* @deprecated use {@link #getOpenFileCount()} instead
*/ */
@Deprecated
public static int getOpenFiles() { public static int getOpenFiles() {
return WindowCache.getInstance().getOpenFiles(); return (int) WindowCache.getInstance().getStats().getOpenFileCount();
} }
/** /**
* @return the number of open bytes. * @return the number of open bytes.
* @deprecated use {@link #getOpenByteCount()} instead
*/ */
@Deprecated
public static long getOpenBytes() { public static long getOpenBytes() {
return WindowCache.getInstance().getOpenBytes(); return WindowCache.getInstance().getStats().getOpenByteCount();
}
/**
* @return cache statistics for the WindowCache
* @since 5.1.13
*/
public static WindowCacheStats getStats() {
return WindowCache.getInstance().getStats();
}
/**
* Number of cache hits
*
* @return number of cache hits
*/
long getHitCount();
/**
* Ratio of cache requests which were hits defined as
* {@code hitCount / requestCount}, or {@code 1.0} when
* {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
*
* @return the ratio of cache requests which were hits
*/
default double getHitRatio() {
long requestCount = getRequestCount();
return (requestCount == 0) ? 1.0
: (double) getHitCount() / requestCount;
} }
/**
* Number of cache misses.
*
* @return number of cash misses
*/
long getMissCount();
/**
* Ratio of cache requests which were misses defined as
* {@code missCount / requestCount}, or {@code 0.0} when
* {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
* Cache misses include all requests which weren't cache hits, including
* requests which resulted in either successful or failed loading attempts.
*
* @return the ratio of cache requests which were misses
*/
default double getMissRatio() {
long requestCount = getRequestCount();
return (requestCount == 0) ? 0.0
: (double) getMissCount() / requestCount;
}
/**
* Number of successful loads
*
* @return number of successful loads
*/
long getLoadSuccessCount();
/**
* Number of failed loads
*
* @return number of failed loads
*/
long getLoadFailureCount();
/**
* Ratio of cache load attempts which threw exceptions. This is defined as
* {@code loadFailureCount / (loadSuccessCount + loadFailureCount)}, or
* {@code 0.0} when {@code loadSuccessCount + loadFailureCount == 0}.
*
* @return the ratio of cache loading attempts which threw exceptions
*/
default double getLoadFailureRatio() {
long loadFailureCount = getLoadFailureCount();
long totalLoadCount = getLoadSuccessCount() + loadFailureCount;
return (totalLoadCount == 0) ? 0.0
: (double) loadFailureCount / totalLoadCount;
}
/**
* Total number of times that the cache attempted to load new values. This
* includes both successful load operations, as well as failed loads. This
* is defined as {@code loadSuccessCount + loadFailureCount}.
*
* @return the {@code loadSuccessCount + loadFailureCount}
*/
default long getLoadCount() {
return getLoadSuccessCount() + getLoadFailureCount();
}
/**
* Number of cache evictions
*
* @return number of evictions
*/
long getEvictionCount();
/**
* Ratio of cache evictions. This is defined as
* {@code evictionCount / requestCount}, or {@code 0.0} when
* {@code requestCount == 0}.
*
* @return the ratio of cache loading attempts which threw exceptions
*/
default double getEvictionRatio() {
long evictionCount = getEvictionCount();
long requestCount = getRequestCount();
return (requestCount == 0) ? 0.0
: (double) evictionCount / requestCount;
}
/**
* Number of times the cache returned either a cached or uncached value.
* This is defined as {@code hitCount + missCount}.
*
* @return the {@code hitCount + missCount}
*/
default long getRequestCount() {
return getHitCount() + getMissCount();
}
/**
* Average time in nanoseconds for loading new values. This is
* {@code totalLoadTime / (loadSuccessCount + loadFailureCount)}.
*
* @return the average time spent loading new values
*/
default double getAverageLoadTime() {
long totalLoadCount = getLoadSuccessCount() + getLoadFailureCount();
return (totalLoadCount == 0) ? 0.0
: (double) getTotalLoadTime() / totalLoadCount;
}
/**
* Total time in nanoseconds the cache spent loading new values.
*
* @return the total number of nanoseconds the cache has spent loading new
* values
*/
long getTotalLoadTime();
/**
* Number of pack files kept open by the cache
*
* @return number of files kept open by cache
*/
long getOpenFileCount();
/**
* Number of bytes cached
*
* @return number of bytes cached
*/
long getOpenByteCount();
/**
* Reset counters. Does not reset open bytes and open files counters.
*/
void resetCounters();
} }

89
org.eclipse.jgit/src/org/eclipse/jgit/util/Monitoring.java

@ -0,0 +1,89 @@
/*
* Copyright (c) 2019 Matthias Sohn <matthias.sohn@sap.com>
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.util;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.ConfigConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Enables monitoring JGit via JMX
*
* @since 5.1.13
*/
public class Monitoring {
private final static Logger LOG = LoggerFactory.getLogger(Monitoring.class);
/**
* Register a MBean with the platform MBean server
*
* @param mbean
* the mbean object to register
* @param metricName
* name of the JGit metric, will be prefixed with
* "org.eclipse.jgit/"
* @return the registered mbean's object instance
*/
public static @Nullable ObjectInstance registerMBean(Object mbean,
String metricName) {
boolean register = false;
try {
Class<?> interfaces[] = mbean.getClass().getInterfaces();
for (Class<?> i : interfaces) {
register = SystemReader.getInstance().getUserConfig()
.getBoolean(
ConfigConstants.CONFIG_JMX_SECTION,
i.getSimpleName(), false);
if (register) {
break;
}
}
} catch (IOException | ConfigInvalidException e) {
LOG.error(e.getMessage(), e);
return null;
}
if (!register) {
return null;
}
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName mbeanName = objectName(mbean.getClass(), metricName);
if (server.isRegistered(mbeanName)) {
server.unregisterMBean(mbeanName);
}
return server.registerMBean(mbean, mbeanName);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException
| MBeanRegistrationException | NotCompliantMBeanException
| InstanceNotFoundException e) {
LOG.error(e.getMessage(), e);
return null;
}
}
private static ObjectName objectName(Class mbean, String metricName)
throws MalformedObjectNameException {
return new ObjectName(String.format("org.eclipse.jgit/%s:type=%s", //$NON-NLS-1$
metricName, mbean.getSimpleName()));
}
}

11
org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java

@ -61,6 +61,7 @@ public class SshSupport {
CommandFailedException failure = null; CommandFailedException failure = null;
@SuppressWarnings("resource") @SuppressWarnings("resource")
MessageWriter stderr = new MessageWriter(); MessageWriter stderr = new MessageWriter();
String out;
try (MessageWriter stdout = new MessageWriter()) { try (MessageWriter stdout = new MessageWriter()) {
session = SshSessionFactory.getInstance().getSession(sshUri, session = SshSessionFactory.getInstance().getSession(sshUri,
provider, fs, 1000 * timeout); provider, fs, 1000 * timeout);
@ -75,11 +76,12 @@ public class SshSupport {
// waitFor with timeout has a bug - JSch' exitValue() throws the // waitFor with timeout has a bug - JSch' exitValue() throws the
// wrong exception type :( // wrong exception type :(
if (process.waitFor() == 0) { if (process.waitFor() == 0) {
return stdout.toString(); out = stdout.toString();
} else {
out = null; // still running after timeout
} }
return null; // still running after timeout
} catch (InterruptedException e) { } catch (InterruptedException e) {
return null; // error out = null; // error
} }
} finally { } finally {
if (errorThread != null) { if (errorThread != null) {
@ -113,10 +115,11 @@ public class SshSupport {
if (session != null) { if (session != null) {
SshSessionFactory.getInstance().releaseSession(session); SshSessionFactory.getInstance().releaseSession(session);
} }
}
if (failure != null) { if (failure != null) {
throw failure; throw failure;
} }
} return out;
} }
} }

2
pom.xml

@ -804,7 +804,6 @@
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration> <configuration>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<source>1.8</source> <source>1.8</source>
@ -873,7 +872,6 @@
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration> <configuration>
<compilerId>eclipse</compilerId> <compilerId>eclipse</compilerId>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>

Loading…
Cancel
Save