Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Dec 2, 2016
1 parent 432e444 commit 09dbc90
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 38 deletions.
Expand Up @@ -289,9 +289,8 @@ public PageCursor openLinkedCursor( long pageId )
}

@Override
public void clear()
public void zapPage()
{
Arrays.fill( buffer.array(), (byte) 0 );
buffer.position( 0 );
}
}
Expand Up @@ -325,8 +325,8 @@ public PageCursor openLinkedCursor( long pageId )
}

@Override
public void clear()
public void zapPage()
{
current.clear();
current.zapPage();
}
}
Expand Up @@ -344,7 +344,6 @@ public abstract class PageCursor implements AutoCloseable

/**
* Sets all bytes in this page to zero, as if this page was newly allocated at the end of the file.
* Offset is also set to 0.
*/
public abstract void clear();
public abstract void zapPage();
}
Expand Up @@ -483,10 +483,10 @@ public PageCursor openLinkedCursor( long pageId )
}

@Override
public void clear()
public void zapPage()
{
first.clear();
second.clear();
first.zapPage();
second.zapPage();
}

/**
Expand Down
Expand Up @@ -255,9 +255,9 @@ public boolean shouldRetry() throws IOException
}

@Override
public void clear()
public void zapPage()
{
delegate.clear();
delegate.zapPage();
}

public DelegatingPageCursor( PageCursor delegate )
Expand Down
Expand Up @@ -778,7 +778,7 @@ public void setCursorException( String message )
}

@Override
public void clear()
public void zapPage()
{
if ( pageSize == 0 )
{
Expand All @@ -789,7 +789,6 @@ public void clear()
else
{
UnsafeUtil.setMemory( pointer, pageSize, (byte) 0 );
offset = 0;
}
}
}
Expand Up @@ -167,7 +167,7 @@ public void putShort( short value )
}

@Override
public void clear()
public void zapPage()
{
throw new IllegalStateException( "Cannot write to read-locked page" );
}
Expand Down
Expand Up @@ -457,7 +457,7 @@ public PageCursor openLinkedCursor( long pageId )
}

@Override
public void clear()
public void zapPage()
{
throw new IllegalStateException( "Cannot write using read cursor" );
}
Expand Down
Expand Up @@ -304,8 +304,8 @@ public PageCursor openLinkedCursor( long pageId )
}

@Override
public void clear()
public void zapPage()
{
delegate.clear();
delegate.zapPage();
}
}
Expand Up @@ -1184,7 +1184,7 @@ private void verifyOnWriteCursor(
testTemplate.accept( ( cursor ) -> cursor.putInt( 0, 1 ) );
testTemplate.accept( ( cursor ) -> cursor.putLong( 0, 1 ) );
testTemplate.accept( ( cursor ) -> cursor.putShort( 0, (short) 1 ) );
testTemplate.accept( ( cursor ) -> cursor.clear() );
testTemplate.accept( ( cursor ) -> cursor.zapPage() );
}

private void checkUnboundReadCursorAccess( PageCursorAction action ) throws IOException
Expand Down Expand Up @@ -2491,10 +2491,10 @@ public void cursorOffsetMustBeUpdatedReadAndWrite() throws IOException

private void verifyWriteOffsets( PageCursor cursor )
{
assertThat( cursor.getOffset(), is( 0 ) );
cursor.setOffset( filePageSize / 2 );
cursor.clear();
assertThat( cursor.getOffset(), is( 0 ) );
cursor.zapPage();
assertThat( cursor.getOffset(), is( filePageSize / 2 ) );
cursor.setOffset( 0 );
cursor.putLong( 1 );
assertThat( cursor.getOffset(), is( 8 ) );
cursor.putInt( 1 );
Expand Down Expand Up @@ -5398,7 +5398,7 @@ public void shouldZeroAllBytesOnClear() throws Exception
try ( PageCursor cursor = pagedFile.io( pageId, PF_SHARED_WRITE_LOCK ) )
{
assertTrue( cursor.next() );
cursor.clear();
cursor.zapPage();

byte[] read = new byte[filePageSize];
cursor.getBytes( read );
Expand All @@ -5411,7 +5411,10 @@ public void shouldZeroAllBytesOnClear() throws Exception
assertTrue( cursor.next() );

byte[] read = new byte[filePageSize];
cursor.getBytes( read );
do
{
cursor.getBytes( read );
} while ( cursor.shouldRetry() );
assertFalse( cursor.checkAndClearBoundsFlag() );
assertArrayEquals( allZeros, read );
}
Expand Down
Expand Up @@ -399,10 +399,9 @@ public void setOffset( int offset )
}

@Override
public void clear()
public void zapPage()
{
page.clear();
currentOffset = 0;
page.zapPage();
}

public Page getPage()
Expand Down
Expand Up @@ -25,14 +25,13 @@
import java.nio.Buffer;
import java.nio.ByteBuffer;

import org.neo4j.io.ByteUnit;
import org.neo4j.io.pagecache.Page;
import org.neo4j.unsafe.impl.internal.dragons.UnsafeUtil;

/** A page backed by a simple byte buffer. */
public class ByteBufferPage implements Page
{
private static final MethodHandle addressOfMH = addressOfMH();
private static final byte[] ZEROS = new byte[(int) ByteUnit.kibiBytes( 1 )];

private static MethodHandle addressOfMH()
{
Expand Down Expand Up @@ -138,16 +137,8 @@ public long address()
return addressOf( buffer );
}

public void clear()
public void zapPage()
{
int remaining = buffer.capacity();
buffer.position( 0 );
while ( remaining >= ZEROS.length )
{
buffer.put( ZEROS );
remaining -= ZEROS.length;
}
buffer.put( ZEROS, 0, remaining );
buffer.position( 0 );
UnsafeUtil.setMemory( address(), size(), (byte) 0 );
}
}

0 comments on commit 09dbc90

Please sign in to comment.