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 mr...@apache.org on 2014/07/09 18:03:36 UTC

svn commit: r1609214 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/kernel/ main/java/org/apache/jackrabbit/oak/plugins/document/ main/java/org/apache/jackrabbit/oak/plugins/document/memory/ main/java/org/apache/jackrabbit...

Author: mreutegg
Date: Wed Jul  9 16:03:35 2014
New Revision: 1609214

URL: http://svn.apache.org/r1609214
Log:
OAK-1961: Introduce DocumentStoreException

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreException.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/BatchCommit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java Wed Jul  9 16:03:35 2014
@@ -32,6 +32,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import static org.apache.jackrabbit.oak.api.CommitFailedException.MERGE;
+import static org.apache.jackrabbit.oak.api.CommitFailedException.OAK;
 
 /**
  * {@code NodeStoreBranch} based on {@link MicroKernel} branching and merging.
@@ -125,7 +126,19 @@ public class KernelNodeStoreBranch exten
         return store.commit(">\"" + source + "\":\"" + target + '"', base);
     }
 
-//------------------------< NodeStoreBranch >-------------------------------
+    @Override
+    protected CommitFailedException convertUnchecked(Exception cause,
+                                                     String msg) {
+        String type;
+        if (cause instanceof MicroKernelException) {
+            type = MERGE;
+        } else {
+            type = OAK;
+        }
+        return new CommitFailedException(type, 1, msg, cause);
+    }
+
+    //------------------------< NodeStoreBranch >-------------------------------
 
     @Nonnull
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/BatchCommit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/BatchCommit.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/BatchCommit.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/BatchCommit.java Wed Jul  9 16:03:35 2014
@@ -20,9 +20,9 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -83,7 +83,11 @@ final class BatchCommit {
                                 BatchCommit.this.wait();
                             }
                         }
-                        return execute(idx).get();
+                        try {
+                            return execute(idx).get();
+                        } catch (ExecutionException e) {
+                            throw DocumentStoreException.convert(e.getCause());
+                        }
                     }
                 };
             } else {
@@ -138,7 +142,7 @@ final class BatchCommit {
                 finished.await();
             } catch (InterruptedException e) {
                 String msg = "Interrupted while waiting for batch commit to finish";
-                return Futures.immediateFailedFuture(new MicroKernelException(msg));
+                return Futures.immediateFailedFuture(new DocumentStoreException(msg));
             }
         }
         return results.get(idx);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/ClusterNodeInfo.java Wed Jul  9 16:03:35 2014
@@ -27,7 +27,6 @@ import java.util.Enumeration;
 import java.util.List;
 import java.util.UUID;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.commons.StringUtils;
 import org.apache.jackrabbit.oak.stats.Clock;
 import org.slf4j.Logger;
@@ -295,7 +294,7 @@ public class ClusterNodeInfo {
                 return clusterNode;
             }
         }
-        throw new MicroKernelException("Could not get cluster node info");
+        throw new DocumentStoreException("Could not get cluster node info");
     }
 
     private static ClusterNodeInfo createInstance(DocumentStore store, String machineId,

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Collision.java Wed Jul  9 16:03:35 2014
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.plugin
 
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -68,10 +67,10 @@ class Collision {
      *
      * @param store the document store.
      * @return the revision that was marked. Either our or their.
-     * @throws MicroKernelException if the mark operation fails.
+     * @throws DocumentStoreException if the mark operation fails.
      */
     @Nonnull
-    Revision mark(DocumentStore store) throws MicroKernelException {
+    Revision mark(DocumentStore store) throws DocumentStoreException {
         // first try to mark their revision
         if (markCommitRoot(document, theirRev, store)) {
             return theirRev;
@@ -141,8 +140,8 @@ class Collision {
 
     private static void throwNoCommitRootException(@Nonnull Revision revision,
                                                    @Nonnull Document document)
-                                                           throws MicroKernelException {
-        throw new MicroKernelException("No commit root for revision: "
+                                                           throws DocumentStoreException {
+        throw new DocumentStoreException("No commit root for revision: "
                 + revision + ", document: " + document.format());
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java Wed Jul  9 16:03:35 2014
@@ -29,7 +29,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import com.google.common.collect.Sets;
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.commons.json.JsopStream;
 import org.apache.jackrabbit.oak.commons.json.JsopWriter;
 import org.apache.jackrabbit.oak.plugins.document.util.Utils;
@@ -131,7 +130,7 @@ public class Commit {
         if (operations.containsKey(path)) {
             String msg = "Node already added: " + path;
             LOG.error(msg);
-            throw new MicroKernelException(msg);
+            throw new DocumentStoreException(msg);
         }
         operations.put(path, n.asOperation(true));
         addedNodes.add(path);
@@ -145,11 +144,10 @@ public class Commit {
      * Applies this commit to the store.
      *
      * @return the commit revision.
-     * @throws MicroKernelException if the commit cannot be applied.
-     *              TODO: use non-MK exception type
+     * @throws DocumentStoreException if the commit cannot be applied.
      */
     @Nonnull
-    Revision apply() throws MicroKernelException {
+    Revision apply() throws DocumentStoreException {
         boolean success = false;
         Revision baseRev = getBaseRevision();
         boolean isBranch = baseRev != null && baseRev.isBranch();
@@ -356,7 +354,7 @@ public class Commit {
                     if (before == null) {
                         String msg = "Conflicting concurrent change. " +
                                 "Update operation failed: " + commitRoot;
-                        throw new MicroKernelException(msg);
+                        throw new DocumentStoreException(msg);
                     } else {
                         // if we get here the commit was successful and
                         // the commit revision is set on the commitRoot
@@ -374,7 +372,7 @@ public class Commit {
                 }
                 operations.put(commitRootPath, commitRoot);
             }
-        } catch (MicroKernelException e) {
+        } catch (DocumentStoreException e) {
             rollback(newNodes, opLog, commitRoot);
             throw e;
         }
@@ -530,7 +528,7 @@ public class Commit {
                 conflictMessage += ", before\n" + revision +
                         "; document:\n" + (before == null ? "" : before.format()) +
                         ",\nrevision order:\n" + nodeStore.getRevisionComparator();
-                throw new MicroKernelException(conflictMessage);
+                throw new DocumentStoreException(conflictMessage);
             }
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java Wed Jul  9 16:03:35 2014
@@ -129,7 +129,11 @@ public class DocumentMK implements Micro
 
     @Override @Nonnull
     public String checkpoint(long lifetime) throws MicroKernelException {
-        return nodeStore.checkpoint(lifetime);
+        try {
+            return nodeStore.checkpoint(lifetime);
+        } catch (DocumentStoreException e) {
+            throw new MicroKernelException(e);
+        }
     }
 
     @Override
@@ -164,7 +168,11 @@ public class DocumentMK implements Micro
         if (path == null || path.equals("")) {
             path = "/";
         }
-        return nodeStore.diff(fromRevisionId, toRevisionId, path);
+        try {
+            return nodeStore.diff(fromRevisionId, toRevisionId, path);
+        } catch (DocumentStoreException e) {
+            throw new MicroKernelException(e);
+        }
     }
 
     @Override
@@ -175,7 +183,12 @@ public class DocumentMK implements Micro
         }
         revisionId = revisionId != null ? revisionId : nodeStore.getHeadRevision().toString();
         Revision rev = Revision.fromString(revisionId);
-        DocumentNodeState n = nodeStore.getNode(path, rev);
+        DocumentNodeState n;
+        try {
+            n = nodeStore.getNode(path, rev);
+        } catch (DocumentStoreException e) {
+            throw new MicroKernelException(e);
+        }
         return n != null;
     }
 
@@ -195,40 +208,44 @@ public class DocumentMK implements Micro
         }
         revisionId = revisionId != null ? revisionId : nodeStore.getHeadRevision().toString();
         Revision rev = Revision.fromString(revisionId);
-        DocumentNodeState n = nodeStore.getNode(path, rev);
-        if (n == null) {
-            return null;
-        }
-        JsopStream json = new JsopStream();
-        boolean includeId = filter != null && filter.contains(":id");
-        includeId |= filter != null && filter.contains(":hash");
-        json.object();
-        n.append(json, includeId);
-        int max;
-        if (maxChildNodes == -1) {
-            max = Integer.MAX_VALUE;
-            maxChildNodes = Integer.MAX_VALUE;
-        } else {
-            // use long to avoid overflows
-            long m = ((long) maxChildNodes) + offset;
-            max = (int) Math.min(m, Integer.MAX_VALUE);
-        }
-        Children c = nodeStore.getChildren(n, null, max);
-        for (long i = offset; i < c.children.size(); i++) {
-            if (maxChildNodes-- <= 0) {
-                break;
+        try {
+            DocumentNodeState n = nodeStore.getNode(path, rev);
+            if (n == null) {
+                return null;
+            }
+            JsopStream json = new JsopStream();
+            boolean includeId = filter != null && filter.contains(":id");
+            includeId |= filter != null && filter.contains(":hash");
+            json.object();
+            n.append(json, includeId);
+            int max;
+            if (maxChildNodes == -1) {
+                max = Integer.MAX_VALUE;
+                maxChildNodes = Integer.MAX_VALUE;
+            } else {
+                // use long to avoid overflows
+                long m = ((long) maxChildNodes) + offset;
+                max = (int) Math.min(m, Integer.MAX_VALUE);
+            }
+            Children c = nodeStore.getChildren(n, null, max);
+            for (long i = offset; i < c.children.size(); i++) {
+                if (maxChildNodes-- <= 0) {
+                    break;
+                }
+                String name = c.children.get((int) i);
+                json.key(name).object().endObject();
             }
-            String name = c.children.get((int) i);
-            json.key(name).object().endObject();
-        }
-        if (c.hasMore) {
-            // TODO use a better way to notify there are more children
-            json.key(":childNodeCount").value(Long.MAX_VALUE);
-        } else {
-            json.key(":childNodeCount").value(c.children.size());
+            if (c.hasMore) {
+                // TODO use a better way to notify there are more children
+                json.key(":childNodeCount").value(Long.MAX_VALUE);
+            } else {
+                json.key(":childNodeCount").value(c.children.size());
+            }
+            json.endObject();
+            return json.toString();
+        } catch (DocumentStoreException e) {
+            throw new MicroKernelException(e);
         }
-        json.endObject();
-        return json.toString();
     }
 
     @Override
@@ -244,6 +261,8 @@ public class DocumentMK implements Micro
             parseJsonDiff(commit, jsonDiff, rootPath);
             rev = commit.apply();
             success = true;
+        } catch (DocumentStoreException e) {
+            throw new MicroKernelException(e);
         } finally {
             if (!success) {
                 nodeStore.canceled(commit);
@@ -273,8 +292,10 @@ public class DocumentMK implements Micro
         }
         try {
             return nodeStore.merge(revision, null).toString();
+        } catch (DocumentStoreException e) {
+            throw new MicroKernelException(e);
         } catch (CommitFailedException e) {
-            throw new MicroKernelException(e.getMessage(), e);
+            throw new MicroKernelException(e);
         }
     }
 
@@ -303,7 +324,11 @@ public class DocumentMK implements Micro
         if (!ancestor.isBranch()) {
             throw new MicroKernelException("Not a branch revision: " + ancestorRevisionId);
         }
-        return nodeStore.reset(branch, ancestor).toString();
+        try {
+            return nodeStore.reset(branch, ancestor).toString();
+        } catch (DocumentStoreException e) {
+            throw new MicroKernelException(e);
+        }
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Wed Jul  9 16:03:35 2014
@@ -56,7 +56,6 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.commons.json.JsopReader;
 import org.apache.jackrabbit.oak.commons.json.JsopTokenizer;
@@ -668,14 +667,14 @@ public final class DocumentNodeStore
             });
             return node == missing ? null : node;
         } catch (ExecutionException e) {
-            throw new MicroKernelException(e);
+            throw DocumentStoreException.convert(e.getCause());
         }
     }
 
     DocumentNodeState.Children getChildren(@Nonnull final DocumentNodeState parent,
                               @Nullable final String name,
                               final int limit)
-            throws MicroKernelException {
+            throws DocumentStoreException {
         if (checkNotNull(parent).hasNoChildren()) {
             return DocumentNodeState.NO_CHILDREN;
         }
@@ -692,9 +691,9 @@ public final class DocumentNodeStore
                     }
                 });
             } catch (ExecutionException e) {
-                throw new MicroKernelException(
+                throw DocumentStoreException.convert(e.getCause(),
                         "Error occurred while fetching children for path "
-                                + path, e.getCause());
+                                + path);
             }
             if (children.hasMore && limit > children.children.size()) {
                 // there are potentially more children and
@@ -869,7 +868,7 @@ public final class DocumentNodeStore
                 String p = PathUtils.concat(parent.getPath(), input);
                 DocumentNodeState result = getNode(p, readRevision);
                 if (result == null) {
-                    throw new MicroKernelException("DocumentNodeState is null for revision " + readRevision + " of " + p
+                    throw new DocumentStoreException("DocumentNodeState is null for revision " + readRevision + " of " + p
                             + " (aborting getChildNodes())");
                 }
                 return result;
@@ -987,10 +986,10 @@ public final class DocumentNodeStore
      * @param commit the updates to apply on the commit root document.
      * @return the document before the update was applied or <code>null</code>
      *          if the update failed because of a collision.
-     * @throws MicroKernelException if the update fails with an error.
+     * @throws DocumentStoreException if the update fails with an error.
      */
     @CheckForNull
-    NodeDocument updateCommitRoot(UpdateOp commit) throws MicroKernelException {
+    NodeDocument updateCommitRoot(UpdateOp commit) throws DocumentStoreException {
         // use batch commit when there are only revision and modified updates
         // and collision checks
         boolean batch = true;
@@ -1012,25 +1011,15 @@ public final class DocumentNodeStore
     }
 
     private NodeDocument batchUpdateCommitRoot(UpdateOp commit)
-            throws MicroKernelException {
+            throws DocumentStoreException {
         try {
             return batchCommitQueue.updateDocument(commit).call();
         } catch (InterruptedException e) {
-            throw new MicroKernelException("Interrupted while updating commit root document");
-        } catch (ExecutionException e) {
-            if (e.getCause() instanceof MicroKernelException) {
-                throw (MicroKernelException) e.getCause();
-            } else {
-                String msg = "Update of commit root document failed";
-                throw new MicroKernelException(msg, e.getCause());
-            }
+            throw DocumentStoreException.convert(e,
+                    "Interrupted while updating commit root document");
         } catch (Exception e) {
-            if (e instanceof MicroKernelException) {
-                throw (MicroKernelException) e;
-            } else {
-                String msg = "Update of commit root document failed";
-                throw new MicroKernelException(msg, e);
-            }
+            throw DocumentStoreException.convert(e,
+                    "Update of commit root document failed");
         }
     }
 
@@ -1088,14 +1077,14 @@ public final class DocumentNodeStore
         checkNotNull(ancestor);
         Branch b = getBranches().getBranch(branchHead);
         if (b == null) {
-            throw new MicroKernelException("Empty branch cannot be reset");
+            throw new DocumentStoreException("Empty branch cannot be reset");
         }
         if (!b.getCommits().last().equals(branchHead)) {
-            throw new MicroKernelException(branchHead + " is not the head " +
+            throw new DocumentStoreException(branchHead + " is not the head " +
                     "of a branch");
         }
         if (!b.containsCommit(ancestor)) {
-            throw new MicroKernelException(ancestor + " is not " +
+            throw new DocumentStoreException(ancestor + " is not " +
                     "an ancestor revision of " + branchHead);
         }
         if (branchHead.equals(ancestor)) {
@@ -1220,7 +1209,7 @@ public final class DocumentNodeStore
 
     String diff(@Nonnull final String fromRevisionId,
                 @Nonnull final String toRevisionId,
-                @Nonnull final String path) throws MicroKernelException {
+                @Nonnull final String path) throws DocumentStoreException {
         if (fromRevisionId.equals(toRevisionId)) {
             return "";
         }
@@ -1233,7 +1222,7 @@ public final class DocumentNodeStore
             String msg = String.format("Diff is only supported if the node exists in both cases. " +
                     "Node [%s], fromRev [%s] -> %s, toRev [%s] -> %s",
                     path, fromRev, from != null, toRev, to != null);
-            throw new MicroKernelException(msg);
+            throw new DocumentStoreException(msg);
         }
         String compactDiff = diffCache.getChanges(fromRev, toRev, path);
         if (compactDiff == null) {
@@ -1527,7 +1516,7 @@ public final class DocumentNodeStore
     }
 
     private String diffImpl(DocumentNodeState from, DocumentNodeState to)
-            throws MicroKernelException {
+            throws DocumentStoreException {
         JsopWriter w = new JsopStream();
         // TODO this does not work well for large child node lists
         // use a document store index instead

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java Wed Jul  9 16:03:35 2014
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.oak.spi.sta
 
 import static com.google.common.base.Preconditions.checkState;
 import static org.apache.jackrabbit.oak.api.CommitFailedException.MERGE;
+import static org.apache.jackrabbit.oak.api.CommitFailedException.OAK;
 
 /**
  * Implementation of a DocumentMK based node store branch.
@@ -121,6 +122,18 @@ class DocumentNodeStoreBranch
         }, base, null);
     }
 
+    @Override
+    protected CommitFailedException convertUnchecked(Exception cause,
+                                                     String msg) {
+        String type;
+        if (cause instanceof DocumentStoreException) {
+            type = MERGE;
+        } else {
+            type = OAK;
+        }
+        return new CommitFailedException(type, 1, msg, cause);
+    }
+
     @Nonnull
     @Override
     public NodeState merge(@Nonnull CommitHook hook, @Nonnull CommitInfo info)

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreException.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreException.java?rev=1609214&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreException.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreException.java Wed Jul  9 16:03:35 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.document;
+
+/**
+ * <code>DocumentStoreException</code> is a runtime exception for
+ * {@code DocumentStore} implementations to signal unexpected problems like
+ * a communication exception.
+ */
+public class DocumentStoreException extends RuntimeException {
+
+    private static final long serialVersionUID = 634445274043721284L;
+
+    public DocumentStoreException(String message) {
+        super(message);
+    }
+
+    public DocumentStoreException(Throwable cause) {
+        super(cause);
+    }
+
+    public DocumentStoreException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public static DocumentStoreException convert(Throwable t) {
+        return convert(t, null);
+    }
+
+    public static DocumentStoreException convert(Throwable t, String msg) {
+        if (t instanceof DocumentStoreException) {
+            return (DocumentStoreException) t;
+        } else {
+            return new DocumentStoreException(msg, t.getCause());
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java Wed Jul  9 16:03:35 2014
@@ -29,10 +29,10 @@ import java.util.concurrent.locks.Reentr
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
 import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.Revision;
 import org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator;
@@ -159,14 +159,12 @@ public class MemoryDocumentStore impleme
 
     @CheckForNull
     @Override
-    public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update)
-            throws MicroKernelException {
+    public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update) {
         return internalCreateOrUpdate(collection, update, false);
     }
 
     @Override
-    public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update)
-            throws MicroKernelException {
+    public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
         return internalCreateOrUpdate(collection, update, true);
     }
 
@@ -206,7 +204,7 @@ public class MemoryDocumentStore impleme
             T doc = collection.newDocument(this);
             if (oldDoc == null) {
                 if (!update.isNew()) {
-                    throw new MicroKernelException("Document does not exist: " + update.getId());
+                    throw new DocumentStoreException("Document does not exist: " + update.getId());
                 }
             } else {
                 oldDoc.deepCopy(doc);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java Wed Jul  9 16:03:35 2014
@@ -40,13 +40,13 @@ import javax.annotation.Nullable;
 import com.google.common.collect.Lists;
 import com.mongodb.MongoClientURI;
 import com.mongodb.ReadPreference;
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.cache.CacheStats;
 import org.apache.jackrabbit.oak.cache.CacheValue;
 import org.apache.jackrabbit.oak.plugins.document.CachedNodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
 import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.Revision;
 import org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator;
@@ -310,6 +310,7 @@ public class MongoDocumentStore implemen
                 }
             }
         }
+        Throwable t;
         try {
             TreeLock lock = acquire(key);
             try {
@@ -345,8 +346,9 @@ public class MongoDocumentStore implemen
                 return (T) doc;
             }
         } catch (ExecutionException e) {
-            throw new IllegalStateException("Failed to load document with " + key, e);
+            t = e.getCause();
         }
+        throw new DocumentStoreException("Failed to load document with " + key, t);
     }
 
     @CheckForNull
@@ -476,7 +478,7 @@ public class MongoDocumentStore implemen
             WriteResult writeResult = dbCollection.remove(getByKeyQuery(key).get(), WriteConcern.SAFE);
             invalidateCache(collection, key);
             if (writeResult.getError() != null) {
-                throw new MicroKernelException("Remove failed: " + writeResult.getError());
+                throw new DocumentStoreException("Remove failed: " + writeResult.getError());
             }
         } finally {
             end("remove", start);
@@ -491,7 +493,7 @@ public class MongoDocumentStore implemen
             WriteResult writeResult = dbCollection.remove(query, WriteConcern.SAFE);
             invalidateCache(collection, keyBatch);
             if (writeResult.getError() != null) {
-                throw new MicroKernelException("Remove failed: " + writeResult.getError());
+                throw new DocumentStoreException("Remove failed: " + writeResult.getError());
             }
         }
 
@@ -558,7 +560,7 @@ public class MongoDocumentStore implemen
             }
             return oldDoc;
         } catch (Exception e) {
-            throw new MicroKernelException(e);
+            throw DocumentStoreException.convert(e);
         } finally {
             lock.unlock();
             end("findAndModify", start);
@@ -568,7 +570,7 @@ public class MongoDocumentStore implemen
     @CheckForNull
     @Override
     public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update)
-            throws MicroKernelException {
+            throws DocumentStoreException {
         log("createOrUpdate", update);
         T doc = findAndModify(collection, update, true, false);
         log("createOrUpdate returns ", doc);
@@ -577,7 +579,7 @@ public class MongoDocumentStore implemen
 
     @Override
     public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update)
-            throws MicroKernelException {
+            throws DocumentStoreException {
         log("findAndUpdate", update);
         T doc = findAndModify(collection, update, false, true);
         log("findAndUpdate returns ", doc);
@@ -678,7 +680,7 @@ public class MongoDocumentStore implemen
             try {
                 WriteResult writeResult = dbCollection.update(query.get(), update, false, true, WriteConcern.SAFE);
                 if (writeResult.getError() != null) {
-                    throw new MicroKernelException("Update failed: " + writeResult.getError());
+                    throw new DocumentStoreException("Update failed: " + writeResult.getError());
                 }
                 if (collection == Collection.NODES) {
                     // update cache
@@ -698,7 +700,7 @@ public class MongoDocumentStore implemen
                     }
                 }
             } catch (MongoException e) {
-                throw new MicroKernelException(e);
+                throw DocumentStoreException.convert(e);
             }
         } finally {
             end("update", start);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java Wed Jul  9 16:03:35 2014
@@ -30,9 +30,9 @@ import java.util.List;
 
 import javax.sql.DataSource;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.commons.StringUtils;
 import org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,7 +48,7 @@ public class RDBBlobStore extends Cachin
         try {
             initialize(ds);
         } catch (Exception ex) {
-            throw new MicroKernelException("initializing RDB blob store", ex);
+            throw new DocumentStoreException("initializing RDB blob store", ex);
         }
     }
 
@@ -485,7 +485,7 @@ public class RDBBlobStore extends Cachin
     private Connection getConnection() throws SQLException {
         DataSource ds = this.ds;
         if (ds == null) {
-            throw new MicroKernelException("This instance of the RDBBlobStore has already been closed.");
+            throw new DocumentStoreException("This instance of the RDBBlobStore has already been closed.");
         }
         Connection c = ds.getConnection();
         c.setAutoCommit(false);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDataSourceFactory.java Wed Jul  9 16:03:35 2014
@@ -30,7 +30,7 @@ import java.util.logging.Logger;
 import javax.sql.DataSource;
 
 import org.apache.commons.dbcp.BasicDataSource;
-import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
 import org.slf4j.LoggerFactory;
 
 /**
@@ -78,7 +78,7 @@ public class RDBDataSourceFactory {
         } catch (SQLException ex) {
             String message = "trying to obtain driver for " + url;
             LOG.info(message, ex);
-            throw new MicroKernelException(message, ex);
+            throw new DocumentStoreException(message, ex);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Wed Jul  9 16:03:35 2014
@@ -48,12 +48,12 @@ import javax.annotation.Nonnull;
 import javax.sql.DataSource;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.cache.CacheStats;
 import org.apache.jackrabbit.oak.cache.CacheValue;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
 import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.Revision;
 import org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator;
@@ -162,7 +162,7 @@ import com.google.common.util.concurrent
  * <h3>Queries</h3>
  * <p>
  * The implementation currently supports only two indexed properties: "_modified" and
- * "_bin". Attempts to use a different indexed property will cause a {@link MicroKernelException}.
+ * "_bin". Attempts to use a different indexed property will cause a {@link DocumentStoreException}.
  */
 public class RDBDocumentStore implements CachingDocumentStore {
 
@@ -174,7 +174,7 @@ public class RDBDocumentStore implements
         try {
             initialize(ds, builder);
         } catch (Exception ex) {
-            throw new MicroKernelException("initializing RDB document store", ex);
+            throw new DocumentStoreException("initializing RDB document store", ex);
         }
     }
 
@@ -226,12 +226,12 @@ public class RDBDocumentStore implements
     }
 
     @Override
-    public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update) throws MicroKernelException {
+    public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update) {
         return internalCreateOrUpdate(collection, update, true, false);
     }
 
     @Override
-    public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) throws MicroKernelException {
+    public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
         return internalCreateOrUpdate(collection, update, false, true);
     }
 
@@ -442,7 +442,7 @@ public class RDBDocumentStore implements
                     update.increment(MODCOUNT, 1);
                     UpdateUtils.applyChanges(doc, update, comparator);
                     if (!update.getId().equals(doc.getId())) {
-                        throw new MicroKernelException("ID mismatch - UpdateOp: " + update.getId() + ", ID property: "
+                        throw new DocumentStoreException("ID mismatch - UpdateOp: " + update.getId() + ", ID property: "
                                 + doc.getId());
                     }
                     docs.add(doc);
@@ -453,7 +453,7 @@ public class RDBDocumentStore implements
                 }
             }
             return true;
-        } catch (MicroKernelException ex) {
+        } catch (DocumentStoreException ex) {
             return false;
         }
     }
@@ -467,7 +467,7 @@ public class RDBDocumentStore implements
             if (!allowCreate) {
                 return null;
             } else if (!update.isNew()) {
-                throw new MicroKernelException("Document does not exist: " + update.getId());
+                throw new DocumentStoreException("Document does not exist: " + update.getId());
             }
             T doc = collection.newDocument(this);
             if (checkConditions && !UpdateUtils.checkConditions(doc, update)) {
@@ -479,7 +479,7 @@ public class RDBDocumentStore implements
                 insertDocuments(collection, Collections.singletonList(doc));
                 addToCache(collection, doc);
                 return oldDoc;
-            } catch (MicroKernelException ex) {
+            } catch (DocumentStoreException ex) {
                 // may have failed due to a race condition; try update instead
                 // this is an edge case, so it's ok to bypass the cache
                 // (avoiding a race condition where the DB is already updated
@@ -546,7 +546,7 @@ public class RDBDocumentStore implements
                 }
 
                 if (!success) {
-                    throw new MicroKernelException("failed update of " + doc.getId() + " (race?) after " + maxRetries + " retries");
+                    throw new DocumentStoreException("failed update of " + doc.getId() + " (race?) after " + maxRetries + " retries");
                 }
 
                 return oldDoc;
@@ -587,7 +587,7 @@ public class RDBDocumentStore implements
         if (indexedProperty != null && (!INDEXEDPROPERTIES.contains(indexedProperty))) {
             String message = "indexed property " + indexedProperty + " not supported, query was '>= '" + startValue + "'; supported properties are "+ INDEXEDPROPERTIES;
             LOG.info(message);
-            throw new MicroKernelException(message);
+            throw new DocumentStoreException(message);
         }
         try {
             connection = getConnection();
@@ -600,7 +600,7 @@ public class RDBDocumentStore implements
             }
         } catch (Exception ex) {
             LOG.error("SQL exception on query", ex);
-            throw new MicroKernelException(ex);
+            throw new DocumentStoreException(ex);
         } finally {
             closeConnection(connection);
         }
@@ -668,7 +668,7 @@ public class RDBDocumentStore implements
             String in = dbRead(connection, tableName, id);
             return in != null ? fromString(collection, in) : null;
         } catch (Exception ex) {
-            throw new MicroKernelException(ex);
+            throw new DocumentStoreException(ex);
         } finally {
             closeConnection(connection);
         }
@@ -682,7 +682,7 @@ public class RDBDocumentStore implements
             dbDelete(connection, tableName, Collections.singletonList(id));
             connection.commit();
         } catch (Exception ex) {
-            throw new MicroKernelException(ex);
+            throw new DocumentStoreException(ex);
         } finally {
             closeConnection(connection);
         }
@@ -697,7 +697,7 @@ public class RDBDocumentStore implements
                 dbDelete(connection, tableName, sublist);
                 connection.commit();
             } catch (Exception ex) {
-                throw new MicroKernelException(ex);
+                throw new DocumentStoreException(ex);
             } finally {
                 closeConnection(connection);
             }
@@ -725,7 +725,7 @@ public class RDBDocumentStore implements
             } catch (SQLException e) {
                 // TODO
             }
-            throw new MicroKernelException(ex);
+            throw new DocumentStoreException(ex);
         } finally {
             closeConnection(connection);
         }
@@ -755,7 +755,7 @@ public class RDBDocumentStore implements
             } catch (SQLException e) {
                 // TODO
             }
-            throw new MicroKernelException(ex);
+            throw new DocumentStoreException(ex);
         } finally {
             closeConnection(connection);
         }
@@ -797,7 +797,7 @@ public class RDBDocumentStore implements
             bytes = data.getBytes("UTF-8");
         } catch (UnsupportedEncodingException ex) {
             LOG.error("UTF-8 not supported??", ex);
-            throw new MicroKernelException(ex);
+            throw new DocumentStoreException(ex);
         }
 
         if (NOGZIP) {
@@ -816,7 +816,7 @@ public class RDBDocumentStore implements
                 return bos.toByteArray();
             } catch (IOException ex) {
                 LOG.error("Error while gzipping contents", ex);
-                throw new MicroKernelException(ex);
+                throw new DocumentStoreException(ex);
             }
         }
     }
@@ -856,7 +856,7 @@ public class RDBDocumentStore implements
             }
             else if (NodeDocument.HAS_BINARY_FLAG.equals(indexedProperty)) {
                 if (startValue != NodeDocument.HAS_BINARY_VAL) {
-                    throw new MicroKernelException("unsupported value for property " + NodeDocument.HAS_BINARY_FLAG);
+                    throw new DocumentStoreException("unsupported value for property " + NodeDocument.HAS_BINARY_FLAG);
                 }
                 t += " and HASBINARY = 1";
             }
@@ -878,7 +878,7 @@ public class RDBDocumentStore implements
             while (rs.next() && result.size() < limit) {
                 String id = rs.getString(1);
                 if (id.compareTo(minId) < 0 || id.compareTo(maxId) > 0) {
-                    throw new MicroKernelException("unexpected query result: '" + minId + "' < '" + id + "' < '" + maxId + "' - broken DB collation?");
+                    throw new DocumentStoreException("unexpected query result: '" + minId + "' < '" + id + "' < '" + maxId + "' - broken DB collation?");
                 }
                 String data = getData(rs, 2, 3);
                 result.add(data);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java Wed Jul  9 16:03:35 2014
@@ -21,11 +21,11 @@ import java.util.concurrent.Callable;
 
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
 import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -186,8 +186,7 @@ public class LoggingDocumentStoreWrapper
     @Nonnull
     @Override
     public <T extends Document> T createOrUpdate(final Collection<T> collection,
-                                                 final UpdateOp update)
-            throws MicroKernelException {
+                                                 final UpdateOp update) {
         try {
             logMethod("createOrUpdate", collection, update);
             return logResult(new Callable<T>() {
@@ -204,8 +203,7 @@ public class LoggingDocumentStoreWrapper
 
     @Override
     public <T extends Document> T findAndUpdate(final Collection<T> collection,
-                                                final UpdateOp update)
-            throws MicroKernelException {
+                                                final UpdateOp update) {
         try {
             logMethod("findAndUpdate", collection, update);
             return logResult(new Callable<T>() {
@@ -308,7 +306,7 @@ public class LoggingDocumentStoreWrapper
             return (RuntimeException) e;
         }
         log("// unexpected exception type: " + e.getClass().getName());
-        return new MicroKernelException("Unexpected exception: " + e.toString(), e);
+        return new DocumentStoreException("Unexpected exception: " + e.toString(), e);
     }
 
     private void logException(Exception e) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java Wed Jul  9 16:03:35 2014
@@ -20,7 +20,6 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
@@ -87,14 +86,12 @@ public class SynchronizingDocumentStoreW
 
     @Nonnull
     @Override
-    public synchronized <T extends Document> T createOrUpdate(final Collection<T> collection, final UpdateOp update)
-            throws MicroKernelException {
+    public synchronized <T extends Document> T createOrUpdate(final Collection<T> collection, final UpdateOp update) {
         return store.createOrUpdate(collection, update);
     }
 
     @Override
-    public synchronized <T extends Document> T findAndUpdate(final Collection<T> collection, final UpdateOp update)
-            throws MicroKernelException {
+    public synchronized <T extends Document> T findAndUpdate(final Collection<T> collection, final UpdateOp update) {
         return store.findAndUpdate(collection, update);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java Wed Jul  9 16:03:35 2014
@@ -28,10 +28,10 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
 import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
 
 /**
@@ -217,8 +217,7 @@ public class TimingDocumentStoreWrapper 
 
     @Override
     @CheckForNull
-    public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update)
-            throws MicroKernelException {
+    public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update) {
         try {
             long start = now();
             T result = base.createOrUpdate(collection, update);
@@ -234,8 +233,7 @@ public class TimingDocumentStoreWrapper 
 
     @Override
     @CheckForNull
-    public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update)
-            throws MicroKernelException {
+    public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) {
         try {
             long start = now();
             T result = base.findAndUpdate(collection, update);
@@ -336,7 +334,7 @@ public class TimingDocumentStoreWrapper 
         if (e instanceof RuntimeException) {
             return (RuntimeException) e;
         }
-        return new MicroKernelException("Unexpected exception: " + e.toString(), e);
+        return new DocumentStoreException("Unexpected exception: " + e.toString(), e);
     }
 
     private void log(String message) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStoreBranch.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStoreBranch.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeStoreBranch.java Wed Jul  9 16:03:35 2014
@@ -32,7 +32,6 @@ import static org.apache.jackrabbit.oak.
 
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.commit.ChangeDispatcher;
@@ -198,6 +197,17 @@ public abstract class AbstractNodeStoreB
      */
     protected abstract N move(String source, String target, N base);
 
+    /**
+     * Convert an implementation specific unchecked exception into a
+     * {@link CommitFailedException}.
+     *
+     * @param cause the unchecked exception cause.
+     * @param msg the message to use for the {@link CommitFailedException}.
+     * @return a {@link CommitFailedException}.
+     */
+    protected abstract CommitFailedException convertUnchecked(Exception cause,
+                                                              String msg);
+
     @Override
     public String toString() {
         return branchState.toString();
@@ -501,12 +511,9 @@ public abstract class AbstractNodeStoreB
                     dispatcher.contentChanged(newHead, info);
                     branchState = new Merged(base);
                     return newHead;
-                } catch (MicroKernelException e) {
-                    throw new CommitFailedException(MERGE, 1,
-                            "Failed to merge changes to the underlying store", e);
                 } catch (Exception e) {
-                    throw new CommitFailedException(OAK, 1,
-                            "Failed to merge changes to the underlying store", e);
+                    throw convertUnchecked(e,
+                            "Failed to merge changes to the underlying store");
                 }
             } finally {
                 dispatcher.contentChanged(getRoot(), null);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1609214&r1=1609213&r2=1609214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java Wed Jul  9 16:03:35 2014
@@ -30,7 +30,6 @@ import java.util.concurrent.atomic.Atomi
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
@@ -227,7 +226,7 @@ public class DocumentNodeStoreTest {
                     c.addNode(new DocumentNodeState(store, "/foo/node", r));
                     c.addNode(new DocumentNodeState(store, "/bar/node", r));
                     c.apply();
-                } catch (MicroKernelException e) {
+                } catch (DocumentStoreException e) {
                     exceptions.add(e);
                 }
             }