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/06/11 14:48:59 UTC

svn commit: r1684868 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy

Author: reschke
Date: Thu Jun 11 12:48:58 2015
New Revision: 1684868

URL: http://svn.apache.org/r1684868
Log:
OAK-2972: Simplify DocumentNodeStoreService handling of custom blob data sources, improve test coverage

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
    jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1684868&r1=1684867&r2=1684868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Thu Jun 11 12:48:58 2015
@@ -27,7 +27,6 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_DOC_CHILDREN_CACHE_PERCENTAGE;
 import static org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_NODE_CACHE_PERCENTAGE;
 import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
-import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.scheduleWithFixedDelay;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -50,7 +49,6 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Modified;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scr.annotations.Reference;
@@ -228,17 +226,6 @@ public class DocumentNodeStoreService {
                     + "Default is " + DEFAULT_JOURNAL_GC_MAX_AGE_MILLIS
     )
     private static final String PROP_JOURNAL_GC_MAX_AGE_MILLIS = "journalGCMaxAge";
-    
-    /**
-     * Boolean value indicating a different DataSource has to be used for
-     * BlobStore
-     */
-    @Property(boolValue = false,
-            label = "Custom DataSource",
-            description = "Boolean value indicating that DataSource is configured " +
-                    "separately, and that it should be used"
-    )
-    public static final String CUSTOM_BLOB_DATA_SOURCE = "customBlobDataSource";
 
     private static final long MB = 1024 * 1024;
 
@@ -330,7 +317,6 @@ public class DocumentNodeStoreService {
     private DocumentStoreType documentStoreType;
 
     private boolean customBlobStore;
-    private boolean customBlobDataSource;
 
     @Activate
     protected void activate(ComponentContext context, Map<String, ?> config) throws Exception {
@@ -340,7 +326,6 @@ public class DocumentNodeStoreService {
         executor.start(whiteboard);
         maxReplicationLagInSecs = toLong(config.get(PROP_REPLICATION_LAG), DEFAULT_MAX_REPLICATION_LAG);
         customBlobStore = toBoolean(prop(CUSTOM_BLOB_STORE), false);
-        customBlobDataSource = toBoolean(prop(CUSTOM_BLOB_DATA_SOURCE), false);
         documentStoreType = DocumentStoreType.fromString(PropertiesUtil.toString(config.get(PROP_DS_TYPE), "MONGO"));
 
         registerNodeStoreIfPossible();
@@ -350,12 +335,11 @@ public class DocumentNodeStoreService {
         if (context == null) {
             log.info("Component still not activated. Ignoring the initialization call");
         } else if (customBlobStore && blobStore == null) {
-            log.info("BlobStore use enabled. DocumentNodeStoreService would be initialized when "
+            log.info("Custom BlobStore use enabled. DocumentNodeStoreService would be initialized when "
                     + "BlobStore would be available");
-        } else if (documentStoreType == DocumentStoreType.RDB
-                && (dataSource == null || (customBlobDataSource && blobDataSource == null))) {
+        } else if (documentStoreType == DocumentStoreType.RDB && (dataSource == null || blobDataSource == null)) {
             log.info("DataSource use enabled. DocumentNodeStoreService would be initialized when "
-                    + "DataSource would be available");
+                    + "DataSource would be available (currently available: nodes: {}, blobs: {})", dataSource, blobDataSource);
         } else {
             registerNodeStore();
         }
@@ -388,7 +372,7 @@ public class DocumentNodeStoreService {
                 setCacheSegmentCount(cacheSegmentCount).
                 setCacheStackMoveDistance(cacheStackMoveDistance).
                 offHeapCacheSize(offHeapCache * MB);
-        
+
         if (persistentCache != null && persistentCache.length() > 0) {
             mkBuilder.setPersistentCache(persistentCache);
         }
@@ -400,14 +384,16 @@ public class DocumentNodeStoreService {
             mkBuilder.setBlobStore(blobStore);
         }
 
-        if (documentStoreType == DocumentStoreType.RDB){
+        if (documentStoreType == DocumentStoreType.RDB) {
             checkNotNull(dataSource, "DataStore type set [%s] but DataSource reference not initialized", PROP_DS_TYPE);
-            if(customBlobDataSource){
-                checkNotNull(blobDataSource, "DataStore type set [%s] and BlobStore is configured to use different " +
-                        "DataSource via [%s] but BlobDataSource reference not initialized", PROP_DS_TYPE, CUSTOM_BLOB_DATA_SOURCE);
+            if (!customBlobStore) {
+                checkNotNull(blobDataSource, "DataStore type set [%s] but BlobDataSource reference not initialized", PROP_DS_TYPE);
                 mkBuilder.setRDBConnection(dataSource, blobDataSource);
                 log.info("Connected to datasources {} {}", dataSource, blobDataSource);
             } else {
+                if (blobDataSource != null && blobDataSource != dataSource) {
+                    log.info("Ignoring blobDataSource {} as custom blob store takes precedence.", blobDataSource);
+                }
                 mkBuilder.setRDBConnection(dataSource);
                 log.info("Connected to datasource {}", dataSource);
             }
@@ -490,6 +476,7 @@ public class DocumentNodeStoreService {
 
     @SuppressWarnings("UnusedDeclaration")
     protected void bindDataSource(DataSource dataSource) throws IOException {
+        log.info("Initializing DocumentNodeStore with dataSource [{}]", dataSource);
         this.dataSource = dataSource;
         registerNodeStoreIfPossible();
     }
@@ -502,6 +489,7 @@ public class DocumentNodeStoreService {
 
     @SuppressWarnings("UnusedDeclaration")
     protected void bindBlobDataSource(DataSource dataSource) throws IOException {
+        log.info("Initializing DocumentNodeStore with blobDataSource [{}]", dataSource);
         this.blobDataSource = dataSource;
         registerNodeStoreIfPossible();
     }

Modified: jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy?rev=1684868&r1=1684867&r2=1684868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy (original)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy Thu Jun 11 12:48:58 2015
@@ -59,6 +59,33 @@ class DocumentNodeStoreConfigTest extend
 
         //3. Check that DS contains tables from both RDBBlobStore and RDBDocumentStore
         assert getExistingTables(ds).containsAll(['NODES', 'DATASTORE_META'])
+
+        //4. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds).size() == 1
+    }
+
+    @Test
+    public void testRDBDocumentStoreLateDataSource() throws Exception {
+        registry = repositoryFactory.initializeServiceRegistry(config)
+
+        //1. Create config for DocumentNodeStore with RDB enabled
+        createConfig([
+                'org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService': [
+                        documentStoreType: 'RDB'
+                ]
+        ])
+
+        //2. Register the DataSource as a service
+        DataSource ds = createDS("jdbc:h2:mem:testRDBlateds;DB_CLOSE_DELAY=-1")
+        registry.registerService(DataSource.class.name, ds, ['datasource.name': 'oak'] as Hashtable)
+
+        DocumentNodeStore ns = getServiceWithWait(NodeStore.class)
+
+        //3. Check that DS contains tables from both RDBBlobStore and RDBDocumentStore
+        assert getExistingTables(ds).containsAll(['NODES', 'DATASTORE_META'])
+
+        //4. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds).size() == 1
     }
 
     @Test
@@ -73,7 +100,6 @@ class DocumentNodeStoreConfigTest extend
         createConfig([
                 'org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService': [
                         documentStoreType      : 'RDB',
-                        customBlobDataSource   : true,
                         'blobDataSource.target': '(datasource.name=oak-blob)',
                 ]
         ])
@@ -95,6 +121,9 @@ class DocumentNodeStoreConfigTest extend
         //DS2 should contain only RDBBlobStore tables
         assert !ds2Tables.contains('NODES')
         assert ds2Tables.contains('DATASTORE_META')
+
+        //4. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds1).size() == 1
     }
 
     @Test
@@ -102,14 +131,19 @@ class DocumentNodeStoreConfigTest extend
         registry = repositoryFactory.initializeServiceRegistry(config)
 
         //1. Register the DataSource as a service
-        DataSource ds = createDS("jdbc:h2:mem:testRDB3;DB_CLOSE_DELAY=-1")
-        registry.registerService(DataSource.class.name, ds, ['datasource.name': 'oak'] as Hashtable)
+        DataSource ds1 = createDS("jdbc:h2:mem:testRDB3;DB_CLOSE_DELAY=-1")
+        registry.registerService(DataSource.class.name, ds1, ['datasource.name': 'oak'] as Hashtable)
+
+        DataSource ds2 = createDS("jdbc:h2:mem:testRDB3b;DB_CLOSE_DELAY=-1")
+        registry.registerService(DataSource.class.name, ds2, ['datasource.name': 'oak-blob'] as Hashtable)
 
         //2. Create config for DocumentNodeStore with RDB enabled
+        // (supply blobDataSource which should be ignored because customBlob takes precedence)
         createConfig([
                 'org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService': [
                         documentStoreType: 'RDB',
-                        customBlobStore  : true
+                        'blobDataSource.target': '(datasource.name=oak-blob)',
+                        customBlobStore  : true,
                 ]
         ])
 
@@ -117,12 +151,20 @@ class DocumentNodeStoreConfigTest extend
 
         DocumentNodeStore ns = getServiceWithWait(NodeStore.class)
 
-        //3. Check that DS contains tables only from both RDBDocumentStore
-        List<String> dsTables = getExistingTables(ds)
+        //3. Check that DS1 contains tables only from both RDBDocumentStore
+        List<String> ds1Tables = getExistingTables(ds1)
+
+        //DS1 should contain RDBDocumentStore tables only
+        assert ds1Tables.contains('NODES')
+        assert !ds1Tables.contains('DATASTORE_META')
 
-        //DS1 should contain RDBDocumentStore tables
-        assert dsTables.contains('NODES')
-        assert !dsTables.contains('DATASTORE_META')
+        //4. Check that DS2 is empty
+        List<String> ds2Tables = getExistingTables(ds2)
+        assert !ds2Tables.contains('NODES')
+        assert !ds2Tables.contains('DATASTORE_META')
+
+        //5. Check that only one cluster node was instantiated
+        assert getIdsOfClusterNodes(ds1).size() == 1
     }
 
     @Test
@@ -204,6 +246,20 @@ class DocumentNodeStoreConfigTest extend
         return existing
     }
 
+    private List<String> getIdsOfClusterNodes(DataSource ds) {
+        Connection con = ds.connection
+        List<String> entries = []
+        try {
+            ResultSet rs = con.prepareStatement("SELECT ID FROM CLUSTERNODES").executeQuery()
+            while (rs.next()) {
+                entries << rs.get(1)
+            }
+        } finally {
+            con.close()
+        }
+        return entries
+    }
+    
     private DataSource createDS(String url) {
         DataSource ds = new JdbcDataSource()
         ds.url = url