Skip to content

Commit

Permalink
Allow to use fixed reference format for records with null references
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 15, 2016
1 parent f3fc07d commit 9cae92c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 26 deletions.
Expand Up @@ -129,8 +129,8 @@ protected byte headerBits( NodeRecord record )
protected boolean canUseFixedReferences( NodeRecord record, int recordSize ) protected boolean canUseFixedReferences( NodeRecord record, int recordSize )
{ {
return (isRecordBigEnoughForFixedReferences( recordSize ) && return (isRecordBigEnoughForFixedReferences( recordSize ) &&
((record.getNextProp() != NULL) && ((record.getNextProp() & HIGH_DWORD_LOWER_NIBBLE_MASK) == 0)) && ((record.getNextProp() == NULL) || ((record.getNextProp() & HIGH_DWORD_LOWER_NIBBLE_MASK) == 0)) &&
((record.getNextRel() != NULL) && ((record.getNextRel() & HIGH_DWORD_LOWER_NIBBLE_MASK) == 0))); ((record.getNextRel() == NULL) || ((record.getNextRel() & HIGH_DWORD_LOWER_NIBBLE_MASK) == 0)));
} }


private boolean isRecordBigEnoughForFixedReferences( int recordSize ) private boolean isRecordBigEnoughForFixedReferences( int recordSize )
Expand Down
Expand Up @@ -184,8 +184,8 @@ public long getNextRecordReference( PropertyRecord record )
private boolean canUseFixedReferences( PropertyRecord record, int recordSize ) private boolean canUseFixedReferences( PropertyRecord record, int recordSize )
{ {
return ( isRecordBigEnoughForFixedReferences( recordSize ) && return ( isRecordBigEnoughForFixedReferences( recordSize ) &&
((record.getNextProp() != NULL) && ((record.getNextProp() & HIGH_DWORD_LOWER_WORD_CHECK_MASK) == 0)) && ((record.getNextProp() == NULL) || ((record.getNextProp() & HIGH_DWORD_LOWER_WORD_CHECK_MASK) == 0)) &&
((record.getPrevProp() != NULL) && ((record.getPrevProp() & HIGH_DWORD_LOWER_WORD_CHECK_MASK) == 0))); ((record.getPrevProp() == NULL) || ((record.getPrevProp() & HIGH_DWORD_LOWER_WORD_CHECK_MASK) == 0)));
} }


private boolean isRecordBigEnoughForFixedReferences( int recordSize ) private boolean isRecordBigEnoughForFixedReferences( int recordSize )
Expand Down
Expand Up @@ -160,11 +160,11 @@ protected void doWriteInternal( RelationshipGroupRecord record, PageCursor curso
protected boolean canUseFixedReferences( RelationshipGroupRecord record, int recordSize ) protected boolean canUseFixedReferences( RelationshipGroupRecord record, int recordSize )
{ {
return (isRecordBigEnoughForFixedReferences( recordSize ) && return (isRecordBigEnoughForFixedReferences( recordSize ) &&
(record.getNext() != NULL) && ((record.getNext() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) && ((record.getNext() == NULL) || ((record.getNext() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
(record.getFirstOut() != NULL) && ((record.getFirstOut() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) && ((record.getFirstOut() == NULL) || ((record.getFirstOut() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
(record.getFirstIn() != NULL) && ((record.getFirstIn() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) && ((record.getFirstIn() == NULL) || ((record.getFirstIn() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
(record.getFirstLoop() != NULL) && ((record.getFirstLoop() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) && ((record.getFirstLoop() == NULL) || ((record.getFirstLoop() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
(record.getOwningNode() != NULL) && ((record.getOwningNode() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)); ((record.getOwningNode() == NULL) || ((record.getOwningNode() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)));
} }


private boolean isRecordBigEnoughForFixedReferences( int recordSize ) private boolean isRecordBigEnoughForFixedReferences( int recordSize )
Expand Down
Expand Up @@ -196,11 +196,11 @@ protected boolean canUseFixedReferences( RelationshipRecord record, int recordSi
return (isRecordBigEnoughForFixedReferences( recordSize ) && return (isRecordBigEnoughForFixedReferences( recordSize ) &&
(record.getFirstNode() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) && (record.getFirstNode() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) &&
((record.getSecondNode() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) && ((record.getSecondNode() & ONE_BIT_OVERFLOW_BIT_MASK) == 0) &&
((record.getFirstPrevRel() != NULL) && ((record.getFirstPrevRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) && ((record.getFirstPrevRel() == NULL) || ((record.getFirstPrevRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
((record.getFirstNextRel() != NULL) && ((record.getFirstNextRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) && ((record.getFirstNextRel() == NULL) || ((record.getFirstNextRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
((record.getSecondPrevRel() != NULL) && ((record.getSecondPrevRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) && ((record.getSecondPrevRel() == NULL) || ((record.getSecondPrevRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
((record.getSecondNextRel() != NULL) && ((record.getSecondNextRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) && ((record.getSecondNextRel() == NULL) || ((record.getSecondNextRel() & ONE_BIT_OVERFLOW_BIT_MASK) == 0)) &&
((record.getNextProp() != NULL) && ((record.getNextProp() & THREE_BITS_OVERFLOW_BIT_MASK) == 0)); ((record.getNextProp() == NULL) || ((record.getNextProp() & THREE_BITS_OVERFLOW_BIT_MASK) == 0));
} }


private boolean isRecordBigEnoughForFixedReferences( int recordSize ) private boolean isRecordBigEnoughForFixedReferences( int recordSize )
Expand Down
Expand Up @@ -72,28 +72,28 @@ public void readWriteFixedReferencesRecord() throws Exception
} }


@Test @Test
public void useVariableLengthFormatWhenRelationshipIsMissing() throws IOException public void useFixedReferencesFormatWhenRelationshipIsMissing() throws IOException
{ {
NodeRecord source = new NodeRecord( 1 ); NodeRecord source = new NodeRecord( 1 );
NodeRecord target = new NodeRecord( 1 ); NodeRecord target = new NodeRecord( 1 );
source.initialize( true, randomFixedReference(), true, Record.NULL_REFERENCE.byteValue(), 0L ); source.initialize( true, randomFixedReference(), true, Record.NULL_REFERENCE.byteValue(), 0L );


writeReadRecord( source, target ); writeReadRecord( source, target );


assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() ); assertTrue( "Record should use fixed reference format.", target.isUseFixedReferences() );
verifySameReferences( source, target ); verifySameReferences( source, target );
} }


@Test @Test
public void useVariableLengthFormatWhenPropertyIsMissing() throws IOException public void useFixedReferencesFormatWhenPropertyIsMissing() throws IOException
{ {
NodeRecord source = new NodeRecord( 1 ); NodeRecord source = new NodeRecord( 1 );
NodeRecord target = new NodeRecord( 1 ); NodeRecord target = new NodeRecord( 1 );
source.initialize( true, Record.NULL_REFERENCE.intValue(), true, randomFixedReference(), 0L ); source.initialize( true, Record.NULL_REFERENCE.intValue(), true, randomFixedReference(), 0L );


writeReadRecord( source, target ); writeReadRecord( source, target );


assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() ); assertTrue( "Record should use fixed reference format.", target.isUseFixedReferences() );
verifySameReferences( source, target ); verifySameReferences( source, target );
} }


Expand Down
Expand Up @@ -104,28 +104,28 @@ public void readWriteFixedReferencesRecord() throws Exception
} }


@Test @Test
public void useVariableLengthFormatWhenNextPropertyIsMissing() throws IOException public void useFixedReferenceFormatWhenNextPropertyIsMissing() throws IOException
{ {
PropertyRecord source = new PropertyRecord( 1 ); PropertyRecord source = new PropertyRecord( 1 );
PropertyRecord target = new PropertyRecord( 1 ); PropertyRecord target = new PropertyRecord( 1 );
source.initialize( true, randomFixedReference(), Record.NULL_REFERENCE.byteValue() ); source.initialize( true, randomFixedReference(), Record.NULL_REFERENCE.byteValue() );


writeReadRecord( source, target ); writeReadRecord( source, target );


assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() ); assertTrue( "Record should use fixed reference format.", target.isUseFixedReferences() );
verifySameReferences( source, target ); verifySameReferences( source, target );
} }


@Test @Test
public void useVariableLengthFormatWhenPreviousPropertyIsMissing() throws IOException public void useFixedReferenceFormatWhenPreviousPropertyIsMissing() throws IOException
{ {
PropertyRecord source = new PropertyRecord( 1 ); PropertyRecord source = new PropertyRecord( 1 );
PropertyRecord target = new PropertyRecord( 1 ); PropertyRecord target = new PropertyRecord( 1 );
source.initialize( true, Record.NULL_REFERENCE.intValue(), randomFixedReference() ); source.initialize( true, Record.NULL_REFERENCE.intValue(), randomFixedReference() );


writeReadRecord( source, target ); writeReadRecord( source, target );


assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() ); assertTrue( "Record should use fixed reference format.", target.isUseFixedReferences() );
verifySameReferences( source, target ); verifySameReferences( source, target );
} }


Expand Down
Expand Up @@ -76,7 +76,7 @@ public void readWriteFixedReferencesRecord() throws Exception
} }


@Test @Test
public void useVariableLengthFormatWhenOneOfTheReferencesIsMissing() throws IOException public void useFixedReferenceFormatWhenOneOfTheReferencesIsMissing() throws IOException
{ {
RelationshipGroupRecord source = new RelationshipGroupRecord( 1 ); RelationshipGroupRecord source = new RelationshipGroupRecord( 1 );
RelationshipGroupRecord target = new RelationshipGroupRecord( 1 ); RelationshipGroupRecord target = new RelationshipGroupRecord( 1 );
Expand Down Expand Up @@ -167,6 +167,7 @@ private void writeRecordWithOldFormat( RelationshipGroupRecord oldFormatRecord )
private void verifyRecordsWithPoisonedReference( RelationshipGroupRecord source, RelationshipGroupRecord target, private void verifyRecordsWithPoisonedReference( RelationshipGroupRecord source, RelationshipGroupRecord target,
long poisonedReference ) throws IOException long poisonedReference ) throws IOException
{ {
boolean nullPoisoned = poisonedReference == BaseHighLimitRecordFormat.NULL;
int differentReferences = 5; int differentReferences = 5;
List<Long> references = buildReferenceList( differentReferences, poisonedReference ); List<Long> references = buildReferenceList( differentReferences, poisonedReference );
for ( int i = 0; i < differentReferences; i++ ) for ( int i = 0; i < differentReferences; i++ )
Expand All @@ -179,7 +180,14 @@ private void verifyRecordsWithPoisonedReference( RelationshipGroupRecord source,


writeReadRecord( source, target ); writeReadRecord( source, target );


assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() ); if ( nullPoisoned )
{
assertTrue( "Record should use fixed reference format.", target.isUseFixedReferences() );
}
else
{
assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() );
}
verifySameReferences( source, target ); verifySameReferences( source, target );
Collections.rotate( references, 1 ); Collections.rotate( references, 1 );
} }
Expand Down
Expand Up @@ -129,7 +129,7 @@ public void readWriteFixedReferencesRecord() throws Exception
} }


@Test @Test
public void useVariableLengthFormatWhenAtLeastOneOfTheReferencesIsMissing() throws IOException public void useFixedRecordFormatWhenAtLeastOneOfTheReferencesIsMissing() throws IOException
{ {
RelationshipRecord source = new RelationshipRecord( 1 ); RelationshipRecord source = new RelationshipRecord( 1 );
RelationshipRecord target = new RelationshipRecord( 1 ); RelationshipRecord target = new RelationshipRecord( 1 );
Expand Down Expand Up @@ -238,7 +238,14 @@ private void verifyRecordsWithPoisonedReference( RelationshipRecord source, Rela


writeReadRecord( source, target ); writeReadRecord( source, target );


assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() ); if ( nullPoison )
{
assertTrue( "Record should use fixed reference format.", target.isUseFixedReferences() );
}
else
{
assertFalse( "Record should use variable length reference format.", target.isUseFixedReferences() );
}
verifySameReferences( source, target ); verifySameReferences( source, target );
Collections.rotate( references, 1 ); Collections.rotate( references, 1 );
} }
Expand Down

0 comments on commit 9cae92c

Please sign in to comment.