Skip to content

Commit

Permalink
Creation and initialisation of stores only during NeoStores construct…
Browse files Browse the repository at this point in the history
…ion, remove laziness.

Previously it was possible to construct stores only when they were requested 'in a lazy way' independently from main NeoStores container lifecycle.
That brings a confusion when container are started/stopped on HA setup, since it was possible to construct stores on closed datasource.
To avoid confusion and simplify component lifecycle, but still keep possibility to open only requested stores
now we can enumerate stores that should be opened, in case if we don't need all, and they will be constructed
during container creation.

In case if we will request store on already closed container, or will request not requested store - exception will be thrown.
  • Loading branch information
MishaDemianenko committed Oct 29, 2015
1 parent 59b4cb2 commit 7676391
Show file tree
Hide file tree
Showing 50 changed files with 1,148 additions and 1,036 deletions.
Expand Up @@ -134,7 +134,7 @@ public PrintWriter get()
} }
} ) ); } ) );


try ( NeoStores neoStores = factory.openNeoStoresEagerly() ) try ( NeoStores neoStores = factory.openAllNeoStores() )
{ {
StoreAccess store = new StoreAccess( neoStores ).initialize(); StoreAccess store = new StoreAccess( neoStores ).initialize();
LabelScanStore labelScanStore = null; LabelScanStore labelScanStore = null;
Expand Down
Expand Up @@ -139,7 +139,7 @@ public PrintWriter get()
} }
} ) ); } ) );


try ( NeoStores neoStores = factory.openNeoStoresEagerly() ) try ( NeoStores neoStores = factory.openAllNeoStores() )
{ {
LabelScanStore labelScanStore = null; LabelScanStore labelScanStore = null;
try try
Expand Down
Expand Up @@ -105,8 +105,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, NullLogProvider.getInstance() ) neoStore = new StoreFactory( fileSystem, directory, pageCache, NullLogProvider.getInstance() ).openAllNeoStores();
.openNeoStoresEagerly();
StoreAccess nativeStores; StoreAccess nativeStores;
if ( keepStatistics ) if ( keepStatistics )
{ {
Expand Down
Expand Up @@ -184,7 +184,6 @@
import static org.neo4j.helpers.Settings.setting; import static org.neo4j.helpers.Settings.setting;
import static org.neo4j.helpers.collection.Iterables.toList; import static org.neo4j.helpers.collection.Iterables.toList;
import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK_SERVICE; import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK_SERVICE;
import static org.neo4j.kernel.impl.store.StoreFactory.SF_CREATE;
import static org.neo4j.kernel.impl.transaction.log.pruning.LogPruneStrategyFactory.fromConfigValue; import static org.neo4j.kernel.impl.transaction.log.pruning.LogPruneStrategyFactory.fromConfigValue;


public class NeoStoreDataSource implements NeoStoresSupplier, Lifecycle, IndexProviders public class NeoStoreDataSource implements NeoStoresSupplier, Lifecycle, IndexProviders
Expand Down Expand Up @@ -659,7 +658,7 @@ public void start() throws IOException
} }
} ); } );


final NeoStores neoStores = storeFactory.openNeoStores( SF_CREATE ); final NeoStores neoStores = storeFactory.openAllNeoStores( true );
return new NeoStoreModule() return new NeoStoreModule()
{ {
@Override @Override
Expand Down
Expand Up @@ -44,6 +44,7 @@


public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAbstractStore & RecordStore<RECORD>> public class DumpStore<RECORD extends AbstractBaseRecord, STORE extends CommonAbstractStore & RecordStore<RECORD>>
{ {

public static void main( String... args ) throws Exception public static void main( String... args ) throws Exception
{ {
if ( args == null || args.length == 0 ) if ( args == null || args.length == 0 )
Expand Down Expand Up @@ -102,40 +103,43 @@ else if ( !file.isDirectory() && file.getName().indexOf( ':' ) != -1 )
throw new IllegalArgumentException( "No such file: " + arg ); throw new IllegalArgumentException( "No such file: " + arg );
} }
} }
try ( NeoStores neoStores = createStoreFactory.apply( file ).openNeoStoresEagerly() ) NeoStores.StoreType storeType = STORE_FILENAME_TYPE_MAPPER.apply( file.getName() );
try ( NeoStores neoStores = createStoreFactory.apply( file ).openNeoStores( storeType ) )
{ {
switch ( file.getName() ) switch ( storeType )
{ {
case "neostore.nodestore.db": case NODE:
dumpNodeStore( neoStores, ids ); dumpNodeStore( neoStores, ids );
break; break;
case "neostore.relationshipstore.db": case RELATIONSHIP:
dumpRelationshipStore( neoStores, ids ); dumpRelationshipStore( neoStores, ids );
break; break;
case "neostore.propertystore.db": case PROPERTY:
dumpPropertyStore( neoStores, ids ); dumpPropertyStore( neoStores, ids );
break; break;
case "neostore.schemastore.db": case SCHEMA:
dumpSchemaStore( neoStores, ids ); dumpSchemaStore( neoStores, ids );
break; break;
case "neostore.propertystore.db.index": case PROPERTY_KEY_TOKEN:
dumpPropertyKeys( neoStores, ids ); dumpPropertyKeys( neoStores, ids );
break; break;
case "neostore.labeltokenstore.db": case LABEL_TOKEN:
dumpLabels( neoStores, ids ); dumpLabels( neoStores, ids );
break; break;
case "neostore.relationshiptypestore.db": case RELATIONSHIP_TYPE_TOKEN:
dumpRelationshipTypes( neoStores, ids ); dumpRelationshipTypes( neoStores, ids );
break; break;
case "neostore.relationshipgroupstore.db": case RELATIONSHIP_GROUP:
dumpRelationshipGroups( neoStores, ids ); dumpRelationshipGroups( neoStores, ids );
break; break;
default: default:
throw new IllegalArgumentException( "Unknown store file: " + arg ); throw new IllegalArgumentException( "Unsupported store type: " + storeType );
} }
} }
} }




private static LogProvider logProvider() private static LogProvider logProvider()
{ {
return Boolean.getBoolean( "logger" ) ? FormattedLogProvider.toOutputStream( System.out ) : NullLogProvider.getInstance(); return Boolean.getBoolean( "logger" ) ? FormattedLogProvider.toOutputStream( System.out ) : NullLogProvider.getInstance();
Expand Down Expand Up @@ -346,4 +350,33 @@ protected Object transform( RECORD record ) throws Exception
{ {
return record.inUse() ? record : null; return record.inUse() ? record : null;
} }

static Function<String,NeoStores.StoreType> STORE_FILENAME_TYPE_MAPPER = new Function<String,NeoStores.StoreType>()
{
@Override
public NeoStores.StoreType apply( String filename )
{
switch ( filename )
{
case "neostore.nodestore.db":
return NeoStores.StoreType.NODE;
case "neostore.relationshipstore.db":
return NeoStores.StoreType.RELATIONSHIP;
case "neostore.propertystore.db":
return NeoStores.StoreType.PROPERTY;
case "neostore.schemastore.db":
return NeoStores.StoreType.SCHEMA;
case "neostore.propertystore.db.index":
return NeoStores.StoreType.PROPERTY_KEY_TOKEN;
case "neostore.labeltokenstore.db":
return NeoStores.StoreType.LABEL_TOKEN;
case "neostore.relationshiptypestore.db":
return NeoStores.StoreType.RELATIONSHIP_TYPE_TOKEN;
case "neostore.relationshipgroupstore.db":
return NeoStores.StoreType.RELATIONSHIP_GROUP;
default:
throw new IllegalArgumentException( "Unknown store file: " + filename );
}
}
};
} }
Expand Up @@ -39,6 +39,7 @@
import org.neo4j.logging.NullLogProvider; import org.neo4j.logging.NullLogProvider;


import static org.neo4j.kernel.impl.pagecache.StandalonePageCacheFactory.createPageCache; import static org.neo4j.kernel.impl.pagecache.StandalonePageCacheFactory.createPageCache;
import static org.neo4j.kernel.impl.store.DumpStore.STORE_FILENAME_TYPE_MAPPER;


public abstract class DumpStoreChain<RECORD extends AbstractBaseRecord> public abstract class DumpStoreChain<RECORD extends AbstractBaseRecord>
{ {
Expand Down Expand Up @@ -106,7 +107,7 @@ void dump( File storeDir ) throws IOException
Config config = new Config(); Config config = new Config();
StoreFactory storeFactory = new StoreFactory( storeDir, config, idGeneratorFactory, pageCache, fs, logProvider() ); StoreFactory storeFactory = new StoreFactory( storeDir, config, idGeneratorFactory, pageCache, fs, logProvider() );


try ( NeoStores neoStores = storeFactory.openNeoStoresEagerly() ) try ( NeoStores neoStores = storeFactory.openNeoStores( getStoreTypes() ) )
{ {
RecordStore<RECORD> store = store( neoStores ); RecordStore<RECORD> store = store( neoStores );
for ( long next = first; next != -1; ) for ( long next = first; next != -1; )
Expand All @@ -119,6 +120,13 @@ void dump( File storeDir ) throws IOException
} }
} }


private NeoStores.StoreType[] getStoreTypes()
{
return new NeoStores.StoreType[]{STORE_FILENAME_TYPE_MAPPER.apply( NODESTORE ),
STORE_FILENAME_TYPE_MAPPER.apply( PROPSTORE ),
STORE_FILENAME_TYPE_MAPPER.apply( RELSTORE )};
}

abstract long next( RECORD record ); abstract long next( RECORD record );


abstract RecordStore<RECORD> store( NeoStores neoStores ); abstract RecordStore<RECORD> store( NeoStores neoStores );
Expand Down

0 comments on commit 7676391

Please sign in to comment.