Author: mduerig
Date: Tue Dec 15 09:28:19 2015
New Revision: 1720099

URL: http://svn.apache.org/viewvc?rev=1720099&view=rev
Log:
OAK-3774: Tool for detecting references to pre compacted segments
Change type of gc graph to String to avoid unnecessary string to int conversion

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraph.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraphTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraph.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraph.java?rev=1720099&r1=1720098&r2=1720099&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraph.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraph.java
 Tue Dec 15 09:28:19 2015
@@ -172,18 +172,18 @@ public final class SegmentGraph {
             throws Exception {
         PrintWriter writer = new PrintWriter(checkNotNull(out));
         try {
-            Graph<Integer> gcGraph = parseGCGraph(checkNotNull(fileStore));
+            Graph<String> gcGraph = parseGCGraph(checkNotNull(fileStore));
 
             writer.write("nodedef>name VARCHAR\n");
-            for (Integer gen : gcGraph.vertices) {
+            for (String gen : gcGraph.vertices) {
                 writer.write(gen + "\n");
             }
 
             writer.write("edgedef>node1 VARCHAR, node2 VARCHAR\n");
-            for (Entry<Integer, Set<Integer>> edge : gcGraph.edges.entrySet()) 
{
-                Integer from = edge.getKey();
-                for (Integer to : edge.getValue()) {
-                    if (!from.equals(to) && to != -1) {
+            for (Entry<String, Set<String>> edge : gcGraph.edges.entrySet()) {
+                String from = edge.getKey();
+                for (String to : edge.getValue()) {
+                    if (!from.equals(to) && !to.isEmpty()) {
                         writer.write(from + "," + to + "\n");
                     }
                 }
@@ -202,35 +202,23 @@ public final class SegmentGraph {
      * @throws IOException
      */
     @Nonnull
-    public static Graph<Integer> parseGCGraph(@Nonnull final ReadOnlyStore 
fileStore)
+    public static Graph<String> parseGCGraph(@Nonnull final ReadOnlyStore 
fileStore)
             throws IOException {
         SegmentNodeState root = checkNotNull(fileStore).getHead();
         HashSet<UUID> roots = newHashSet(root.getRecordId().asUUID());
-        return parseSegmentGraph(fileStore, roots, new Function<UUID, 
Integer>() {
+        return parseSegmentGraph(fileStore, roots, new Function<UUID, 
String>() {
             @Override @Nullable
-            public Integer apply(UUID segmentId) {
+            public String apply(UUID segmentId) {
                 Map<String, String> info = getSegmentInfo(segmentId, 
fileStore.getTracker());
                 if (info != null) {
-                    return toInt(info.get("gc"), -1);
+                    return info.get("gc");
                 } else {
-                    return -1;
+                    return "";
                 }
             }
         });
     }
 
-    private static int toInt(String number, int defaultValue) {
-        if (number == null) {
-            return defaultValue;
-        } else {
-            try {
-                return Integer.parseInt(number);
-            } catch (NumberFormatException e) {
-                return defaultValue;
-            }
-        }
-    }
-
     /**
      * Parse the segment graph of a file store starting with a given set of 
root segments.
      * The full segment graph is mapped through the passed {@code 
homomorphism} to the

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraphTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraphTest.java?rev=1720099&r1=1720098&r2=1720099&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraphTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/segment/SegmentGraphTest.java
 Tue Dec 15 09:28:19 2015
@@ -51,8 +51,8 @@ public class SegmentGraphTest {
     private final Set<UUID> segments = newHashSet();
     private final Map<UUID, Set<UUID>> references = newHashMap();
 
-    private final Set<Integer> gcGenerations = newHashSet();
-    private final Map<Integer, Set<Integer>> gcReferences = newHashMap();
+    private final Set<String> gcGenerations = newHashSet();
+    private final Map<String, Set<String>> gcReferences = newHashMap();
 
     private File storeDir;
 
@@ -126,10 +126,10 @@ public class SegmentGraphTest {
 
         store.close();
 
-        gcGenerations.add(0);
-        gcGenerations.add(1);
-        gcReferences.put(0, singleton(0));
-        gcReferences.put(1, singleton(0));
+        gcGenerations.add("0");
+        gcGenerations.add("1");
+        gcReferences.put("0", singleton("0"));
+        gcReferences.put("1", singleton("0"));
     }
 
     @After
@@ -153,7 +153,7 @@ public class SegmentGraphTest {
     public void testGCGraph() throws IOException {
         ReadOnlyStore store = new ReadOnlyStore(storeDir);
         try {
-            Graph<Integer> gcGraph = SegmentGraph.parseGCGraph(store);
+            Graph<String> gcGraph = SegmentGraph.parseGCGraph(store);
             assertEquals(gcGenerations, gcGraph.vertices);
             assertEquals(gcReferences, gcGraph.edges);
         } finally {


Reply via email to