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 2016/06/29 13:16:35 UTC
svn commit: r1750630 - in /jackrabbit/oak/branches/1.4: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/
oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/
oak-core/src/test/java/org/apache/jackrabbit/oak/plugin...
Author: reschke
Date: Wed Jun 29 13:16:35 2016
New Revision: 1750630
URL: http://svn.apache.org/viewvc?rev=1750630&view=rev
Log:
OAK-4510: RDBDocumentStore: can't persist _modified value of null (ported to 1.4)
Modified:
jackrabbit/oak/branches/1.4/ (props changed)
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java
Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun 29 13:16:35 2016
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738775,1738795,1738833,1738950,1738957,1738963,1739894,1740116,1740625-1740626,1740971,1741032,1741339,1741343,1742520,1742888,1742916,1743097,1743172,1743343,1744265,1744959,1745038,1745197,1745368,1746086,1746117,1746342,1746345,1746696,1746981,1747341-1747342,1747492,1747512,1748505,1748553,1748870,1749275,1749350,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750076-1750077,1750287,1750457,1750465,1750495
+/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738775,1738795,1738833,1738950,1738957,1738963,1739894,1740116,1740625-1740626,1740971,1741032,1741339,1741343,1742520,1742888,1742916,1743097,1743172,1743343,1744265,1744959,1745038,1745197,1745368,1746086,1746117,1746342,1746345,1746696,1746981,1747341-1747342,1747492,1747512,1748505,1748553,1748870,1749275,1749350,1749464,1749475,1749645,1749662,1749815,1749872,1749875,1749899,1750076-1750077,1750287,1750457,1750465,1750495,1750626
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java?rev=1750630&r1=1750629&r2=1750630&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java Wed Jun 29 13:16:35 2016
@@ -146,11 +146,13 @@ public class RDBDocumentSerializer {
public <T extends Document> T fromRow(@Nonnull Collection<T> collection, @Nonnull RDBRow row) throws DocumentStoreException {
T doc = collection.newDocument(store);
doc.put(ID, row.getId());
- if (row.getModified() != 0) {
+ if (row.getModified() != RDBRow.LONG_UNSET) {
doc.put(MODIFIED, row.getModified());
}
- doc.put(MODCOUNT, row.getModcount());
- if (RDBDocumentStore.USECMODCOUNT) {
+ if (row.getModcount() != RDBRow.LONG_UNSET) {
+ doc.put(MODCOUNT, row.getModcount());
+ }
+ if (RDBDocumentStore.USECMODCOUNT && row.getCollisionsModcount() != RDBRow.LONG_UNSET) {
doc.put(CMODCOUNT, row.getCollisionsModcount());
}
if (row.hasBinaryProperties()) {
Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java?rev=1750630&r1=1750629&r2=1750630&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java Wed Jun 29 13:16:35 2016
@@ -540,9 +540,9 @@ public class RDBDocumentStoreJDBC {
throw new DocumentStoreException(
"unexpected query result: '" + minId + "' < '" + id + "' < '" + maxId + "' - broken DB collation?");
}
- long modified = rs.getLong(2);
- long modcount = rs.getLong(3);
- long cmodcount = rs.getLong(4);
+ long modified = readLongFromResultSet(rs, 2);
+ long modcount = readLongFromResultSet(rs, 3);
+ long cmodcount = readLongFromResultSet(rs, 4);
long hasBinary = rs.getLong(5);
long deletedOnce = rs.getLong(6);
String data = rs.getString(7);
@@ -593,9 +593,9 @@ public class RDBDocumentStoreJDBC {
while (rs.next()) {
int col = 1;
String id = getIdFromRS(tmd, rs, col++);
- long modified = rs.getLong(col++);
- long modcount = rs.getLong(col++);
- long cmodcount = rs.getLong(col++);
+ long modified = readLongFromResultSet(rs, col++);
+ long modcount = readLongFromResultSet(rs, col++);
+ long cmodcount = readLongFromResultSet(rs, col++);
long hasBinary = rs.getLong(col++);
long deletedOnce = rs.getLong(col++);
String data = rs.getString(col++);
@@ -652,9 +652,9 @@ public class RDBDocumentStoreJDBC {
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
- long modified = rs.getLong(1);
- long modcount = rs.getLong(2);
- long cmodcount = rs.getLong(3);
+ long modified = readLongFromResultSet(rs, 1);
+ long modcount = readLongFromResultSet(rs, 2);
+ long cmodcount = readLongFromResultSet(rs, 3);
long hasBinary = rs.getLong(4);
long deletedOnce = rs.getLong(5);
String data = rs.getString(6);
@@ -752,6 +752,11 @@ public class RDBDocumentStoreJDBC {
}
}
+ private static long readLongFromResultSet(ResultSet res, int index) throws SQLException {
+ long v = res.getLong(index);
+ return res.wasNull() ? RDBRow.LONG_UNSET : v;
+ }
+
private static <T extends Document> List<T> sortDocuments(Collection<T> documents) {
List<T> result = new ArrayList<T>(documents);
Collections.sort(result, new Comparator<T>() {
Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java?rev=1750630&r1=1750629&r2=1750630&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java Wed Jun 29 13:16:35 2016
@@ -28,19 +28,21 @@ import javax.annotation.Nonnull;
*/
public class RDBRow {
+ public static final long LONG_UNSET = Long.MIN_VALUE;
+
private final String id;
private final boolean hasBinaryProperties, deletedOnce;
private final long modified, modcount, cmodcount;
private final String data;
private final byte[] bdata;
- public RDBRow(String id, boolean hasBinaryProperties, boolean deletedOnce, long modified, long modcount, long cmodcount, String data, byte[] bdata) {
+ public RDBRow(String id, boolean hasBinaryProperties, boolean deletedOnce, Long modified, Long modcount, Long cmodcount, String data, byte[] bdata) {
this.id = id;
this.hasBinaryProperties = hasBinaryProperties;
this.deletedOnce = deletedOnce;
- this.modified = modified;
- this.modcount = modcount;
- this.cmodcount = cmodcount;
+ this.modified = modified != null ? modified.longValue() : LONG_UNSET;
+ this.modcount = modcount != null ? modcount.longValue() : LONG_UNSET;
+ this.cmodcount = cmodcount != null ? cmodcount.longValue() : LONG_UNSET;
this.data = data;
this.bdata = bdata;
}
@@ -63,17 +65,23 @@ public class RDBRow {
return data;
}
- @Nonnull
+ /**
+ * @return {@link #LONG_UNSET} when not set in the database
+ */
public long getModified() {
return modified;
}
- @Nonnull
+ /**
+ * @return {@link #LONG_UNSET} when not set in the database
+ */
public long getModcount() {
return modcount;
}
- @Nonnull
+ /**
+ * @return {@link #LONG_UNSET} when not set in the database
+ */
public long getCollisionsModcount() {
return cmodcount;
}
Modified: jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java?rev=1750630&r1=1750629&r2=1750630&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java Wed Jun 29 13:16:35 2016
@@ -36,6 +36,7 @@ public abstract class AbstractDocumentSt
protected DocumentStoreFixture dsf;
protected DataSource rdbDataSource;
protected List<String> removeMe = new ArrayList<String>();
+ protected List<String> removeMeSettings = new ArrayList<String>();
static final Logger LOG = LoggerFactory.getLogger(AbstractDocumentStoreTest.class);
@@ -48,26 +49,8 @@ public abstract class AbstractDocumentSt
@After
public void cleanUp() throws Exception {
- if (!removeMe.isEmpty()) {
- long start = System.nanoTime();
- try {
- ds.remove(org.apache.jackrabbit.oak.plugins.document.Collection.NODES, removeMe);
- } catch (Exception ex) {
- // retry one by one
- for (String id : removeMe) {
- try {
- ds.remove(org.apache.jackrabbit.oak.plugins.document.Collection.NODES, id);
- } catch (Exception ex2) {
- // best effort
- }
- }
- }
- if (removeMe.size() > 1) {
- long elapsed = (System.nanoTime() - start) / (1000 * 1000);
- float rate = (((float)removeMe.size()) / (elapsed == 0 ? 1 : elapsed));
- LOG.info(removeMe.size() + " documents removed in " + elapsed + "ms (" + rate + "/ms)");
- }
- }
+ removeTestNodes(org.apache.jackrabbit.oak.plugins.document.Collection.NODES, removeMe);
+ removeTestNodes(org.apache.jackrabbit.oak.plugins.document.Collection.SETTINGS, removeMeSettings);
ds.dispose();
dsf.dispose();
}
@@ -120,4 +103,28 @@ public abstract class AbstractDocumentSt
}
return new String(s);
}
+
+ private <T extends Document> void removeTestNodes(org.apache.jackrabbit.oak.plugins.document.Collection<T> col,
+ List<String> ids) {
+ if (!ids.isEmpty()) {
+ long start = System.nanoTime();
+ try {
+ ds.remove(col, ids);
+ } catch (Exception ex) {
+ // retry one by one
+ for (String id : ids) {
+ try {
+ ds.remove(col, id);
+ } catch (Exception ex2) {
+ // best effort
+ }
+ }
+ }
+ if (ids.size() > 1) {
+ long elapsed = (System.nanoTime() - start) / (1000 * 1000);
+ float rate = (((float) ids.size()) / (elapsed == 0 ? 1 : elapsed));
+ LOG.info(ids.size() + " documents removed in " + elapsed + "ms (" + rate + "/ms)");
+ }
+ }
+ }
}
Modified: jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1750630&r1=1750629&r2=1750630&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java Wed Jun 29 13:16:35 2016
@@ -668,25 +668,23 @@ public class BasicDocumentStoreTest exte
public void testUpdateModified() {
String id = this.getClass().getName() + ".testUpdateModified";
// create a test node
- super.ds.remove(Collection.NODES, id);
+ super.ds.remove(Collection.SETTINGS, id);
UpdateOp up = new UpdateOp(id, true);
up.set("_id", id);
- boolean success = super.ds.create(Collection.NODES, Collections.singletonList(up));
+ boolean success = super.ds.create(Collection.SETTINGS, Collections.singletonList(up));
assertTrue(success);
- removeMe.add(id);
+ removeMeSettings.add(id);
- ds.invalidateCache();
- Document d = super.ds.find(Collection.NODES, id);
+ Document d = super.ds.find(Collection.SETTINGS, id);
Object m = d.get("_modified");
assertNull("_modified should be null until set", m);
up = new UpdateOp(id, true);
up.set("_id", id);
up.set("_modified", 123L);
- super.ds.findAndUpdate(Collection.NODES, up);
+ super.ds.findAndUpdate(Collection.SETTINGS, up);
- ds.invalidateCache();
- d = super.ds.find(Collection.NODES, id);
+ d = super.ds.find(Collection.SETTINGS, id);
m = d.get("_modified");
assertNotNull("_modified should now be != null", m);
assertEquals("123", m.toString());
@@ -694,10 +692,9 @@ public class BasicDocumentStoreTest exte
up = new UpdateOp(id, true);
up.set("_id", id);
up.max("_modified", 122L);
- super.ds.findAndUpdate(Collection.NODES, up);
+ super.ds.findAndUpdate(Collection.SETTINGS, up);
- ds.invalidateCache();
- d = super.ds.find(Collection.NODES, id);
+ d = super.ds.find(Collection.SETTINGS, id);
m = d.get("_modified");
assertNotNull("_modified should now be != null", m);
assertEquals("123", m.toString());
@@ -705,10 +702,10 @@ public class BasicDocumentStoreTest exte
up = new UpdateOp(id, true);
up.set("_id", id);
up.max("_modified", 124L);
- super.ds.findAndUpdate(Collection.NODES, up);
+ super.ds.findAndUpdate(Collection.SETTINGS, up);
ds.invalidateCache();
- d = super.ds.find(Collection.NODES, id);
+ d = super.ds.find(Collection.SETTINGS, id);
m = d.get("_modified");
assertNotNull("_modified should now be != null", m);
assertEquals("124", m.toString());
Modified: jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java?rev=1750630&r1=1750629&r2=1750630&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java Wed Jun 29 13:16:35 2016
@@ -56,7 +56,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testSimpleString() {
- RDBRow row = new RDBRow("_foo", true, true, 1, 2, 3, "{}", null);
+ RDBRow row = new RDBRow("_foo", true, true, 1l, 2l, 3l, "{}", null);
NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
assertEquals("_foo", doc.getId());
assertEquals(true, doc.hasBinary());
@@ -66,7 +66,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testSimpleBlob() throws UnsupportedEncodingException {
- RDBRow row = new RDBRow("_foo", false, false, 1, 2, 3, "\"blob\"", "{}".getBytes("UTF-8"));
+ RDBRow row = new RDBRow("_foo", false, false, 1l, 2l, 3l, "\"blob\"", "{}".getBytes("UTF-8"));
NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
assertEquals("_foo", doc.getId());
assertEquals(false, doc.hasBinary());
@@ -75,7 +75,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testSimpleBlob2() throws UnsupportedEncodingException {
- RDBRow row = new RDBRow("_foo", false, false, 1, 2, 3, "\"blob\"",
+ RDBRow row = new RDBRow("_foo", false, false, 1l, 2l, 3l, "\"blob\"",
"{\"s\":\"string\", \"b\":true, \"i\":1}".getBytes("UTF-8"));
NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
assertEquals("_foo", doc.getId());
@@ -89,7 +89,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testSimpleBoth() throws UnsupportedEncodingException {
try {
- RDBRow row = new RDBRow("_foo", true, false, 1, 2, 3, "{}", "{}".getBytes("UTF-8"));
+ RDBRow row = new RDBRow("_foo", true, false, 1l, 2l, 3l, "{}", "{}".getBytes("UTF-8"));
this.ser.fromRow(Collection.NODES, row);
fail("should fail");
} catch (DocumentStoreException expected) {
@@ -98,7 +98,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testBlobAndDiff() throws UnsupportedEncodingException {
- RDBRow row = new RDBRow("_foo", true, false, 1, 2, 3,
+ RDBRow row = new RDBRow("_foo", true, false, 1l, 2l, 3l,
"\"blob\", [[\"=\", \"foo\", \"bar\"],[\"M\", \"m1\", 1],[\"M\", \"m2\", 3]]",
"{\"m1\":2, \"m2\":2}".getBytes("UTF-8"));
NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
@@ -110,7 +110,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testBlobAndDiffBorked() throws UnsupportedEncodingException {
try {
- RDBRow row = new RDBRow("_foo", true, false, 1, 2, 3, "[[\"\", \"\", \"\"]]", "{}".getBytes("UTF-8"));
+ RDBRow row = new RDBRow("_foo", true, false, 1l, 2l, 3l, "[[\"\", \"\", \"\"]]", "{}".getBytes("UTF-8"));
this.ser.fromRow(Collection.NODES, row);
fail("should fail");
} catch (DocumentStoreException expected) {
@@ -118,9 +118,16 @@ public class RDBDocumentSerializerTest {
}
@Test
+ public void testNullModified() throws UnsupportedEncodingException {
+ RDBRow row = new RDBRow("_foo", true, true, null, 2l, 3l, "{}", null);
+ NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
+ assertNull(doc.getModified());
+ }
+
+ @Test
public void testBrokenJSONTrailingComma() throws UnsupportedEncodingException {
try {
- RDBRow row = new RDBRow("_foo", true, false, 1, 2, 3, "{ \"x\" : 1, }", null);
+ RDBRow row = new RDBRow("_foo", true, false, 1l, 2l, 3l, "{ \"x\" : 1, }", null);
this.ser.fromRow(Collection.NODES, row);
fail("should fail");
} catch (DocumentStoreException expected) {
@@ -130,7 +137,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testBrokenJSONUnquotedIdentifier() throws UnsupportedEncodingException {
try {
- RDBRow row = new RDBRow("_foo", true, false, 1, 2, 3, "{ x : 1, }", null);
+ RDBRow row = new RDBRow("_foo", true, false, 1l, 2l, 3l, "{ x : 1, }", null);
this.ser.fromRow(Collection.NODES, row);
fail("should fail");
} catch (DocumentStoreException expected) {
@@ -139,7 +146,7 @@ public class RDBDocumentSerializerTest {
@Test
public void testSimpleStringNonAscii() {
- RDBRow row = new RDBRow("_foo", true, false, 1, 2, 3, "{\"x\":\"\u20ac\uD834\uDD1E\"}", null);
+ RDBRow row = new RDBRow("_foo", true, false, 1l, 2l, 3l, "{\"x\":\"\u20ac\uD834\uDD1E\"}", null);
NodeDocument doc = this.ser.fromRow(Collection.NODES, row);
assertEquals("_foo", doc.getId());
assertEquals("\u20ac\uD834\uDD1E", doc.get("x"));