Index: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java =================================================================== --- oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java (revision 1822639) +++ oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java (working copy) @@ -718,10 +718,6 @@ protected void setGCBlobStore(GarbageCollectableBlobStore s) { configureBlobStore(s); - PersistentCache p = getPersistentCache(); - if (p != null) { - s = p.wrapBlobStore(s); - } this.blobStore = s; } Index: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BlobCache.java =================================================================== --- oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BlobCache.java (revision 1822639) +++ oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BlobCache.java (nonexistent) @@ -1,236 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jackrabbit.oak.plugins.document.persistentCache; - -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.Iterator; -import java.util.List; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache.GenerationCache; -import org.apache.jackrabbit.oak.spi.blob.BlobOptions; -import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore; -import org.h2.mvstore.MVMap; -import org.h2.mvstore.StreamStore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A persistent blob cache. Only blobs that are smaller than 10% of the maximum - * cache size are stored. - */ -public class BlobCache implements GarbageCollectableBlobStore, GenerationCache, Closeable { - - static final Logger LOG = LoggerFactory.getLogger(BlobCache.class); - - private final GarbageCollectableBlobStore base; - private final PersistentCache cache; - private final MultiGenerationMap meta; - private MultiGenerationMap data; - private StreamStore streamStore; - private long maxEntrySize; - - public BlobCache( - PersistentCache cache, - GarbageCollectableBlobStore base) { - this.cache = cache; - this.base = base; - data = new MultiGenerationMap(); - meta = new MultiGenerationMap(); - maxEntrySize = cache.getMaxBinaryEntrySize(); - } - - @Override - public CacheType getType() { - return CacheType.BLOB; - } - - @Override - public void addGeneration(int generation, boolean readOnly) { - CacheMap d = cache.openMap(generation, "data", - new MVMap.Builder()); - data.addReadMap(generation, d); - CacheMap m = cache.openMap(generation, "meta", - new MVMap.Builder()); - meta.addReadMap(generation, m); - if (!readOnly) { - // the order is important: - // if we switch the data first, - // we could end up with the data in store 1 - // but the metadata in store 2 - which could - // result in a data block not found if store 1 - // is removed later on - meta.setWriteMap(m); - data.setWriteMap(d); - } - if (streamStore == null) { - streamStore = new StreamStore(data); - } - } - - @Override - public void removeGeneration(int generation) { - data.removeReadMap(generation); - meta.removeReadMap(generation); - } - - @Override - public InputStream getInputStream(String blobId) throws IOException { - if (streamStore == null) { - return base.getInputStream(blobId); - } - cache.switchGenerationIfNeeded(); - byte[] id = meta.get(blobId); - if (id == null) { - long length = base.getBlobLength(blobId); - InputStream in = base.getInputStream(blobId); - if (length < base.getBlockSizeMin()) { - // in-place - return in; - } - if (length > maxEntrySize) { - // too large, don't cache - return in; - } - id = streamStore.put(in); - in.close(); - meta.put(blobId, id); - } - return streamStore.get(id); - } - - @Override - public String writeBlob(InputStream in) throws IOException { - // TODO maybe copy the binary to the cache in a background thread - return base.writeBlob(in); - } - - /** - * Ignores the options provided and delegates to {@link #writeBlob(InputStream)}. - * - * @param in the input stream to write - * @param options the options to use - * @return - * @throws IOException - */ - @Override - public String writeBlob(InputStream in, BlobOptions options) throws IOException { - return writeBlob(in); - } - - @Override - public int readBlob(String blobId, long pos, byte[] buff, int off, - int length) throws IOException { - InputStream in = getInputStream(blobId); - long remainingSkip = pos; - while (remainingSkip > 0) { - remainingSkip -= in.skip(remainingSkip); - } - return in.read(buff, off, length); - } - - @Override - public long getBlobLength(String blobId) throws IOException { - return base.getBlobLength(blobId); - } - - @Override - @CheckForNull - public String getBlobId(@Nonnull String reference) { - return base.getBlobId(reference); - } - - @Override - @CheckForNull - public String getReference(@Nonnull String blobId) { - return base.getReference(blobId); - } - - @Override - public void clearCache() { - base.clearCache(); - } - - @Override - public void clearInUse() { - base.clearInUse(); - } - - @Override - @Deprecated - public boolean deleteChunks(List chunkIds, long maxLastModifiedTime) throws Exception { - return base.deleteChunks(chunkIds, maxLastModifiedTime); - } - - @Override - public long countDeleteChunks(List chunkIds, long maxLastModifiedTime) throws Exception { - return base.countDeleteChunks(chunkIds, maxLastModifiedTime); - } - - @Override - public Iterator getAllChunkIds(long maxLastModifiedTime) throws Exception { - return base.getAllChunkIds(maxLastModifiedTime); - } - - @Override - public long getBlockSizeMin() { - return base.getBlockSizeMin(); - } - - @Override - public Iterator resolveChunks(String blobId) throws IOException { - return base.resolveChunks(blobId); - } - - @Override - public void setBlockSize(int x) { - base.setBlockSize(x); - } - - @Override - public void startMark() throws IOException { - base.startMark(); - } - - @Override - public int sweep() throws IOException { - return base.sweep(); - } - - @Override - public String writeBlob(String tempFileName) throws IOException { - return base.writeBlob(tempFileName); - } - - @Override - public void receive(ByteBuffer buff) { - throw new UnsupportedOperationException(); - } - - @Override - public void close() throws IOException { - if (base instanceof Closeable) { - ((Closeable)base).close(); - } - } - -} Property changes on: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BlobCache.java ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Index: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java =================================================================== --- oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java (revision 1822639) +++ oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java (working copy) @@ -126,63 +126,31 @@ } }, - DOC_CHILDREN { - @Override - public String keyToString(K key) { - return ((StringValue) key).asString(); - } - @SuppressWarnings("unchecked") - @Override - public K keyFromString(String key) { - return (K) StringValue.fromString(key); - } - @Override - public int compareKeys(K a, K b) { - return ((StringValue) a).asString().compareTo(((StringValue) b).asString()); - } - @Override - public String valueToString(V value) { - return ((NodeDocument.Children) value).asString(); - } - @SuppressWarnings("unchecked") - @Override - public V valueFromString( - DocumentNodeStore store, DocumentStore docStore, String value) { - return (V) NodeDocument.Children.fromString(value); - } - @Override - public boolean shouldCache(DocumentNodeStore store, K key) { - return true; - } - }, - DOCUMENT { @Override public String keyToString(K key) { - return ((StringValue) key).asString(); + throw new UnsupportedOperationException(); } - @SuppressWarnings("unchecked") @Override public K keyFromString(String key) { - return (K) StringValue.fromString(key); + throw new UnsupportedOperationException(); } @Override public int compareKeys(K a, K b) { - return ((StringValue) a).asString().compareTo(((StringValue) b).asString()); + throw new UnsupportedOperationException(); } @Override public String valueToString(V value) { - return ((NodeDocument) value).asString(); + throw new UnsupportedOperationException(); } - @SuppressWarnings("unchecked") @Override public V valueFromString( DocumentNodeStore store, DocumentStore docStore, String value) { - return (V) NodeDocument.fromString(docStore, value); + throw new UnsupportedOperationException(); } @Override public boolean shouldCache(DocumentNodeStore store, K key) { - return true; + return false; } }, @@ -244,40 +212,6 @@ public boolean shouldCache(DocumentNodeStore store, K key) { return true; } - }, - - BLOB { - - @Override - public String keyToString(K key) { - throw new UnsupportedOperationException(); - } - - @Override - public K keyFromString(String key) { - throw new UnsupportedOperationException(); - } - - @Override - public int compareKeys(K a, K b) { - throw new UnsupportedOperationException(); - } - - @Override - public String valueToString(V value) { - throw new UnsupportedOperationException(); - } - - @Override - public V valueFromString(DocumentNodeStore store, - DocumentStore docStore, String value) { - throw new UnsupportedOperationException(); - } - @Override - public boolean shouldCache(DocumentNodeStore store, K key) { - return true; - } - }; public static final CacheType[] VALUES = CacheType.values(); Index: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java =================================================================== --- oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java (revision 1822639) +++ oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java (working copy) @@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.InMemoryBroadcaster; import org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster; import org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.UDPBroadcaster; -import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.h2.mvstore.FileStore; import org.h2.mvstore.MVMap; @@ -63,8 +62,6 @@ private boolean cacheDiff = true; private boolean cacheLocalDiff = true; private boolean cachePrevDocs = true; - private boolean cacheDocs; - private boolean cacheDocChildren; private boolean compactOnClose; private boolean compress = true; private boolean asyncCache = true; @@ -79,7 +76,6 @@ private int memCache = -1; private int readGeneration = -1; private int writeGeneration; - private long maxBinaryEntry = 1024 * 1024; private int autoCompact = 0; private boolean appendOnly; private boolean manualCommit; @@ -107,15 +103,11 @@ String broadcast = "disabled"; for (String p : parts) { if (p.equals("+docs")) { - // enabling this can lead to consistency problems, - // specially if multiple cluster nodes are used - cacheDocs = true; + logUnsupportedWarning("docs"); } else if (p.equals("-prevDocs")) { cachePrevDocs = false; } else if (p.equals("+docChildren")) { - // enabling this can lead to consistency problems, - // specially if multiple cluster nodes are used - cacheDocChildren = true; + logUnsupportedWarning("docChildren"); } else if (p.equals("-nodes")) { cacheNodes = false; } else if (p.equals("-children")) { @@ -125,8 +117,7 @@ } else if (p.equals("-localDiff")) { cacheLocalDiff = false; } else if (p.equals("+all")) { - cacheDocs = true; - cacheDocChildren = true; + logUnsupportedWarning("all"); } else if (p.equals("-compact")) { compactOnClose = false; } else if (p.equals("+compact")) { @@ -140,7 +131,7 @@ } else if (p.startsWith("memCache=")) { memCache = Integer.parseInt(p.split("=")[1]); } else if (p.startsWith("binary=")) { - maxBinaryEntry = Long.parseLong(p.split("=")[1]); + logUnsupportedWarning("binary"); } else if (p.startsWith("autoCompact=")) { autoCompact = Integer.parseInt(p.split("=")[1]); } else if (p.equals("appendOnly")) { @@ -215,6 +206,11 @@ writeDispatcherThread.setDaemon(true); writeDispatcherThread.start(); } + + private void logUnsupportedWarning(String configKey) { + LOG.warn("Support for '{}' has been removed from persistent cache. " + + "Please update the configuration.", configKey); + } private void initBroadcast(String broadcast) { if (broadcast == null) { @@ -384,16 +380,6 @@ writeBuffer.remove(); } - public synchronized GarbageCollectableBlobStore wrapBlobStore( - GarbageCollectableBlobStore base) { - if (maxBinaryEntry == 0) { - return base; - } - BlobCache c = new BlobCache(this, base); - initGenerationCache(c); - return c; - } - public synchronized Cache wrap( DocumentNodeStore docNodeStore, DocumentStore docStore, @@ -423,12 +409,6 @@ wrap = cacheLocalDiff; async = asyncDiffCache; break; - case DOC_CHILDREN: - wrap = cacheDocChildren; - break; - case DOCUMENT: - wrap = cacheDocs; - break; case PREV_DOCUMENT: wrap = cachePrevDocs; break; @@ -510,10 +490,6 @@ return maxSizeMB; } - public long getMaxBinaryEntrySize() { - return maxBinaryEntry; - } - public int getOpenCount() { return writeStore.getOpenCount(); } Index: oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java =================================================================== --- oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java (revision 1822639) +++ oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java (working copy) @@ -22,10 +22,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; -import java.util.Random; import com.google.common.cache.Cache; import org.apache.commons.io.FileUtils; @@ -34,8 +32,6 @@ import org.apache.jackrabbit.oak.plugins.document.Revision; import org.apache.jackrabbit.oak.plugins.document.RevisionVector; import org.apache.jackrabbit.oak.plugins.document.util.StringValue; -import org.apache.jackrabbit.oak.spi.blob.BlobStore; -import org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore; import org.junit.Test; public class CacheTest { @@ -96,26 +92,6 @@ } @Test - public void test() throws Exception { - FileUtils.deleteDirectory(new File("target/cacheTest")); - PersistentCache cache = new PersistentCache("target/cacheTest,size=1,-compress"); - try { - MemoryBlobStore mem = new MemoryBlobStore(); - mem.setBlockSizeMin(100); - BlobStore b = cache.wrapBlobStore(mem); - Random r = new Random(); - for (int i = 0; i < 10000; i++) { - byte[] data = new byte[100]; - r.nextBytes(data); - String id = b.writeBlob(new ByteArrayInputStream(data)); - b.readBlob(id, 0, new byte[1], 0, 1); - } - } finally { - cache.close(); - } - } - - @Test public void interrupt() throws Exception { FileUtils.deleteDirectory(new File("target/cacheTest")); PersistentCache cache = new PersistentCache("target/cacheTest,size=1,-compress");