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 fr...@apache.org on 2017/06/29 10:10:57 UTC

svn commit: r1800259 - in /jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar: TarConstants.java TarReader.java TarWriter.java

Author: frm
Date: Thu Jun 29 10:10:57 2017
New Revision: 1800259

URL: http://svn.apache.org/viewvc?rev=1800259&view=rev
Log:
OAK-6405 - Move common constants to TarConstants

The TarReader and TarWriter classes share some constants. These constants have
been historically defined by TarWriter, but they are supposed to be shared
between the two. This commit moves the common constants to TarConstants.

Modified:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarConstants.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarConstants.java?rev=1800259&r1=1800258&r2=1800259&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarConstants.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarConstants.java Thu Jun 29 10:10:57 2017
@@ -25,4 +25,47 @@ class TarConstants {
 
     static final String FILE_NAME_FORMAT = "data%05d%s.tar";
 
+    /**
+     * Magic byte sequence at the end of the index block.
+     * <p>
+     * <ul>
+     * <li>For each segment in that file, an index entry that contains the UUID,
+     * the offset within the file and the size of the segment. Sorted by UUID,
+     * to allow using interpolation search.</li>
+     * <li>
+     * The index footer, which contains metadata of the index (the size,
+     * checksum).</li>
+     * </ul>
+     */
+    static final int INDEX_MAGIC = ('\n' << 24) + ('0' << 16) + ('K' << 8) + '\n';
+
+    /**
+     * Magic byte sequence at the end of the graph block.
+     * <p>
+     * The file is read from the end (the tar file is read from the end: the
+     * last entry is the index, then the graph). File format:
+     * <ul>
+     * <li>0 padding to make the footer end at a 512 byte boundary</li>
+     * <li>The list of UUIDs (segments included the graph; this includes
+     * segments in this tar file, and referenced segments in tar files with a
+     * lower sequence number). 16 bytes each.</li>
+     * <li>The graph data. The index of the source segment UUID (in the above
+     * list, 4 bytes), then the list of referenced segments (the indexes of
+     * those; 4 bytes each). Then the list is terminated by -1.</li>
+     * <li>The last part is the footer, which contains metadata of the graph
+     * (size, checksum, the number of UUIDs).</li>
+     * </ul>
+     */
+    static final int GRAPH_MAGIC = ('\n' << 24) + ('0' << 16) + ('G' << 8) + '\n';
+
+    /**
+     * Magic sequence at the end of the binary references block.
+     */
+    static final int BINARY_REFERENCES_MAGIC = ('\n' << 24) + ('0' << 16) + ('B' << 8) + '\n';
+
+    /**
+     * The tar file block size.
+     */
+    static final int BLOCK_SIZE = 512;
+
 }

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java?rev=1800259&r1=1800258&r2=1800259&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarReader.java Thu Jun 29 10:10:57 2017
@@ -31,6 +31,10 @@ import static com.google.common.collect.
 import static java.nio.ByteBuffer.wrap;
 import static java.util.Collections.singletonList;
 import static org.apache.jackrabbit.oak.segment.SegmentId.isDataSegmentId;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BINARY_REFERENCES_MAGIC;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.INDEX_MAGIC;
 
 import java.io.Closeable;
 import java.io.File;
@@ -69,9 +73,6 @@ class TarReader implements Closeable {
     /** Logger instance */
     private static final Logger log = LoggerFactory.getLogger(TarReader.class);
 
-    /** Magic byte sequence at the end of the index block. */
-    private static final int INDEX_MAGIC = TarWriter.INDEX_MAGIC;
-
     /**
      * Pattern of the segment entry names. Note the trailing (\\..*)? group
      * that's included for compatibility with possible future extensions.
@@ -80,9 +81,6 @@ class TarReader implements Closeable {
             "([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
             + "(\\.([0-9a-f]{8}))?(\\..*)?");
 
-    /** The tar file block size. */
-    private static final int BLOCK_SIZE = TarWriter.BLOCK_SIZE;
-
     static int getEntrySize(int size) {
         return BLOCK_SIZE + size + TarWriter.getPaddingSize(size);
     }
@@ -1012,7 +1010,7 @@ class TarReader implements Closeable {
         int size = meta.getInt();
         int magic = meta.getInt();
 
-        if (magic != TarWriter.BINARY_REFERENCES_MAGIC) {
+        if (magic != BINARY_REFERENCES_MAGIC) {
             log.warn("Invalid binary references magic number");
             return null;
         }
@@ -1092,7 +1090,7 @@ class TarReader implements Closeable {
         int bytes = meta.getInt();
         int magic = meta.getInt();
 
-        if (magic != TarWriter.GRAPH_MAGIC) {
+        if (magic != GRAPH_MAGIC) {
             log.warn("Invalid graph magic number in {}", file);
             return null;
         }

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java?rev=1800259&r1=1800258&r2=1800259&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/tar/TarWriter.java Thu Jun 29 10:10:57 2017
@@ -27,7 +27,11 @@ import static com.google.common.collect.
 import static com.google.common.collect.Maps.newLinkedHashMap;
 import static com.google.common.collect.Sets.newHashSet;
 import static java.lang.String.format;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BINARY_REFERENCES_MAGIC;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.BLOCK_SIZE;
 import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.FILE_NAME_FORMAT;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC;
+import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.INDEX_MAGIC;
 
 import java.io.Closeable;
 import java.io.File;
@@ -58,50 +62,6 @@ class TarWriter implements Closeable {
     /** Logger instance */
     private static final Logger log = LoggerFactory.getLogger(TarWriter.class);
 
-    /**
-     * Magic byte sequence at the end of the index block.
-     * <p>
-     * <ul>
-     * <li>For each segment in that file, an index entry that contains the UUID,
-     * the offset within the file and the size of the segment. Sorted by UUID,
-     * to allow using interpolation search.</li>
-     * <li>
-     * The index footer, which contains metadata of the index (the size,
-     * checksum).</li>
-     * </ul>
-     */
-    static final int INDEX_MAGIC =
-            ('\n' << 24) + ('0' << 16) + ('K' << 8) + '\n';
-
-    /**
-     * Magic byte sequence at the end of the graph block.
-     * <p>
-     * The file is read from the end (the tar file is read from the end: the
-     * last entry is the index, then the graph). File format:
-     * <ul>
-     * <li>0 padding to make the footer end at a 512 byte boundary</li>
-     * <li>The list of UUIDs (segments included the graph; this includes
-     * segments in this tar file, and referenced segments in tar files with a
-     * lower sequence number). 16 bytes each.</li>
-     * <li>The graph data. The index of the source segment UUID (in the above
-     * list, 4 bytes), then the list of referenced segments (the indexes of
-     * those; 4 bytes each). Then the list is terminated by -1.</li>
-     * <li>The last part is the footer, which contains metadata of the graph
-     * (size, checksum, the number of UUIDs).</li>
-     * </ul>
-     * 
-     */
-    static final int GRAPH_MAGIC =
-            ('\n' << 24) + ('0' << 16) + ('G' << 8) + '\n';
-
-    /**
-     * Magic sequence at the end of the binary references block.
-     */
-    static final int BINARY_REFERENCES_MAGIC = ('\n' << 24) + ('0' << 16) + ('B' << 8) + '\n';
-
-    /** The tar file block size. */
-    static final int BLOCK_SIZE = 512;
-
     private static final byte[] ZERO_BYTES = new byte[BLOCK_SIZE];
 
     static final int getPaddingSize(int size) {