Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions oak-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
</build>

<dependencies>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import javax.jcr.Repository;

import org.apache.jackrabbit.guava.common.cache.Cache;
import com.github.benmanes.caffeine.cache.Cache;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.fixture.OakFixture;
import org.apache.jackrabbit.oak.fixture.OakRepositoryFixture;
Expand Down
4 changes: 4 additions & 0 deletions oak-blob-cloud-azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
<artifactId>oak-shaded-guava</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>

<!-- Dependencies to other Oak components -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.apache.jackrabbit.core.data.DataIdentifier;
import org.apache.jackrabbit.core.data.DataRecord;
import org.apache.jackrabbit.core.data.DataStoreException;
import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.apache.jackrabbit.oak.commons.conditions.Validate;
import org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord;
Expand Down Expand Up @@ -767,7 +767,7 @@ protected void setHttpDownloadURICacheSize(int maxSize) {
// max size 0 or smaller is used to turn off the cache
if (maxSize > 0) {
LOG.info("presigned GET URI cache enabled, maxSize = {} items, expiry = {} seconds", maxSize, httpDownloadURIExpirySeconds / 2);
httpDownloadURICache = CacheBuilder.newBuilder()
httpDownloadURICache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(httpDownloadURIExpirySeconds / 2, TimeUnit.SECONDS)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;

import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.jackrabbit.oak.commons.collections.AbstractIterator;
import org.apache.jackrabbit.oak.commons.time.Stopwatch;

Expand Down Expand Up @@ -731,7 +731,7 @@ protected void setHttpDownloadURICacheSize(int maxSize) {
// max size 0 or smaller is used to turn off the cache
if (maxSize > 0) {
LOG.info("presigned GET URI cache enabled, maxSize = {} items, expiry = {} seconds", maxSize, httpDownloadURIExpirySeconds / 2);
httpDownloadURICache = CacheBuilder.newBuilder()
httpDownloadURICache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(httpDownloadURIExpirySeconds / 2, TimeUnit.SECONDS)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.jackrabbit.core.data.DataIdentifier;
import org.apache.jackrabbit.core.data.DataRecord;
import org.apache.jackrabbit.core.data.DataStoreException;
import org.apache.jackrabbit.guava.common.cache.Cache;
import com.github.benmanes.caffeine.cache.Cache;
import org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions;
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordDownloadOptions;
import org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess.DataRecordUpload;
Expand Down
5 changes: 4 additions & 1 deletion oak-blob-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

<!-- Jackrabbit/Oak -->
org.apache.jackrabbit.core.data,
org.apache.jackrabbit.guava.common.cache,
org.apache.jackrabbit.oak.commons.*,
org.apache.jackrabbit.oak.plugins.blob.*,
org.apache.jackrabbit.oak.spi.blob,
Expand Down Expand Up @@ -430,6 +429,10 @@
<artifactId>oak-shaded-guava</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.async.AsyncRequestBody;
Expand Down Expand Up @@ -812,7 +812,7 @@ void setHttpDownloadURICacheSize(int maxSize) {
// max size 0 or smaller is used to turn off the cache
if (maxSize > 0) {
LOG.info("presigned GET URI cache enabled, maxSize = {} items, expiry = {} seconds", maxSize, httpDownloadURIExpirySeconds / 2);
httpDownloadURICache = CacheBuilder.newBuilder()
httpDownloadURICache = Caffeine.newBuilder()
.maximumSize(maxSize)
// cache for half the expiry time of the URIs before giving out new ones
.expireAfterWrite(httpDownloadURIExpirySeconds / 2, TimeUnit.SECONDS)
Expand Down
4 changes: 4 additions & 0 deletions oak-blob-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
<artifactId>oak-shaded-guava</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.apache.jackrabbit.core.data.DataRecord;
import org.apache.jackrabbit.core.data.DataStoreException;
import org.apache.jackrabbit.core.data.MultiDataStoreAware;
import org.apache.jackrabbit.guava.common.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.CacheLoader;
import org.apache.jackrabbit.oak.plugins.blob.datastore.TypedDataStore;
import org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord;
import org.apache.jackrabbit.oak.spi.blob.AbstractSharedBackend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.blob;

import org.apache.jackrabbit.guava.common.cache.Weigher;
import com.github.benmanes.caffeine.cache.Weigher;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.commons.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;

import org.apache.jackrabbit.guava.common.cache.AbstractCache;
import org.apache.jackrabbit.guava.common.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.CacheLoader;
import org.apache.jackrabbit.oak.commons.IOUtils;
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
import org.jetbrains.annotations.Nullable;
Expand All @@ -37,7 +36,7 @@

/**
*/
public class CompositeDataStoreCache extends AbstractCache<String, File> implements Closeable {
public class CompositeDataStoreCache implements Closeable {
/**
* Logger instance.
*/
Expand Down Expand Up @@ -96,7 +95,6 @@ public File getIfPresent(String key) {
}

@Nullable
@Override
public File getIfPresent(Object key) {
return getIfPresent((String) key);
}
Expand All @@ -116,7 +114,6 @@ public File get(String key) throws IOException {
}
}

@Override
public void invalidate(Object key) {
stagingCache.invalidate((String) key);
downloadCache.invalidate(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.CacheLoader;
import org.apache.jackrabbit.guava.common.cache.RemovalCause;
import org.apache.jackrabbit.guava.common.cache.Weigher;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.Weigher;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.commons.StringUtils;
Expand All @@ -49,11 +49,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.jackrabbit.guava.common.cache.AbstractCache;

/**
*/
public class FileCache extends AbstractCache<String, File> implements Closeable {
public class FileCache implements Closeable {
/**
* Logger instance.
*/
Expand Down Expand Up @@ -201,7 +199,7 @@
* Get the current entry count (number of files).
*/
public long getEntryCount() {
return cache.size();
return cache.estimatedSize();
}

private FileCache() {
Expand Down Expand Up @@ -257,7 +255,6 @@
* @param key of the file
* @param file to put into cache
*/
@Override
public void put(String key, File file) {
adjustSize();
put(key, file, true);
Expand Down Expand Up @@ -302,7 +299,6 @@
}

@Nullable
@Override
public File getIfPresent(Object key) {
return getIfPresent((String) key);
}
Expand All @@ -311,7 +307,7 @@
adjustSize();
try {
// get from cache and download if not available
cache.get(key, () -> cacheLoader.load(key));

Check warning on line 310 in oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/FileCache.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this use of "get"; it is deprecated.

See more on https://sonarcloud.io/project/issues?id=org.apache.jackrabbit%3Ajackrabbit-oak&issues=AZ0O5CJ021WDqUHGXrZh&open=AZ0O5CJ021WDqUHGXrZh&pullRequest=2807
return getFile(key);
} catch (ExecutionException e) {
LOG.error("Error loading [{}] from cache", key);
Expand All @@ -320,7 +316,7 @@
}

private void adjustSize() {
long currentSize = cache.size();
long currentSize = cache.estimatedSize();
if (currentSize > highWaterMark) {
highWaterMark = currentSize;
// low for each additional 50'000 entries
Expand Down Expand Up @@ -362,11 +358,10 @@
// never grow larger than the configured size
currentBlockLimit = Math.min(currentBlockLimit, maxBlocks);
LOG.info("Shrinking the file cache size to {} because there are {} files (limit: {})",
currentBlockLimit, cache.size(), maxEntryCount);
currentBlockLimit, cache.estimatedSize(), maxEntryCount);
cache.setMaxMemory(currentBlockLimit);
}

@Override
public void invalidate(Object key) {
cache.invalidate(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.util.stream.Stream;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.apache.jackrabbit.guava.common.cache.Weigher;
import com.github.benmanes.caffeine.cache.Weigher;
import org.apache.jackrabbit.core.data.DataStoreException;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;

import javax.jcr.RepositoryException;
Expand All @@ -47,8 +46,8 @@
import org.apache.jackrabbit.core.data.DataStore;
import org.apache.jackrabbit.core.data.DataStoreException;
import org.apache.jackrabbit.core.data.MultiDataStoreAware;
import org.apache.jackrabbit.guava.common.cache.LoadingCache;
import org.apache.jackrabbit.guava.common.cache.Weigher;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.Weigher;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.blob.BlobAccessProvider;
import org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions;
Expand Down Expand Up @@ -420,19 +419,16 @@ public InputStream getInputStream(final String encodedBlobId) throws IOException
&& blobId.hasLengthInfo()
&& blobId.length <= maxCachedBinarySize) {
try {
byte[] content = cache.get(blobId.blobId, new Callable<byte[]>() {
@Override
public byte[] call() throws Exception {
boolean threw = true;
try (InputStream stream = getStream(blobId.blobId)) {
byte[] result = IOUtils.toByteArray(stream);
return result;
}
byte[] content = cache.get(blobId.blobId, key -> {
try (InputStream stream = getStream(key)) {
return IOUtils.toByteArray(stream);
} catch (IOException e) {
throw new CompletionException(e);
}
});

return new ByteArrayInputStream(content);
} catch (ExecutionException e) {
} catch (CompletionException e) {
log.warn("Error occurred while loading bytes from steam while fetching for id {}", encodedBlobId, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.apache.jackrabbit.core.data.DataIdentifier;
import org.apache.jackrabbit.core.data.DataRecord;
import org.apache.jackrabbit.core.data.DataStoreException;
import org.apache.jackrabbit.guava.common.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.CacheLoader;
import org.apache.jackrabbit.oak.commons.FileIOUtils;
import org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord;
import org.apache.jackrabbit.oak.spi.blob.AbstractSharedBackend;
Expand Down Expand Up @@ -112,7 +112,7 @@ public File read(String id) {
}


static class TestCacheLoader extends CacheLoader<String, InputStream> {
static class TestCacheLoader implements CacheLoader<String, InputStream> {
protected File root;

public TestCacheLoader(File dir) {
Expand Down
4 changes: 4 additions & 0 deletions oak-blob/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
<artifactId>oak-shaded-guava</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.jackrabbit.oak.commons.collections.BloomFilter;

class BlobIdSet {
Expand All @@ -46,7 +46,7 @@ class BlobIdSet {
BlobIdSet(String repositoryDir, String filename) {
store = new File(new File(repositoryDir), filename);
bloomFilter = BloomFilter.construct(9000000, 0.03); // 9M entries, 3% false positive rate
cache = CacheBuilder.newBuilder().maximumSize(1000).build();
cache = Caffeine.newBuilder().maximumSize(1000).build();
fillBloomFilter();
}

Expand Down
6 changes: 6 additions & 0 deletions oak-core-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@
<version>${project.version}</version>
</dependency>

<!-- Caffeine cache -->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Loading
Loading