@Override void set( RelationshipRecord rel, long id, boolean isFirst ) { rel.setFirstPrevRel( id ); rel.setFirstInFirstChain( isFirst ); }
public static Consumer<RelationshipRecord> sPrev( long id ) { return n -> { n.setFirstInFirstChain( false ); n.setFirstPrevRel( id ); }; }
public static Consumer<RelationshipRecord> sCount( long count ) { return n -> { n.setFirstInFirstChain( true ); n.setFirstPrevRel( count ); }; }
@Override RelationshipRecord populateRelationshipFromCache( long nodeId, RelationshipRecord rel, CacheAccess.Client cacheAccess ) { if ( cacheAccess.getFromCache( nodeId, SLOT_SOURCE_OR_TARGET ) == SOURCE ) { rel.setFirstPrevRel( cacheAccess.getFromCache( nodeId, SLOT_REFERENCE ) ); } else { rel.setSecondPrevRel( cacheAccess.getFromCache( nodeId, SLOT_REFERENCE ) ); } rel.setInUse( cacheAccess.getBooleanFromCache( nodeId, SLOT_IN_USE ) ); return rel; }
@Override RelationshipRecord populateRelationshipFromCache( long nodeId, RelationshipRecord rel, CacheAccess.Client cacheAccess ) { if ( cacheAccess.getFromCache( nodeId, SLOT_SOURCE_OR_TARGET ) == SOURCE ) { rel.setFirstPrevRel( cacheAccess.getFromCache( nodeId, SLOT_REFERENCE ) ); } else { rel.setSecondPrevRel( cacheAccess.getFromCache( nodeId, SLOT_REFERENCE ) ); } rel.setInUse( cacheAccess.getBooleanFromCache( nodeId, SLOT_IN_USE ) ); return rel; }
protected static RelationshipRecord firstInChains( RelationshipRecord relationship, int count ) { relationship.setFirstInFirstChain( true ); relationship.setFirstPrevRel( count ); relationship.setFirstInSecondChain( true ); relationship.setSecondPrevRel( count ); return relationship; }
private RelationshipRecord withPrev( RelationshipRecord relationship, long prev ) { relationship.setFirstInFirstChain( false ); relationship.setFirstInSecondChain( false ); relationship.setFirstPrevRel( prev ); relationship.setSecondPrevRel( prev ); return relationship; }
@Override protected void linkStart( RelationshipRecord record ) { int typeId = record.getType(); long firstPrevRel = cache.getAndPutRelationship( record.getFirstNode(), typeId, Direction.OUTGOING, record.getId(), false ); if ( firstPrevRel == ID_NOT_FOUND ) { // First one record.setFirstInFirstChain( true ); firstPrevRel = cache.getCount( record.getFirstNode(), typeId, Direction.OUTGOING ); } record.setFirstPrevRel( firstPrevRel ); }
@Override protected void linkLoop( RelationshipRecord record ) { int typeId = record.getType(); long prevRel = cache.getAndPutRelationship( record.getFirstNode(), typeId, Direction.BOTH, record.getId(), false ); if ( prevRel == ID_NOT_FOUND ) { // First one record.setFirstInFirstChain( true ); record.setFirstInSecondChain( true ); prevRel = cache.getCount( record.getFirstNode(), typeId, Direction.BOTH ); } record.setFirstPrevRel( prevRel ); record.setSecondPrevRel( prevRel ); } }
@Test void shouldReportLoopRelationshipNotFirstInTargetAndSourceChains() { // given NodeRecord node = inUse( new NodeRecord( 42, false, 7, NONE ) ); RelationshipRecord relationship = add( inUse( new RelationshipRecord( 7, 42, 42, 0 ) ) ); relationship.setFirstPrevRel( 8 ); relationship.setFirstInFirstChain( false ); relationship.setSecondPrevRel( 8 ); relationship.setFirstInSecondChain( false ); // when ConsistencyReport.NodeConsistencyReport report = check( node ); // then verify( report ).relationshipNotFirstInSourceChain( relationship ); verify( report ).relationshipNotFirstInTargetChain( relationship ); verifyNoMoreInteractions( report ); }
@Test void shouldReportRelationshipNotFirstInSourceChain() { // given NodeRecord node = inUse( new NodeRecord( 42, false, 7, NONE ) ); RelationshipRecord relationship = add( inUse( new RelationshipRecord( 7, 42, 0, 0 ) ) ); relationship.setFirstPrevRel( 6 ); relationship.setFirstInFirstChain( false ); relationship.setSecondPrevRel( 8 ); relationship.setFirstInSecondChain( false ); // when ConsistencyReport.NodeConsistencyReport report = check( node ); // then verify( report ).relationshipNotFirstInSourceChain( relationship ); verifyNoMoreInteractions( report ); }
@Test void shouldReportRelationshipNotFirstInTargetChain() { // given NodeRecord node = inUse( new NodeRecord( 42, false, 7, NONE ) ); RelationshipRecord relationship = add( inUse( new RelationshipRecord( 7, 0, 42, 0 ) ) ); relationship.setFirstPrevRel( 6 ); relationship.setFirstInFirstChain( false ); relationship.setSecondPrevRel( 8 ); relationship.setFirstInSecondChain( false ); // when ConsistencyReport.NodeConsistencyReport report = check( node ); // then verify( report ).relationshipNotFirstInTargetChain( relationship ); verifyNoMoreInteractions( report ); }
private void decrementTotalRelationshipCount( long nodeId, RelationshipRecord rel, long firstRelId, RecordAccess<RelationshipRecord, Void> relRecords, ResourceLocker locks ) { if ( firstRelId == Record.NO_PREV_RELATIONSHIP.intValue() ) { return; } boolean firstInChain = relIsFirstInChain( nodeId, rel ); if ( !firstInChain ) { locks.acquireExclusive( LockTracer.NONE, ResourceTypes.RELATIONSHIP, firstRelId ); } RelationshipRecord firstRel = relRecords.getOrLoad( firstRelId, null ).forChangingLinkage(); if ( nodeId == firstRel.getFirstNode() ) { firstRel.setFirstPrevRel( firstInChain ? relCount( nodeId, rel ) - 1 : relCount( nodeId, firstRel ) - 1 ); firstRel.setFirstInFirstChain( true ); } if ( nodeId == firstRel.getSecondNode() ) { firstRel.setSecondPrevRel( firstInChain ? relCount( nodeId, rel ) - 1 : relCount( nodeId, firstRel ) - 1 ); firstRel.setFirstInSecondChain( true ); } }
@Test void shouldReportSourcePrevReferencingOtherNodes() { // given RelationshipRecord relationship = inUse( new RelationshipRecord( 42, 1, 2, 4 ) ); add( inUse( new RelationshipTypeTokenRecord( 4 ) ) ); add( inUse( new NodeRecord( 1, false, 0, NONE ) ) ); add( inUse( new NodeRecord( 2, false, 42, NONE ) ) ); RelationshipRecord sPrev = add( inUse( new RelationshipRecord( 51, 8, 9, 0 ) ) ); relationship.setFirstPrevRel( sPrev.getId() ); relationship.setFirstInFirstChain( false ); // when RelationshipConsistencyReport report = check( relationship ); // then verify( report ).sourcePrevReferencesOtherNodes( sPrev ); verifyNoMoreInteractions( report ); }
@Test void shouldReportSourcePrevNotReferencingBack() { // given RelationshipRecord relationship = inUse( new RelationshipRecord( 42, 1, 2, 4 ) ); add( inUse( new RelationshipTypeTokenRecord( 4 ) ) ); add( inUse( new NodeRecord( 1, false, 0, NONE ) ) ); add( inUse( new NodeRecord( 2, false, 42, NONE ) ) ); RelationshipRecord sPrev = add( inUse( new RelationshipRecord( 51, 1, 3, 0 ) ) ); relationship.setFirstPrevRel( sPrev.getId() ); relationship.setFirstInFirstChain( false ); // when RelationshipConsistencyReport report = check( relationship ); // then verify( report ).sourcePrevDoesNotReferenceBack( sPrev ); verifyNoMoreInteractions( report ); }
@Test void shouldReportSourcePrevReferencingOtherNodesWhenReferencingTargetNode() { // given RelationshipRecord relationship = inUse( new RelationshipRecord( 42, 1, 2, 4 ) ); add( inUse( new RelationshipTypeTokenRecord( 4 ) ) ); add( inUse( new NodeRecord( 1, false, 0, NONE ) ) ); add( inUse( new NodeRecord( 2, false, 42, NONE ) ) ); RelationshipRecord sPrev = add( inUse( new RelationshipRecord( 51, 2, 0, 0 ) ) ); relationship.setFirstPrevRel( sPrev.getId() ); relationship.setFirstInFirstChain( false ); // when RelationshipConsistencyReport report = check( relationship ); // then verify( report ).sourcePrevReferencesOtherNodes( sPrev ); verifyNoMoreInteractions( report ); }
private Sabotage sabotage( RelationshipStore store, long id ) { RelationshipRecord before = store.getRecord( id, store.newRecord(), RecordLoad.NORMAL ); RelationshipRecord after = before.clone(); long otherReference; if ( !after.isFirstInFirstChain() ) { after.setFirstPrevRel( otherReference = after.getFirstPrevRel() + 1 ); } else { after.setFirstNextRel( otherReference = after.getFirstNextRel() + 1 ); } store.prepareForCommit( after ); store.updateRecord( after ); RelationshipRecord other = store.getRecord( otherReference, store.newRecord(), RecordLoad.FORCE ); return new Sabotage( before, after, other ); } }
@Test void shouldReportSourceNodeWithoutChainForRelationshipInTheMiddleOfChain() { // given checkSingleDirection(); initialize( RELATIONSHIPS, NODES ); RelationshipRecord relationship = inUse( new RelationshipRecord( 42, 1, 2, 4 ) ); add( inUse( new RelationshipTypeTokenRecord( 4 ) ) ); NodeRecord source = add( inUse( new NodeRecord( 1, false, NONE, NONE ) ) ); add( inUse( new NodeRecord( 2, false, 42, NONE ) ) ); RelationshipRecord sPrev = add( inUse( new RelationshipRecord( 51, 1, 0, 0 ) ) ); relationship.setFirstPrevRel( sPrev.getId() ); relationship.setFirstInFirstChain( false ); sPrev.setFirstNextRel( relationship.getId() ); // when RelationshipConsistencyReport report = check( relationship ); // then verify( report ).sourceNodeHasNoRelationships( source ); verifyNoMoreInteractions( report ); }
record.setInUse( true ); record.setRequiresSecondaryUnit( requiresSecondaryUnit ); record.setFirstPrevRel( channel.getLong() ); record.setFirstNextRel( channel.getLong() ); record.setSecondPrevRel( channel.getLong() );
sNext.setFirstPrevRel( relationship.getId() ); sNext.setFirstInFirstChain( false ); relationship.setSecondNextRel( tNext.getId() ); tNext.setFirstPrevRel( relationship.getId() ); tNext.setFirstInFirstChain( false ); relationship.setSecondPrevRel( tPrev.getId() );