private Command visitRelationshipGroupCommand( ReadableChannel channel ) throws IOException { long id = channel.getLong(); byte inUseByte = channel.get(); boolean inUse = inUseByte == Record.IN_USE.byteValue(); if ( inUseByte != Record.IN_USE.byteValue() && inUseByte != Record.NOT_IN_USE.byteValue() ) { throw new IOException( "Illegal in use flag: " + inUseByte ); } int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); return new Command.RelationshipGroupCommand( null, record ); }
@Override public void write( RelationshipGroupRecord record, PageCursor cursor, int recordSize ) if ( record.inUse() ) long nextMod = record.getNext() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (record.getNext() & 0x700000000L) >> 31; long nextOutMod = record.getFirstOut() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (record.getFirstOut() & 0x700000000L) >> 28; long nextInMod = record.getFirstIn() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (record.getFirstIn() & 0x700000000L) >> 31; long nextLoopMod = record.getFirstLoop() == Record.NO_NEXT_RELATIONSHIP.intValue() ? 0 : (record.getFirstLoop() & 0x700000000L) >> 28; cursor.putShort( (short) record.getType() ); cursor.putInt( (int) record.getNext() ); cursor.putInt( (int) record.getFirstOut() ); cursor.putInt( (int) record.getFirstIn() ); cursor.putInt( (int) record.getFirstLoop() ); cursor.putInt( (int) record.getOwningNode() ); cursor.putByte( (byte) (record.getOwningNode() >> 32) );
@Override public RelationshipGroupRecord clone() { RelationshipGroupRecord clone = new RelationshipGroupRecord( getId() ).initialize( inUse(), type, firstOut, firstIn, firstLoop, owningNode, next ); clone.setSecondaryUnitId( getSecondaryUnitId() ); return clone; }
@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 protected void process( RelationshipGroupRecord[] batch, BatchSender sender ) { for ( RelationshipGroupRecord record : batch ) { if ( record.inUse() ) { cache.incrementGroupCount( record.getOwningNode() ); } } } }
private RelationshipGroupRecord readRelationshipGroupRecord( long id, ReadableChannel channel ) throws IOException { byte flags = channel.get(); boolean inUse = bitFlag( flags, Record.IN_USE.byteValue() ); boolean requireSecondaryUnit = bitFlag( flags, Record.REQUIRE_SECONDARY_UNIT ); boolean hasSecondaryUnit = bitFlag( flags, Record.HAS_SECONDARY_UNIT ); boolean usesFixedReferenceFormat = bitFlag( flags, Record.USES_FIXED_REFERENCE_FORMAT ); int type = unsignedShortToInt( channel.getShort() ); RelationshipGroupRecord record = new RelationshipGroupRecord( id, type ); record.setInUse( inUse ); record.setNext( channel.getLong() ); record.setFirstOut( channel.getLong() ); record.setFirstIn( channel.getLong() ); record.setFirstLoop( channel.getLong() ); record.setOwningNode( channel.getLong() ); record.setRequiresSecondaryUnit( requireSecondaryUnit ); if ( hasSecondaryUnit ) { record.setSecondaryUnitId( channel.getLong() ); } record.setUseFixedReferences( usesFixedReferenceFormat ); return record; }
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 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() ); }
change = relGroupRecords.create( id, type ); RelationshipGroupRecord record = change.forChangingData(); record.setInUse( true ); record.setCreated(); record.setOwningNode( node.getId() ); record.setNext( closestPrevious.getNext() ); record.setPrev( closestPrevious.getId() ); closestPrevious.setNext( id ); record.setNext( previousFirstRecord.getId() ); previousFirstRecord.setPrev( id );
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() ); }
public void delete( RelationshipGroupRecord group ) { group.setInUse( false ); add( group, new RelationshipGroupRecord( group.getId(), group.getType() ) ); }
public void create( RelationshipGroupRecord group ) { group.setCreated(); update( new RelationshipGroupRecord( group.getId(), group.getType() ), group ); }
RecordStore<RelationshipGroupRecord> groupStore = neoStores.getRelationshipGroupStore(); RelationshipGroupRecord groupRecord = getRecord( groupStore, group ); assertEquals( -1, groupRecord.getNext() ); assertEquals( -1, groupRecord.getPrev() ); assertRelationshipChain( neoStores.getRelationshipStore(), node, groupRecord.getFirstOut(), rel1.getId(), rel4.getId() ); assertRelationshipChain( neoStores.getRelationshipStore(), node, groupRecord.getFirstIn(), rel2.getId(), rel5.getId() ); assertRelationshipChain( neoStores.getRelationshipStore(), node, groupRecord.getFirstLoop(), rel3.getId(), rel6.getId() );
@Override public RelationshipGroupRecord newRecord() { return new RelationshipGroupRecord( -1 ); }
public static RelationshipGroupRecord relGroup( long id, Consumer<RelationshipGroupRecord>... modifiers ) { RelationshipGroupRecord record = new RelationshipGroupRecord( id ); record.initialize( true, 0, Record.NO_NEXT_RELATIONSHIP.longValue(), Record.NO_NEXT_RELATIONSHIP.longValue(), Record.NO_NEXT_RELATIONSHIP.longValue(), -1, Record.NO_NEXT_RELATIONSHIP.longValue() ); for ( Consumer<RelationshipGroupRecord> modifier : modifiers ) { modifier.accept( record ); } return record; }
if ( cache.put( new RelationshipGroupRecord( nodeId ) .initialize( true, typeId, -1, -1, -1, nodeId, -1 ) ) ) for ( RelationshipGroupRecord group : cache ) assertTrue( group.getOwningNode() >= currentNodeId ); if ( group.getOwningNode() > currentNodeId ) currentNodeId = group.getOwningNode(); currentTypeId = -1; assertTrue( group.getType() > currentTypeId ); readCount++;
@Test public void readRelationshipGroupCommandWithSecondaryUnit() throws IOException { // Given InMemoryClosableChannel channel = new InMemoryClosableChannel(); RelationshipGroupRecord before = new RelationshipGroupRecord( 42, 3 ); RelationshipGroupRecord after = new RelationshipGroupRecord( 42, 3, 4, 5, 6, 7, 8, true ); after.setRequiresSecondaryUnit( true ); after.setSecondaryUnitId( 17 ); after.setCreated(); new Command.RelationshipGroupCommand( before, after ).serialize( channel ); // When PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0(); Command command = reader.read( channel ); assertTrue( command instanceof Command.RelationshipGroupCommand); Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command; // Then assertEquals( before, relationshipGroupCommand.getBefore() ); assertEquals( after, relationshipGroupCommand.getAfter() ); verifySecondaryUnit( after, relationshipGroupCommand.getAfter() ); }
private void deleteGroup( RecordProxy<NodeRecord, Void> nodeChange, RelationshipGroupRecord group, RecordAccess<RelationshipGroupRecord, Integer> relGroupRecords ) { long previous = group.getPrev(); long next = group.getNext(); if ( previous == Record.NO_NEXT_RELATIONSHIP.intValue() ) { // This is the first one, just point the node to the next group nodeChange.forChangingLinkage().setNextRel( next ); } else { // There are others before it, point the previous to the next group RelationshipGroupRecord previousRecord = relGroupRecords.getOrLoad( previous, null ).forChangingLinkage(); previousRecord.setNext( next ); } if ( next != Record.NO_NEXT_RELATIONSHIP.intValue() ) { // There are groups after this one, point that next group to the previous of the group to be deleted RelationshipGroupRecord nextRecord = relGroupRecords.getOrLoad( next, null ).forChangingLinkage(); nextRecord.setPrev( previous ); } group.setInUse( false ); }
relationship.setRequiresSecondaryUnit( true ); RelationshipGroupRecord relationshipGroup = new RelationshipGroupRecord( 8 ) .initialize( true, 0, 1, 2, 3, 4, 5 ); relationshipGroup.setSecondaryUnitId( 20 ); relationshipGroup.setRequiresSecondaryUnit( true ); new RelationshipRecord( relationship.getId() ), relationship ) ); tracker.visitRelationshipGroupCommand( new RelationshipGroupCommand( new RelationshipGroupRecord( relationshipGroup.getId() ), relationshipGroup ) ); tracker.close(); assertEquals( relationshipGroup.getSecondaryUnitId() + 1, neoStores.getRelationshipGroupStore().getHighId() );
public static RelationshipGroupCommand createRelationshipGroup( long id, int type ) { RelationshipGroupRecord before = new RelationshipGroupRecord( id ); RelationshipGroupRecord after = new RelationshipGroupRecord( id, type ); after.setInUse( true ); after.setCreated(); return new RelationshipGroupCommand( before, after ); }