Author: mduerig
Date: Tue Aug  8 13:39:57 2017
New Revision: 1804423

URL: http://svn.apache.org/viewvc?rev=1804423&view=rev
Log:
OAK-6372: ListRecord cannot handle more than 16581375 entries
Limit lists to 16581375 and fail fast on bigger lists

Modified:
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/ListRecord.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/RecordTest.java

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/ListRecord.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/ListRecord.java?rev=1804423&r1=1804422&r2=1804423&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/ListRecord.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/ListRecord.java
 Tue Aug  8 13:39:57 2017
@@ -34,13 +34,19 @@ class ListRecord extends Record {
 
     static final int LEVEL_SIZE = 255;
 
+    /** The maximum number of elements a list can contain */
+    static final int MAX_ELEMENTS = LEVEL_SIZE * LEVEL_SIZE * LEVEL_SIZE;
+
     private final int size;
 
     private final int bucketSize;
 
     ListRecord(RecordId id, int size) {
         super(id);
-        checkArgument(size >= 0);
+        checkArgument(size >= 0,
+                "Negative list size: " + size);
+        checkArgument(size <= MAX_ELEMENTS,
+                "Too many elements in list: " + size);
         this.size = size;
 
         int bs = 1;

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/RecordTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/RecordTest.java?rev=1804423&r1=1804422&r2=1804423&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/RecordTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/RecordTest.java
 Tue Aug  8 13:39:57 2017
@@ -30,6 +30,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 import static 
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.segment.ListRecord.LEVEL_SIZE;
+import static org.apache.jackrabbit.oak.segment.ListRecord.MAX_ELEMENTS;
 import static 
org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -60,7 +61,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -145,14 +145,20 @@ public class RecordTest {
     }
 
     @Test
-    @Ignore("OAK-6372")  // FIXME OAK-6372: ListRecord cannot handle more than 
16581375 entries
     public void testLargeListRecord() throws IOException {
         RecordId blockId = writer.writeBlock(bytes, 0, bytes.length);
 
-        ListRecord one = writeList(LEVEL_SIZE * LEVEL_SIZE * LEVEL_SIZE + 1, 
blockId);
+        ListRecord one = writeList(MAX_ELEMENTS, blockId);
         one.getEntry(0);
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void testTooLargeListRecord() throws IOException {
+        RecordId blockId = writer.writeBlock(bytes, 0, bytes.length);
+
+        ListRecord one = writeList(MAX_ELEMENTS + 1, blockId);
+    }
+
     private ListRecord writeList(int size, RecordId id) throws IOException {
         List<RecordId> list = Collections.nCopies(size, id);
         return new ListRecord(writer.writeList(list), size);


Reply via email to