Skip to content

Commit

Permalink
Simplified store classes
Browse files Browse the repository at this point in the history
- RecordStore changed to only have one method for getting records,
  accepts a record instance to write into. RecordStore#newRecord()
  was added for creating records and to give clients full control over
  instantiation of those.
- RecordStore#newRecordCursor() added for allowing client to use one
  PageCursor over multiple records.
- CommonAbstractStore/AbstractStore was collapsed into AbstractRecordStore.
- AbstractRecordStore implements #getRecord(), no other store does,
  giving consistent behaviour over all stores.
- Each store mostly implements its format in read/WriteRecord,
  this could even be injected later on.
  • Loading branch information
tinwelint committed Feb 1, 2016
1 parent 2dafdd0 commit cab9968
Show file tree
Hide file tree
Showing 178 changed files with 2,599 additions and 2,689 deletions.
Expand Up @@ -165,7 +165,7 @@ public void checkIndexRule( IndexRule rule, DynamicRecord record, RecordAccess r

if ( rule.isConstraintIndex() && rule.getOwningConstraint() != null )
{
DynamicRecord previousObligation = constraintObligations.put( rule.getOwningConstraint(), record );
DynamicRecord previousObligation = constraintObligations.put( rule.getOwningConstraint(), record.clone() );
if ( previousObligation != null )
{
engine.report().duplicateObligation( previousObligation );
Expand All @@ -179,7 +179,7 @@ public void checkUniquenessConstraintRule( UniquePropertyConstraintRule rule, Dy
{
checkLabelAndPropertyRule( rule, rule.getPropertyKey(), record, records, engine );

DynamicRecord previousObligation = indexObligations.put( rule.getOwnedIndex(), record );
DynamicRecord previousObligation = indexObligations.put( rule.getOwnedIndex(), record.clone() );
if ( previousObligation != null )
{
engine.report().duplicateObligation( previousObligation );
Expand Down Expand Up @@ -283,7 +283,7 @@ private void checkRelTypeAndPropertyRule( SchemaRule rule, int propertyKey, Dyna
private void checkForDuplicates( SchemaRule rule, DynamicRecord record,
CheckerEngine<DynamicRecord,ConsistencyReport.SchemaConsistencyReport> engine )
{
DynamicRecord previousContentRecord = verifiedRulesWithRecords.put( rule, record );
DynamicRecord previousContentRecord = verifiedRulesWithRecords.put( rule, record.clone() );
if ( previousContentRecord != null )
{
engine.report().duplicateRuleContent( previousContentRecord );
Expand Down
Expand Up @@ -48,6 +48,7 @@

import static org.neo4j.kernel.impl.store.counts.keys.CountsKeyFactory.nodeKey;
import static org.neo4j.kernel.impl.store.counts.keys.CountsKeyFactory.relationshipKey;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;
import static org.neo4j.legacy.consistency.checking.full.NodeLabelReader.getListOfLabels;

class CountsBuilderDecorator extends CheckDecorator.Adapter
Expand Down Expand Up @@ -338,6 +339,6 @@ private static Set<Long> labelsFor( NodeStore nodeStore,
RecordAccess recordAccess,
long nodeId )
{
return getListOfLabels( nodeStore.forceGetRecord( nodeId ), recordAccess, engine );
return getListOfLabels( nodeStore.getRecord( nodeId, nodeStore.newRecord(), FORCE ), recordAccess, engine );
}
}
Expand Up @@ -47,6 +47,8 @@
import org.neo4j.legacy.consistency.store.DirectRecordAccess;
import org.neo4j.logging.Log;

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

public class FullCheck
{
private final boolean checkPropertyOwners;
Expand Down Expand Up @@ -161,7 +163,7 @@ private static <T extends AbstractBaseRecord> T[] readAllRecords( Class<T> type,
T[] records = (T[]) Array.newInstance( type, (int) store.getHighId() );
for ( int i = 0; i < records.length; i++ )
{
records[i] = store.forceGetRecord( i );
records[i] = store.getRecord( i, store.newRecord(), FORCE );
}
return records;
}
Expand Down
Expand Up @@ -27,13 +27,14 @@
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.api.properties.Property;
import org.neo4j.kernel.impl.store.InvalidRecordException;
import org.neo4j.kernel.impl.store.NodeStore;
import org.neo4j.kernel.impl.store.PropertyStore;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PropertyBlock;
import org.neo4j.kernel.impl.store.record.PropertyRecord;

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

public class PropertyReader implements PropertyAccessor
{
private final PropertyStore propertyStore;
Expand Down Expand Up @@ -67,9 +68,9 @@ public DefinedProperty propertyValue( PropertyBlock block )
@Override
public Property getProperty( long nodeId, int propertyKeyId )
{
try
NodeRecord nodeRecord = nodeStore.getRecord( nodeId, nodeStore.newRecord(), FORCE );
if ( nodeRecord.inUse() )
{
NodeRecord nodeRecord = nodeStore.getRecord( nodeId );
for ( PropertyBlock block : propertyBlocks( nodeRecord ) )
{
if ( block.getKeyIndexId() == propertyKeyId )
Expand All @@ -78,11 +79,6 @@ public Property getProperty( long nodeId, int propertyKeyId )
}
}
}
catch ( InvalidRecordException e )
{
// Fine, we'll just return an empty property below
}

return Property.noNodeProperty( nodeId, propertyKeyId );
}
}
Expand Up @@ -23,6 +23,8 @@
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;

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

public class OwningNodeRelationshipChain
{
private final RelationshipChainExplorer relationshipChainExplorer;
Expand All @@ -42,11 +44,9 @@ public RecordSet<RelationshipRecord> findRelationshipChainsThatThisRecordShouldB
for ( RelationshipNodeField field : RelationshipNodeField.values() )
{
long nodeId = field.get( relationship );
NodeRecord nodeRecord = nodeStore.forceGetRecord( nodeId );
NodeRecord nodeRecord = nodeStore.getRecord( nodeId, nodeStore.newRecord(), FORCE );
records.addAll( relationshipChainExplorer.followChainFromNode( nodeId, nodeRecord.getNextRel() ) );
}
return records;
}


}
Expand Up @@ -22,6 +22,8 @@
import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;

import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;
import static org.neo4j.legacy.consistency.repair.RelationshipChainDirection.NEXT;
import static org.neo4j.legacy.consistency.repair.RelationshipChainDirection.PREV;

Expand Down Expand Up @@ -63,7 +65,7 @@ private RecordSet<RelationshipRecord> expandChainInBothDirections( RelationshipR

protected RecordSet<RelationshipRecord> followChainFromNode(long nodeId, long relationshipId )
{
RelationshipRecord record = recordStore.getRecord( relationshipId );
RelationshipRecord record = recordStore.getRecord( relationshipId, recordStore.newRecord(), NORMAL );
return expandChain( record, nodeId, NEXT );
}

Expand All @@ -76,7 +78,7 @@ private RecordSet<RelationshipRecord> expandChain( RelationshipRecord record, lo
long nextRelId = direction.fieldFor( nodeId, currentRecord ).relOf( currentRecord );
while ( currentRecord.inUse() && !direction.fieldFor( nodeId, currentRecord ).endOfChain( currentRecord ) )
{
currentRecord = recordStore.forceGetRecord( nextRelId );
currentRecord = recordStore.getRecord( nextRelId, recordStore.newRecord(), FORCE );
chain.add( currentRecord );
nextRelId = direction.fieldFor( nodeId, currentRecord ).relOf( currentRecord );
}
Expand Down
Expand Up @@ -32,6 +32,8 @@
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord;

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

public class DirectRecordAccess implements DiffRecordAccess
{
final StoreAccess access;
Expand Down Expand Up @@ -127,7 +129,7 @@ public RecordReference<DynamicRecord> propertyKeyName( int id )

<RECORD extends AbstractBaseRecord> RecordReference<RECORD> referenceTo( RecordStore<RECORD> store, long id )
{
return new DirectRecordReference<>( store.forceGetRecord( id ), this );
return new DirectRecordReference<>( store.getRecord( id, store.newRecord(), FORCE ), this );
}

@Override
Expand Down
Expand Up @@ -32,8 +32,8 @@
*/
public class CountsEntry extends AbstractBaseRecord
{
private final CountsKey key;
private final long count;
private CountsKey key;
private long count;

public CountsEntry( CountsKey key, long count )
{
Expand All @@ -42,6 +42,14 @@ public CountsEntry( CountsKey key, long count )
setInUse( true );
}

@Override
public void clear()
{
super.clear();
key = null;
count = 0;
}

@Override
public String toString()
{
Expand All @@ -54,6 +62,12 @@ public long getLongId()
throw new UnsupportedOperationException();
}

@Override
public void setId( long id )
{
throw new UnsupportedOperationException();
}

public CountsKey getCountsKey()
{
return key;
Expand Down
Expand Up @@ -30,7 +30,13 @@ public class IndexEntry extends Abstract64BitRecord
public IndexEntry( long nodeId )
{
super( nodeId );
setInUse( true );
initialize( true );
}

@Override
public void clear()
{
initialize( false );
}

@Override
Expand Down
Expand Up @@ -28,13 +28,20 @@
*/
public class LabelScanDocument extends Abstract64BitRecord
{
private final NodeLabelRange nodeLabelRange;
private NodeLabelRange nodeLabelRange;

public LabelScanDocument( NodeLabelRange nodeLabelRange )
{
super( nodeLabelRange.id() );
initialize( true );
this.nodeLabelRange = nodeLabelRange;
setInUse( true );
}

@Override
public void clear()
{
initialize( false );
this.nodeLabelRange = null;
}

public NodeLabelRange getNodeLabelRange()
Expand Down
Expand Up @@ -330,8 +330,8 @@ public static RecordStore<DynamicRecord> configureDynamicStore( int blockSize )
{
@SuppressWarnings( "unchecked" )
RecordStore<DynamicRecord> mock = mock( RecordStore.class );
when( mock.getRecordSize() ).thenReturn( blockSize + AbstractDynamicStore.BLOCK_HEADER_SIZE );
when( mock.getRecordHeaderSize() ).thenReturn( AbstractDynamicStore.BLOCK_HEADER_SIZE );
when( mock.getRecordSize() ).thenReturn( blockSize + AbstractDynamicStore.RECORD_HEADER_SIZE );
when( mock.getRecordHeaderSize() ).thenReturn( AbstractDynamicStore.RECORD_HEADER_SIZE );
return mock;
}
}
Expand Up @@ -99,7 +99,7 @@ public void shouldReportRelationshipNotInUse() throws Exception
{
// given
NodeRecord node = inUse( new NodeRecord( 42, false, 7, 11 ) );
RelationshipRecord relationship = add( notInUse( new RelationshipRecord( 7, 0, 0, 0 ) ) );
RelationshipRecord relationship = add( new RelationshipRecord( 7, 0, 0, 0 ) );
add( inUse( new PropertyRecord( 11 ) ) );

// when
Expand Down
Expand Up @@ -122,6 +122,8 @@
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_PROPERTY;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.Record.NO_PREV_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;
import static org.neo4j.kernel.impl.store.record.RelationshipPropertyExistenceConstraintRule.relPropertyExistenceConstraintRule;
import static org.neo4j.kernel.impl.util.Bits.bits;
import static org.neo4j.legacy.consistency.checking.RecordCheckTestBase.inUse;
Expand Down Expand Up @@ -402,7 +404,7 @@ public void shouldReportIndexInconsistencies() throws Exception
// given
for ( Long indexedNodeId : indexedNodes )
{
fixture.directStoreAccess().nativeStores().getNodeStore().forceUpdateRecord(
fixture.directStoreAccess().nativeStores().getNodeStore().updateRecord(
notInUse( new NodeRecord( indexedNodeId, false, -1, -1 ) ) );
}

Expand Down Expand Up @@ -442,7 +444,7 @@ public void shouldNotReportIndexInconsistenciesIfIndexIsFailed() throws Exceptio

for ( Long indexedNodeId : indexedNodes )
{
storeAccess.nativeStores().getNodeStore().forceUpdateRecord(
storeAccess.nativeStores().getNodeStore().updateRecord(
notInUse( new NodeRecord( indexedNodeId, false, -1, -1 ) ) );
}

Expand Down Expand Up @@ -1100,7 +1102,8 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
}
} );
StoreAccess access = fixture.directStoreAccess().nativeStores();
DynamicRecord record = access.getRelationshipTypeNameStore().forceGetRecord( inconsistentName.get() );
DynamicRecord record = access.getRelationshipTypeNameStore().getRecord( inconsistentName.get(),
access.getRelationshipTypeNameStore().newRecord(), FORCE );
record.setNextBlock( record.getId() );
access.getRelationshipTypeNameStore().updateRecord( record );

Expand Down Expand Up @@ -1128,7 +1131,8 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
}
} );
StoreAccess access = fixture.directStoreAccess().nativeStores();
DynamicRecord record = access.getPropertyKeyNameStore().forceGetRecord( inconsistentName.get()+1 );
DynamicRecord record = access.getPropertyKeyNameStore().getRecord( inconsistentName.get()+1,
access.getPropertyKeyNameStore().newRecord(), NORMAL );
record.setNextBlock( record.getId() );
access.getPropertyKeyNameStore().updateRecord( record );

Expand All @@ -1146,7 +1150,8 @@ public void shouldReportRelationshipTypeInconsistencies() throws Exception
// given
StoreAccess access = fixture.directStoreAccess().nativeStores();
RecordStore<RelationshipTypeTokenRecord> relTypeStore = access.getRelationshipTypeTokenStore();
RelationshipTypeTokenRecord record = relTypeStore.forceGetRecord( (int) relTypeStore.nextId() );
RelationshipTypeTokenRecord record = relTypeStore.getRecord( (int) relTypeStore.nextId(),
relTypeStore.newRecord(), FORCE );
record.setNameId( 20 );
record.setInUse( true );
relTypeStore.updateRecord( record );
Expand All @@ -1165,7 +1170,8 @@ public void shouldReportLabelInconsistencies() throws Exception
{
// given
StoreAccess access = fixture.directStoreAccess().nativeStores();
LabelTokenRecord record = access.getLabelTokenStore().forceGetRecord( 1 );
LabelTokenRecord record = access.getLabelTokenStore().getRecord( 1,
access.getLabelTokenStore().newRecord(), FORCE );
record.setNameId( 20 );
record.setInUse( true );
access.getLabelTokenStore().updateRecord( record );
Expand Down Expand Up @@ -1194,7 +1200,8 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
}
} );
StoreAccess access = fixture.directStoreAccess().nativeStores();
DynamicRecord record = access.getPropertyKeyNameStore().forceGetRecord( inconsistentKey.get()+1 );
DynamicRecord record = access.getPropertyKeyNameStore().getRecord( inconsistentKey.get()+1,
access.getPropertyKeyNameStore().newRecord(), FORCE );
record.setInUse( false );
access.getPropertyKeyNameStore().updateRecord( record );

Expand Down

0 comments on commit cab9968

Please sign in to comment.