Skip to content

Commit

Permalink
Just for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klaren authored and MishaDemianenko committed Jul 4, 2017
1 parent 542580a commit 629eef1
Show file tree
Hide file tree
Showing 22 changed files with 313 additions and 201 deletions.
Expand Up @@ -88,6 +88,7 @@
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.StoreId;
import org.neo4j.kernel.impl.store.format.RecordFormatPropertyConfigurator;
Expand Down Expand Up @@ -276,6 +277,7 @@ boolean applicable( DiagnosticsPhase phase )
private LabelScanStoreProvider labelScanStoreProvider;
private File storeDir;
private boolean readOnly;
private final IdController idController;
private final RecoveryCleanupWorkCollector recoveryCleanupWorkCollector;
private final AccessCapability accessCapability;

Expand Down Expand Up @@ -325,7 +327,8 @@ public NeoStoreDataSource(
SystemNanoClock clock,
AccessCapability accessCapability,
StoreCopyCheckPointMutex storeCopyCheckPointMutex,
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector )
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector,
IdController idController )
{
this.storeDir = storeDir;
this.config = config;
Expand Down Expand Up @@ -364,6 +367,7 @@ public NeoStoreDataSource(
this.recoveryCleanupWorkCollector = recoveryCleanupWorkCollector;

readOnly = config.get( Configuration.read_only );
this.idController = idController;
msgLog = logProvider.getLog( getClass() );
this.lockService = new ReentrantLockService();
this.legacyIndexProviderLookup = new LegacyIndexProviderLookup()
Expand Down Expand Up @@ -479,6 +483,9 @@ public void start() throws IOException
clock,
propertyAccessor );

Supplier<KernelTransactionsSnapshot> transactionsSnapshotSupplier = () -> kernelModule.kernelTransactions().get();
idController.initialize( transactionsSnapshotSupplier );

kernelModule.satisfyDependencies( dependencies );

// Do these assignments last so that we can ensure no cyclical dependencies exist
Expand Down Expand Up @@ -577,17 +584,12 @@ private StorageEngine buildStorageEngine(
LegacyIndexProviderLookup legacyIndexProviderLookup, IndexConfigStore indexConfigStore,
SchemaState schemaState, SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering )
{
// TODO we should break this dependency on the kernelModule (which has not yet been created at this point in
// TODO the code) and instead let information about generations of transactions flow through the StorageEngine
// TODO API
Supplier<KernelTransactionsSnapshot> transactionSnapshotSupplier =
() -> kernelModule.kernelTransactions().get();
RecordStorageEngine storageEngine = new RecordStorageEngine( storeDir, config, idGeneratorFactory,
eligibleForReuse, idTypeConfigurationProvider, pageCache, fs, logProvider, propertyKeyTokenHolder,
labelTokens, relationshipTypeTokens, schemaState, constraintSemantics, scheduler,
tokenNameLookup, lockService, schemaIndexProvider, indexingServiceMonitor, databaseHealth,
labelScanStoreProvider, legacyIndexProviderLookup, indexConfigStore, legacyIndexTransactionOrdering,
transactionSnapshotSupplier );
RecordStorageEngine storageEngine =
new RecordStorageEngine( storeDir, config, pageCache, fs, logProvider, propertyKeyTokenHolder,
labelTokens, relationshipTypeTokens, schemaState, constraintSemantics, scheduler,
tokenNameLookup, lockService, schemaIndexProvider, indexingServiceMonitor, databaseHealth,
labelScanStoreProvider, legacyIndexProviderLookup, indexConfigStore,
legacyIndexTransactionOrdering, idGeneratorFactory, idController );

// We pretend that the storage engine abstract hides all details within it. Whereas that's mostly
// true it's not entirely true for the time being. As long as we need this call below, which
Expand Down
Expand Up @@ -106,7 +106,10 @@ public CommunityEditionModule( PlatformModule platformModule )
statementLocksFactory = createStatementLocksFactory( lockManager, config, logging );

idTypeConfigurationProvider = createIdTypeConfigurationProvider( config );
eligibleForIdReuse = IdReuseEligibility.ALWAYS;

idGeneratorFactory = dependencies.satisfyDependency( createIdGeneratorFactory( fileSystem, idTypeConfigurationProvider ) );
idController = createIdController( platformModule );

propertyKeyTokenHolder = life.add( dependencies.satisfyDependency( new DelegatingPropertyKeyTokenHolder(
createPropertyKeyCreator( config, dataSourceManager, idGeneratorFactory ) ) ) );
Expand All @@ -132,8 +135,6 @@ public CommunityEditionModule( PlatformModule platformModule )

ioLimiter = IOLimiter.unlimited();

eligibleForIdReuse = IdReuseEligibility.ALWAYS;

registerRecovery( platformModule.databaseInfo, life, dependencies );

publishEditionInfo( dependencies.resolveDependency( UsageData.class ), platformModule.databaseInfo, config );
Expand Down
Expand Up @@ -63,9 +63,9 @@
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.core.TokenNotFoundException;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.proc.ProcedureTransactionProvider;
import org.neo4j.kernel.impl.proc.ProcedureConfig;
import org.neo4j.kernel.impl.proc.ProcedureGDSFactory;
import org.neo4j.kernel.impl.proc.ProcedureTransactionProvider;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.proc.TerminationGuardProvider;
import org.neo4j.kernel.impl.proc.TypeMappers.SimpleConverter;
Expand Down Expand Up @@ -220,7 +220,8 @@ public DataSourceModule( final PlatformModule platformModule, EditionModule edit
platformModule.availabilityGuard,
platformModule.clock, editionModule.accessCapability,
platformModule.storeCopyCheckPointMutex,
platformModule.recoveryCleanupWorkCollector ) );
platformModule.recoveryCleanupWorkCollector,
editionModule.idController ) );

dataSourceManager.register( neoStoreDataSource );

Expand Down
Expand Up @@ -44,21 +44,27 @@
import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.BufferedIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.DefaultIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.kernel.impl.store.id.BufferingIdGeneratorFactory;
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;
import org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory;
import org.neo4j.kernel.impl.util.DependencySatisfier;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.kernel.impl.util.watcher.DefaultFileDeletionEventListener;
import org.neo4j.kernel.impl.util.watcher.DefaultFileSystemWatcherService;
import org.neo4j.kernel.impl.util.watcher.FileSystemWatcherService;
import org.neo4j.kernel.info.DiagnosticsManager;
import org.neo4j.kernel.internal.KernelDiagnostics;
import org.neo4j.kernel.lifecycle.LifeSupport;
import org.neo4j.logging.Log;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.udc.UsageData;
import org.neo4j.udc.UsageDataKeys;
import org.neo4j.unsafe.impl.internal.dragons.FeatureToggles;

import static java.util.Collections.singletonMap;

Expand All @@ -68,6 +74,9 @@
*/
public abstract class EditionModule
{
protected static final boolean safeIdBuffering = FeatureToggles.flag(
RecordStorageEngine.class, "safeIdBuffering", true ); // TODO: fix this!

void registerProcedures( Procedures procedures ) throws KernelException
{
procedures.registerProcedure( org.neo4j.kernel.builtinprocs.BuiltInProcedures.class );
Expand Down Expand Up @@ -112,6 +121,8 @@ void registerProcedures( Procedures procedures ) throws KernelException

public FileSystemWatcherService watcherService;

public IdController idController;

protected FileSystemWatcherService createFileSystemWatcherService( FileSystemAbstraction fileSystem, File storeDir,
LogService logging, JobScheduler jobScheduler, Predicate<String> fileNameFilter )
{
Expand Down Expand Up @@ -225,4 +236,24 @@ protected BoltConnectionTracker createSessionTracker()
{
return BoltConnectionTracker.NOOP;
}

protected IdController createIdController( PlatformModule platformModule )
{
return safeIdBuffering ? createBufferedIdController( idGeneratorFactory, platformModule.jobScheduler,
eligibleForIdReuse, idTypeConfigurationProvider ) : createDefaultIdController();
}

protected BufferedIdController createBufferedIdController( IdGeneratorFactory idGeneratorFactory,
JobScheduler scheduler, IdReuseEligibility eligibleForIdReuse,
IdTypeConfigurationProvider idTypeConfigurationProvider )
{
BufferingIdGeneratorFactory bufferingIdGeneratorFactory =
new BufferingIdGeneratorFactory( idGeneratorFactory, eligibleForIdReuse, idTypeConfigurationProvider );
return new BufferedIdController( bufferingIdGeneratorFactory, scheduler );
}

protected DefaultIdController createDefaultIdController()
{
return new DefaultIdController();
}
}
Expand Up @@ -47,7 +47,6 @@
import org.neo4j.kernel.impl.api.CountsRecordState;
import org.neo4j.kernel.impl.api.CountsStoreBatchTransactionApplier;
import org.neo4j.kernel.impl.api.IndexReaderFactory;
import org.neo4j.kernel.impl.api.KernelTransactionsSnapshot;
import org.neo4j.kernel.impl.api.LegacyBatchIndexApplier;
import org.neo4j.kernel.impl.api.LegacyIndexApplierLookup;
import org.neo4j.kernel.impl.api.LegacyIndexProviderLookup;
Expand All @@ -71,8 +70,6 @@
import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.locking.LockGroup;
import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.BufferedIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.DefaultIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.RecordStore;
Expand All @@ -81,8 +78,6 @@
import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.store.format.RecordFormat;
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;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.transaction.command.CacheInvalidationBatchTransactionApplier;
import org.neo4j.kernel.impl.transaction.command.HighIdBatchTransactionApplier;
Expand Down Expand Up @@ -131,8 +126,6 @@ public class RecordStorageEngine implements StorageEngine, Lifecycle
{
private static final boolean takePropertyReadLocks = FeatureToggles.flag(
RecordStorageEngine.class, "propertyReadLocks", false );
private static final boolean safeIdBuffering = FeatureToggles.flag(
RecordStorageEngine.class, "safeIdBuffering", true );

private final StoreReadLayer storeLayer;
private final IndexingService indexingService;
Expand All @@ -152,7 +145,6 @@ public class RecordStorageEngine implements StorageEngine, Lifecycle
private final SchemaStorage schemaStorage;
private final ConstraintSemantics constraintSemantics;
private final IdOrderingQueue legacyIndexTransactionOrdering;
private final JobScheduler scheduler;
private final LockService lockService;
private final WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork> labelScanStoreSync;
private final CommandReaderFactory commandReaderFactory;
Expand All @@ -173,9 +165,6 @@ public class RecordStorageEngine implements StorageEngine, Lifecycle
public RecordStorageEngine(
File storeDir,
Config config,
IdGeneratorFactory idGeneratorFactory,
IdReuseEligibility eligibleForReuse,
IdTypeConfigurationProvider idTypeConfigurationProvider,
PageCache pageCache,
FileSystemAbstraction fs,
LogProvider logProvider,
Expand All @@ -194,23 +183,22 @@ public RecordStorageEngine(
LegacyIndexProviderLookup legacyIndexProviderLookup,
IndexConfigStore indexConfigStore,
IdOrderingQueue legacyIndexTransactionOrdering,
Supplier<KernelTransactionsSnapshot> transactionsSnapshotSupplier )
IdGeneratorFactory idGeneratorFactory,
IdController idController )
{
this.propertyKeyTokenHolder = propertyKeyTokenHolder;
this.relationshipTypeTokenHolder = relationshipTypeTokens;
this.labelTokenHolder = labelTokens;
this.schemaState = schemaState;
this.scheduler = scheduler;
this.lockService = lockService;
this.databaseHealth = databaseHealth;
this.legacyIndexProviderLookup = legacyIndexProviderLookup;
this.indexConfigStore = indexConfigStore;
this.constraintSemantics = constraintSemantics;
this.legacyIndexTransactionOrdering = legacyIndexTransactionOrdering;

this.idController = createStorageIdController( idGeneratorFactory, eligibleForReuse,
idTypeConfigurationProvider, transactionsSnapshotSupplier );
StoreFactory factory = new StoreFactory( storeDir, config, idController.getIdGeneratorFactory(), pageCache, fs, logProvider );
this.idController = idController;
StoreFactory factory = new StoreFactory( storeDir, config, idGeneratorFactory, pageCache, fs, logProvider );
neoStores = factory.openAllNeoStores( true );

try
Expand Down Expand Up @@ -263,17 +251,6 @@ public RecordStorageEngine(
}
}

private IdController createStorageIdController( IdGeneratorFactory idGeneratorFactory,
IdReuseEligibility eligibleForReuse,
IdTypeConfigurationProvider idTypeConfigurationProvider,
Supplier<KernelTransactionsSnapshot> transactionsSnapshotSupplier )
{
return safeIdBuffering ?
new BufferedIdController( idGeneratorFactory, transactionsSnapshotSupplier,
eligibleForReuse, idTypeConfigurationProvider, scheduler ) :
new DefaultIdController( idGeneratorFactory );
}

private Supplier<StorageStatement> storeStatementSupplier( NeoStores neoStores )
{
Supplier<IndexReaderFactory> indexReaderFactory = () -> new IndexReaderFactory.Caching( indexingService );
Expand Down
Expand Up @@ -24,11 +24,8 @@

import org.neo4j.kernel.impl.api.KernelTransactionsSnapshot;
import org.neo4j.kernel.impl.store.id.BufferingIdGeneratorFactory;
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;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.scheduler.JobScheduler;

/**
* Storage id controller that provide buffering possibilities to be able so safely free and reuse ids.
Expand All @@ -37,23 +34,14 @@
*/
public class BufferedIdController extends LifecycleAdapter implements IdController
{

private final BufferingIdGeneratorFactory bufferingIdGeneratorFactory;
private final JobScheduler scheduler;
private JobScheduler.JobHandle jobHandle;

public BufferedIdController( IdGeneratorFactory idGeneratorFactory,
Supplier<KernelTransactionsSnapshot> transactionsSnapshotSupplier, IdReuseEligibility eligibleForReuse,
IdTypeConfigurationProvider idTypeConfigurationProvider, JobScheduler scheduler )
public BufferedIdController( BufferingIdGeneratorFactory bufferingIdGeneratorFactory, JobScheduler scheduler )
{
this.bufferingIdGeneratorFactory = bufferingIdGeneratorFactory;
this.scheduler = scheduler;
bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(
idGeneratorFactory, transactionsSnapshotSupplier, eligibleForReuse, idTypeConfigurationProvider );
}

public IdGeneratorFactory getIdGeneratorFactory()
{
return bufferingIdGeneratorFactory;
}

@Override
Expand All @@ -80,4 +68,10 @@ public void maintenance()
{
bufferingIdGeneratorFactory.maintenance();
}

@Override
public void initialize( Supplier<KernelTransactionsSnapshot> transactionsSnapshotSupplier )
{
bufferingIdGeneratorFactory.initialize( transactionsSnapshotSupplier );
}
}
Expand Up @@ -20,6 +20,9 @@
package org.neo4j.kernel.impl.storageengine.impl.recordstorage.id;


import java.util.function.Supplier;

import org.neo4j.kernel.impl.api.KernelTransactionsSnapshot;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;

Expand All @@ -29,26 +32,22 @@
*/
public class DefaultIdController extends LifecycleAdapter implements IdController
{

private IdGeneratorFactory idGeneratorFactory;

public DefaultIdController( IdGeneratorFactory idGeneratorFactory )
public DefaultIdController()
{
this.idGeneratorFactory = idGeneratorFactory;
}

public IdGeneratorFactory getIdGeneratorFactory()
@Override
public void clear()
{
return idGeneratorFactory;
}

@Override
public void clear()
public void maintenance()
{
}

@Override
public void maintenance()
public void initialize( Supplier<KernelTransactionsSnapshot> transactionsSnapshotSupplier )
{
}
}

0 comments on commit 629eef1

Please sign in to comment.