Skip to content

Commit

Permalink
Merge branch 'master' of github.com:neo4j/community
Browse files Browse the repository at this point in the history
  • Loading branch information
systay committed Apr 10, 2012
2 parents 23346cd + a2403ea commit e9b7443
Show file tree
Hide file tree
Showing 46 changed files with 1,031 additions and 2,082 deletions.
14 changes: 3 additions & 11 deletions kernel/pom.xml
Expand Up @@ -288,26 +288,18 @@ public class ComponentVersion extends Version
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_compendium</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
<optional>true</optional>
</dependency>
<dependency>
<!-- <dependency>
<groupId>janino</groupId>
<artifactId>janino</artifactId>
<version>2.5.10</version>
<optional>true</optional>
</dependency>
</dependency> -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.kernel.EmbeddedReadOnlyGraphDatabase;
import org.neo4j.kernel.KernelExtension;
import org.neo4j.kernel.impl.cache.CacheProvider;

import static org.neo4j.graphdb.factory.GraphDatabaseSetting.BooleanSetting.*;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.*;
Expand All @@ -41,11 +42,13 @@ public class GraphDatabaseFactory
{
protected List<IndexProvider> indexProviders;
protected List<KernelExtension> kernelExtensions;
protected List<CacheProvider> cacheProviders;

public GraphDatabaseFactory()
{
indexProviders = Iterables.toList(Service.load( IndexProvider.class ));
kernelExtensions = Iterables.toList( Service.load(KernelExtension.class) );
cacheProviders = Iterables.toList( Service.load(CacheProvider.class) );
}

public GraphDatabaseService newEmbeddedDatabase(String path)
Expand All @@ -62,9 +65,9 @@ public GraphDatabaseService newDatabase(Map<String, String> config)
config.put( "ephemeral", "false" );

if ( TRUE.equalsIgnoreCase(config.get( read_only.name() )))
return new EmbeddedReadOnlyGraphDatabase(path, config, indexProviders, kernelExtensions);
return new EmbeddedReadOnlyGraphDatabase(path, config, indexProviders, kernelExtensions, cacheProviders);
else
return new EmbeddedGraphDatabase(path, config, indexProviders, kernelExtensions);
return new EmbeddedGraphDatabase(path, config, indexProviders, kernelExtensions, cacheProviders);
}
});
}
Expand Down
Expand Up @@ -22,6 +22,14 @@

import static org.neo4j.graphdb.factory.GraphDatabaseSetting.*;

import java.util.ArrayList;
import java.util.List;

import org.neo4j.graphdb.factory.GraphDatabaseSetting.FloatSetting;
import org.neo4j.graphdb.factory.GraphDatabaseSetting.StringSetting;
import org.neo4j.helpers.Service;
import org.neo4j.kernel.impl.cache.CacheProvider;

/**
* Settings for the Community edition of Neo4j. Use this with GraphDatabaseBuilder.
*/
Expand All @@ -33,7 +41,8 @@ public abstract class GraphDatabaseSettings
public static final BooleanSetting read_only = new BooleanSetting("read_only");

@Description("Select the type of high-level cache to use")
@Default( CacheTypeSetting.gcr )
// @Default( CacheTypeSetting.gcr )
@Default( "soft" )
public static final CacheTypeSetting cache_type = new CacheTypeSetting();

@Default( TRUE)
Expand Down Expand Up @@ -179,7 +188,7 @@ public abstract class GraphDatabaseSettings
public static final FloatSetting relationship_cache_array_fraction = new FloatSetting( "relationship_cache_array_fraction", "Must be a valid fraction", 1.0f, 10.0f);

@Default( "60s" )
public static final StringSetting array_cache_min_log_interval = new StringSetting( "array_cache_min_log_interval", DURATION, "Must be a valid interval" );
public static final StringSetting gcr_cache_min_log_interval = new StringSetting( "gcr_cache_min_log_interval", DURATION, "Must be a valid interval" );

@Default( FALSE )
public static BooleanSetting execution_guard_enabled = new BooleanSetting( "execution_guard_enabled" );
Expand All @@ -194,28 +203,36 @@ public abstract class GraphDatabaseSettings
public static class CacheTypeSetting
extends OptionsSetting
{
@Description("Use weak reference cache")
public static final String weak = "weak";

@Description("Provides optimal utilization of the available memory. Suitable for high performance traversal. \n"+
"May run into GC issues under high load if the frequently accessed parts of the graph does not fit in the cache." )
public static final String soft = "soft";

@Description("Don't use caching")
public static final String none = "none";

@Description("Use strong references")
public static final String strong = "strong";

@Description("GC resistant cache. Gets assigned a configurable amount of space in the JVM heap \n" +
"and will evict objects whenever it grows bigger than that, instead of relying on GC for eviction. \n" +
"It has got the fastest insert/lookup times and should be optimal for most use cases. \n" +
"This is the default cache setting." )
public static final String gcr = "gcr";
// @Description("Use weak reference cache")
// public static final String weak = "weak";
//
// @Description("Provides optimal utilization of the available memory. Suitable for high performance traversal. \n"+
// "May run into GC issues under high load if the frequently accessed parts of the graph does not fit in the cache." )
// public static final String soft = "soft";
//
// @Description("Don't use caching")
// public static final String none = "none";
//
// @Description("Use strong references")
// public static final String strong = "strong";
//
// @Description("GC resistant cache. Gets assigned a configurable amount of space in the JVM heap \n" +
// "and will evict objects whenever it grows bigger than that, instead of relying on GC for eviction. \n" +
// "It has got the fastest insert/lookup times and should be optimal for most use cases. \n" +
// "This is the default cache setting." )
// public static final String gcr = "gcr";

public CacheTypeSetting()
{
super( "cache_type", availableCaches() );
}

public CacheTypeSetting( )
private static String[] availableCaches()
{
super( "cache_type", weak, soft, none, strong, gcr );
List<String> list = new ArrayList<String>();
for ( CacheProvider provider : Service.load( CacheProvider.class ) )
list.add( provider.getName() );
return list.toArray( new String[list.size()] );
}
}

Expand Down
62 changes: 47 additions & 15 deletions kernel/src/main/java/org/neo4j/kernel/AbstractGraphDatabase.java
Expand Up @@ -20,6 +20,8 @@

package org.neo4j.kernel;

import static org.neo4j.helpers.Exceptions.launderedException;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -36,7 +38,9 @@
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import javax.transaction.TransactionManager;

import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
Expand All @@ -61,8 +65,12 @@
import org.neo4j.kernel.configuration.ConfigurationMigrator;
import org.neo4j.kernel.configuration.SystemPropertiesConfiguration;
import org.neo4j.kernel.guard.Guard;
import org.neo4j.kernel.impl.cache.Cache;
import org.neo4j.kernel.impl.cache.CacheProvider;
import org.neo4j.kernel.impl.cache.MeasureDoNothing;
import org.neo4j.kernel.impl.cache.MonitorGc;
import org.neo4j.kernel.impl.core.Caches;
import org.neo4j.kernel.impl.core.DefaultCaches;
import org.neo4j.kernel.impl.core.DefaultRelationshipTypeCreator;
import org.neo4j.kernel.impl.core.KernelPanicEventGenerator;
import org.neo4j.kernel.impl.core.LastCommittedTxIdSetter;
Expand Down Expand Up @@ -116,15 +124,12 @@
import org.neo4j.kernel.logging.Logging;
import org.neo4j.tooling.GlobalGraphOperations;

import static org.neo4j.helpers.Exceptions.*;

/**
* Exposes the methods {@link #getManagementBeans(Class)}() a.s.o.
*/
public abstract class AbstractGraphDatabase
implements GraphDatabaseService, GraphDatabaseAPI
{

public static class Configuration
{
public static final GraphDatabaseSetting.BooleanSetting dump_configuration = GraphDatabaseSettings.dump_configuration;
Expand Down Expand Up @@ -189,20 +194,32 @@ public static class Configuration
protected NodeAutoIndexerImpl nodeAutoIndexer;
protected RelationshipAutoIndexerImpl relAutoIndexer;
protected KernelData extensions;
protected Caches caches;

private final LifeSupport life = new LifeSupport();
protected final LifeSupport life = new LifeSupport();
private final Map<String,CacheProvider> cacheProviders;

protected AbstractGraphDatabase(String storeDir, Map<String, String> params,
Iterable<IndexProvider> indexProviders, Iterable<KernelExtension> kernelExtensions)
Iterable<IndexProvider> indexProviders, Iterable<KernelExtension> kernelExtensions,
Iterable<CacheProvider> cacheProviders )
{
this.params = params;
this.cacheProviders = mapCacheProviders( cacheProviders );
this.storeDir = FileUtils.fixSeparatorsInPath( canonicalize( storeDir ));

// SPI - provided services
this.indexProviders = indexProviders;
this.kernelExtensions = kernelExtensions;
}

private Map<String, CacheProvider> mapCacheProviders( Iterable<CacheProvider> cacheProviders )
{
Map<String, CacheProvider> map = new HashMap<String, CacheProvider>();
for ( CacheProvider provider : cacheProviders )
map.put( provider.getName(), provider );
return map;
}

protected void run()
{
create();
Expand Down Expand Up @@ -282,10 +299,14 @@ private void create()
// Instantiate all services - some are overridable by subclasses
boolean readOnly = config.getBoolean( Configuration.read_only );

NodeManager.CacheType cacheType = config.getEnum(NodeManager.CacheType.class, Configuration.cache_type);
String cacheTypeName = config.get( Configuration.cache_type );
CacheProvider cacheProvider = cacheProviders.get( cacheTypeName );
if ( cacheProvider == null )
throw new IllegalArgumentException( "No cache type '" + cacheTypeName + "'" );

kernelEventHandlers = new KernelEventHandlers();

caches = createCaches();
diagnosticsManager = life.add(new DiagnosticsManager( logging.getLogger( Loggers.DIAGNOSTICS )) );

kernelPanicEventGenerator = new KernelPanicEventGenerator( kernelEventHandlers );
Expand Down Expand Up @@ -352,9 +373,13 @@ private void create()
relationshipTypeHolder = new RelationshipTypeHolder( txManager,
persistenceManager, persistenceSource, relationshipTypeCreator );

caches.configure( cacheProvider, config );
Cache<NodeImpl> nodeCache = diagnosticsManager.tryAppendProvider( caches.node() );
Cache<RelationshipImpl> relCache = diagnosticsManager.tryAppendProvider( caches.relationship() );

nodeManager = guard != null ?
createGuardedNodeManager( readOnly, cacheType ) :
createNodeManager( readOnly, cacheType );
createGuardedNodeManager( readOnly, cacheProvider, nodeCache, relCache ) :
createNodeManager( readOnly, cacheProvider, nodeCache, relCache );

life.add( nodeManager );

Expand Down Expand Up @@ -436,27 +461,29 @@ private void create()
life.add( new ConfigurationChangedRestarter() );
}

private NodeManager createNodeManager( final boolean readOnly, final NodeManager.CacheType cacheType )
private NodeManager createNodeManager( final boolean readOnly, final CacheProvider cacheType,
Cache<NodeImpl> nodeCache, Cache<RelationshipImpl> relCache )
{
if ( readOnly )
{
return new ReadOnlyNodeManager( config, this, lockManager, lockReleaser, txManager, persistenceManager,
persistenceSource, relationshipTypeHolder, cacheType, propertyIndexManager, createNodeLookup(),
createRelationshipLookups(), msgLog, diagnosticsManager );
createRelationshipLookups(), nodeCache, relCache );
}

return new NodeManager( config, this, lockManager, lockReleaser, txManager, persistenceManager,
persistenceSource, relationshipTypeHolder, cacheType, propertyIndexManager, createNodeLookup(),
createRelationshipLookups(), msgLog, diagnosticsManager );
createRelationshipLookups(), nodeCache, relCache );
}

private NodeManager createGuardedNodeManager( final boolean readOnly, final NodeManager.CacheType cacheType )
private NodeManager createGuardedNodeManager( final boolean readOnly, final CacheProvider cacheType,
Cache<NodeImpl> nodeCache, Cache<RelationshipImpl> relCache )
{
if ( readOnly )
{
return new ReadOnlyNodeManager( config, this, lockManager, lockReleaser, txManager, persistenceManager,
persistenceSource, relationshipTypeHolder, cacheType, propertyIndexManager, createNodeLookup(),
createRelationshipLookups(), msgLog, diagnosticsManager )
createRelationshipLookups(), nodeCache, relCache )
{
@Override
protected Node getNodeByIdOrNull( final long nodeId )
Expand Down Expand Up @@ -505,7 +532,7 @@ public Relationship createRelationship( final Node startNodeProxy, final NodeImp

return new NodeManager( config, this, lockManager, lockReleaser, txManager, persistenceManager,
persistenceSource, relationshipTypeHolder, cacheType, propertyIndexManager, createNodeLookup(),
createRelationshipLookups(), msgLog, diagnosticsManager )
createRelationshipLookups(), nodeCache, relCache )
{
@Override
protected Node getNodeByIdOrNull( final long nodeId )
Expand Down Expand Up @@ -590,7 +617,12 @@ protected TxIdGenerator createTxIdGenerator()
{
return TxIdGenerator.DEFAULT;
}


protected Caches createCaches()
{
return new DefaultCaches( msgLog );
}

protected RelationshipProxy.RelationshipLookups createRelationshipLookups()
{
return new RelationshipProxy.RelationshipLookups()
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.index.IndexProvider;
import org.neo4j.helpers.Service;
import org.neo4j.kernel.impl.cache.CacheProvider;

/**
* An implementation of {@link GraphDatabaseService} that is used to embed Neo4j
Expand Down Expand Up @@ -66,12 +67,14 @@ public EmbeddedGraphDatabase( String storeDir )
*/
public EmbeddedGraphDatabase( String storeDir, Map<String,String> params )
{
this( storeDir, params, Service.load( IndexProvider.class ), Service.load( KernelExtension.class ) );
this( storeDir, params, Service.load( IndexProvider.class ), Service.load( KernelExtension.class ),
Service.load( CacheProvider.class ) );
}

public EmbeddedGraphDatabase( String storeDir, Map<String,String> params, Iterable<IndexProvider> indexProviders, Iterable<KernelExtension> kernelExtensions)
public EmbeddedGraphDatabase( String storeDir, Map<String,String> params, Iterable<IndexProvider> indexProviders,
Iterable<KernelExtension> kernelExtensions, Iterable<CacheProvider> cacheProviders )
{
super( storeDir, params, indexProviders, kernelExtensions );
super( storeDir, params, indexProviders, kernelExtensions, cacheProviders );

run();
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.index.IndexProvider;
import org.neo4j.helpers.Service;
import org.neo4j.kernel.impl.cache.CacheProvider;

/**
* A read-only version of {@link EmbeddedGraphDatabase}.
Expand Down Expand Up @@ -68,13 +69,15 @@ public EmbeddedReadOnlyGraphDatabase( String storeDir )
public EmbeddedReadOnlyGraphDatabase( String storeDir,
Map<String, String> params )
{
this( storeDir, params, Service.load( IndexProvider.class ), Service.load( KernelExtension.class ));
this( storeDir, params, Service.load( IndexProvider.class ), Service.load( KernelExtension.class ),
Service.load( CacheProvider.class ));
}

public EmbeddedReadOnlyGraphDatabase( String storeDir,
Map<String, String> params, Iterable<IndexProvider> indexProviders1, Iterable<KernelExtension> kernelExtensions)
Map<String, String> params, Iterable<IndexProvider> indeProviders, Iterable<KernelExtension> kernelExtensions,
Iterable<CacheProvider> cacheProviders )
{
super( storeDir, addReadOnly(params), indexProviders1, kernelExtensions );
super( storeDir, addReadOnly(params), indeProviders, kernelExtensions, cacheProviders );
run();
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/main/java/org/neo4j/kernel/guard/Guard.java
Expand Up @@ -67,7 +67,7 @@ public void start( final GuardInternal guard )

public <T extends GuardInternal> T stop()
{
T guardInternal = currentGuard();
T guardInternal = Guard.this.<T>currentGuard();
if ( guardInternal != null )
{
threadLocal.remove();
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/main/java/org/neo4j/kernel/impl/cache/Cache.java
Expand Up @@ -89,4 +89,6 @@ public interface Cache<E extends EntityWithSize>
public long missCount();

public void updateSize( E entity, int newSize );

public void printStatistics();
}

0 comments on commit e9b7443

Please sign in to comment.