Skip to content

Commit

Permalink
PR comments (cleanup, renaming)
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Jul 12, 2016
1 parent 91ee61d commit 6a63973
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 81 deletions.
Expand Up @@ -69,9 +69,9 @@
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.BufferedRecordStorageIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.DefaultRecordStorageIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.RecordStorageIdController;
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.SchemaStorage;
import org.neo4j.kernel.impl.store.StoreFactory;
Expand Down Expand Up @@ -154,7 +154,7 @@ public class RecordStorageEngine implements StorageEngine, Lifecycle
private final LegacyIndexProviderLookup legacyIndexProviderLookup;
private final PropertyPhysicalToLogicalConverter indexUpdatesConverter;
private final Supplier<StorageStatement> storeStatementSupplier;
private final RecordStorageIdController recordStorageIdController;
private final IdController idController;

// Immutable state for creating/applying commands
private final Loaders loaders;
Expand Down Expand Up @@ -201,9 +201,9 @@ public RecordStorageEngine(
this.constraintSemantics = constraintSemantics;
this.legacyIndexTransactionOrdering = legacyIndexTransactionOrdering;

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

try
Expand Down Expand Up @@ -256,15 +256,15 @@ public RecordStorageEngine(
}
}

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

private Supplier<StorageStatement> storeStatementSupplier( NeoStores neoStores )
Expand Down Expand Up @@ -402,7 +402,7 @@ public void satisfyDependencies( DependencySatisfier satisfier )
// providing TransactionIdStore, LogVersionRepository
satisfier.satisfyDependency( neoStores.getMetaDataStore() );
satisfier.satisfyDependency( indexStoreView );
satisfier.satisfyDependency( recordStorageIdController );
satisfier.satisfyDependency( idController );
}

@Override
Expand All @@ -428,7 +428,7 @@ public void start() throws Throwable
loadSchemaCache();
indexingService.start();
labelScanStore.start();
recordStorageIdController.start();
idController.start();
}

@Override
Expand All @@ -441,15 +441,15 @@ public void loadSchemaCache()
@Override
public void clearBufferedIds()
{
recordStorageIdController.clear();
idController.clear();
}

@Override
public void stop() throws Throwable
{
labelScanStore.stop();
indexingService.stop();
recordStorageIdController.stop();
idController.stop();
}

@Override
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.kernel.impl.storageengine.impl.recordstorage.id;


import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

Expand All @@ -36,19 +35,20 @@
* Allows perform clear and maintenance operations over currently buffered set of ids.
* @see BufferingIdGeneratorFactory
*/
public class BufferedRecordStorageIdController extends LifecycleAdapter implements RecordStorageIdController
public class BufferedIdController extends LifecycleAdapter implements IdController
{

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

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

public IdGeneratorFactory getIdGeneratorFactory()
Expand All @@ -59,13 +59,14 @@ public IdGeneratorFactory getIdGeneratorFactory()
@Override
public void start() throws Throwable
{
idMaintenanceController.start();
jobHandle = scheduler.scheduleRecurring( JobScheduler.Groups.storageMaintenance, this::maintenance, 1,
TimeUnit.SECONDS );
}

@Override
public void stop() throws Throwable
{
idMaintenanceController.stop();
jobHandle.cancel( false );
}

@Override
Expand All @@ -77,36 +78,6 @@ public void clear()
@Override
public void maintenance()
{
idMaintenanceController.maintenance();
}

private static class BufferedIdMaintenanceController
{
private final BufferingIdGeneratorFactory bufferingIdGeneratorFactory;
private final JobScheduler scheduler;
private JobScheduler.JobHandle jobHandle;

BufferedIdMaintenanceController( BufferingIdGeneratorFactory bufferingIdGeneratorFactory,
JobScheduler scheduler )
{
this.bufferingIdGeneratorFactory = bufferingIdGeneratorFactory;
this.scheduler = scheduler;
}

public void start() throws Throwable
{
jobHandle = scheduler.scheduleRecurring( JobScheduler.Groups.storageMaintenance, this::maintenance, 1,
TimeUnit.SECONDS );
}

public void stop() throws Throwable
{
jobHandle.cancel( false );
}

public void maintenance()
{
bufferingIdGeneratorFactory.maintenance();
}
bufferingIdGeneratorFactory.maintenance();
}
}
Expand Up @@ -24,15 +24,15 @@
import org.neo4j.kernel.lifecycle.LifecycleAdapter;

/**
* Default implementation of {@link RecordStorageIdController}.
* Default implementation of {@link IdController}.
* Do not add any additional possibilities or functionality. Wraps provided {@link IdGeneratorFactory}.
*/
public class DefaultRecordStorageIdController extends LifecycleAdapter implements RecordStorageIdController
public class DefaultIdController extends LifecycleAdapter implements IdController
{

private IdGeneratorFactory idGeneratorFactory;

public DefaultRecordStorageIdController( IdGeneratorFactory idGeneratorFactory )
public DefaultIdController( IdGeneratorFactory idGeneratorFactory )
{
this.idGeneratorFactory = idGeneratorFactory;
}
Expand Down
Expand Up @@ -27,7 +27,7 @@
* Represent abstraction that responsible for any id related operations on a storage engine level: buffering,
* maintenance, clearing, resetting, generation.
*/
public interface RecordStorageIdController extends Lifecycle
public interface IdController extends Lifecycle
{
/**
* Retrieve id generation factory for current storage engine
Expand Down
Expand Up @@ -41,6 +41,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

public class StoreSingleRelationshipCursorTest
{
Expand Down Expand Up @@ -114,17 +115,8 @@ private StoreFactory getStoreFactory()

private StoreSingleRelationshipCursor createRelationshipCursor()
{
InstanceCache<StoreSingleRelationshipCursor> instanceCache = new TestCursorCache();
InstanceCache<StoreSingleRelationshipCursor> instanceCache = mock(InstanceCache.class);
return new StoreSingleRelationshipCursor( new RelationshipRecord( -1 ), instanceCache,
new RecordCursors( neoStores ), LockService.NO_LOCK_SERVICE );
}

private class TestCursorCache extends InstanceCache<StoreSingleRelationshipCursor>
{
@Override
protected StoreSingleRelationshipCursor create()
{
return null;
}
}
}
}
Expand Up @@ -28,7 +28,7 @@
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.RecordStorageIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.Barrier;
import org.neo4j.test.OtherThreadExecutor.WorkerCommand;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void shouldNotSeeFreedIdsCrossRoleSwitch() throws Throwable

private void triggerIdMaintenance( GraphDatabaseAPI db )
{
db.getDependencyResolver().resolveDependency( RecordStorageIdController.class )
db.getDependencyResolver().resolveDependency( IdController.class )
.maintenance();
}

Expand Down
Expand Up @@ -44,7 +44,7 @@
import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase;
import org.neo4j.kernel.ha.UpdatePuller;
import org.neo4j.kernel.impl.ha.ClusterManager;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.RecordStorageIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.test.Race;
import org.neo4j.test.ha.ClusterRule;

Expand Down Expand Up @@ -410,7 +410,7 @@ private static String longString( char ch )

private void forceMaintenance( HighlyAvailableGraphDatabase master )
{
master.getDependencyResolver().resolveDependency( RecordStorageIdController.class )
master.getDependencyResolver().resolveDependency( IdController.class )
.maintenance();
}

Expand Down
Expand Up @@ -35,7 +35,7 @@
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.impl.enterprise.configuration.EnterpriseEditionSettings;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.RecordStorageIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.kernel.impl.store.id.IdType;
import org.neo4j.test.EmbeddedDatabaseRule;

Expand Down Expand Up @@ -134,7 +134,7 @@ public void sequentialOperationRelationshipIdReuse()
assertEquals( "Ids should be sequential", relationship1 + 1, relationship2 );
assertEquals( "Ids should be sequential", relationship2 + 1, relationship3 );

final RecordStorageIdController idMaintenanceController = getIdMaintenanceController();
final IdController idMaintenanceController = getIdMaintenanceController();

deleteRelationshipByLabelAndRelationshipType( marker );

Expand All @@ -151,7 +151,7 @@ public void relationshipIdReusableOnlyAfterTransactionFinish()
Label testLabel = Label.label( "testLabel" );
long relationshipId = createRelationship( testLabel );

final RecordStorageIdController idMaintenanceController = getIdMaintenanceController();
final IdController idMaintenanceController = getIdMaintenanceController();

try ( Transaction transaction = dbRule.beginTx();
ResourceIterator<Node> nodes = dbRule.findNodes( testLabel ) )
Expand Down Expand Up @@ -196,9 +196,9 @@ private void deleteRelationshipByLabelAndRelationshipType( Label marker )
}
}

private RecordStorageIdController getIdMaintenanceController()
private IdController getIdMaintenanceController()
{
return dbRule.getDependencyResolver().resolveDependency( RecordStorageIdController.class );
return dbRule.getDependencyResolver().resolveDependency( IdController.class );
}

private long createRelationship( Label label )
Expand Down
Expand Up @@ -37,7 +37,6 @@
import java.util.concurrent.locks.LockSupport;

import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.DynamicLabel;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
Expand All @@ -51,7 +50,7 @@
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.DeadlockDetectedException;
import org.neo4j.kernel.impl.enterprise.configuration.EnterpriseEditionSettings;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.RecordStorageIdController;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.id.IdController;
import org.neo4j.kernel.impl.store.id.IdType;
import org.neo4j.test.EmbeddedDatabaseRule;

Expand Down Expand Up @@ -86,8 +85,8 @@ public void tearDown()
@Test
public void relationshipIdReused() throws Exception
{
Label cityLabel = DynamicLabel.label( "city" );
final Label bandLabel = DynamicLabel.label( "band" );
Label cityLabel = Label.label( "city" );
final Label bandLabel = Label.label( "band" );
createBands( bandLabel );
createCities( cityLabel );

Expand All @@ -100,7 +99,7 @@ public void relationshipIdReused() throws Exception
futures.add( startRelationshipTypesCalculator( bandLabel, stopFlag ) );
futures.add( startRelationshipCalculator( bandLabel, stopFlag ) );

Thread.sleep( TimeUnit.SECONDS.toMillis( 5 ) );
TimeUnit.SECONDS.sleep( 5 );
stopFlag.set( true );
executorService.shutdown();
executorService.awaitTermination( 5, TimeUnit.SECONDS );
Expand All @@ -115,7 +114,7 @@ public void relationshipIdReused() throws Exception

private long getHighestUsedIdForRelationships()
{
RecordStorageIdController idController = embeddedDatabase.getDependencyResolver().resolveDependency( RecordStorageIdController.class );
IdController idController = embeddedDatabase.getDependencyResolver().resolveDependency( IdController.class );
return idController.getIdGeneratorFactory().get( IdType.RELATIONSHIP ).getHighestPossibleIdInUse();
}

Expand Down

0 comments on commit 6a63973

Please sign in to comment.