You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2016/05/17 09:58:53 UTC
svn commit: r1744236 - in
/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment:
RecordCache.java SegmentWriter.java
Author: mduerig
Date: Tue May 17 09:58:53 2016
New Revision: 1744236
URL: http://svn.apache.org/viewvc?rev=1744236&view=rev
Log:
OAK-4277: Finalise de-duplication caches
Simplify cache usage
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordCache.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordCache.java?rev=1744236&r1=1744235&r2=1744236&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordCache.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/RecordCache.java Tue May 17 09:58:53 2016
@@ -45,7 +45,6 @@ public class RecordCache<T> {
private static final Logger LOG = LoggerFactory.getLogger(RecordCache.class);
// FIXME OAK-4277: Finalise de-duplication caches
// make this configurable
- private static final int RETENTION_THRESHOLD = 1;
private final ConcurrentMap<Integer, Supplier<Cache<T>>> generations = newConcurrentMap();
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java?rev=1744236&r1=1744235&r2=1744236&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentWriter.java Tue May 17 09:58:53 2016
@@ -331,6 +331,9 @@ public class SegmentWriter {
private final Supplier<Boolean> cancel;
private SegmentBufferWriter writer;
+ private Cache<String> stringCache;
+ private Cache<Template> templateCache;
+ private Cache<String> nodeCache;
protected SegmentWriteOperation(Supplier<Boolean> cancel) {
this.cancel = cancel;
@@ -346,13 +349,13 @@ public class SegmentWriter {
SegmentWriteOperation with(SegmentBufferWriter writer) {
checkState(this.writer == null);
this.writer = writer;
+ int generation = writer.getGeneration();
+ this.stringCache = SegmentWriter.this.stringCache.generation(generation);
+ this.templateCache = SegmentWriter.this.templateCache.generation(generation);
+ this.nodeCache = SegmentWriter.this.nodeCache.generation(generation);
return this;
}
- private int generation() {
- return writer.getGeneration();
- }
-
private RecordId writeMap(MapRecord base, Map<String, RecordId> changes) throws IOException {
if (base != null && base.isDiff()) {
Segment segment = base.getSegment();
@@ -578,7 +581,7 @@ public class SegmentWriter {
* @return value record identifier
*/
private RecordId writeString(String string) throws IOException {
- RecordId id = stringCache.generation(generation()).get(string);
+ RecordId id = stringCache.get(string);
if (id != null) {
return id; // shortcut if the same string was recently stored
}
@@ -588,7 +591,7 @@ public class SegmentWriter {
if (data.length < Segment.MEDIUM_LIMIT) {
// only cache short strings to avoid excessive memory use
id = writeValueRecord(data.length, data);
- stringCache.generation(generation()).put(string, id);
+ stringCache.put(string, id);
return id;
}
@@ -776,7 +779,7 @@ public class SegmentWriter {
private RecordId writeTemplate(Template template) throws IOException {
checkNotNull(template);
- RecordId id = templateCache.generation(generation()).get(template);
+ RecordId id = templateCache.get(template);
if (id != null) {
return id; // shortcut if the same template was recently stored
}
@@ -843,7 +846,7 @@ public class SegmentWriter {
RecordId tid = RecordWriters.newTemplateWriter(ids, propertyNames,
propertyTypes, head, primaryId, mixinIds, childNameId,
propNamesId, version).write(writer);
- templateCache.generation(generation()).put(template, tid);
+ templateCache.put(template, tid);
return tid;
}
@@ -855,10 +858,10 @@ public class SegmentWriter {
if (state instanceof SegmentNodeState) {
SegmentNodeState sns = ((SegmentNodeState) state);
if (hasSegment(sns)) {
+ // This is a segment node state from an old generation. Check whether
+ // an equivalent one of the current generation is in the cache
if (isOldGen(sns.getRecordId())) {
- // This is a segment node state from an old generation. Check whether
- // an equivalent one of the current generation is in the cache
- RecordId cachedId = nodeCache.generation(generation()).get(sns.getStableId());
+ RecordId cachedId = nodeCache.get(sns.getStableId());
if (cachedId != null) {
return cachedId;
}
@@ -876,7 +879,7 @@ public class SegmentWriter {
// generation (e.g. due to compaction). Put it into the cache for
// deduplication of hard links to it (e.g. checkpoints).
SegmentNodeState sns = (SegmentNodeState) state;
- nodeCache.generation(generation()).put(sns.getStableId(), recordId, depth);
+ nodeCache.put(sns.getStableId(), recordId, depth);
}
return recordId;
}