diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/watcher/DefaultFileSystemWatcherService.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/watcher/DefaultFileSystemWatcherService.java index 7b9ca424a33e3..443f0ac688165 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/watcher/DefaultFileSystemWatcherService.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/watcher/DefaultFileSystemWatcherService.java @@ -53,6 +53,7 @@ public void init() throws Throwable @Override public void start() throws Throwable { + assert watcher == null; watcher = fileWatchers.newThread( eventWatcher ); watcher.start(); } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabase.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabase.java index d3f78312446c1..ffd79aef19386 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabase.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabase.java @@ -88,11 +88,16 @@ public LocalDatabase( File storeDir, StoreFiles storeFiles, DataSourceManager da public void init() throws Throwable { dataSourceManager.init(); + watcherService.init(); } @Override public synchronized void start() throws Throwable { + if ( isAvailable() ) + { + return; + } storeId = readStoreIdFromDisk(); log.info( "Starting with storeId: " + storeId ); @@ -127,6 +132,7 @@ public boolean isAvailable() @Override public void shutdown() throws Throwable { + watcherService.shutdown(); dataSourceManager.shutdown(); } diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java index a6df9bcfa2372..8d56975af3c77 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/core/EnterpriseCoreEditionModule.java @@ -169,7 +169,6 @@ public void registerEditionSpecificProcedures( Procedures procedures ) throws Ke watcherService = createFileSystemWatcherService( fileSystem, storeDir, logging, platformModule.jobScheduler, fileWatcherFileNameFilter() ); dependencies.satisfyDependencies( watcherService ); - life.add( watcherService ); LocalDatabase localDatabase = new LocalDatabase( platformModule.storeDir, new StoreFiles( fileSystem, platformModule.pageCache ), platformModule.dataSourceManager, diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/readreplica/EnterpriseReadReplicaEditionModule.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/readreplica/EnterpriseReadReplicaEditionModule.java index 1d1f9711b549a..7f7ae2d48ca47 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/readreplica/EnterpriseReadReplicaEditionModule.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/readreplica/EnterpriseReadReplicaEditionModule.java @@ -130,7 +130,6 @@ public class EnterpriseReadReplicaEditionModule extends EditionModule watcherService = createFileSystemWatcherService( fileSystem, storeDir, logging, platformModule.jobScheduler, fileWatcherFileNameFilter() ); dependencies.satisfyDependencies( watcherService ); - life.add( watcherService ); GraphDatabaseFacade graphDatabaseFacade = platformModule.graphDatabaseFacade; diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabaseTest.java b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabaseTest.java index 2c14653a4ece5..ff7336e133750 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabaseTest.java +++ b/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/catchup/storecopy/LocalDatabaseTest.java @@ -40,7 +40,9 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; public class LocalDatabaseTest { @@ -130,6 +132,27 @@ public void availabilityGuardRaisedBeforeDataSourceManagerIsStoppedForStoreCopy( inOrder.verify( dataSourceManager ).stop(); } + @Test + public void doNotRestartServicesIfAlreadyStarted() throws Throwable + { + DataSourceManager dataSourceManager = mock( DataSourceManager.class ); + FileSystemWatcherService watcherService = mock( FileSystemWatcherService.class ); + LocalDatabase localDatabase = newLocalDatabase( newAvailabilityGuard(), dataSourceManager, watcherService ); + + localDatabase.start(); + + verify( dataSourceManager ).start(); + verify( watcherService ).start(); + reset( dataSourceManager ); + reset( watcherService ); + + localDatabase.start(); + localDatabase.start(); + + verify( dataSourceManager, times( 0 ) ).start(); + verify( watcherService, times( 0 ) ).start(); + } + private static LocalDatabase newLocalDatabase( AvailabilityGuard availabilityGuard ) { return newLocalDatabase( availabilityGuard, mock( DataSourceManager.class ) ); @@ -137,9 +160,15 @@ private static LocalDatabase newLocalDatabase( AvailabilityGuard availabilityGua private static LocalDatabase newLocalDatabase( AvailabilityGuard availabilityGuard, DataSourceManager dataSourceManager ) + { + return newLocalDatabase( availabilityGuard, dataSourceManager, FileSystemWatcherService.EMPTY_WATCHER ); + } + + private static LocalDatabase newLocalDatabase( AvailabilityGuard availabilityGuard, + DataSourceManager dataSourceManager, FileSystemWatcherService fileWatcher ) { return new LocalDatabase( new File( "." ), mock( StoreFiles.class ), dataSourceManager, - () -> mock( DatabaseHealth.class ), FileSystemWatcherService.EMPTY_WATCHER, availabilityGuard, + () -> mock( DatabaseHealth.class ), fileWatcher, availabilityGuard, NullLogProvider.getInstance() ); }