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 js...@apache.org on 2022/10/21 08:01:27 UTC

[jackrabbit-oak] branch 1.22 updated: OAK-9785 - Tar SegmentStore can be corrupted during compaction

This is an automated email from the ASF dual-hosted git repository.

jsedding pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/1.22 by this push:
     new 031ec00acb OAK-9785 - Tar SegmentStore can be corrupted during compaction
     new 3a1b993d6c Merge pull request #733 from jsedding/backport/1.22/OAK-9785-tar-segmentstore-can-be-corrupted-during-compaction
031ec00acb is described below

commit 031ec00acbb44b5a471c8479ff73f3672f5bc6a7
Author: Julian Sedding <js...@apache.org>
AuthorDate: Tue Aug 23 16:54:40 2022 +0200

    OAK-9785 - Tar SegmentStore can be corrupted during compaction
    
    Backport to 1.22 branch
---
 .../segment/file/AbstractCompactionStrategy.java   |  4 +-
 .../oak/segment/file/CompactionStrategyTest.java   | 56 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractCompactionStrategy.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractCompactionStrategy.java
index bcd5ecccf0..fe2035a2b3 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractCompactionStrategy.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/AbstractCompactionStrategy.java
@@ -232,8 +232,8 @@ abstract class AbstractCompactionStrategy implements CompactionStrategy {
             context.getGCListener().error("compaction interrupted", e);
             currentThread().interrupt();
             return compactionAborted(context, nextGeneration);
-        } catch (IOException e) {
-            context.getGCListener().error("compaction encountered an error", e);
+        } catch (Throwable e) {
+            context.getGCListener().error("compaction encountered an error", e instanceof Exception ? (Exception) e : new Exception(e));
             return compactionAborted(context, nextGeneration);
         }
     }
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionStrategyTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionStrategyTest.java
new file mode 100644
index 0000000000..c7f67e6338
--- /dev/null
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/CompactionStrategyTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.segment.file;
+
+import org.apache.jackrabbit.oak.segment.memory.MemoryStore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+
+public class CompactionStrategyTest {
+
+    private static final Throwable MARKER_THROWABLE =
+            new RuntimeException("We pretend that something went horribly wrong.");
+
+    @Test
+    public void compactionIsAbortedOnAnyThrowable() throws IOException {
+        MemoryStore store = new MemoryStore();
+        CompactionStrategy.Context throwingContext = Mockito.mock(CompactionStrategy.Context.class);
+        when(throwingContext.getGCListener()).thenReturn(Mockito.mock(GCListener.class));
+        when(throwingContext.getRevisions()).thenReturn(store.getRevisions());
+        when(throwingContext.getGCOptions()).thenThrow(MARKER_THROWABLE);
+
+        try {
+            final CompactionResult compactionResult = new FullCompactionStrategy().compact(throwingContext);
+            assertThat("Compaction should be properly aborted.", compactionResult.isSuccess(), is(false));
+        } catch (Throwable e) {
+            if (e == MARKER_THROWABLE) {
+                fail("The marker throwable was not caught by the CompactionStrategy and therefore not properly aborted.");
+            } else {
+                throw new IllegalStateException("The test likely needs to be adjusted.", e);
+            }
+        }
+    }
+}
\ No newline at end of file