Skip to content

Commit

Permalink
Use page cursors directly and remove record cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed May 8, 2017
1 parent 5fd0468 commit 2b7af77
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 431 deletions.
Expand Up @@ -24,6 +24,7 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.OpenOption;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collection;

import org.neo4j.graphdb.config.Setting;
Expand Down Expand Up @@ -53,6 +54,7 @@
import static org.neo4j.io.pagecache.PagedFile.PF_READ_AHEAD;
import static org.neo4j.io.pagecache.PagedFile.PF_SHARED_READ_LOCK;
import static org.neo4j.io.pagecache.PagedFile.PF_SHARED_WRITE_LOCK;
import static org.neo4j.kernel.impl.store.record.Record.NULL_REFERENCE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK;
import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;

Expand Down Expand Up @@ -1128,13 +1130,26 @@ public <EXCEPTION extends Exception> void scanAllRecords( Visitor<RECORD,EXCEPTI
}
}

@SuppressWarnings( "unchecked" )
@Override
public Collection<RECORD> getRecords( long firstId, RecordLoad mode )
{
try ( RecordCursor<RECORD> cursor = newRecordCursor( newRecord() ) )
RECORD record = newRecord();
ArrayList<RECORD> records = new ArrayList<>();
try ( PageCursor cursor = newPageCursor() )
{
cursor.acquire( firstId, mode );
return cursor.getAll();
long id = firstId;
while ( !NULL_REFERENCE.is( id ) )
{
readRecord( id, record, CHECK, cursor );
if ( record.inUse() )
{
records.add( (RECORD) record.clone() );
}
id = getNextRecordReference( record );
}

return records;
}
}

Expand All @@ -1151,12 +1166,6 @@ public PageCursor newPageCursor()
}
}

@Override
public RecordCursor<RECORD> newRecordCursor( final RECORD record )
{
return new StoreRecordCursor<>( record, this );
}

private void verifyAfterNotRead( RECORD record, RecordLoad mode )
{
record.clear();
Expand Down
Expand Up @@ -107,14 +107,6 @@ public void ensureHeavy( NodeRecord node, long firstDynamicLabelRecord )
node.setLabelField( node.getLabelField(), dynamicLabelStore.getRecords( firstDynamicLabelRecord, RecordLoad.NORMAL ) );
}

public static void ensureHeavy( NodeRecord node, RecordCursor<DynamicRecord> dynamicLabelCursor )
{
long firstDynamicLabelId = NodeLabelsField.firstDynamicLabelRecordId( node.getLabelField() );
dynamicLabelCursor.placeAt( firstDynamicLabelId, RecordLoad.NORMAL );
List<DynamicRecord> dynamicLabelRecords = dynamicLabelCursor.getAll();
node.setLabelField( node.getLabelField(), dynamicLabelRecords );
}

@Override
public void updateRecord( NodeRecord record )
{
Expand Down
Expand Up @@ -27,10 +27,10 @@
import java.util.List;

import org.neo4j.collection.primitive.PrimitiveLongObjectMap;
import org.neo4j.cursor.Cursor;
import org.neo4j.helpers.collection.Iterables;
import org.neo4j.helpers.collection.Pair;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.store.format.standard.StandardFormatSettings;
Expand All @@ -46,6 +46,7 @@

import static org.neo4j.kernel.impl.store.DynamicArrayStore.getRightArray;
import static org.neo4j.kernel.impl.store.NoStoreHeaderFormat.NO_STORE_HEADER_FORMAT;
import static org.neo4j.kernel.impl.store.record.Record.NULL_REFERENCE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;

/**
Expand Down Expand Up @@ -179,13 +180,16 @@ public void ensureHeavy( PropertyBlock block )
return;
}

try ( Cursor<DynamicRecord> dynamicRecords = dynamicStore.newRecordCursor( dynamicStore.newRecord() )
.acquire( block.getSingleValueLong(), NORMAL ) )
DynamicRecord dynamicRecord = dynamicStore.newRecord();
long id = block.getSingleValueLong();
try ( PageCursor cursor = dynamicStore.newPageCursor() )
{
while ( dynamicRecords.next() )
while ( !NULL_REFERENCE.is( id ) )
{
dynamicRecords.get().setType( type.intValue() );
block.addValueRecord( dynamicRecords.get().clone() );
dynamicStore.readRecord( id, dynamicRecord, NORMAL, cursor );
dynamicRecord.setType( type.intValue() );
block.addValueRecord( dynamicRecord.clone() );
id = dynamicStore.getNextRecordReference( dynamicRecord );
}
}
}
Expand Down

This file was deleted.

Expand Up @@ -139,19 +139,6 @@ public interface RecordStore<RECORD extends AbstractBaseRecord> extends IdSequen
*/
Collection<RECORD> getRecords( long firstId, RecordLoad mode ) throws InvalidRecordException;

/**
* Instantiates a new record cursor capable of iterating over records in this store. A {@link RecordCursor}
* gets created with one record and will use every time it reads records.
*
* This method relates to {@link #placeRecordCursor(long, RecordCursor, RecordLoad)} just like
* {@link #newRecord()} relates to {@link #getRecord(long, AbstractBaseRecord, RecordLoad)} in that
* instantiation of object is separate from reading record data.
*
* @param record instance to use when reading record data.
* @return a new {@link RecordCursor} instance capable of reading records in this store.
*/
RecordCursor<RECORD> newRecordCursor( RECORD record );

/**
* Instantiates a new page cursor capable of iterating over records in this store.
*
Expand Down Expand Up @@ -291,12 +278,6 @@ public Collection<R> getRecords( long firstId, RecordLoad mode ) throws InvalidR
return actual.getRecords( firstId, mode );
}

@Override
public RecordCursor<R> newRecordCursor( R record )
{
return actual.newRecordCursor( record );
}

@Override
public PageCursor newPageCursor()
{
Expand Down

This file was deleted.

0 comments on commit 2b7af77

Please sign in to comment.