@Override public long visit( long nodeId, int typeId, long out, long in, long loop ) { long id = store.nextId(); RelationshipGroupRecord record = batch[cursor++]; record.setId( id ); record.initialize( true, typeId, out, in, loop, nodeId, loop ); if ( cursor == batchSize ) { send(); batch = control.reuse( this ); cursor = 0; } return id; }
@Override public RelationshipGroupRecord clone() { RelationshipGroupRecord clone = new RelationshipGroupRecord( getId() ).initialize( inUse(), type, firstOut, firstIn, firstLoop, owningNode, next ); clone.setSecondaryUnitId( getSecondaryUnitId() ); return clone; }
@Override public void clear() { initialize( false, NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue() ); prev = NULL_REFERENCE.intValue(); }
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; }
@Override protected RelationshipGroupRecord fetchNextOrNull() { while ( cursor < highCacheId ) { RelationshipGroupRecord group = null; if ( cache.getByte( cursor, 0 ) == 1 ) { // Here we have an alive group group = new RelationshipGroupRecord( -1 ).initialize( true, cache.get3ByteInt( cursor, 1 ), cache.get6ByteLong( cursor, 1 + 3 ), cache.get6ByteLong( cursor, 1 + 3 + 6 ), cache.get6ByteLong( cursor, 1 + 3 + 6 + 6 ), nodeId, // Special: we want to convey information about how many groups are coming // after this one so that chains can be ordered accordingly in the store // so this isn't at all "next" in the true sense of chain next. countLeftForThisNode - 1 ); } cursor++; countLeftForThisNode--; findNextNodeWithGroupsIfNeeded(); if ( group != null ) { return group; } } return null; }
@Test public void shouldNotFindSpaceToPutMoreGroupsThanSpecifiedForANode() { // GIVEN int nodeCount = 10; RelationshipGroupCache cache = new RelationshipGroupCache( HEAP, ByteUnit.kibiBytes( 4 ), nodeCount ); setCount( cache, 1, 7 ); assertEquals( nodeCount, cache.prepare( 0 ) ); // WHEN for ( int i = 0; i < 7; i++ ) { cache.put( new RelationshipGroupRecord( i + 1 ).initialize( true, i, -1, -1, -1, 1, -1 ) ); } try { cache.put( new RelationshipGroupRecord( 8 ).initialize( true, 8, -1, -1, -1, 1, -1 ) ); fail( "Should have failed" ); } catch ( IllegalStateException e ) { // Good } }
@Override public Generator<RelationshipGroupRecord> relationshipGroup() { return ( recordSize, format, recordId ) -> new RelationshipGroupRecord( recordId ).initialize( random.nextBoolean(), randomInt( tokenBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ), randomLongOrOccasionallyNull( entityBits ) ); }
@Test public void checkingIfRecordIsInUseMustHappenAfterConsistentRead() { AtomicBoolean nextReadIsInconsistent = new AtomicBoolean( false ); PageCache pageCache = pageCacheRule.getPageCache( fs, config().withInconsistentReads( nextReadIsInconsistent ) ); StoreFactory factory = factory( null, pageCache ); try ( NeoStores neoStores = factory.openAllNeoStores( true ) ) { RecordStore<RelationshipGroupRecord> relationshipGroupStore = neoStores.getRelationshipGroupStore(); RelationshipGroupRecord record = new RelationshipGroupRecord( 1 ).initialize( true, 2, 3, 4, 5, 6, Record.NO_NEXT_RELATIONSHIP.intValue() ); relationshipGroupStore.updateRecord( record ); nextReadIsInconsistent.set( true ); // Now the following should not throw any RecordNotInUse exceptions RelationshipGroupRecord readBack = relationshipGroupStore.getRecord( 1, relationshipGroupStore.newRecord(), NORMAL ); assertThat( readBack.toString(), equalTo( record.toString() ) ); } }
groupRecord.initialize( true, typeId, cursor, cursor + 1, cursor + 2, nodeId, 4 ); groupRecord.setId( groupStore.nextId() ); groupStore.updateRecord( groupRecord );
long nextLoopMod = (highByte & 0x70) << 28; record.initialize( inUse, type, BaseRecordFormat.longFromIntAndMod( nextOutLowBits, nextOutMod ), BaseRecordFormat.longFromIntAndMod( nextInLowBits, nextInMod ),
@Test public void shouldReadUnsignedRelationshipTypeId() throws Exception { // GIVEN try ( PageCursor cursor = new StubPageCursor( 1, recordSize * 10 ) ) { int offset = 10; cursor.next(); RelationshipGroupRecord group = new RelationshipGroupRecord( 2 ) .initialize( true, Short.MAX_VALUE + offset, 1, 2, 3, 4, 5 ); cursor.setOffset( offset ); format.write( group, cursor, recordSize ); // WHEN RelationshipGroupRecord read = new RelationshipGroupRecord( group.getId() ); cursor.setOffset( offset ); format.read( read, cursor, NORMAL, recordSize ); // THEN assertEquals( group, read ); } } }
groupRecord.initialize( true, typeId, cursor, cursor + 1, cursor + 2, nodeId, 4 ); groupRecord.setId( groupStore.nextId() ); groupStore.updateRecord( groupRecord );
int typeId = counts[nodeId]--; if ( cache.put( new RelationshipGroupRecord( nodeId ) .initialize( true, typeId, -1, -1, -1, nodeId, -1 ) ) )
.initialize( true, typeId, -1, -1, -1, nodeId, -1 ) ) )
.initialize( true, 0, 1, 2, 3, 4, 5 ); relationshipGroup.setSecondaryUnitId( 20 ); relationshipGroup.setRequiresSecondaryUnit( true );
@Override public long visit( long nodeId, int typeId, long out, long in, long loop ) { long id = store.nextId(); RelationshipGroupRecord record = batch[cursor++]; record.setId( id ); record.initialize( true, typeId, out, in, loop, nodeId, loop ); if ( cursor == batchSize ) { send(); batch = control.reuse( this ); cursor = 0; } return id; }
@Override public RelationshipGroupRecord clone() { RelationshipGroupRecord clone = new RelationshipGroupRecord( getId() ).initialize( inUse(), type, firstOut, firstIn, firstLoop, owningNode, next ); clone.setSecondaryUnitId( getSecondaryUnitId() ); return clone; }
@Override protected void doReadInternal( RelationshipGroupRecord record, PageCursor cursor, int recordSize, long headerByte, boolean inUse ) { record.initialize( inUse, cursor.getShort() & 0xFFFF, decodeCompressedReference( cursor, headerByte, HAS_OUTGOING_BIT, NULL ), decodeCompressedReference( cursor, headerByte, HAS_INCOMING_BIT, NULL ), decodeCompressedReference( cursor, headerByte, HAS_LOOP_BIT, NULL ), decodeCompressedReference( cursor ), decodeCompressedReference( cursor, headerByte, HAS_NEXT_BIT, NULL ) ); }
@Override public void clear() { initialize( false, NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue(), NULL_REFERENCE.intValue() ); prev = NULL_REFERENCE.intValue(); }
@Override protected void doReadInternal( RelationshipGroupRecord record, PageCursor cursor, int recordSize, long headerByte, boolean inUse ) { if ( record.isUseFixedReferences() ) { // read record in fixed references format readFixedReferencesMethod( record, cursor, inUse ); record.setUseFixedReferences( true ); } else { record.initialize( inUse, cursor.getShort() & 0xFFFF, decodeCompressedReference( cursor, headerByte, HAS_OUTGOING_BIT, NULL ), decodeCompressedReference( cursor, headerByte, HAS_INCOMING_BIT, NULL ), decodeCompressedReference( cursor, headerByte, HAS_LOOP_BIT, NULL ), decodeCompressedReference( cursor ), decodeCompressedReference( cursor, headerByte, HAS_NEXT_BIT, NULL ) ); } }