Skip to content

Commit

Permalink
Add possibility to auto select record format based on available forma…
Browse files Browse the repository at this point in the history
…ts factory services.
  • Loading branch information
MishaDemianenko committed Apr 3, 2016
1 parent 11e5367 commit d930d8a
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 135 deletions.
Expand Up @@ -126,8 +126,8 @@ public Result runFullConsistencyCheck( final File storeDir, Config tuningConfigu
MapUtil.stringMap( GraphDatabaseSettings.read_only.name(), Settings.TRUE ) ); MapUtil.stringMap( GraphDatabaseSettings.read_only.name(), Settings.TRUE ) );
StoreFactory factory = new StoreFactory( storeDir, consistencyCheckerConfig, StoreFactory factory = new StoreFactory( storeDir, consistencyCheckerConfig,
new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem, new DefaultIdGeneratorFactory( fileSystem ), pageCache, fileSystem,
RecordFormatSelector.select( consistencyCheckerConfig, LowLimitV3_0.RECORD_FORMATS, RecordFormatSelector.autoSelectFormat( consistencyCheckerConfig, NullLogService.getInstance() ),
NullLogService.getInstance()), logProvider ); logProvider );


ConsistencySummaryStatistics summary; ConsistencySummaryStatistics summary;
final File reportFile = chooseReportPath(tuningConfiguration ); final File reportFile = chooseReportPath(tuningConfiguration );
Expand Down
Expand Up @@ -46,8 +46,6 @@
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.kernel.impl.store.record.NodeRecord; import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.logging.NullLogProvider; import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.TargetDirectory; import org.neo4j.test.TargetDirectory;
Expand All @@ -64,7 +62,7 @@
public class ConsistencyCheckServiceIntegrationTest public class ConsistencyCheckServiceIntegrationTest
{ {


private final GraphStoreFixture fixture = new GraphStoreFixture(getRecordFormats(), getRecordFormatName()) private final GraphStoreFixture fixture = new GraphStoreFixture( getRecordFormatName() )
{ {
@Override @Override
protected void generateInitialData( GraphDatabaseService graphDb ) protected void generateInitialData( GraphDatabaseService graphDb )
Expand Down Expand Up @@ -239,9 +237,4 @@ protected String getRecordFormatName()
{ {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }

protected RecordFormats getRecordFormats()
{
return LowLimitV3_0.RECORD_FORMATS;
}
} }
Expand Up @@ -57,7 +57,7 @@
import org.neo4j.kernel.impl.store.NodeStore; import org.neo4j.kernel.impl.store.NodeStore;
import org.neo4j.kernel.impl.store.StoreAccess; import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.StoreFactory; import org.neo4j.kernel.impl.store.StoreFactory;
import org.neo4j.kernel.impl.store.format.RecordFormats; import org.neo4j.kernel.impl.store.format.RecordFormatSelector;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0; import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.NeoStoreRecord; import org.neo4j.kernel.impl.store.record.NeoStoreRecord;
Expand Down Expand Up @@ -103,30 +103,22 @@ public abstract class GraphStoreFixture extends PageCacheRule implements TestRul
private long arrayPropId; private long arrayPropId;
private int relTypeId; private int relTypeId;
private int propKeyId; private int propKeyId;
private RecordFormats recordFormats = LowLimitV3_0.RECORD_FORMATS;
private String formatName = StringUtils.EMPTY; private String formatName = StringUtils.EMPTY;


public GraphStoreFixture( boolean keepStatistics, RecordFormats recordFormats, String formatName ) public GraphStoreFixture( boolean keepStatistics, String formatName )
{ {
this.keepStatistics = keepStatistics; this.keepStatistics = keepStatistics;
this.recordFormats = recordFormats;
this.formatName = formatName; this.formatName = formatName;
} }


public GraphStoreFixture(RecordFormats recordFormats, String formatName) public GraphStoreFixture( String formatName )
{ {
this( false, recordFormats, formatName ); this( false, formatName );
} }


public GraphStoreFixture() public GraphStoreFixture()
{ {
this( false, LowLimitV3_0.RECORD_FORMATS, LowLimitV3_0.NAME ); this( false, LowLimitV3_0.NAME );
}

public GraphStoreFixture withRecordFormats( RecordFormats recordFormats )
{
this.recordFormats = recordFormats;
return this;
} }


public void apply( Transaction transaction ) throws TransactionFailureException public void apply( Transaction transaction ) throws TransactionFailureException
Expand All @@ -140,7 +132,7 @@ public DirectStoreAccess directStoreAccess()
{ {
DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(); DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = getPageCache( fileSystem ); PageCache pageCache = getPageCache( fileSystem );
neoStore = new StoreFactory( fileSystem, directory, pageCache, recordFormats, neoStore = new StoreFactory( fileSystem, directory, pageCache, RecordFormatSelector.autoSelectFormat(),
NullLogProvider.getInstance() ).openAllNeoStores(); NullLogProvider.getInstance() ).openAllNeoStores();
StoreAccess nativeStores; StoreAccess nativeStores;
if ( keepStatistics ) if ( keepStatistics )
Expand Down
Expand Up @@ -47,8 +47,7 @@
import org.neo4j.kernel.impl.store.StoreAccess; import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.StoreFactory; import org.neo4j.kernel.impl.store.StoreFactory;
import org.neo4j.kernel.impl.store.StoreType; import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.store.format.RecordFormats; import org.neo4j.kernel.impl.store.format.RecordFormatSelector;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.kernel.impl.store.record.RecordLoad; import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.kernel.internal.GraphDatabaseAPI;
Expand Down Expand Up @@ -98,7 +97,7 @@ public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception
DependencyResolver resolver = db.getDependencyResolver(); DependencyResolver resolver = db.getDependencyResolver();
PageCache pageCache = resolver.resolveDependency( PageCache.class ); PageCache pageCache = resolver.resolveDependency( PageCache.class );
StoreFactory storeFactory = new StoreFactory( fileSystem, directory.directory(), pageCache, StoreFactory storeFactory = new StoreFactory( fileSystem, directory.directory(), pageCache,
getRecordFormats(), NullLogProvider.getInstance() ); RecordFormatSelector.autoSelectFormat(), NullLogProvider.getInstance() );


try ( NeoStores neoStores = storeFactory.openNeoStores( false, StoreType.RELATIONSHIP ) ) try ( NeoStores neoStores = storeFactory.openNeoStores( false, StoreType.RELATIONSHIP ) )
{ {
Expand All @@ -119,7 +118,7 @@ public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception
DependencyResolver resolver = db.getDependencyResolver(); DependencyResolver resolver = db.getDependencyResolver();
PageCache pageCache = resolver.resolveDependency( PageCache.class ); PageCache pageCache = resolver.resolveDependency( PageCache.class );
StoreFactory storeFactory = new StoreFactory( fileSystem, directory.directory(), pageCache, StoreFactory storeFactory = new StoreFactory( fileSystem, directory.directory(), pageCache,
getRecordFormats(), NullLogProvider.getInstance() ); RecordFormatSelector.autoSelectFormat(), NullLogProvider.getInstance() );


try ( NeoStores neoStores = storeFactory.openAllNeoStores() ) try ( NeoStores neoStores = storeFactory.openAllNeoStores() )
{ {
Expand Down Expand Up @@ -165,11 +164,6 @@ protected String getRecordFormatName()
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }


protected RecordFormats getRecordFormats()
{
return LowLimitV3_0.RECORD_FORMATS;
}

private static class Sabotage private static class Sabotage
{ {
private final RelationshipRecord before; private final RelationshipRecord before;
Expand Down
Expand Up @@ -32,7 +32,6 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;


import org.neo4j.consistency.ConsistencyCheckSettings;
import org.neo4j.consistency.checking.CheckDecorator; import org.neo4j.consistency.checking.CheckDecorator;
import org.neo4j.consistency.checking.CheckerEngine; import org.neo4j.consistency.checking.CheckerEngine;
import org.neo4j.consistency.checking.ComparativeRecordChecker; import org.neo4j.consistency.checking.ComparativeRecordChecker;
Expand All @@ -58,8 +57,6 @@
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.store.StoreAccess; import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord; import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
Expand Down Expand Up @@ -87,7 +84,7 @@
public class ExecutionOrderIntegrationTest public class ExecutionOrderIntegrationTest
{ {
@Rule @Rule
public final GraphStoreFixture fixture = new GraphStoreFixture(getRecordFormats(), getRecordFormatName()) public final GraphStoreFixture fixture = new GraphStoreFixture( getRecordFormatName() )
{ {
@Override @Override
protected void generateInitialData( GraphDatabaseService graphDb ) protected void generateInitialData( GraphDatabaseService graphDb )
Expand Down Expand Up @@ -139,11 +136,6 @@ protected String getRecordFormatName()
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }


protected RecordFormats getRecordFormats()
{
return LowLimitV3_0.RECORD_FORMATS;
}

private static class InvocationLog private static class InvocationLog
{ {
private final Map<String, Throwable> data = new HashMap<>(); private final Map<String, Throwable> data = new HashMap<>();
Expand Down
Expand Up @@ -90,8 +90,6 @@
import org.neo4j.kernel.impl.store.SchemaStorage; import org.neo4j.kernel.impl.store.SchemaStorage;
import org.neo4j.kernel.impl.store.SchemaStore; import org.neo4j.kernel.impl.store.SchemaStore;
import org.neo4j.kernel.impl.store.StoreAccess; import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.kernel.impl.store.record.AbstractSchemaRule; import org.neo4j.kernel.impl.store.record.AbstractSchemaRule;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.store.record.IndexRule;
Expand Down Expand Up @@ -203,7 +201,7 @@ public static void verifyThatWeHaveExercisedAllTypesOfInconsistenciesThatWeHave(
} }




private final GraphStoreFixture fixture = new GraphStoreFixture(getRecordFormats(), getRecordFormatName()) private final GraphStoreFixture fixture = new GraphStoreFixture( getRecordFormatName() )
{ {
@Override @Override
protected void generateInitialData( GraphDatabaseService db ) protected void generateInitialData( GraphDatabaseService db )
Expand Down Expand Up @@ -2059,11 +2057,6 @@ protected String getRecordFormatName()
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }


protected RecordFormats getRecordFormats()
{
return LowLimitV3_0.RECORD_FORMATS;
}

private int createLabel() throws Exception private int createLabel() throws Exception
{ {
final MutableInteger id = new MutableInteger( -1 ); final MutableInteger id = new MutableInteger( -1 );
Expand Down
Expand Up @@ -37,15 +37,12 @@
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.store.RecordStore; import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.StoreAccess; import org.neo4j.kernel.impl.store.StoreAccess;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.test.PageCacheRule; import org.neo4j.test.PageCacheRule;
import org.neo4j.test.TargetDirectory; import org.neo4j.test.TargetDirectory;
import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.TestGraphDatabaseFactory;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL; import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;


public class RelationshipChainExplorerTest public class RelationshipChainExplorerTest
Expand Down Expand Up @@ -144,12 +141,7 @@ private StoreAccess createStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes( in
} }
database.shutdown(); database.shutdown();
PageCache pageCache = pageCacheRule.getPageCache( new DefaultFileSystemAbstraction() ); PageCache pageCache = pageCacheRule.getPageCache( new DefaultFileSystemAbstraction() );
return new StoreAccess( pageCache, storeDirectory, getRecordFormats() ).initialize(); return new StoreAccess( pageCache, storeDirectory ).initialize();
}

protected RecordFormats getRecordFormats()
{
return LowLimitV3_0.RECORD_FORMATS;
} }


protected String getRecordFormatName() protected String getRecordFormatName()
Expand Down
Expand Up @@ -24,11 +24,11 @@
import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.CountsAccessor; import org.neo4j.kernel.impl.api.CountsAccessor;
import org.neo4j.kernel.impl.logging.NullLogService;
import org.neo4j.kernel.impl.store.format.RecordFormatSelector;
import org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord; import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord; import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
Expand Down Expand Up @@ -74,21 +74,21 @@ public StoreAccess( NeoStores store )
this.counts = store.getCounts(); this.counts = store.getCounts();
} }


public StoreAccess( PageCache pageCache, File storeDir, RecordFormats recordFormats ) public StoreAccess( PageCache pageCache, File storeDir )
{ {
this( new DefaultFileSystemAbstraction(), pageCache, storeDir, recordFormats); this( new DefaultFileSystemAbstraction(), pageCache, storeDir );
} }


public StoreAccess( FileSystemAbstraction fileSystem, PageCache pageCache, File storeDir, RecordFormats recordFormats ) public StoreAccess( FileSystemAbstraction fileSystem, PageCache pageCache, File storeDir )
{ {
this( fileSystem, pageCache, storeDir, Config.defaults(), recordFormats ); this( fileSystem, pageCache, storeDir, Config.defaults() );
} }


private StoreAccess( FileSystemAbstraction fileSystem, PageCache pageCache, File storeDir, Config config, private StoreAccess( FileSystemAbstraction fileSystem, PageCache pageCache, File storeDir, Config config )
RecordFormats recordFormats )
{ {
this( new StoreFactory( storeDir, config, new DefaultIdGeneratorFactory( fileSystem ), pageCache, this( new StoreFactory( storeDir, config, new DefaultIdGeneratorFactory( fileSystem ), pageCache,
fileSystem, recordFormats, NullLogProvider.getInstance() ).openAllNeoStores() ); fileSystem, RecordFormatSelector.autoSelectFormat(config, NullLogService.getInstance()),
NullLogProvider.getInstance() ).openAllNeoStores() );
this.closeable = true; this.closeable = true;
} }


Expand Down
Expand Up @@ -21,6 +21,8 @@


import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;


import java.util.Iterator;

import org.neo4j.helpers.Service; import org.neo4j.helpers.Service;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
Expand All @@ -43,6 +45,9 @@
*/ */
public class RecordFormatSelector public class RecordFormatSelector
{ {

private static final RecordFormats DEFAULT_AUTOSELECT_FORMAT = LowLimitV3_0.RECORD_FORMATS;

private static final Iterable<RecordFormats> KNOWN_FORMATS = asList( private static final Iterable<RecordFormats> KNOWN_FORMATS = asList(
LowLimitV2_0.RECORD_FORMATS, LowLimitV2_0.RECORD_FORMATS,
LowLimitV2_1.RECORD_FORMATS, LowLimitV2_1.RECORD_FORMATS,
Expand Down Expand Up @@ -132,6 +137,30 @@ private static RecordFormats loadRecordFormat( String recordFormat )
return null; return null;
} }


public static RecordFormats autoSelectFormat()
{
return autoSelectFormat( Config.empty(), NullLogService.getInstance() );
}

public static RecordFormats autoSelectFormat( Config config, LogService logService )
{
String recordFormat = configuredRecordFormat( config );
RecordFormats formats = loadRecordFormat( recordFormat );
if ( formats != null )
{
logService.getInternalLog( RecordFormatSelector.class ).warn( "Selected " +
recordFormat.getClass().getName() + " record format." );
return formats;
}
Iterable<RecordFormats.Factory> formatFactories = Service.load( RecordFormats.Factory.class );
Iterator<RecordFormats.Factory> factoryIterator = formatFactories.iterator();
RecordFormats recordFormats = factoryIterator.hasNext() ? factoryIterator.next().newInstance() : DEFAULT_AUTOSELECT_FORMAT;
logService.getInternalLog( RecordFormatSelector.class ).warn( "Selected " +
recordFormats.getClass().getName() + " record " +
"format." );
return recordFormats;
}

private static RecordFormats handleMissingFormat( String recordFormat, LogService logService ) private static RecordFormats handleMissingFormat( String recordFormat, LogService logService )
{ {
logService.getInternalLog( RecordFormatSelector.class ) logService.getInternalLog( RecordFormatSelector.class )
Expand Down
Expand Up @@ -31,7 +31,6 @@
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.impl.recovery.RecoveryRequiredChecker; import org.neo4j.kernel.impl.recovery.RecoveryRequiredChecker;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimitV3_0;
import org.neo4j.test.EphemeralFileSystemRule; import org.neo4j.test.EphemeralFileSystemRule;
import org.neo4j.test.PageCacheRule; import org.neo4j.test.PageCacheRule;
import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.TestGraphDatabaseFactory;
Expand All @@ -56,7 +55,7 @@ public void openingThroughStoreAccessShouldNotTriggerRecovery() throws Exception
snapshot.deleteFile( messages ); snapshot.deleteFile( messages );


PageCache pageCache = pageCacheRule.getPageCache( snapshot ); PageCache pageCache = pageCacheRule.getPageCache( snapshot );
new StoreAccess( snapshot, pageCache, storeDir, LowLimitV3_0.RECORD_FORMATS ).initialize().close(); new StoreAccess( snapshot, pageCache, storeDir ).initialize().close();
assertTrue( "Store should be unclean", isUnclean( snapshot ) ); assertTrue( "Store should be unclean", isUnclean( snapshot ) );
} }


Expand Down

0 comments on commit d930d8a

Please sign in to comment.