Author: reschke
Date: Thu Apr 11 05:56:25 2019
New Revision: 1857293
URL: http://svn.apache.org/viewvc?rev=1857293&view=rev
Log:
OAK-8201: RDBDocumentStore in ReadOnly mode should never modify persistence
(ported to 1.10)
Modified:
jackrabbit/oak/branches/1.10/ (props changed)
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreSchemaUpgradeTest.java
Propchange: jackrabbit/oak/branches/1.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 11 05:56:25 2019
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855776,1857010,1857104,1857159
+/jackrabbit/oak/trunk:1850874,1850882,1851236,1851253,1851451,1851533-1851535,1851619,1852052,1852084,1852120,1852451,1852492-1852493,1852528,1852582,1852584,1852601,1852920,1853141,1853229,1853393,1853429,1853433,1853441,1853866,1853868,1853870,1853893,1853969,1853997,1854034,1854044,1854055,1854058,1854113,1854373,1854377,1854380,1854385,1854401,1854403,1854455,1854461-1854462,1854466,1854468,1854515,1854533,1854539,1854701,1854773-1854774,1854827,1854848,1854859,1854930,1854990-1854991,1855032,1855221,1855477-1855478,1855776,1857010,1857104,1857159,1857253
/jackrabbit/trunk:1345480
Modified:
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1857293&r1=1857292&r2=1857293&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.10/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Thu Apr 11 05:56:25 2019
@@ -937,9 +937,11 @@ public class RDBDocumentStore implements
private DocumentStoreStatsCollector stats;
+ private boolean readOnly;
+
// VERSION column mapping in queries used by RDBVersionGCSupport
public static String VERSIONPROP = "__version";
-
+
// set of supported indexed properties
private static final Set<String> INDEXEDPROPERTIES = new
HashSet<String>(Arrays.asList(new String[] { MODIFIED,
NodeDocument.HAS_BINARY_FLAG, NodeDocument.DELETED_ONCE,
NodeDocument.SD_TYPE, NodeDocument.SD_MAX_REV_TIME_IN_SECS, VERSIONPROP }));
@@ -967,6 +969,8 @@ public class RDBDocumentStore implements
this.callStack = LOG.isDebugEnabled() ? new Exception("call stack of
RDBDocumentStore creation") : null;
+ this.readOnly = builder.getReadOnlyMode();
+
this.ch = new RDBConnectionHandler(ds);
Connection con = this.ch.getRWConnection();
String catalog = con.getCatalog();
@@ -1302,16 +1306,21 @@ public class RDBDocumentStore implements
closeResultSet(checkResultSet);
boolean dbWasChanged = false;
- if (!hasVersionColumn && upgradeToSchema >= 1) {
- dbWasChanged |= upgradeTable(con, tableName, 1);
+ if (this.readOnly) {
+ LOG.debug("Skipping table update code because store is
initialized in readOnly mode");
}
+ else {
+ if (!hasVersionColumn && upgradeToSchema >= 1) {
+ dbWasChanged |= upgradeTable(con, tableName, 1);
+ }
- if (!hasSDTypeColumn && upgradeToSchema >= 2) {
- dbWasChanged |= upgradeTable(con, tableName, 2);
- }
+ if (!hasSDTypeColumn && upgradeToSchema >= 2) {
+ dbWasChanged |= upgradeTable(con, tableName, 2);
+ }
- if (!indexOn.contains("MODIFIED") && col == Collection.NODES) {
- dbWasChanged |= addModifiedIndex(con, tableName);
+ if (!indexOn.contains("MODIFIED") && col == Collection.NODES) {
+ dbWasChanged |= addModifiedIndex(con, tableName);
+ }
}
tablesPresent.add(tableName);
@@ -1323,6 +1332,12 @@ public class RDBDocumentStore implements
// table does not appear to exist
con.rollback();
+ LOG.debug("trying to read from '" + tableName + "'", ex);
+ if (this.readOnly) {
+ throw new SQLException("Would like to create table '" +
tableName
+ + "', but RDBDocumentStore has been initialized in
'readonly' mode");
+ }
+
try {
creatStatement = con.createStatement();
creatStatement.execute(this.dbInfo.getTableCreationStatement(tableName,
initialSchema));
@@ -1349,7 +1364,7 @@ public class RDBDocumentStore implements
getTableMetaData(con, col, tmd);
}
catch (SQLException ex2) {
- LOG.error("Failed to create table " + tableName + " in " +
dbname, ex2);
+ LOG.error("Failed to create table '" + tableName + "' in '" +
dbname + "'", ex2);
throw ex2;
}
}
@@ -1441,6 +1456,10 @@ public class RDBDocumentStore implements
}
}
+ public boolean isReadOnly() {
+ return readOnly;
+ }
+
@Override
protected void finalize() throws Throwable {
if (!this.ch.isClosed() && this.callStack != null) {
Modified:
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreSchemaUpgradeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreSchemaUpgradeTest.java?rev=1857293&r1=1857292&r2=1857293&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreSchemaUpgradeTest.java
(original)
+++
jackrabbit/oak/branches/1.10/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreSchemaUpgradeTest.java
Thu Apr 11 05:56:25 2019
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
@@ -33,6 +34,7 @@ import javax.sql.DataSource;
import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType;
@@ -84,6 +86,22 @@ public class RDBDocumentStoreSchemaUpgra
} finally {
if (rdb != null) {
rdb.dispose();
+ }
+ }
+ }
+
+ @Test
+ public void initDefaultRO() {
+ RDBOptions op = new
RDBOptions().tablePrefix("T00RO").initialSchema(0).upgradeToSchema(0).dropTablesOnClose(true);
+ RDBDocumentStore rdb = null;
+ try {
+ DocumentMK.Builder builder = new
DocumentMK.Builder().setReadOnlyMode();
+ rdb = new RDBDocumentStore(this.ds, builder, op);
+ fail("should fail");
+ } catch (DocumentStoreException expected) {
+ } finally {
+ if (rdb != null) {
+ rdb.dispose();
}
}
}