Author: reschke
Date: Mon Nov 21 15:07:57 2016
New Revision: 1770694

URL: http://svn.apache.org/viewvc?rev=1770694&view=rev
Log:
OAK-5098: improve DocumentNodeStoreService robustness for RDB configurations

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=1770694&r1=1770693&r2=1770694&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
 Mon Nov 21 15:07:57 2016
@@ -637,28 +637,47 @@ public class DocumentNodeStoreService {
 
     @SuppressWarnings("UnusedDeclaration")
     protected void bindDataSource(DataSource dataSource) throws IOException {
-        log.info("Initializing DocumentNodeStore with dataSource [{}]", 
dataSource);
-        this.dataSource = dataSource;
-        registerNodeStoreIfPossible();
+        if (this.dataSource != null) {
+            log.info("Ignoring bindDataSource [{}] because dataSource [{}] is 
already bound", dataSource, this.dataSource);
+        } else {
+            log.info("Initializing DocumentNodeStore with dataSource [{}]", 
dataSource);
+            this.dataSource = dataSource;
+            registerNodeStoreIfPossible();
+        }
     }
 
     @SuppressWarnings("UnusedDeclaration")
     protected void unbindDataSource(DataSource dataSource) {
-        this.dataSource = null;
-        unregisterNodeStore();
+        if (this.dataSource != dataSource) {
+            log.info("Ignoring unbindDataSource [{}] because dataSource is 
bound to [{}]", dataSource, this.dataSource);
+        } else {
+            log.info("Unregistering DocumentNodeStore because dataSource [{}] 
was unbound", dataSource);
+            this.dataSource = null;
+            unregisterNodeStore();
+        }
     }
 
     @SuppressWarnings("UnusedDeclaration")
     protected void bindBlobDataSource(DataSource dataSource) throws 
IOException {
-        log.info("Initializing DocumentNodeStore with blobDataSource [{}]", 
dataSource);
-        this.blobDataSource = dataSource;
-        registerNodeStoreIfPossible();
+        if (this.blobDataSource != null) {
+            log.info("Ignoring bindBlobDataSource [{}] because blobDataSource 
[{}] is already bound", dataSource,
+                    this.blobDataSource);
+        } else {
+            log.info("Initializing DocumentNodeStore with blobDataSource 
[{}]", dataSource);
+            this.blobDataSource = dataSource;
+            registerNodeStoreIfPossible();
+        }
     }
 
     @SuppressWarnings("UnusedDeclaration")
     protected void unbindBlobDataSource(DataSource dataSource) {
-        this.blobDataSource = null;
-        unregisterNodeStore();
+        if (this.blobDataSource != dataSource) {
+            log.info("Ignoring unbindBlobDataSource [{}] because dataSource is 
bound to [{}]", dataSource, this.blobDataSource);
+        } else {
+            log.info("Unregistering DocumentNodeStore because blobDataSource 
[{}] was unbound", dataSource);
+            this.blobDataSource = null;
+            unregisterNodeStore();
+        }
     }
 
     @SuppressWarnings("UnusedDeclaration")

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=1770694&r1=1770693&r2=1770694&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
 Mon Nov 21 15:07:57 2016
@@ -81,6 +81,36 @@ class DocumentNodeStoreConfigTest extend
     }
 
     @Test
+    public void testRDBDocumentStore2Datasources() throws Exception {
+        // see https://issues.apache.org/jira/browse/OAK-5098
+        registry = repositoryFactory.initializeServiceRegistry(config)
+
+        //1. Register the DataSource as a service
+        DataSource ds = createDS("jdbc:h2:mem:testRDB;DB_CLOSE_DELAY=-1")
+        ServiceRegistration fds = 
registry.registerService(DataSource.class.name, ds, ['datasource.name': 'oak'] 
as Hashtable)
+
+        //2. Register another DataSource as a service with the same name
+        DataSource ds2 = createDS("jdbc:h2:mem:testRDB;DB_CLOSE_DELAY=-1")
+        registry.registerService(DataSource.class.name, ds2, 
['datasource.name': 'oak'] as Hashtable)
+
+        //3. Create config for DocumentNodeStore with RDB enabled
+        createConfig([
+                
'org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService': [
+                        documentStoreType: 'RDB'
+                ]
+        ])
+
+        DocumentNodeStore ns = getServiceWithWait(NodeStore.class)
+
+        //4. unregister first DS
+        fds.unregister()
+
+        //5. check that nodestore is gone
+        TimeUnit.MILLISECONDS.sleep(500)
+        assertNoService(NodeStore.class)
+    }
+
+    @Test
     public void testRDBDocumentStoreRestart() throws Exception {
         registry = repositoryFactory.initializeServiceRegistry(config)
 


Reply via email to