Skip to content

Commit

Permalink
All single datablock property values
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jun 25, 2017
1 parent 7451cb3 commit 5a6d48c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
Expand Up @@ -21,9 +21,10 @@

public abstract class MemoryManager
{
protected static void setup( ReadCursor cursor, long virtualAddress, PageHandle page, long pageId, long base )
protected static void setup( ReadCursor cursor, long virtualAddress, PageHandle page, long pageId, long base,
int offset )
{
cursor.access( virtualAddress, page, pageId, base, 0 );
cursor.access( virtualAddress, page, pageId, base, offset );
}

protected static void read(
Expand Down
Expand Up @@ -65,7 +65,7 @@ class PropertyCursor extends org.neo4j.impl.store.prototype.PropertyCursor<ReadS
* SHORT: [ , ] [ , ] [ ,xxxx] [xxxx,xxxx] [xxxx,type][K][K][K] (>>28) (0x0000_0FFF_F000_0000)
* CHAR: [ , ] [ , ] [ ,xxxx] [xxxx,xxxx] [xxxx,type][K][K][K] (>>28) (0x0000_0FFF_F000_0000)
* INT: [ ,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxxx,type][K][K][K] (>>28) (0x0FFF_FFFF_F000_0000)
* LONG: [xxxx,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxx1,type][K][K][K] inline>>29(0xFFFF_FFFF_7000_0000)
* LONG: [xxxx,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxx1,type][K][K][K] inline>>29(0xFFFF_FFFF_E000_0000)
* LONG: [ , ] [ , ] [ , ] [ , ] [ 0,type][K][K][K] value in next long block
* FLOAT: [ ,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxxx,xxxx] [xxxx,type][K][K][K] (>>28) (0x0FFF_FFFF_F000_0000)
* DOUBLE: [ , ] [ , ] [ , ] [ , ] [ ,type][K][K][K] value in next long block
Expand Down Expand Up @@ -173,20 +173,25 @@ public Value propertyValue()
switch ( typeIdentifier() )
{
case BOOL:
// return (block(block) & 0x0000_0000_1000_0000) != 0;
throw new UnsupportedOperationException( "not implemented" );
return Values.booleanValue( (block(block) & 0x0000_0000_1000_0000) != 0 );
case BYTE:
throw new UnsupportedOperationException( "not implemented" );
return Values.byteValue( (byte)((block( this.block ) & 0x0000_000F_F000_0000L) >> 28) );
case SHORT:
throw new UnsupportedOperationException( "not implemented" );
return Values.shortValue( (short)((block( this.block ) & 0x0000_0FFF_F000_0000L) >> 28) );
case CHAR:
throw new UnsupportedOperationException( "not implemented" );
case INT:
return Values.intValue( (int)(block( block ) & 0x0FFF_FFFF_F000_0000L) >> 28 );
case LONG:
throw new UnsupportedOperationException( "not implemented" );
long valueBytes = block( this.block );
if ( ( valueBytes & 0x0000_0000_1000_0000 ) == 0 )
{
throw new UnsupportedOperationException( "not implemented" ); // long bytes in next block
}
return Values.longValue( (valueBytes & 0xFFFF_FFFF_E000_0000L) >> 29 );
case FLOAT:
throw new UnsupportedOperationException( "not implemented" );
return Values.floatValue(
Float.intBitsToFloat((int)((block( this.block ) & 0x0FFF_FFFF_F000_0000L) >> 28) ) );
case DOUBLE:
throw new UnsupportedOperationException( "not implemented" );
case STRING_REFERENCE:
Expand Down
Expand Up @@ -217,7 +217,8 @@ public void shutdown()
static <Cursor extends ReadCursor> void setup( StoreFile store, Cursor cursor, long reference )
{
int pageId = store.pageOf( reference );
setup( cursor, reference, store, pageId, store.page( pageId ) );
int offset = store.offsetIntoPage( reference, pageId );
setup( cursor, reference, store, pageId, store.page( pageId ), offset );
}

static int nextPowerOfTwo( int v )
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

Expand All @@ -52,6 +53,26 @@ int recordSize()
};
}

static StoreFile dynamicSizeRecordFile( File file ) throws IOException
{
FileChannel channel = new RandomAccessFile( file, "r" ).getChannel();
ByteBuffer buffer = ByteBuffer.allocate( 4 );
System.out.println( channel.read( buffer ) );
buffer.flip();

final int recordSize = buffer.getInt();
channel.close();

return new StoreFile( file )
{
@Override
int recordSize()
{
return recordSize;
}
};
}

private final FileChannel channel;
final long maxReference;
private final int pageSize;
Expand Down Expand Up @@ -235,4 +256,9 @@ public int pageOf( long reference )
{
return (int) (reference * recordSize() / pageSize);
}

public int offsetIntoPage( long reference, int pageId )
{
return (int) (reference * recordSize() - pageSize * pageId);
}
}
Expand Up @@ -35,7 +35,8 @@

public class PropertyCursorTest
{
private static long bare, intProp;
private static long bare, byteProp, shortProp, intProp, inlineLongProp, longProp,
floatProp, doubleProp, trueProp, falseProp;

@ClassRule
public static final GraphSetup graph = new GraphSetup()
Expand All @@ -47,13 +48,27 @@ protected void create( GraphDatabaseService graphDb )
{
bare = graphDb.createNode().getId();

Node p = graphDb.createNode();
p.setProperty( "intProp", 1 );
intProp = p.getId();
byteProp = createNodeWithProperty( graphDb, "byteProp", (byte)13 );
shortProp = createNodeWithProperty( graphDb, "shortProp", (short)13 );
intProp = createNodeWithProperty( graphDb, "intProp", 13 );
inlineLongProp = createNodeWithProperty( graphDb, "inlineLongProp", 13L );

floatProp = createNodeWithProperty( graphDb, "floatProp", 13.0f );
doubleProp = createNodeWithProperty( graphDb, "doubleProp", 13.0 );

trueProp = createNodeWithProperty( graphDb, "trueProp", true );
falseProp = createNodeWithProperty( graphDb, "falseProp", false );

tx.success();
}
}

private long createNodeWithProperty( GraphDatabaseService graphDb, String propertyKey, Object value )
{
Node p = graphDb.createNode();
p.setProperty( propertyKey, value );
return p.getId();
}
}
.withConfig( dense_node_threshold, "1" );

Expand Down Expand Up @@ -81,24 +96,35 @@ public void shouldNotAccessNonExistentProperties() throws Exception

@Test
public void shouldAccessIntProperty() throws Exception
{
assertAccessSingleProperty( byteProp, (byte)13 );
assertAccessSingleProperty( shortProp, (short)13 );
assertAccessSingleProperty( intProp, 13 );
assertAccessSingleProperty( inlineLongProp, 13L );
assertAccessSingleProperty( floatProp, 13.0f );
assertAccessSingleProperty( trueProp, true );
assertAccessSingleProperty( falseProp, false );
}

private void assertAccessSingleProperty( long nodeId, Object expectedValue )
{
// given
try ( NodeCursor node = graph.allocateNodeCursor();
PropertyCursor props = graph.allocatePropertyCursor() )
{
// when
graph.singleNode( intProp, node );
graph.singleNode( nodeId, node );
assertTrue( "node by reference", node.next() );
assertTrue( "has properties", node.hasProperties() );

node.properties( props );
assertTrue( "has properties by direct method", props.next() );
assertEquals( "correct value", 1, props.propertyValue() );
assertEquals( "correct value", expectedValue, props.propertyValue() );
assertFalse( "single property", props.next() );

graph.nodeProperties( node.propertiesReference(), props );
assertTrue( "has properties via property ref", props.next() );
assertEquals( "correct value", 1, props.propertyValue() );
assertEquals( "correct value", expectedValue, props.propertyValue() );
assertFalse( "single property", props.next() );
}
}
Expand Down

0 comments on commit 5a6d48c

Please sign in to comment.