Skip to content

Commit

Permalink
Renaming configure to open.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed May 4, 2017
1 parent 51ef0bd commit 41253d9
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 34 deletions.
Expand Up @@ -41,20 +41,11 @@
public interface PageSwapperFactory public interface PageSwapperFactory
{ {
/** /**
* Configure page swapper factory with filesystem and config * Open page swapper factory with provided filesystem and config
* @param fs file system to use in page swappers * @param fs file system to use in page swappers
* @param config custom page swapper configuration * @param config custom page swapper configuration
*/ */
void configure( FileSystemAbstraction fs, Configuration config ); void open( FileSystemAbstraction fs, Configuration config );

/**
* Configure swapper with filesystem to use.
* @param fs file system to use in page swappers
*/
default void configure( FileSystemAbstraction fs )
{
this.configure( fs, Configuration.EMPTY );
}


/** /**
* Get the name of this PageSwapperFactory implementation, for configuration purpose. * Get the name of this PageSwapperFactory implementation, for configuration purpose.
Expand Down
Expand Up @@ -46,7 +46,7 @@ public class SingleFilePageSwapperFactory implements PageSwapperFactory
private FileSystemAbstraction fs; private FileSystemAbstraction fs;


@Override @Override
public void configure( FileSystemAbstraction fs, Configuration config ) public void open( FileSystemAbstraction fs, Configuration config )
{ {
this.fs = fs; this.fs = fs;
} }
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/ */
package org.neo4j.io.pagecache.impl.muninn; package org.neo4j.io.pagecache.impl.muninn;


import org.neo4j.graphdb.config.Configuration;
import org.neo4j.io.ByteUnit; import org.neo4j.io.ByteUnit;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static PageCache createPageCache( FileSystemAbstraction fileSystem, Integ
PageCacheTracer tracer, PageCursorTracerSupplier cursorTracerSupplier ) PageCacheTracer tracer, PageCursorTracerSupplier cursorTracerSupplier )
{ {
SingleFilePageSwapperFactory factory = new SingleFilePageSwapperFactory(); SingleFilePageSwapperFactory factory = new SingleFilePageSwapperFactory();
factory.configure( fileSystem ); factory.open( fileSystem, Configuration.EMPTY );


int cachePageSize = pageSize != null ? pageSize : factory.getCachePageSizeHint(); int cachePageSize = pageSize != null ? pageSize : factory.getCachePageSizeHint();
long pageCacheMemory = ByteUnit.mebiBytes( 8 ); long pageCacheMemory = ByteUnit.mebiBytes( 8 );
Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.neo4j.adversaries.pagecache.AdversarialPagedFile; import org.neo4j.adversaries.pagecache.AdversarialPagedFile;
import org.neo4j.concurrent.BinaryLatch; import org.neo4j.concurrent.BinaryLatch;
import org.neo4j.function.ThrowingConsumer; import org.neo4j.function.ThrowingConsumer;
import org.neo4j.graphdb.config.Configuration;
import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction; import org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction;
import org.neo4j.graphdb.mockfs.DelegatingStoreChannel; import org.neo4j.graphdb.mockfs.DelegatingStoreChannel;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction; import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
Expand Down Expand Up @@ -3744,7 +3745,7 @@ public void force() throws IOException
}; };
} }
}; };
factory.configure( fs ); factory.open( fs, Configuration.EMPTY );
return factory; return factory;
} }


Expand Down
Expand Up @@ -37,6 +37,7 @@
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;


import org.neo4j.graphdb.config.Configuration;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction; import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.fs.StoreChannel; import org.neo4j.io.fs.StoreChannel;
Expand Down Expand Up @@ -117,7 +118,7 @@ protected T createPageCache( FileSystemAbstraction fs, int maxPages, int pageSiz
PageCursorTracerSupplier cursorTracerSupplier ) PageCursorTracerSupplier cursorTracerSupplier )
{ {
PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(); PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory();
swapperFactory.configure( fs ); swapperFactory.open( fs, Configuration.EMPTY );
return createPageCache( swapperFactory, maxPages, pageSize, tracer, cursorTracerSupplier ); return createPageCache( swapperFactory, maxPages, pageSize, tracer, cursorTracerSupplier );
} }


Expand Down
Expand Up @@ -82,7 +82,7 @@ public void tearDown() throws Exception
protected PageSwapperFactory swapperFactory() protected PageSwapperFactory swapperFactory()
{ {
SingleFilePageSwapperFactory factory = new SingleFilePageSwapperFactory(); SingleFilePageSwapperFactory factory = new SingleFilePageSwapperFactory();
factory.configure( getFs(), Configuration.EMPTY ); factory.open( getFs(), Configuration.EMPTY );
return factory; return factory;
} }


Expand Down Expand Up @@ -236,7 +236,7 @@ public void creatingSwapperForFileMustTakeLockOnFile() throws Exception
assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS );


PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( fileSystem ); factory.open( fileSystem, Configuration.EMPTY );
File file = testDir.file( "file" ); File file = testDir.file( "file" );
fileSystem.create( file ).close(); fileSystem.create( file ).close();


Expand All @@ -260,7 +260,7 @@ public void creatingSwapperForInternallyLockedFileMustThrow() throws Exception
assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows. assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows.


PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( fileSystem ); factory.open( fileSystem, Configuration.EMPTY );
File file = testDir.file( "file" ); File file = testDir.file( "file" );


StoreFileChannel channel = fileSystem.create( file ); StoreFileChannel channel = fileSystem.create( file );
Expand All @@ -279,7 +279,7 @@ public void creatingSwapperForExternallyLockedFileMustThrow() throws Exception
assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows. assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows.


PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( fileSystem ); factory.open( fileSystem, Configuration.EMPTY );
File file = testDir.file( "file" ); File file = testDir.file( "file" );


fileSystem.create( file ).close(); fileSystem.create( file ).close();
Expand Down Expand Up @@ -313,7 +313,7 @@ public void mustUnlockFileWhenThePageSwapperIsClosed() throws Exception
assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows. assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows.


PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( fileSystem ); factory.open( fileSystem, Configuration.EMPTY );
File file = testDir.file( "file" ); File file = testDir.file( "file" );
fileSystem.create( file ).close(); fileSystem.create( file ).close();


Expand All @@ -332,7 +332,7 @@ public void fileMustRemainLockedEvenIfChannelIsClosedByStrayInterrupt() throws E
assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows. assumeFalse( "No file locking on Windows", SystemUtils.IS_OS_WINDOWS ); // no file locking on Windows.


PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( fileSystem ); factory.open( fileSystem, Configuration.EMPTY );
File file = testDir.file( "file" ); File file = testDir.file( "file" );
fileSystem.create( file ).close(); fileSystem.create( file ).close();


Expand Down Expand Up @@ -361,7 +361,7 @@ public void mustCloseFilesIfTakingFileLockThrows() throws Exception


final AtomicInteger openFilesCounter = new AtomicInteger(); final AtomicInteger openFilesCounter = new AtomicInteger();
PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( new DelegatingFileSystemAbstraction( fileSystem ) factory.open( new DelegatingFileSystemAbstraction( fileSystem )
{ {
@Override @Override
public StoreChannel open( File fileName, String mode ) throws IOException public StoreChannel open( File fileName, String mode ) throws IOException
Expand All @@ -377,7 +377,7 @@ public void close() throws IOException
} }
}; };
} }
} ); }, Configuration.EMPTY );
File file = testDir.file( "file" ); File file = testDir.file( "file" );
try ( StoreChannel ch = fileSystem.create( file ); try ( StoreChannel ch = fileSystem.create( file );
FileLock ignore = ch.tryLock() ) FileLock ignore = ch.tryLock() )
Expand Down Expand Up @@ -422,7 +422,7 @@ public void mustHandleMischiefInPositionedRead() throws Exception
ThreadLocalRandom.current().nextBytes( data ); ThreadLocalRandom.current().nextBytes( data );


PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( getFs() ); factory.open( getFs(), Configuration.EMPTY );
File file = getFile(); File file = getFile();
PageSwapper swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, true ); PageSwapper swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, true );
try try
Expand All @@ -435,7 +435,7 @@ public void mustHandleMischiefInPositionedRead() throws Exception
} }


RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 ); RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 );
factory.configure( new AdversarialFileSystemAbstraction( adversary, getFs() ) ); factory.open( new AdversarialFileSystemAbstraction( adversary, getFs() ), Configuration.EMPTY );
swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, false ); swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, false );


ByteBufferPage page = createPage( bytesTotal ); ByteBufferPage page = createPage( bytesTotal );
Expand Down Expand Up @@ -467,7 +467,7 @@ public void mustHandleMischiefInPositionedWrite() throws Exception
File file = getFile(); File file = getFile();
PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 ); RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 );
factory.configure( new AdversarialFileSystemAbstraction( adversary, getFs() ) ); factory.open( new AdversarialFileSystemAbstraction( adversary, getFs() ), Configuration.EMPTY );
PageSwapper swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, true ); PageSwapper swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, true );


ByteBufferPage page = createPage( bytesTotal ); ByteBufferPage page = createPage( bytesTotal );
Expand Down Expand Up @@ -503,7 +503,7 @@ public void mustHandleMischiefInPositionedVectoredRead() throws Exception
ThreadLocalRandom.current().nextBytes( data ); ThreadLocalRandom.current().nextBytes( data );


PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
factory.configure( getFs() ); factory.open( getFs(), Configuration.EMPTY );
File file = getFile(); File file = getFile();
PageSwapper swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, true ); PageSwapper swapper = createSwapper( factory, file, bytesTotal, NO_CALLBACK, true );
try try
Expand All @@ -516,7 +516,7 @@ public void mustHandleMischiefInPositionedVectoredRead() throws Exception
} }


RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 ); RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 );
factory.configure( new AdversarialFileSystemAbstraction( adversary, getFs() ) ); factory.open( new AdversarialFileSystemAbstraction( adversary, getFs() ), Configuration.EMPTY );
swapper = createSwapper( factory, file, bytesPerPage, NO_CALLBACK, false ); swapper = createSwapper( factory, file, bytesPerPage, NO_CALLBACK, false );


ByteBufferPage[] pages = new ByteBufferPage[pageCount]; ByteBufferPage[] pages = new ByteBufferPage[pageCount];
Expand Down Expand Up @@ -562,7 +562,7 @@ public void mustHandleMischiefInPositionedVectoredWrite() throws Exception
File file = getFile(); File file = getFile();
PageSwapperFactory factory = createSwapperFactory(); PageSwapperFactory factory = createSwapperFactory();
RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 ); RandomAdversary adversary = new RandomAdversary( 0.5, 0.0, 0.0 );
factory.configure( new AdversarialFileSystemAbstraction( adversary, getFs() ) ); factory.open( new AdversarialFileSystemAbstraction( adversary, getFs() ), Configuration.EMPTY );
PageSwapper swapper = createSwapper( factory, file, bytesPerPage, NO_CALLBACK, true ); PageSwapper swapper = createSwapper( factory, file, bytesPerPage, NO_CALLBACK, true );


ByteBufferPage[] writePages = new ByteBufferPage[pageCount]; ByteBufferPage[] writePages = new ByteBufferPage[pageCount];
Expand Down
Expand Up @@ -37,6 +37,7 @@


import org.neo4j.adversaries.RandomAdversary; import org.neo4j.adversaries.RandomAdversary;
import org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction; import org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction;
import org.neo4j.graphdb.config.Configuration;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction; import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageSwapperFactory; import org.neo4j.io.pagecache.PageSwapperFactory;
Expand Down Expand Up @@ -382,7 +383,7 @@ private void runIteration( long timeout, TimeUnit unit ) throws Exception
} }


PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(); PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory();
swapperFactory.configure( fs ); swapperFactory.open( fs, Configuration.EMPTY );
MuninnPageCache cache = new MuninnPageCache( swapperFactory, cachePageCount, cachePageSize, tracer, MuninnPageCache cache = new MuninnPageCache( swapperFactory, cachePageCount, cachePageSize, tracer,
cursorTracerSupplier ); cursorTracerSupplier );
cache.setPrintExceptionsOnClose( false ); cache.setPrintExceptionsOnClose( false );
Expand Down
Expand Up @@ -21,6 +21,7 @@


import java.io.File; import java.io.File;


import org.neo4j.graphdb.config.Configuration;
import org.neo4j.io.fs.DefaultFileSystemAbstraction; import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void run() throws Exception
try ( FileSystemAbstraction fs = new DefaultFileSystemAbstraction() ) try ( FileSystemAbstraction fs = new DefaultFileSystemAbstraction() )
{ {
PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(); PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory();
swapperFactory.configure( fs ); swapperFactory.open( fs, Configuration.EMPTY );


try ( PageCache pageCacheUnderTest = new MuninnPageCache( swapperFactory, numberOfCachePages, cachePageSize, try ( PageCache pageCacheUnderTest = new MuninnPageCache( swapperFactory, numberOfCachePages, cachePageSize,
tracer, pageCursorTracerSupplier ) ) tracer, pageCursorTracerSupplier ) )
Expand Down
Expand Up @@ -196,7 +196,7 @@ public void dumpConfiguration()
private static PageSwapperFactory createAndConfigureSwapperFactory( FileSystemAbstraction fs, Config config, Log log ) private static PageSwapperFactory createAndConfigureSwapperFactory( FileSystemAbstraction fs, Config config, Log log )
{ {
PageSwapperFactory factory = getPageSwapperFactory( config, log ); PageSwapperFactory factory = getPageSwapperFactory( config, log );
factory.configure( fs, config ); factory.open( fs, config );
return factory; return factory;
} }


Expand Down
Expand Up @@ -81,9 +81,9 @@ public Stream<FileHandle> streamFilesRecursive( File directory )
} }


@Override @Override
public void configure( FileSystemAbstraction fs, Configuration configuration ) public void open( FileSystemAbstraction fs, Configuration configuration )
{ {
super.configure( fs, configuration ); super.open( fs, configuration );
configuredCounter.getAndIncrement(); configuredCounter.getAndIncrement();
} }
} }

0 comments on commit 41253d9

Please sign in to comment.