Skip to content

Commit

Permalink
Drop 'Store' prefix from PropertyCursors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed May 8, 2017
1 parent 164707e commit 5dd935c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 77 deletions.
Expand Up @@ -35,9 +35,9 @@
import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;

public abstract class StoreAbstractPropertyCursor implements PropertyItem, Cursor<PropertyItem>, Disposable
public abstract class AbstractPropertyCursor implements PropertyItem, Cursor<PropertyItem>, Disposable
{
private final StorePropertyPayloadCursor payload;
private final PropertyPayloadCursor payload;
private final PageCursor cursor;
private final PropertyRecord record;
private final PropertyStore propertyStore;
Expand All @@ -50,12 +50,12 @@ public abstract class StoreAbstractPropertyCursor implements PropertyItem, Curso
private Lock lock;
protected PropertyContainerState state;

StoreAbstractPropertyCursor( PropertyStore propertyStore )
AbstractPropertyCursor( PropertyStore propertyStore )
{
this.cursor = propertyStore.newPageCursor();
this.propertyStore = propertyStore;
this.record = propertyStore.newRecord();
this.payload = new StorePropertyPayloadCursor( propertyStore.getStringStore(), propertyStore.getArrayStore() );
this.payload = new PropertyPayloadCursor( propertyStore.getStringStore(), propertyStore.getArrayStore() );
}

protected final void initialize( IntPredicate propertyKeyIds, long firstPropertyId, Lock lock,
Expand Down
Expand Up @@ -40,8 +40,8 @@ public class GlobalCursorPools implements CursorPools
private final CursorPool<StoreSingleRelationshipCursor> singleRelationshipCursor;
private final CursorPool<StoreIteratorRelationshipCursor> iteratorRelationshipCursor;
private final CursorPool<StoreNodeRelationshipCursor> nodeRelationshipsCursor;
private final CursorPool<StorePropertyCursor> propertyCursor;
private final CursorPool<StoreSinglePropertyCursor> singlePropertyCursor;
private final CursorPool<PropertyCursor> propertyCursor;
private final CursorPool<SinglePropertyCursor> singlePropertyCursor;
private final CursorPool<RelationshipGroupCursor> relationshipGroupCursorCache;
private final CursorPool<DenseNodeDegreeCounter> degreeCounter;
private final NeoStores neoStores;
Expand All @@ -59,9 +59,9 @@ public GlobalCursorPools( NeoStores neoStores, LockService lockService )
cache -> new StoreNodeRelationshipCursor( neoStores.getRelationshipStore(),
neoStores.getRelationshipGroupStore(), cache, lockService ) );
this.propertyCursor =
new CursorPool<>( 10, cache -> new StorePropertyCursor( neoStores.getPropertyStore(), cache ) );
new CursorPool<>( 10, cache -> new PropertyCursor( neoStores.getPropertyStore(), cache ) );
this.singlePropertyCursor =
new CursorPool<>( 10, cache -> new StoreSinglePropertyCursor( neoStores.getPropertyStore(), cache ) );
new CursorPool<>( 10, cache -> new SinglePropertyCursor( neoStores.getPropertyStore(), cache ) );
this.degreeCounter = new CursorPool<>( 10,
cache -> new DenseNodeDegreeCounter( neoStores.getRelationshipStore(),
neoStores.getRelationshipGroupStore(), cache ) );
Expand Down
Expand Up @@ -33,19 +33,19 @@
/**
* Cursor for all properties on a node or relationship.
*/
public class StorePropertyCursor extends StoreAbstractPropertyCursor
public class PropertyCursor extends AbstractPropertyCursor
{
private final Consumer<StorePropertyCursor> consumer;
private final Consumer<PropertyCursor> consumer;

private Iterator<StorageProperty> storagePropertyIterator;

public StorePropertyCursor( PropertyStore propertyStore, Consumer<StorePropertyCursor> consumer )
public PropertyCursor( PropertyStore propertyStore, Consumer<PropertyCursor> consumer )
{
super( propertyStore );
this.consumer = consumer;
}

public StorePropertyCursor init( long firstPropertyId, Lock lock, PropertyContainerState state )
public PropertyCursor init( long firstPropertyId, Lock lock, PropertyContainerState state )
{
storagePropertyIterator = state.addedProperties();
initialize( ALWAYS_TRUE_INT, firstPropertyId, lock, state );
Expand Down
Expand Up @@ -48,7 +48,7 @@
* During initialization the raw property block {@code long}s are read from
* the given property record.
*/
class StorePropertyPayloadCursor implements Disposable
class PropertyPayloadCursor implements Disposable
{
private static final int MAX_BYTES_IN_SHORT_STRING_OR_SHORT_ARRAY = 32;
private static final int INTERNAL_BYTE_ARRAY_SIZE = 4096;
Expand All @@ -72,7 +72,7 @@ class StorePropertyPayloadCursor implements Disposable
private IntPredicate propertyKeyIds;
private boolean exhausted;

StorePropertyPayloadCursor( DynamicStringStore stringStore, DynamicArrayStore arrayStore )
PropertyPayloadCursor( DynamicStringStore stringStore, DynamicArrayStore arrayStore )
{
this.record = stringStore.newRecord();
this.stringStore = stringStore;
Expand Down
Expand Up @@ -26,18 +26,18 @@
import org.neo4j.kernel.impl.store.PropertyStore;
import org.neo4j.storageengine.api.txstate.PropertyContainerState;

public class StoreSinglePropertyCursor extends StoreAbstractPropertyCursor
public class SinglePropertyCursor extends AbstractPropertyCursor
{
private final Consumer<StoreSinglePropertyCursor> consumer;
private final Consumer<SinglePropertyCursor> consumer;
private int propertyKeyId;

StoreSinglePropertyCursor( PropertyStore propertyStore, Consumer<StoreSinglePropertyCursor> consumer )
SinglePropertyCursor( PropertyStore propertyStore, Consumer<SinglePropertyCursor> consumer )
{
super( propertyStore );
this.consumer = consumer;
}

public StoreSinglePropertyCursor init( int propertyKeyId, long firstPropertyId, Lock lock,
public SinglePropertyCursor init( int propertyKeyId, long firstPropertyId, Lock lock,
PropertyContainerState state )
{
this.propertyKeyId = propertyKeyId;
Expand Down
Expand Up @@ -46,7 +46,7 @@ public class PropertyRecord extends AbstractBaseRecord implements Iterable<Prope
private long nextProp;
private long prevProp;
// Holds the purely physical representation of the loaded properties in this record. This is so that
// StorePropertyCursor is able to use this raw data without the rather heavy and bloated data structures
// PropertyCursor is able to use this raw data without the rather heavy and bloated data structures
// of PropertyBlock and thereabouts. So when a property record is loaded only these blocks are read,
// the construction of all PropertyBlock instances are loaded lazile when they are first needed, loaded
// by ensureBlocksLoaded().
Expand Down
Expand Up @@ -50,7 +50,7 @@
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.store.StorePropertyCursor;
import org.neo4j.kernel.impl.api.store.PropertyCursor;
import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.store.CountsComputer;
Expand Down Expand Up @@ -93,7 +93,6 @@
import org.neo4j.kernel.impl.util.CustomIOConfigValidator;
import org.neo4j.kernel.lifecycle.Lifespan;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.storageengine.api.txstate.NodeState;
import org.neo4j.storageengine.api.txstate.PropertyContainerState;
import org.neo4j.unsafe.impl.batchimport.AdditionalInitialIds;
import org.neo4j.unsafe.impl.batchimport.BatchImporter;
Expand Down Expand Up @@ -685,7 +684,7 @@ private <ENTITY extends InputEntity, RECORD extends PrimitiveRecord> BiConsumer<
};
}

final StorePropertyCursor cursor = new StorePropertyCursor( propertyStore, ignored -> {} );
final PropertyCursor cursor = new PropertyCursor( propertyStore, ignored -> {} );
final List<Object> scratch = new ArrayList<>();
return ( ENTITY entity, RECORD record ) ->
{
Expand Down
Expand Up @@ -54,7 +54,6 @@
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.storageengine.api.PropertyItem;
import org.neo4j.storageengine.api.txstate.PropertyContainerState;
import org.neo4j.test.rule.PageCacheRule;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;

Expand All @@ -74,7 +73,7 @@
import static org.neo4j.storageengine.api.txstate.PropertyContainerState.EMPTY;

@RunWith( Enclosed.class )
public class StorePropertyCursorTest
public class PropertyCursorTest
{
private static final List<Object[]> PARAMETERS = asList(
new Object[]{false, PropertyType.BOOL},
Expand Down Expand Up @@ -243,35 +242,35 @@ public void shouldReturnTheCursorToTheCacheOnClose() throws Throwable
{
// given
@SuppressWarnings( "unchecked" )
Consumer<StorePropertyCursor> cache = mock( Consumer.class );
Consumer<PropertyCursor> cache = mock( Consumer.class );

StorePropertyCursor storePropertyCursor = new StorePropertyCursor( propertyStore, cache );
storePropertyCursor.init( 0, NO_LOCK, EMPTY );
PropertyCursor propertyCursor = new PropertyCursor( propertyStore, cache );
propertyCursor.init( 0, NO_LOCK, EMPTY );

// when
storePropertyCursor.close();
propertyCursor.close();

// then
verify( cache, times( 1 ) ).accept( storePropertyCursor );
verify( cache, times( 1 ) ).accept( propertyCursor );
}

@Test
public void shouldClosePageCursorsOnDispose() throws Throwable
{
// given
PageCursor propertyCursor = mock( PageCursor.class );
when( propertyStore.newPageCursor() ).thenReturn( propertyCursor );
PageCursor cursor = mock( PageCursor.class );
when( propertyStore.newPageCursor() ).thenReturn( cursor );
PageCursor stringCursor = mock( PageCursor.class );
when( stringStore.newPageCursor() ).thenReturn( stringCursor );
PageCursor arrayCursor = mock( PageCursor.class );
when( arrayStore.newPageCursor() ).thenReturn( arrayCursor );
StorePropertyCursor storePropertyCursor = new StorePropertyCursor( propertyStore, c -> {} );
PropertyCursor propertyCursor = new PropertyCursor( propertyStore, c -> {} );

// when
storePropertyCursor.dispose();
propertyCursor.dispose();

// then
verify( propertyCursor ).close();
verify( cursor ).close();
verify( stringCursor ).close();
verify( arrayCursor ).close();
}
Expand Down Expand Up @@ -343,10 +342,10 @@ public void shouldReturnAProperty() throws Throwable

long recordId = createSinglePropertyValue( propertyStore, keyId, expectedValue ).getId();

StorePropertyCursor storePropertyCursor = newStorePropertyCursor( propertyStore );
PropertyCursor propertyCursor = newPropertyCursor( propertyStore );

// when
try ( Cursor<PropertyItem> cursor = storePropertyCursor.init( recordId, NO_LOCK, EMPTY ) )
try ( Cursor<PropertyItem> cursor = propertyCursor.init( recordId, NO_LOCK, EMPTY ) )
{
// then
assertTrue( cursor.next() );
Expand Down Expand Up @@ -406,10 +405,10 @@ public void shouldReturnAPropertyBySkippingOne() throws Throwable
long recordId = createTwoPropertyValues(
propertyStore, keyId1, expectedValue1, keyId2, expectedValue2 ).getId();

StorePropertyCursor storePropertyCursor = newStorePropertyCursor( propertyStore );
PropertyCursor propertyCursor = newPropertyCursor( propertyStore );

// when
try ( Cursor<PropertyItem> cursor = storePropertyCursor.init( recordId, NO_LOCK, EMPTY ) )
try ( Cursor<PropertyItem> cursor = propertyCursor.init( recordId, NO_LOCK, EMPTY ) )
{
// then
assertTrue( cursor.next() );
Expand Down Expand Up @@ -438,10 +437,10 @@ public void shouldReturnTwoProperties() throws Throwable
long recordId = createTwoPropertyValues(
propertyStore, keyId1, expectedValue1, keyId2, expectedValue2 ).getId();

StorePropertyCursor storePropertyCursor = newStorePropertyCursor( propertyStore );
PropertyCursor propertyCursor = newPropertyCursor( propertyStore );

// when
try ( Cursor<PropertyItem> cursor = storePropertyCursor.init( recordId, NO_LOCK, EMPTY ) )
try ( Cursor<PropertyItem> cursor = propertyCursor.init( recordId, NO_LOCK, EMPTY ) )
{
PropertyItem item;

Expand Down Expand Up @@ -485,9 +484,9 @@ public void shouldReuseCorrectlyCursor() throws Throwable

long recordId = createSinglePropertyValue( propertyStore, keyId, expectedValue ).getId();

StorePropertyCursor storePropertyCursor = newStorePropertyCursor( propertyStore );
PropertyCursor propertyCursor = newPropertyCursor( propertyStore );

try ( Cursor<PropertyItem> cursor = storePropertyCursor.init( recordId, NO_LOCK, EMPTY ) )
try ( Cursor<PropertyItem> cursor = propertyCursor.init( recordId, NO_LOCK, EMPTY ) )
{
assertTrue( cursor.next() );
PropertyItem item = cursor.get();
Expand All @@ -497,7 +496,7 @@ public void shouldReuseCorrectlyCursor() throws Throwable
}

// when using it
try ( Cursor<PropertyItem> cursor = storePropertyCursor.init( recordId, NO_LOCK, EMPTY ) )
try ( Cursor<PropertyItem> cursor = propertyCursor.init( recordId, NO_LOCK, EMPTY ) )
{
// then
assertTrue( cursor.next() );
Expand All @@ -519,7 +518,7 @@ public void readPropertyChainWithMultipleEntries()

long firstPropertyId = firstIdOf( createPropertyChain( propertyStore, propertyKeyId, propertyValues ) );

try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( firstPropertyId, NO_LOCK, EMPTY );

Expand All @@ -535,7 +534,7 @@ public void callNextAfterReadingPropertyChain()

long firstPropertyId = firstIdOf( createPropertyChain( propertyStore, propertyKeyId, "1", "2" ) );

try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( firstPropertyId, NO_LOCK, EMPTY );

Expand All @@ -561,7 +560,7 @@ public void skipUnusedRecordsInChain()
long firstPropertyId = firstIdOf( propertyChain );
markPropertyRecordsNoInUse( propertyStore, idsOf( propertyChain, 1, 2, 4 ) );

try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( firstPropertyId, NO_LOCK, EMPTY );

Expand All @@ -580,7 +579,7 @@ public void skipUnusedConsecutiveRecordsInChain()
long firstPropertyId = firstIdOf( propertyChain );
markPropertyRecordsNoInUse( propertyStore, idsOf( propertyChain, 2, 1, 3 ) );

try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( firstPropertyId, NO_LOCK, EMPTY );

Expand All @@ -600,7 +599,7 @@ public void skipAllRecordsWhenWholeChainNotInUse()
int[] recordIds = idsOf( propertyChain, 0, 1, propertyValues.length );
markPropertyRecordsNoInUse( propertyStore, recordIds );

try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( firstPropertyId, NO_LOCK, EMPTY );

Expand All @@ -619,7 +618,7 @@ public void readPropertyChainWithLongStringDynamicRecordsNotInUse()

markDynamicRecordsNotInUse( keyId, propertyChain.get( 1 ), propertyStore, 2 );

try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( chainStartId, NO_LOCK, EMPTY );

Expand Down Expand Up @@ -685,7 +684,7 @@ public void readPropertyChainWithLongArrayDynamicRecordsNotInUse()

markDynamicRecordsNotInUse( keyId, propertyChain.get( 1 ), propertyStore, 2 );

try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( chainStartId, NO_LOCK, EMPTY );

Expand Down Expand Up @@ -723,7 +722,7 @@ public void readPropertyValueWhenSomeLongArrayDynamicRecordsAreNotInUse()

private void verifyPropertyValue( String expectedValue, long recordId )
{
try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( recordId, NO_LOCK, EMPTY );
assertTrue( cursor.next() );
Expand All @@ -734,7 +733,7 @@ private void verifyPropertyValue( String expectedValue, long recordId )

private void verifyPropertyValue( byte[] expectedValue, long recordId )
{
try ( StorePropertyCursor cursor = newStorePropertyCursor( propertyStore ) )
try ( PropertyCursor cursor = newPropertyCursor( propertyStore ) )
{
cursor.init( recordId, NO_LOCK, EMPTY );
assertTrue( cursor.next() );
Expand Down Expand Up @@ -764,9 +763,9 @@ public static long firstIdOf( List<PropertyRecord> propertyChain )
return propertyChain.get( 0 ).getId();
}

private static StorePropertyCursor newStorePropertyCursor( PropertyStore propertyStore )
private static PropertyCursor newPropertyCursor( PropertyStore propertyStore )
{
return new StorePropertyCursor( propertyStore, ignored -> {} );
return new PropertyCursor( propertyStore, ignored -> {} );
}

private static List<PropertyRecord> createPropertyChain( PropertyStore store, int keyId,
Expand Down Expand Up @@ -876,7 +875,7 @@ private static void markDynamicRecordsNotInUse( int keyId, PropertyRecord record
updateRecord( store, record );
}

private static List<Object> asPropertyValuesList( StorePropertyCursor cursor )
private static List<Object> asPropertyValuesList( PropertyCursor cursor )
{
List<Object> values = new ArrayList<>();
while ( cursor.next() )
Expand Down

0 comments on commit 5dd935c

Please sign in to comment.