Author: mreutegg
Date: Tue Mar 6 14:54:24 2018
New Revision: 1825990
URL: http://svn.apache.org/viewvc?rev=1825990&view=rev
Log:
OAK-7306: MongoDocumentStore: use transient DocumentStoreException type where
appropriate
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1825990&r1=1825989&r2=1825990&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
Tue Mar 6 14:54:24 2018
@@ -100,12 +100,12 @@ import com.mongodb.QueryBuilder;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;
-import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Maps.filterKeys;
import static com.google.common.collect.Sets.difference;
+import static
org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.asDocumentStoreException;
import static
org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE;
import static
org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS;
import static
org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS;
@@ -113,6 +113,7 @@ import static org.apache.jackrabbit.oak.
import static
org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition;
import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createIndex;
import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createPartialIndex;
+import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor;
import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex;
/**
@@ -1745,7 +1746,8 @@ public class MongoDocumentStore implemen
invalidateCache(collection, id);
}
}
- return DocumentStoreException.convert(ex, ids);
+ return asDocumentStoreException(ex.getMessage(), ex,
+ getDocumentStoreExceptionTypeFor(ex), ids);
}
private <T extends Document> DocumentStoreException
handleException(Throwable ex,
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java?rev=1825990&r1=1825989&r2=1825990&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
Tue Mar 6 14:54:24 2018
@@ -22,7 +22,13 @@ import com.google.common.collect.Sets;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
+import com.mongodb.MongoCommandException;
import com.mongodb.MongoException;
+import com.mongodb.MongoNotPrimaryException;
+import com.mongodb.MongoSocketException;
+import com.mongodb.MongoWriteConcernException;
+
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type;
import static com.google.common.base.Preconditions.checkArgument;
@@ -133,4 +139,28 @@ class MongoUtils {
}
return false;
}
+
+ /**
+ * Returns the {@code DocumentStoreException} {@link Type} for the given
+ * throwable.
+ *
+ * @param t the throwable.
+ * @return the type.
+ */
+ static Type getDocumentStoreExceptionTypeFor(Throwable t) {
+ Type type = Type.GENERIC;
+ if (t instanceof MongoSocketException
+ || t instanceof MongoWriteConcernException
+ || t instanceof MongoNotPrimaryException) {
+ type = Type.TRANSIENT;
+ } else if (t instanceof MongoCommandException) {
+ int code = ((MongoCommandException) t).getErrorCode();
+ if (code == 11600 // InterruptedAtShutdown
+ || code == 11601 // Interrupted
+ || code == 11602) { // InterruptedDueToReplStateChange
+ type = Type.TRANSIENT;
+ }
+ }
+ return type;
+ }
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java?rev=1825990&r1=1825989&r2=1825990&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
Tue Mar 6 14:54:24 2018
@@ -16,16 +16,28 @@
*/
package org.apache.jackrabbit.oak.plugins.document.mongo;
+import java.io.IOException;
+
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
+import com.mongodb.MongoCommandException;
+import com.mongodb.MongoException;
+import com.mongodb.MongoSocketException;
+import com.mongodb.ServerAddress;
import org.apache.jackrabbit.oak.plugins.document.MongoConnectionFactory;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.bson.BsonDocument;
+import org.bson.BsonInt32;
+import org.bson.BsonString;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
+import static
org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type.GENERIC;
+import static
org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type.TRANSIENT;
import static
org.apache.jackrabbit.oak.plugins.document.MongoUtils.isAvailable;
+import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -116,4 +128,23 @@ public class MongoUtilsTest {
MongoUtils.createIndex(collection, new String[]{"foo", "bar"},
new boolean[]{true}, false, true);
}
+
+ @Test
+ public void documentStoreExceptionType() {
+ assertEquals(GENERIC, getDocumentStoreExceptionTypeFor(new
IOException()));
+ assertEquals(GENERIC, getDocumentStoreExceptionTypeFor(new
MongoException("message")));
+ assertEquals(GENERIC,
getDocumentStoreExceptionTypeFor(createMongoCommandException(42)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(createMongoCommandException(11600)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(createMongoCommandException(11601)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(createMongoCommandException(11602)));
+ assertEquals(TRANSIENT, getDocumentStoreExceptionTypeFor(new
MongoSocketException("message", new ServerAddress())));
+ }
+
+ private static MongoCommandException createMongoCommandException(int code)
{
+ BsonDocument response = new BsonDocument();
+ response.put("code", new BsonInt32(code));
+ response.put("errmsg", new BsonString("message"));
+ ServerAddress address = new ServerAddress();
+ return new MongoCommandException(response, address);
+ }
}