public static long[] getDynamicLabelsArrayFromHeavyRecords( Iterable<DynamicRecord> records ) { long[] storedLongs = (long[]) DynamicArrayStore.getRightArray( readFullByteArrayFromHeavyRecords( records, PropertyType.ARRAY ) ).asObject(); return LabelIdArray.stripNodeId( storedLongs ); }
private static void allocateStringRecords( Collection<DynamicRecord> target, byte[] chars, DynamicRecordAllocator allocator ) { AbstractDynamicStore.allocateRecordsFromBytes( target, chars, allocator ); }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }
Pair<byte[]/*header in the first record*/, byte[]/*all other bytes*/> readFullByteArray( Iterable<DynamicRecord> records, PropertyType propertyType ) { for ( DynamicRecord record : records ) { ensureHeavy( record ); } return readFullByteArrayFromHeavyRecords( records, propertyType ); }
private static ByteBuffer readDynamic( AbstractDynamicStore store, long reference, ByteBuffer buffer, PageCursor page ) { if ( buffer == null ) { buffer = ByteBuffer.allocate( 512 ); } else { buffer.clear(); } DynamicRecord record = store.newRecord(); do { //We need to load forcefully here since otherwise we can have inconsistent reads //for properties across blocks, see org.neo4j.graphdb.ConsistentPropertyReadsIT store.getRecordByCursor( reference, record, RecordLoad.FORCE, page ); reference = record.getNextBlock(); byte[] data = record.getData(); if ( buffer.remaining() < data.length ) { buffer = grow( buffer, data.length ); } buffer.put( data, 0, data.length ); } while ( reference != NO_ID ); return buffer; }
@Test public void dynamicRecordCursorReadsInUseRecords() { try ( AbstractDynamicStore store = newTestableDynamicStore() ) { DynamicRecord first = createDynamicRecord( 1, store, 0 ); DynamicRecord second = createDynamicRecord( 2, store, 0 ); DynamicRecord third = createDynamicRecord( 3, store, 10 ); store.setHighId( 3 ); first.setNextBlock( second.getId() ); store.updateRecord( first ); second.setNextBlock( third.getId() ); store.updateRecord( second ); Iterator<DynamicRecord> records = store.getRecords( 1, NORMAL ).iterator(); assertTrue( records.hasNext() ); assertEquals( first, records.next() ); assertTrue( records.hasNext() ); assertEquals( second, records.next() ); assertTrue( records.hasNext() ); assertEquals( third, records.next() ); assertFalse( records.hasNext() ); } }
@Override public String toString() { return super.toString() + "[fileName:" + storageFile.getName() + ", blockSize:" + getRecordDataSize() + "]"; }
Pair<byte[]/*header in the first record*/, byte[]/*all other bytes*/> readFullByteArray( Iterable<DynamicRecord> records, PropertyType propertyType ) { for ( DynamicRecord record : records ) { ensureHeavy( record ); } return readFullByteArrayFromHeavyRecords( records, propertyType ); }
@Test public void dynamicRecordCursorReadsNotInUseRecords() { try ( AbstractDynamicStore store = newTestableDynamicStore() ) { DynamicRecord first = createDynamicRecord( 1, store, 0 ); DynamicRecord second = createDynamicRecord( 2, store, 0 ); DynamicRecord third = createDynamicRecord( 3, store, 10 ); store.setHighId( 3 ); first.setNextBlock( second.getId() ); store.updateRecord( first ); second.setNextBlock( third.getId() ); store.updateRecord( second ); second.setInUse( false ); store.updateRecord( second ); Iterator<DynamicRecord> records = store.getRecords( 1, FORCE ).iterator(); assertTrue( records.hasNext() ); assertEquals( first, records.next() ); assertTrue( records.hasNext() ); DynamicRecord secondReadRecord = records.next(); assertEquals( second, secondReadRecord ); assertFalse( secondReadRecord.inUse() ); // because mode == FORCE we can still move through the chain assertTrue( records.hasNext() ); assertEquals( third, records.next() ); assertFalse( records.hasNext() ); } }
private static ByteBuffer readDynamic( AbstractDynamicStore store, long reference, ByteBuffer buffer, PageCursor page ) { if ( buffer == null ) { buffer = ByteBuffer.allocate( 512 ); } else { buffer.clear(); } DynamicRecord record = store.newRecord(); do { //We need to load forcefully here since otherwise we can have inconsistent reads //for properties across blocks, see org.neo4j.graphdb.ConsistentPropertyReadsIT store.getRecordByCursor( reference, record, RecordLoad.FORCE, page ); reference = record.getNextBlock(); byte[] data = record.getData(); if ( buffer.remaining() < data.length ) { buffer = grow( buffer, data.length ); } buffer.put( data, 0, data.length ); } while ( reference != NO_ID ); return buffer; }
@Override public String toString() { return super.toString() + "[fileName:" + storageFile.getName() + ", blockSize:" + getRecordDataSize() + "]"; }
public static long[] labelIds( List<DynamicRecord> recordList ) { long[] idArray = (long[]) getRightArray( readFullByteArrayFromHeavyRecords( recordList, PropertyType.ARRAY ) ).asObject(); return LabelIdArray.stripNodeId( idArray ); }
void allocateRecordsFromBytes( Collection<DynamicRecord> target, byte[] src ) { allocateRecordsFromBytes( target, src, this ); }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }
@Override public long[] getIfLoaded() { if ( node.isLight() ) { return null; } return stripNodeId( (long[]) getRightArray( readFullByteArrayFromHeavyRecords( node.getUsedDynamicLabelRecords(), ARRAY ) ).asObject() ); }
private static Collection<DynamicRecord> serializeRule( SchemaRule rule, DynamicRecord... records ) { byte[] data = SchemaRuleSerialization.serialize( rule ); DynamicRecordAllocator dynamicRecordAllocator = new ReusableRecordsCompositeAllocator( asList( records ), schemaAllocator ); Collection<DynamicRecord> result = new ArrayList<>(); AbstractDynamicStore.allocateRecordsFromBytes( result, data, dynamicRecordAllocator ); return result; }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { long nodeId = ((long[]) getRightArray( readFullByteArrayFromHeavyRecords( chain, ARRAY ) ).asObject())[0]; NodeRecord before = inUse( new NodeRecord( nodeId, false, -1, -1 ) ); NodeRecord after = inUse( new NodeRecord( nodeId, false, -1, -1 ) ); DynamicRecord record1 = chain.get( 0 ).clone(); DynamicRecord record2 = chain.get( 1 ).clone(); DynamicRecord record3 = chain.get( 2 ).clone(); record3.setNextBlock( record2.getId() ); before.setLabelField( dynamicPointer( chain ), chain ); after.setLabelField( dynamicPointer( chain ), asList( record1, record2, record3 ) ); tx.update( before, after ); } } );
void allocateRecordsFromBytes( Collection<DynamicRecord> target, byte[] src ) { allocateRecordsFromBytes( target, src, this ); }
private SchemaRule readSchemaRule( Collection<DynamicRecord> recordsBefore ) { // TODO: Why was this assertion here? // assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in // use."; SchemaRule rule; ByteBuffer deserialized = AbstractDynamicStore.concatData( recordsBefore, new byte[100] ); try { rule = SchemaRuleSerialization.deserialize( Iterables.first( recordsBefore ).getId(), deserialized ); } catch ( MalformedSchemaRuleException e ) { return null; } return rule; }