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 ju...@apache.org on 2014/04/10 18:35:56 UTC

svn commit: r1586363 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/ oak-run/src/main/java/org/apache/jackrabbit/oak/run/

Author: jukka
Date: Thu Apr 10 16:35:56 2014
New Revision: 1586363

URL: http://svn.apache.org/r1586363
Log:
OAK-1446: Offline tool to repair TarMK

Improved debug output

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/RecordId.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/RecordId.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/RecordId.java?rev=1586363&r1=1586362&r2=1586363&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/RecordId.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/RecordId.java Thu Apr 10 16:35:56 2014
@@ -18,24 +18,39 @@ package org.apache.jackrabbit.oak.plugin
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static java.lang.Integer.parseInt;
+import static org.apache.jackrabbit.oak.plugins.segment.Segment.RECORD_ALIGN_BITS;
 
 import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 public final class RecordId implements Comparable<RecordId> {
 
+    private static final Pattern PATTERN = Pattern.compile(
+            "([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
+            + "(:(0|[1-9][0-9]*)|\\.([0-9a-f]{4}))");
+
     public static RecordId[] EMPTY_ARRAY = new RecordId[0];
 
     public static RecordId fromString(SegmentTracker factory, String id) {
-        int colon = id.indexOf(':');
-        if (colon != -1) {
-            UUID uuid = UUID.fromString(id.substring(0, colon));
-            return new RecordId(
-                    factory.getSegmentId(
-                            uuid.getMostSignificantBits(),
-                            uuid.getLeastSignificantBits()),
-                    Integer.parseInt(id.substring(colon + 1)));
+        Matcher matcher = PATTERN.matcher(id);
+        if (matcher.matches()) {
+            UUID uuid = UUID.fromString(matcher.group(1));
+            SegmentId segmentId = factory.getSegmentId(
+                    uuid.getMostSignificantBits(),
+                    uuid.getLeastSignificantBits());
+
+            int offset;
+            if (matcher.group(3) != null) {
+                offset = parseInt(matcher.group(3));
+            } else {
+                offset = parseInt(matcher.group(4), 16) << RECORD_ALIGN_BITS;
+            }
+
+            return new RecordId(segmentId, offset);
         } else {
-            throw new IllegalArgumentException("Bad RecordId: " + id);
+            throw new IllegalArgumentException("Bad record identifier: " + id);
         }
     }
 
@@ -45,7 +60,7 @@ public final class RecordId implements C
 
     public RecordId(SegmentId segmentId, int offset) {
         checkArgument(offset < Segment.MAX_SEGMENT_SIZE);
-        checkArgument((offset & 3) == 0);
+        checkArgument((offset % (1 << RECORD_ALIGN_BITS)) == 0);
         this.segmentId = checkNotNull(segmentId);
         this.offset = offset;
     }
@@ -78,7 +93,7 @@ public final class RecordId implements C
 
     @Override
     public String toString() {
-        return segmentId + ":" + offset;
+        return String.format("%s.%04x", segmentId, offset >> RECORD_ALIGN_BITS);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java?rev=1586363&r1=1586362&r2=1586363&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java Thu Apr 10 16:35:56 2014
@@ -447,10 +447,30 @@ public class Segment {
         int length = data.remaining();
 
         writer.format("Segment %s (%d bytes)%n", id, length);
-        writer.println("--------------------------------------------------------------------------");
-        int refcount = getRefCount();
-        for (int refid = 0; refid < refcount; refid++) {
-            writer.format("reference %02x: %s%n", refid, getRefId(refid));
+        if (id.isDataSegmentId()) {
+            writer.println("--------------------------------------------------------------------------");
+            int refcount = getRefCount();
+            for (int refid = 0; refid < refcount; refid++) {
+                writer.format("reference %02x: %s%n", refid, getRefId(refid));
+            }
+            int rootcount = data.getShort(ROOT_COUNT_OFFSET) & 0xffff;
+            int pos = refcount * 16;
+            for (int rootid = 0; rootid < rootcount; rootid++) {
+                writer.format(
+                        "root %d: %s at %04x%n", rootid,
+                        RecordType.values()[data.get(pos + rootid * 3) & 0xff],
+                        data.getShort(pos + rootid * 3 + 1) & 0xffff);
+            }
+            int blobrefcount = data.getShort(BLOBREF_COUNT_OFFSET) & 0xffff;
+            pos += rootcount * 3;
+            for (int blobrefid = 0; blobrefid < blobrefcount; blobrefid++) {
+                int offset = data.getShort(pos + blobrefid * 2) & 0xffff;
+                SegmentBlob blob = new SegmentBlob(
+                        new RecordId(id, offset << RECORD_ALIGN_BITS));
+                writer.format(
+                        "blobref %d: %s at %04x%n", blobrefid,
+                        blob.getBlobId(), offset);
+            }
         }
         writer.println("--------------------------------------------------------------------------");
         int pos = data.limit() - ((length + 15) & ~15);

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1586363&r1=1586362&r2=1586363&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java Thu Apr 10 16:35:56 2014
@@ -178,7 +178,6 @@ public class Main {
                             dataCount++;
                             dataSize += segment.size();
                             idmap.put(id, segment.getReferencedIds());
-                            System.out.println(id + " -> " + idmap.get(id));
                         } else if (id.isBulkSegmentId()) {
                             bulkCount++;
                             bulkSize += id.getSegment().size();
@@ -246,10 +245,15 @@ public class Main {
                                 path = matcher.group(3);
                             }
                             NodeState node = new SegmentNodeState(id);
-                            System.out.println("/ -> " + node);
+                            System.out.println("/ (" + id + ") -> " + node);
                             for (String name : PathUtils.elements(path)) {
                                 node = node.getChildNode(name);
-                                System.out.println(" " + name  + " -> " + node);
+                                RecordId nid = null;
+                                if (node instanceof SegmentNodeState) {
+                                    nid = ((SegmentNodeState) node).getRecordId();
+                                }
+                                System.out.println(
+                                        "  " + name  + " (" + nid + ") -> " + node);
                             }
                         }
                     }