@Override public long valueFrom( RelationshipGroupRecord record ) { return record.getOwningNode(); } }
@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { for ( RelationshipGroupRecord record : batch ) { if ( record.inUse() ) { cache.incrementGroupCount( record.getOwningNode() ); } } } }
@Override public void checkConsistency( RelationshipGroupRecord record, CheckerEngine<RelationshipGroupRecord, RelationshipGroupConsistencyReport> engine, RecordAccess records ) { if ( record.getOwningNode() < 0 ) { engine.report().illegalOwner(); } else { engine.comparativeCheck( records.node( record.getOwningNode() ), this ); } }
@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { long lastOwningNode = lastBatchLastOwningNode; for ( RelationshipGroupRecord record : batch ) { assertTrue( record.getOwningNode() >= lastOwningNode ); assertTrue( record.getOwningNode() > lastBatchLastOwningNode ); } processCounter.incrementAndGet(); if ( batch.length > 0 ) { lastBatchLastOwningNode = batch[batch.length - 1].getOwningNode(); } } }
lastOwner = item.getOwningNode(); if ( item.getOwningNode() != lastOwner )
@Override public String toString() { return "RelationshipGroup[" + getId() + ",type=" + type + ",out=" + firstOut + ",in=" + firstIn + ",loop=" + firstLoop + ",prev=" + prev + ",next=" + next + ",used=" + inUse() + ",owner=" + getOwningNode() + ",secondaryUnitId=" + getSecondaryUnitId() + "]"; }
@Override public void checkReference( RelationshipGroupRecord record, RelationshipGroupRecord referred, CheckerEngine<RelationshipGroupRecord, RelationshipGroupConsistencyReport> engine, RecordAccess records ) { if ( !referred.inUse() ) { engine.report().nextGroupNotInUse(); } else { if ( record.getType() >= referred.getType() ) { engine.report().invalidTypeSortOrder(); } if ( record.getOwningNode() != referred.getOwningNode() ) { engine.report().nextHasOtherOwner( referred ); } } } }
@Override public void checkReference( NodeRecord record, RelationshipGroupRecord group, CheckerEngine<NodeRecord, NodeConsistencyReport> engine, RecordAccess records ) { if ( !group.inUse() ) { engine.report().relationshipGroupNotInUse( group ); } else { if ( group.getOwningNode() != record.getId() ) { engine.report().relationshipGroupHasOtherOwner( group ); } } } }
private void assertBatch( RelationshipGroupRecord[] batch, long lastOwningNodeLastBatch ) { for ( int i = 0; i < batch.length; i++ ) { RelationshipGroupRecord record = batch[i]; assertTrue( record.getId() > Record.NULL_REFERENCE.longValue() ); assertTrue( record.getOwningNode() > lastOwningNodeLastBatch ); assertEquals( 1, record.getFirstOut() ); // the mark our store mock sets when preparing if ( record.getNext() == Record.NULL_REFERENCE.longValue() ) { // This is the last in the chain, verify that this is either: assertTrue( // - the last one in the batch, or i == batch.length - 1 || // - the last one for this node batch[i + 1].getOwningNode() > record.getOwningNode() ); } } }
@Override protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { for ( RelationshipGroupRecord group : batch ) { if ( !group.inUse() ) { continue; } long nodeId = group.getOwningNode(); if ( cache.getByte( nodeId, 0 ) == 0 ) { cache.setByte( nodeId, 0, (byte) 1 ); NodeRecord nodeRecord = nodeStore.newRecord(); nodeStore.getRecordByCursor( nodeId, nodeRecord, NORMAL, nodeCursor ); nodeRecord.setNextRel( group.getId() ); nodeRecord.setDense( true ); current[cursor++] = nodeRecord; if ( cursor == batchSize ) { sender.send( current ); newBatch(); } } } control.recycle( batch ); }
private String diff( RelationshipGroupRecord expected, RelationshipGroupRecord actual ) { if ( actual.getId() == expected.getId() && actual.getType() == expected.getType() && actual.getNext() == expected.getNext() && actual.getFirstOut() == expected.getFirstOut() && actual.getFirstIn() == expected.getFirstIn() && actual.getFirstLoop() == expected.getFirstLoop() && actual.getOwningNode() == expected.getOwningNode() ) { return null; } return describeDiff( expected.toString(), actual.toString() ); }
lastOwningNodeLastBatch = batch[batch.length - 1].getOwningNode();
@Override public RecordKey<RelationshipGroupRecord> relationshipGroup() { return ( written, read ) -> { assertEquals( written.getType(), read.getType() ); assertEquals( written.getFirstOut(), read.getFirstOut() ); assertEquals( written.getFirstIn(), read.getFirstIn() ); assertEquals( written.getFirstLoop(), read.getFirstLoop() ); assertEquals( written.getNext(), read.getNext() ); assertEquals( written.getOwningNode(), read.getOwningNode() ); }; }
/** * Caches a relationship group into this cache, it will be cached if the * {@link RelationshipGroupRecord#getOwningNode() owner} is within the {@link #prepare(long) prepared} range, * where {@code true} will be returned, otherwise {@code false}. * * @param groupRecord {@link RelationshipGroupRecord} to cache. * @return whether or not the group was cached, i.e. whether or not it was within the prepared range. */ public boolean put( RelationshipGroupRecord groupRecord ) { long nodeId = groupRecord.getOwningNode(); assert nodeId < highNodeId; if ( nodeId < fromNodeId || nodeId >= toNodeId ) { return false; } long baseIndex = offsets.get( rebase( nodeId ) ); // grouCount is extra validation, really int groupCount = groupCount( nodeId ); long index = scanForFreeFrom( baseIndex, groupCount, groupRecord.getType(), nodeId ); // Put the group at this index cache.setByte( index, 0, (byte) 1 ); cache.set3ByteInt( index, 1, groupRecord.getType() ); cache.set6ByteLong( index, 1 + 3, groupRecord.getFirstOut() ); cache.set6ByteLong( index, 1 + 3 + 6, groupRecord.getFirstIn() ); cache.set6ByteLong( index, 1 + 3 + 6 + 6, groupRecord.getFirstLoop() ); return true; }
cursor.putInt( (int) record.getFirstIn() ); cursor.putInt( (int) record.getFirstLoop() ); cursor.putInt( (int) record.getOwningNode() ); cursor.putByte( (byte) (record.getOwningNode() >> 32) );
for ( RelationshipGroupRecord group : cache ) assertTrue( group.getOwningNode() >= currentNodeId ); if ( group.getOwningNode() > currentNodeId ) currentNodeId = group.getOwningNode(); currentTypeId = -1;
for ( RelationshipGroupRecord cachedGroup : cache ) assertTrue( cachedGroup.getOwningNode() >= 0 && cachedGroup.getOwningNode() < toNodeId ); readCount++;
private void writeRelationshipGroupRecord( WritableChannel channel, RelationshipGroupRecord record ) throws IOException { byte flags = bitFlags( bitFlag( record.inUse(), Record.IN_USE.byteValue() ), 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 ); channel.putShort( (short) record.getType() ); channel.putLong( record.getNext() ); channel.putLong( record.getFirstOut() ); channel.putLong( record.getFirstIn() ); channel.putLong( record.getFirstLoop() ); channel.putLong( record.getOwningNode() ); if ( record.hasSecondaryUnitId() ) { channel.putLong( record.getSecondaryUnitId() ); } } }
private static void assertValidRelGroupCommand( StorageCommand command ) { assertThat( command, instanceOf( RelationshipGroupCommand.class ) ); RelationshipGroupCommand relGroupCommand = (RelationshipGroupCommand) command; RelationshipGroupRecord record = relGroupCommand.getAfter(); assertEquals( ID, record.getId() ); if ( IN_USE_FLAG == Record.IN_USE.byteValue() ) { assertTrue( record.inUse() ); } else if ( IN_USE_FLAG == Record.NOT_IN_USE.byteValue() ) { assertFalse( record.inUse() ); } else { throw new IllegalStateException( "Illegal inUse flag: " + IN_USE_FLAG ); } assertEquals( TYPE_AS_INT, record.getType() ); assertEquals( NEXT, record.getNext() ); assertEquals( FIRST_OUT, record.getFirstOut() ); assertEquals( FIRST_IN, record.getFirstIn() ); assertEquals( FIRST_LOOP, record.getNext() ); assertEquals( OWNING_NODE, record.getOwningNode() ); }
long nodeId = groupRecord.getOwningNode(); assertTrue( "Expected a group for node >= " + currentNodeId + ", but was " + nodeId + " in " + groupRecord,