Skip to content

Commit

Permalink
Merge 2.3 into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 8, 2016
2 parents 4a87b49 + 59d88d0 commit 039d4bb
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.ResourceTypes;
import org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory;
import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.locking.community.CommunityLockManger;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory;
Expand Down Expand Up @@ -83,6 +85,7 @@ public CommunityEditionModule( PlatformModule platformModule )
GraphDatabaseFacade graphDatabaseFacade = platformModule.graphDatabaseFacade;

lockManager = dependencies.satisfyDependency( createLockManager( config, logging ) );
statementLocksFactory = createStatementLocksFactory( lockManager, config, logging );

idTypeConfigurationProvider = createIdTypeConfigurationProvider( config );
idGeneratorFactory = dependencies.satisfyDependency( createIdGeneratorFactory( fileSystem, idTypeConfigurationProvider ) );
Expand Down Expand Up @@ -129,6 +132,11 @@ protected ConstraintSemantics createSchemaRuleVerifier()
return new StandardConstraintSemantics();
}

protected StatementLocksFactory createStatementLocksFactory( Locks locks, Config config, LogService logService )
{
return new SimpleStatementLocksFactory( locks );
}

protected SchemaWriteGuard createSchemaWriteGuard()
{
return () -> {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.kernel.impl.factory;

import java.io.File;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

Expand All @@ -32,8 +31,6 @@
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.Service;
import org.neo4j.helpers.collection.Iterables;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.AvailabilityGuard;
Expand Down Expand Up @@ -62,9 +59,6 @@
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.core.TokenNotFoundException;
import org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory;
import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.proc.ProcedureGDSFactory;
import org.neo4j.kernel.impl.proc.Procedures;
Expand Down Expand Up @@ -116,15 +110,12 @@ public class DataSourceModule

public final AutoIndexing autoIndexing;

private final Log log;

public DataSourceModule( final GraphDatabaseFacadeFactory.Dependencies dependencies,
final PlatformModule platformModule, EditionModule editionModule )
{
final org.neo4j.kernel.impl.util.Dependencies deps = platformModule.dependencies;
Config config = platformModule.config;
LogService logging = platformModule.logging;
this.log = logging.getInternalLog( DataSourceModule.class );
FileSystemAbstraction fileSystem = platformModule.fileSystem;
DataSourceManager dataSourceManager = platformModule.dataSourceManager;
LifeSupport life = platformModule.life;
Expand Down Expand Up @@ -184,8 +175,6 @@ public DataSourceModule( final GraphDatabaseFacadeFactory.Dependencies dependenc
editionModule.relationshipTypeTokenHolder,
editionModule.propertyKeyTokenHolder );

StatementLocksFactory locksFactory = createStatementLocksFactory( editionModule.lockManager, config, log );

neoStoreDataSource = deps.satisfyDependency( new NeoStoreDataSource(
storeDir,
config,
Expand All @@ -199,7 +188,7 @@ public DataSourceModule( final GraphDatabaseFacadeFactory.Dependencies dependenc
editionModule.propertyKeyTokenHolder,
editionModule.labelTokenHolder,
relationshipTypeTokenHolder,
locksFactory,
editionModule.statementLocksFactory,
schemaWriteGuard,
transactionEventHandlers,
platformModule.monitors.newMonitor( IndexingService.Monitor.class ),
Expand Down Expand Up @@ -392,37 +381,6 @@ private Procedures setupProcedures( PlatformModule platform, CoreAPIAvailability
return procedures;
}

private static StatementLocksFactory createStatementLocksFactory( Locks locks, Config config, Log log )
{
StatementLocksFactory statementLocksFactory;

String serviceName = StatementLocksFactory.class.getSimpleName();
List<StatementLocksFactory> factories = Iterables.asList( Service.load( StatementLocksFactory.class ) );
if ( factories.isEmpty() )
{
statementLocksFactory = new SimpleStatementLocksFactory();

log.info( "No services implementing " + serviceName + " found. " +
"Using " + SimpleStatementLocksFactory.class.getSimpleName() );
}
else if ( factories.size() == 1 )
{
statementLocksFactory = factories.get( 0 );

log.info( "Found single implementation of " + serviceName +
". Namely " + statementLocksFactory.getClass().getSimpleName() );
}
else
{
throw new IllegalStateException(
"Found more than one implementation of " + serviceName + ": " + factories );
}

statementLocksFactory.initialize( locks, config );

return statementLocksFactory;
}

/**
* At end of startup, wait for instance to become available for transactions.
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.Configuration;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdReuseEligibility;
import org.neo4j.kernel.impl.store.id.configuration.IdTypeConfigurationProvider;
Expand Down Expand Up @@ -67,6 +68,8 @@ public abstract class EditionModule

public Locks lockManager;

public StatementLocksFactory statementLocksFactory;

public CommitProcessFactory commitProcessFactory;

public long transactionStartTimeout;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.factory;

import java.util.List;

import org.neo4j.helpers.Service;
import org.neo4j.helpers.collection.Iterables;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory;
import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.logging.Log;

public class StatementLocksFactorySelector
{
private final Locks locks;
private final Config config;
private final Log log;

public StatementLocksFactorySelector( Locks locks, Config config, LogService logService )
{
this.locks = locks;
this.config = config;
this.log = logService.getInternalLog( getClass() );
}

public StatementLocksFactory select()
{
StatementLocksFactory statementLocksFactory;

String serviceName = StatementLocksFactory.class.getSimpleName();
List<StatementLocksFactory> factories = serviceLoadFactories();
if ( factories.isEmpty() )
{
statementLocksFactory = new SimpleStatementLocksFactory();

log.info( "No services implementing " + serviceName + " found. " +
"Using " + SimpleStatementLocksFactory.class.getSimpleName() );
}
else if ( factories.size() == 1 )
{
statementLocksFactory = factories.get( 0 );

log.info( "Found single implementation of " + serviceName +
". Namely " + statementLocksFactory.getClass().getSimpleName() );
}
else
{
throw new IllegalStateException(
"Found more than one implementation of " + serviceName + ": " + factories );
}

statementLocksFactory.initialize( locks, config );

return statementLocksFactory;
}

/**
* Load all available factories via {@link Service}.
* <b>Visible for testing only.</b>
*
* @return list of available factories.
*/
List<StatementLocksFactory> serviceLoadFactories()
{
return Iterables.asList( Service.load( StatementLocksFactory.class ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public SimpleStatementLocksFactory()

/**
* Creates a new factory initialized with given {@code locks}.
* <b>Note:</b> should be used for tests only.
*
* @param locks the locks to use.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.factory;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.Locks.Client;
import org.neo4j.kernel.impl.locking.SimpleStatementLocks;
import org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory;
import org.neo4j.kernel.impl.locking.StatementLocks;
import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.logging.NullLogService;

import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class StatementLocksFactorySelectorTest
{
@Test
public void loadSimpleStatementLocksFactoryWhenNoServices()
{
Locks locks = mock( Locks.class );
Locks.Client locksClient = mock( Client.class );
when( locks.newClient() ).thenReturn( locksClient );

StatementLocksFactorySelector loader = newLoader( locks );

StatementLocksFactory factory = loader.select();
StatementLocks statementLocks = factory.newInstance();

assertThat( factory, instanceOf( SimpleStatementLocksFactory.class ) );
assertThat( statementLocks, instanceOf( SimpleStatementLocks.class ) );

assertSame( locksClient, statementLocks.optimistic() );
assertSame( locksClient, statementLocks.pessimistic() );
}

@Test
public void loadSingleAvailableFactory()
{
Locks locks = mock( Locks.class );
StatementLocksFactory factory = mock( StatementLocksFactory.class );

StatementLocksFactorySelector loader = newLoader( locks, factory );

StatementLocksFactory loadedFactory = loader.select();

assertSame( factory, loadedFactory );
verify( factory ).initialize( same( locks ), any( Config.class ) );
}

@Test
public void throwWhenMultipleFactoriesLoaded()
{
TestStatementLocksFactorySelector loader = newLoader( mock( Locks.class ),
mock( StatementLocksFactory.class ),
mock( StatementLocksFactory.class ),
mock( StatementLocksFactory.class ) );

try
{
loader.select();
}
catch ( Exception e )
{
assertThat( e, instanceOf( IllegalStateException.class ) );
}
}

private static TestStatementLocksFactorySelector newLoader( Locks locks, StatementLocksFactory... factories )
{
return new TestStatementLocksFactorySelector( locks, Config.empty(), NullLogService.getInstance(), factories );
}

private static class TestStatementLocksFactorySelector extends StatementLocksFactorySelector
{
private final List<StatementLocksFactory> factories;

TestStatementLocksFactorySelector( Locks locks, Config config, LogService logService,
StatementLocksFactory... factories )
{
super( locks, config, logService );
this.factories = Arrays.asList( factories );
}

@Override
List<StatementLocksFactory> serviceLoadFactories()
{
return factories;
}
}
}
13 changes: 13 additions & 0 deletions enterprise/deferred-locks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-enterprise-kernel</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-enterprise-kernel</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-io</artifactId>
Expand Down

0 comments on commit 039d4bb

Please sign in to comment.