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 re...@apache.org on 2015/07/14 16:47:30 UTC
svn commit: r1690948 - in /jackrabbit/oak/branches/1.2: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/
oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/
Author: reschke
Date: Tue Jul 14 14:47:30 2015
New Revision: 1690948
URL: http://svn.apache.org/r1690948
Log:
OAK-3096: improve diagnostics for failed batch inserts, add test case observing the DocumentStore's behavior wrt to atomicity (ported to 1.2)
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 14 14:47:30 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868,1685023,1685370,1685552
,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820,1684868,1685023,1685370,1685552
,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1690948&r1=1690947&r2=1690948&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Tue Jul 14 14:47:30 2015
@@ -1498,15 +1498,25 @@ public class RDBDocumentStore implements
private <T extends Document> boolean insertDocuments(Collection<T> collection, List<T> documents) {
Connection connection = null;
String tableName = getTable(collection);
- List<String> ids = new ArrayList<String>();
try {
connection = this.ch.getRWConnection();
boolean result = dbInsert(connection, tableName, documents);
connection.commit();
return result;
} catch (SQLException ex) {
- LOG.debug("insert of " + ids + " failed", ex);
this.ch.rollbackConnection(connection);
+
+ List<String> ids = new ArrayList<String>();
+ for (T doc : documents) {
+ ids.add(doc.getId());
+ }
+ LOG.debug("insert of " + ids + " failed", ex);
+
+ // collect additional exceptions
+ String messages = LOG.isDebugEnabled() ? RDBJDBCTools.getAdditionalMessages(ex) : "";
+ if (!messages.isEmpty()) {
+ LOG.debug("additional diagnostics: " + messages);
+ }
throw new DocumentStoreException(ex);
} finally {
this.ch.closeConnection(connection);
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java?rev=1690948&r1=1690947&r2=1690948&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBJDBCTools.java Tue Jul 14 14:47:30 2015
@@ -17,6 +17,9 @@
package org.apache.jackrabbit.oak.plugins.document.rdb;
import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -119,4 +122,22 @@ public class RDBJDBCTools {
}
return String.format("%s (%d)", name, isolationLevel);
}
+
+ /**
+ * Return a string containing additional messages from chained exceptions.
+ */
+ protected static @Nonnull String getAdditionalMessages(SQLException ex) {
+ List<String> messages = new ArrayList<String>();
+ String message = ex.getMessage();
+ SQLException next = ex.getNextException();
+ while (next != null) {
+ String m = next.getMessage();
+ if (!message.equals(m)) {
+ messages.add(m);
+ }
+ next = next.getNextException();
+ }
+
+ return messages.isEmpty() ? "" : messages.toString();
+ }
}
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1690948&r1=1690947&r2=1690948&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java Tue Jul 14 14:47:30 2015
@@ -25,10 +25,11 @@ import static org.junit.Assert.fail;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition;
@@ -226,26 +227,63 @@ public class BasicDocumentStoreTest exte
@Test
public void testCreatePartialFailure() {
- String id = this.getClass().getName() + ".testCreatePartialFailure";
+ String bid = this.getClass().getName() + ".testCreatePartialFailure-";
+ int cnt = 10;
+ assertTrue(cnt > 8);
+
+ // clear repo
+ for (int i = 0; i < cnt; i++) {
+ super.ds.remove(Collection.NODES, bid + i);
+ removeMe.add(bid + i);
+ }
- // remove if present
- NodeDocument nd = super.ds.find(Collection.NODES, id);
- if (nd != null) {
- super.ds.remove(Collection.NODES, id);
+ // create one of the test nodes
+ int pre = cnt / 2;
+ UpdateOp up = new UpdateOp(bid + pre, true);
+ up.set("_id", bid + pre);
+ up.set("foo", "bar");
+ assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(up)));
+
+ // batch create
+ Set<String> toCreate = new HashSet<String>();
+ Set<String> toCreateFailEarly = new HashSet<String>();
+ List<UpdateOp> ups = new ArrayList<UpdateOp>();
+ for (int i = 0; i < cnt; i++) {
+ UpdateOp op = new UpdateOp(bid + i, true);
+ op.set("_id", bid + i);
+ op.set("foo", "qux");
+ ups.add(op);
+ if (i != pre) {
+ toCreate.add(bid + i);
+ }
+ if (i < pre) {
+ toCreateFailEarly.add(bid + i);
+ }
}
+ assertFalse(super.ds.create(Collection.NODES, ups));
- // create a test node
- UpdateOp up = new UpdateOp(id, true);
- up.set("_id", id);
- boolean success = super.ds.create(Collection.NODES, Collections.singletonList(up));
- assertTrue(success);
- removeMe.add(id);
+ // check how many nodes are there
+ Set<String> created = new HashSet<String>();
+ for (int i = 0; i < cnt; i++) {
+ boolean present = null != super.ds.find(Collection.NODES, bid + i, 0);
+ if (i == pre && !present) {
+ fail(super.dsname + ": batch update removed previously existing node " + (bid + i));
+ } else if (present && i != pre) {
+ created.add(bid + i);
+ }
+ }
- // try to create two nodes, of which one exists
- UpdateOp up2 = new UpdateOp(id + "2", true);
- up2.set("_id", id + "2");
- success = super.ds.create(Collection.NODES, Arrays.asList(new UpdateOp[] { up, up2 }));
- assertFalse(success);
+ // diagnostics
+ toCreate.removeAll(created);
+ if (created.isEmpty()) {
+ LOG.info(super.dsname + ": create() apparently is atomic");
+ } else if (created.size() == toCreate.size()) {
+ LOG.info(super.dsname + ": create() apparently is best-effort");
+ } else if (created.equals(toCreateFailEarly)) {
+ LOG.info(super.dsname + ": create() stops at first failure");
+ } else {
+ LOG.info(super.dsname + ": create() created: " + created + ", missing: " + toCreate);
+ }
}
@Test