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 12:41:52 UTC

svn commit: r1750626 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/rdb/ test/java/org/apache/jackrabbit/oak/plugins/document/ test/java/org/apache/jackrabbit/oak/plugins/document/rdb/

Author: reschke
Date: Wed Jun 29 12:41:52 2016
New Revision: 1750626

URL: http://svn.apache.org/viewvc?rev=1750626&view=rev
Log:
OAK-4510: RDBDocumentStore: can't persist _modified value of null

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java?rev=1750626&r1=1750625&r2=1750626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializer.java Wed Jun 29 12:41:52 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/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java?rev=1750626&r1=1750625&r2=1750626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java Wed Jun 29 12:41:52 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/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java?rev=1750626&r1=1750625&r2=1750626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBRow.java Wed Jun 29 12:41:52 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/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java?rev=1750626&r1=1750625&r2=1750626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractDocumentStoreTest.java Wed Jun 29 12:41:52 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/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1750626&r1=1750625&r2=1750626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java Wed Jun 29 12:41:52 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/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java?rev=1750626&r1=1750625&r2=1750626&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentSerializerTest.java Wed Jun 29 12:41:52 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"));