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 al...@apache.org on 2014/11/24 11:12:12 UTC

svn commit: r1641352 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java

Author: alexparvulescu
Date: Mon Nov 24 10:12:12 2014
New Revision: 1641352

URL: http://svn.apache.org/r1641352
Log:
OAK-2271 Compaction estimation time should not depend on number of checkpoints


Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java?rev=1641352&r1=1641351&r2=1641352&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/CompactionGainEstimate.java Mon Nov 24 10:12:12 2014
@@ -19,14 +19,17 @@ package org.apache.jackrabbit.oak.plugin
 import static org.apache.jackrabbit.oak.api.Type.BINARIES;
 
 import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.UUID;
 
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.segment.RecordId;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentBlob;
 import org.apache.jackrabbit.oak.plugins.segment.SegmentId;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeState;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.hash.BloomFilter;
 import com.google.common.hash.Funnel;
@@ -48,23 +51,28 @@ class CompactionGainEstimate implements 
 
     private long reachableSize = 0;
 
-    CompactionGainEstimate(NodeState node, int estimatedBulkCount) {
+    CompactionGainEstimate(SegmentNodeState node, int estimatedBulkCount) {
         uuids = BloomFilter.create(UUID_FUNNEL, estimatedBulkCount);
-        collectBulkSegments(node);
+        collectBulkSegments(node, new HashSet<ThinRecordId>());
     }
 
-    private void collectBulkSegments(NodeState node) {
-        for (PropertyState property : node.getProperties()) {
-            for (Blob blob : property.getValue(BINARIES)) {
-                for (SegmentId id : SegmentBlob.getBulkSegmentIds(blob)) {
-                    uuids.put(new UUID(
-                            id.getMostSignificantBits(),
-                            id.getLeastSignificantBits()));
+    private void collectBulkSegments(SegmentNodeState node,
+            Set<ThinRecordId> visited) {
+        ThinRecordId tr = ThinRecordId.apply(node.getRecordId());
+        if (!visited.contains(tr)) {
+            for (PropertyState property : node.getProperties()) {
+                for (Blob blob : property.getValue(BINARIES)) {
+                    for (SegmentId id : SegmentBlob.getBulkSegmentIds(blob)) {
+                        uuids.put(new UUID(id.getMostSignificantBits(), id
+                                .getLeastSignificantBits()));
+                    }
                 }
             }
-        }
-        for (ChildNodeEntry child : node.getChildNodeEntries()) {
-            collectBulkSegments(child.getNodeState());
+            for (ChildNodeEntry child : node.getChildNodeEntries()) {
+                collectBulkSegments((SegmentNodeState) child.getNodeState(),
+                        visited);
+            }
+            visited.add(tr);
         }
     }
 
@@ -89,7 +97,7 @@ class CompactionGainEstimate implements 
         return reachableSize;
     }
 
-    //---------------------------------------------------< TarEntryVisitor >--
+    // ---------------------------------------------------< TarEntryVisitor >--
 
     @Override
     public void visit(long msb, long lsb, File file, int offset, int size) {
@@ -101,4 +109,54 @@ class CompactionGainEstimate implements 
         }
     }
 
+    private static class ThinRecordId {
+
+        static ThinRecordId apply(RecordId r) {
+            return new ThinRecordId(r.getOffset(), r.getSegmentId()
+                    .getMostSignificantBits(), r.getSegmentId()
+                    .getLeastSignificantBits());
+        }
+
+        private final int offset;
+
+        private final long msb;
+
+        private final long lsb;
+
+        public ThinRecordId(int offset, long msb, long lsb) {
+            super();
+            this.offset = offset;
+            this.msb = msb;
+            this.lsb = lsb;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + (int) (lsb ^ (lsb >>> 32));
+            result = prime * result + (int) (msb ^ (msb >>> 32));
+            result = prime * result + offset;
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            ThinRecordId other = (ThinRecordId) obj;
+            if (lsb != other.lsb)
+                return false;
+            if (msb != other.msb)
+                return false;
+            if (offset != other.offset)
+                return false;
+            return true;
+        }
+    }
+
 }