Skip to content

Commit

Permalink
List of TODOs for implementing eviction in PageList
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed May 26, 2017
1 parent 8fada65 commit d7189e7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
Expand Up @@ -52,6 +52,12 @@ class PageList
private static final int OFFSET_FILE_PAGE_ID = 16; // 8 bytes
private static final int OFFSET_SWAPPER_ID = 24; // 4 bytes
private static final int OFFSET_USAGE_COUNTER = 28; // 1 byte
// todo it's possible to reduce the overhead of the individual page to just 24 bytes,
// todo because the file page id can be represented with 5 bytes (enough to address 8-4 PBs),
// todo and then the usage counter can use the high bits of that word, and the swapper id
// todo can use the rest (2 bytes or 20 bits).
// todo we can alternatively also make use of the lower 12 bits of the address field, because
// todo the addresses are page aligned, and we can assume them to be at least 4096 bytes in size.

private final long pageCount;
private final int cachePageSize;
Expand Down Expand Up @@ -317,4 +323,9 @@ private IllegalStateException cannotFaultException( long pageRef, PageSwapper sw
filePageId, swapper, swapperId, pageRef, currentFilePageId, currentSwapper );
return new IllegalStateException( msg );
}

public boolean tryEvict( long pageRef, PageSwapper swapper )
{
return false;
}
}
Expand Up @@ -64,6 +64,7 @@ public class PageListTest
private static final int ALIGNMENT = 8;

private static final long[] pageIds = new long[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
private static final DummyPageSwapper DUMMY_SWAPPER = new DummyPageSwapper( "" );

@Parameterized.Parameters( name = "pageRef = {0}")
public static Iterable<Object[]> parameters()
Expand Down Expand Up @@ -921,7 +922,7 @@ public void faultMustThrowWithoutExclusiveLock() throws Exception
{
pageList.initBuffer( pageRef );
exception.expect( IllegalStateException.class );
pageList.fault( pageRef, new DummyPageSwapper( "" ), 0, 0, PageFaultEvent.NULL );
pageList.fault( pageRef, DUMMY_SWAPPER, 0, 0, PageFaultEvent.NULL );
}

@Test
Expand All @@ -939,7 +940,7 @@ public void faultMustThrowIfFilePageIdIsUnbound() throws Exception
assertTrue( pageList.tryExclusiveLock( pageRef ) );
pageList.initBuffer( pageRef );
exception.expect( IllegalStateException.class );
pageList.fault( pageRef, new DummyPageSwapper( "" ), 0, PageCursor.UNBOUND_PAGE_ID, PageFaultEvent.NULL );
pageList.fault( pageRef, DUMMY_SWAPPER, 0, PageCursor.UNBOUND_PAGE_ID, PageFaultEvent.NULL );
}

@Test
Expand Down Expand Up @@ -982,12 +983,11 @@ public long read( long fpId, long bufferAddress, int bufferSize ) throws IOExcep
@Test
public void pageMustBeLoadedAndBoundAfterFault() throws Exception
{
PageSwapper swapper = new DummyPageSwapper( "file" );
int swapperId = 1;
long filePageId = 42;
assertTrue( pageList.tryExclusiveLock( pageRef ) );
pageList.initBuffer( pageRef );
pageList.fault( pageRef, swapper, swapperId, filePageId, PageFaultEvent.NULL );
pageList.fault( pageRef, DUMMY_SWAPPER, swapperId, filePageId, PageFaultEvent.NULL );
assertThat( pageList.getFilePageId( pageRef ), is( filePageId ) );
assertThat( pageList.getSwapperId( pageRef ), is( swapperId ) );
assertTrue( pageList.isLoaded( pageRef ) );
Expand Down Expand Up @@ -1030,11 +1030,10 @@ public void faultMustThrowIfPageIsAlreadyBound() throws Exception
long filePageId = 42;
assertTrue( pageList.tryExclusiveLock( pageRef ) );
pageList.initBuffer( pageRef );
DummyPageSwapper swapper = new DummyPageSwapper( "" );
pageList.fault( pageRef, swapper, swapperId, filePageId, PageFaultEvent.NULL );
pageList.fault( pageRef, DUMMY_SWAPPER, swapperId, filePageId, PageFaultEvent.NULL );

exception.expect( IllegalStateException.class );
pageList.fault( pageRef, swapper, swapperId, filePageId, PageFaultEvent.NULL );
pageList.fault( pageRef, DUMMY_SWAPPER, swapperId, filePageId, PageFaultEvent.NULL );
}

@Test
Expand All @@ -1047,7 +1046,7 @@ public void faultMustThrowIfPageIsLoadedButNotBound() throws Exception
// After the failed page fault, the page is loaded but not bound.
// We still can't fault into a loaded page, though.
exception.expect( IllegalStateException.class );
pageList.fault( pageRef, new DummyPageSwapper( "" ), swapperId, filePageId, PageFaultEvent.NULL );
pageList.fault( pageRef, DUMMY_SWAPPER, swapperId, filePageId, PageFaultEvent.NULL );
}

private void doFailedFault( int swapperId, long filePageId )
Expand Down Expand Up @@ -1121,7 +1120,7 @@ private void doFault( int swapperId, long filePageId ) throws IOException
{
assertTrue( pageList.tryExclusiveLock( pageRef ) );
pageList.initBuffer( pageRef );
pageList.fault( pageRef, new DummyPageSwapper( "" ), swapperId, filePageId, PageFaultEvent.NULL );
pageList.fault( pageRef, DUMMY_SWAPPER, swapperId, filePageId, PageFaultEvent.NULL );
}

@Test
Expand Down Expand Up @@ -1161,8 +1160,41 @@ public void failedFaultMustNotInterfereWithAdjacentPages() throws Exception
assertFalse( pageList.isBoundTo( nextPageRef, 0, 0 ) );
}

// xxx ---[ Page flush tests ]---
@Test
public void exclusiveLockMustStillBeHeldAfterFault() throws Exception
{
doFault( 1, 42 );
pageList.unlockExclusive( pageRef ); // will throw if lock is not held
}

// xxx ---[ Page eviction tests ]---

@Test
public void tryEvictMustFailIfPageIsAlreadyExclusivelyLocked() throws Exception
{
doFault( 1, 42 ); // page is now loaded
// pages are delivered from the fault routine with the exclusive lock already held!
assertFalse( pageList.tryEvict( pageRef, DUMMY_SWAPPER ) );
}

@Test
public void tryEvictMustFailIfPageIsNotLoaded() throws Exception
{
assertFalse( pageList.tryEvict( pageRef, DUMMY_SWAPPER ) );
}
// todo try evict must leave page exclusively locked on success
// todo try evict must flush page if modified
// todo page must not be loaded after successful eviction
// todo page must not be bound after successful eviction
// todo page must not be modified after successful eviction
// todo try evict must notify swapper on success
// todo try evict must leave page unlocked if flush throws
// todo try evict must leave page loaded if flush throws
// todo try evict must report to eviction event
// todo try evict that flushes must report to flush event
// todo try evict that fails must not interfere with adjacent pages
// todo try evict that succeeds must not interfere with adjacent pages

// todo flush
// todo evict
// todo flush
}

0 comments on commit d7189e7

Please sign in to comment.