@Override protected void process( RelationshipRecord[] batch, BatchSender sender ) { RelationshipCountsProcessor processor = processor(); for ( RelationshipRecord record : batch ) { if ( record.inUse() ) { processor.process( record ); } } progressMonitor.progress( batch.length ); }
private Command visitRelationshipCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); RelationshipRecord before = readRelationshipRecord( id, channel ); if ( before == null ) { return null; } RelationshipRecord after = readRelationshipRecord( id, channel ); if ( after == null ) { return null; } if ( !before.inUse() && after.inUse() ) { after.setCreated(); } return new Command.RelationshipCommand( before, after ); }
private Command visitRelationshipCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); RelationshipRecord before = readRelationshipRecord( id, channel ); if ( before == null ) { return null; } RelationshipRecord after = readRelationshipRecord( id, channel ); if ( after == null ) { return null; } if ( !before.inUse() && after.inUse() ) { after.setCreated(); } return new Command.RelationshipCommand( before, after ); }
@Override public String toString() { return "Relationship[" + getId() + ",used=" + inUse() + ",source=" + firstNode + ",target=" + secondNode + ",type=" + type + (firstInFirstChain ? ",sCount=" : ",sPrev=") + firstPrevRel + ",sNext=" + firstNextRel + (firstInSecondChain ? ",tCount=" : ",tPrev=") + secondPrevRel + ",tNext=" + secondNextRel + ",prop=" + getNextProp() + ",secondaryUnitId=" + getSecondaryUnitId() + (firstInFirstChain ? ", sFirst" : ",!sFirst") + (firstInSecondChain ? ", tFirst" : ",!tFirst") + "]"; }
@Override protected void forkedProcess( int id, int processors, RelationshipRecord[] batch ) { int stride = forwards ? 1 : -1; int start = forwards ? 0 : batch.length - 1; int end = forwards ? batch.length : -1; int localChangeCount = 0; for ( int i = start; i != end; i += stride ) { RelationshipRecord item = batch[i]; if ( item != null && item.inUse() ) { int changeCount = process( item, id, processors ); if ( changeCount == -1 ) { // No change for this record, it's OK, all the processors will reach the same conclusion batch[i].setInUse( false ); } else { localChangeCount += changeCount; } } } progress.add( localChangeCount ); }
@Override public RelationshipRecord clone() { RelationshipRecord record = new RelationshipRecord( getId() ).initialize( inUse(), nextProp, firstNode, secondNode, type, firstPrevRel, firstNextRel, secondPrevRel, secondNextRel, firstInFirstChain, firstInSecondChain ); record.setSecondaryUnitId( getSecondaryUnitId() ); return record; }
@Override protected void forkedProcess( int id, int processors, RelationshipRecord[] batch ) { for ( RelationshipRecord record : batch ) { if ( record.inUse() ) { long startNodeId = record.getFirstNode(); long endNodeId = record.getSecondNode(); processNodeId( id, processors, startNodeId ); if ( startNodeId != endNodeId ) // avoid counting loops twice { // Loops only counts as one processNodeId( id, processors, endNodeId ); } } } }
@Override public void checkReference( RECORD record, RelationshipRecord relationshipRecord, CheckerEngine<RECORD,REPORT> engine, RecordAccess records ) { if ( relationshipRecord.inUse() ) { // Relationship indexes are always semantically multi-token, which means that the relationship record just need to have one of the possible // relationship types mentioned by the index. Relationships can't have more than one type anyway. long type = relationshipRecord.getType(); if ( Arrays.binarySearch( indexRelationshipTypes, type ) < 0 ) { // The relationship did not have any of the relationship types mentioned by the index. for ( long indexRelationshipType : indexRelationshipTypes ) { engine.report().relationshipDoesNotHaveExpectedRelationshipType( relationshipRecord, indexRelationshipType ); } } } else { engine.report().relationshipNotInUse( relationshipRecord ); } } }
@Override public <EXCEPTION extends Exception> void relationshipVisit( long relationshipId, RelationshipVisitor<EXCEPTION> relationshipVisitor ) throws EntityNotFoundException, EXCEPTION { // TODO Please don't create a record for this, it's ridiculous RelationshipRecord record = relationshipStore.getRecord( relationshipId, relationshipStore.newRecord(), CHECK ); if ( !record.inUse() ) { throw new EntityNotFoundException( EntityType.RELATIONSHIP, relationshipId ); } relationshipVisitor.visit( relationshipId, record.getType(), record.getFirstNode(), record.getSecondNode() ); }
@Override public void checkReference( RelationshipGroupRecord record, RelationshipRecord referred, CheckerEngine<RelationshipGroupRecord, RelationshipGroupConsistencyReport> engine, RecordAccess records ) { if ( !referred.inUse() ) { relationshipNotInUse( engine.report() ); } else { if ( !isFirstInChain( referred ) ) { relationshipNotFirstInChain( engine.report() ); } if ( referred.getType() != record.getType() ) { relationshipOfOtherType( engine.report() ); } } }
private RecordSet<RelationshipRecord> expandChain( RelationshipRecord record, long nodeId, RelationshipChainDirection direction ) { RecordSet<RelationshipRecord> chain = new RecordSet<>(); chain.add( record ); RelationshipRecord currentRecord = record; long nextRelId = direction.fieldFor( nodeId, currentRecord ).relOf( currentRecord ); while ( currentRecord.inUse() && !direction.fieldFor( nodeId, currentRecord ).endOfChain( currentRecord ) ) { currentRecord = recordStore.getRecord( nextRelId, recordStore.newRecord(), FORCE ); chain.add( currentRecord ); nextRelId = direction.fieldFor( nodeId, currentRecord ).relOf( currentRecord ); } return chain; } }
@Override protected void assertRecordsEqual( RelationshipRecord actualRecord, RelationshipRecord expectedRecord ) { assertNotNull( "actualRecord", actualRecord ); assertNotNull( "expectedRecord", expectedRecord ); assertThat( "getFirstNextRel", actualRecord.getFirstNextRel(), is( expectedRecord.getFirstNextRel() ) ); assertThat( "getFirstNode", actualRecord.getFirstNode(), is( expectedRecord.getFirstNode() ) ); assertThat( "getFirstPrevRel", actualRecord.getFirstPrevRel(), is( expectedRecord.getFirstPrevRel() ) ); assertThat( "getSecondNextRel", actualRecord.getSecondNextRel(), is( expectedRecord.getSecondNextRel() ) ); assertThat( "getSecondNode", actualRecord.getSecondNode(), is( expectedRecord.getSecondNode() ) ); assertThat( "getSecondPrevRel", actualRecord.getSecondPrevRel(), is( expectedRecord.getSecondPrevRel() ) ); assertThat( "getType", actualRecord.getType(), is( expectedRecord.getType() ) ); assertThat( "isFirstInFirstChain", actualRecord.isFirstInFirstChain(), is( expectedRecord.isFirstInFirstChain() ) ); assertThat( "isFirstInSecondChain", actualRecord.isFirstInSecondChain(), is( expectedRecord.isFirstInSecondChain() ) ); assertThat( "getId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "getLongId", actualRecord.getId(), is( expectedRecord.getId() ) ); assertThat( "getNextProp", actualRecord.getNextProp(), is( expectedRecord.getNextProp() ) ); assertThat( "inUse", actualRecord.inUse(), is( expectedRecord.inUse() ) ); }
RecordAccess records ) if ( !relationship.inUse() )
private static void breakTheChain( RecordStore<RelationshipRecord> relationshipStore ) { RelationshipRecord record = relationshipStore.getRecord( 10, relationshipStore.newRecord(), NORMAL ); long relationshipTowardsEndOfChain = record.getFirstNode(); while ( record.inUse() && !record.isFirstInFirstChain() ) { record = relationshipStore.getRecord( relationshipTowardsEndOfChain, relationshipStore.newRecord(), FORCE ); relationshipTowardsEndOfChain = record.getFirstPrevRel(); } relationshipStore.updateRecord( new RelationshipRecord( relationshipTowardsEndOfChain, 0, 0, 0 ) ); }
private void writeRelationshipRecord( WritableChannel channel, RelationshipRecord record ) throws IOException { byte flags = bitFlags( bitFlag( record.inUse(), Record.IN_USE.byteValue() ), bitFlag( record.isCreated(), Record.CREATED_IN_TX ), bitFlag( record.requiresSecondaryUnit(), Record.REQUIRE_SECONDARY_UNIT ), bitFlag( record.hasSecondaryUnitId(), Record.HAS_SECONDARY_UNIT ), bitFlag( record.isUseFixedReferences(), Record.USES_FIXED_REFERENCE_FORMAT ) ); channel.put( flags ); if ( record.inUse() ) { channel.putLong( record.getFirstNode() ).putLong( record.getSecondNode() ).putInt( record.getType() ) .putLong( record.getFirstPrevRel() ).putLong( record.getFirstNextRel() ) .putLong( record.getSecondPrevRel() ).putLong( record.getSecondNextRel() ) .putLong( record.getNextProp() ) .put( (byte) ((record.isFirstInFirstChain() ? 1 : 0) | (record.isFirstInSecondChain() ? 2 : 0)) ); if ( record.hasSecondaryUnitId() ) { channel.putLong( record.getSecondaryUnitId() ); } } else { channel.putInt( record.getType() ); } } }
if ( record.inUse() )
if ( !referenceShouldBeSkipped( record, referred.getId(), records ) && !referred.inUse() )
@Override public void endOfEntity() if ( relationshipRecord.inUse() && relationshipRecord.getFirstNode() != ID_NOT_FOUND && relationshipRecord.getSecondNode() != ID_NOT_FOUND &&
RecordAccess records ) if ( !relationship.inUse() )