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 md...@apache.org on 2014/12/01 12:26:55 UTC

svn commit: r1642667 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: SegmentNodeStore.java SegmentOverflowException.java SegmentWriter.java

Author: mduerig
Date: Mon Dec  1 11:26:54 2014
New Revision: 1642667

URL: http://svn.apache.org/r1642667
Log:
OAK-2294: Corrupt repository after concurrent version operations
Throw custom exception instead of ISE when segment references are exceeded

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentOverflowException.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java?rev=1642667&r1=1642666&r2=1642667&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStore.java Mon Dec  1 11:26:54 2014
@@ -151,6 +151,9 @@ public class SegmentNodeStore implements
         } catch (InterruptedException e) {
             throw new CommitFailedException(
                     "Segment", 2, "Merge interrupted", e);
+        } catch (SegmentOverflowException e) {
+            throw new CommitFailedException(
+                    "Segment", 3, "Merge failed", e);
         }
     }
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentOverflowException.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentOverflowException.java?rev=1642667&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentOverflowException.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentOverflowException.java Mon Dec  1 11:26:54 2014
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.segment;
+
+/**
+ * This exception is thrown by the Segment MicroKernel when an internal
+ * limit is exceeded such as too many segment references. Clients should
+ * only ever see this exception as the cause of a
+ * {@link org.apache.jackrabbit.oak.api.CommitFailedException CommitFailedException}.
+ */
+public class SegmentOverflowException extends RuntimeException {
+
+    public SegmentOverflowException(String message) {
+        super(message);
+    }
+
+    public SegmentOverflowException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public SegmentOverflowException(Throwable cause) {
+        super(cause);
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java?rev=1642667&r1=1642666&r2=1642667&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java Mon Dec  1 11:26:54 2014
@@ -37,6 +37,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.segment.MapRecord.BUCKETS_PER_LEVEL;
 import static org.apache.jackrabbit.oak.plugins.segment.Segment.MAX_SEGMENT_SIZE;
 import static org.apache.jackrabbit.oak.plugins.segment.Segment.RECORD_ID_BYTES;
+import static org.apache.jackrabbit.oak.plugins.segment.Segment.SEGMENT_REFERENCE_LIMIT;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -340,7 +341,10 @@ public class SegmentWriter {
 
     private synchronized int getSegmentRef(SegmentId segmentId) {
         int refcount = segment.getRefCount();
-        checkState(refcount < 256, "Segment cannot have more than 255 references", segment.getSegmentId());
+        if (refcount > SEGMENT_REFERENCE_LIMIT) {
+          throw new SegmentOverflowException(
+                  "Segment cannot have more than 255 references " + segment.getSegmentId());
+        }
         for (int index = 0; index < refcount; index++) {
             if (segmentId == segment.getRefId(index)) {
                 return index;