Skip to content

Commit

Permalink
Use file to for storeDir representation if GraphDatabaseFacade API.
Browse files Browse the repository at this point in the history
Use file instead of string to represent store dir,
cleanup all the wrapping and converting around that
  • Loading branch information
MishaDemianenko committed Jul 6, 2017
1 parent 7038b68 commit 0486e14
Show file tree
Hide file tree
Showing 28 changed files with 50 additions and 54 deletions.
Expand Up @@ -699,9 +699,9 @@ public URL validateURLAccess( URL url ) throws URLAccessValidationError
}

@Override
public String getStoreDir()
public File getStoreDir()
{
return spi.storeDir().getAbsolutePath();
return spi.storeDir();
}

@Override
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.kernel.internal;

import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -52,7 +53,7 @@ public interface GraphDatabaseAPI extends GraphDatabaseService
*/
URL validateURLAccess( URL url ) throws URLAccessValidationError;

String getStoreDir();
File getStoreDir();

/**
* Begin internal transaction with specified type and access mode
Expand Down
Expand Up @@ -95,7 +95,7 @@ private long countLogEntries()
{
GraphDatabaseAPI db = dbr.getGraphDatabaseAPI();
FileSystemAbstraction fs = db.getDependencyResolver().resolveDependency( FileSystemAbstraction.class );
File storeDir = new File( db.getStoreDir() );
File storeDir = db.getStoreDir();
try
{
CountingLogHook<LogEntry> logicalLogCounter = new CountingLogHook<>();
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.After;
import org.junit.Test;

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

import org.neo4j.graphdb.Node;
Expand Down Expand Up @@ -182,7 +181,7 @@ private GraphDatabaseAPI newDb( String logPruning, int rotateEveryNTransactions
GraphDatabaseBuilder builder = gdf.newImpermanentDatabaseBuilder();
builder.setConfig( keep_logical_logs, logPruning );
this.db = (GraphDatabaseAPI) builder.newGraphDatabase();
files = new PhysicalLogFiles( new File( db.getStoreDir() ), PhysicalLogFile.DEFAULT_NAME, fs );
files = new PhysicalLogFiles( db.getStoreDir(), PhysicalLogFile.DEFAULT_NAME, fs );
return db;
}

Expand Down
Expand Up @@ -114,7 +114,7 @@ public void setUp() throws IOException

private void createIndexDbFile() throws IOException
{
File storeDir = new File( db.getStoreDir() );
File storeDir = db.getStoreDir();
final File indexFile = new File( storeDir, "index.db" );
if ( !indexFile.exists() )
{
Expand Down
Expand Up @@ -176,7 +176,7 @@ public void shutdown()
{
if ( TRACK_UNCLOSED_DATABASE_INSTANCES )
{
startedButNotYetClosed.remove( new File( getStoreDir() ) );
startedButNotYetClosed.remove( getStoreDir() );
}

super.shutdown();
Expand Down
Expand Up @@ -65,7 +65,7 @@ public abstract class DatabaseRule extends ExternalResource implements GraphData
{
private GraphDatabaseBuilder databaseBuilder;
private GraphDatabaseAPI database;
private String storeDir;
private File storeDir;
private Supplier<Statement> statementSupplier;
private boolean startEagerly = true;
private Map<Setting<?>, String> config;
Expand Down Expand Up @@ -378,7 +378,7 @@ public GraphDatabaseAPI restartDatabase( RestartAction action ) throws IOExcepti
{
FileSystemAbstraction fs = resolveDependency( FileSystemAbstraction.class );
database.shutdown();
action.run( fs, new File( storeDir ) );
action.run( fs, storeDir );
database = null;
return getGraphDatabaseAPI();
}
Expand Down Expand Up @@ -438,19 +438,19 @@ public StoreId storeId()
}

@Override
public String getStoreDir()
public File getStoreDir()
{
return database.getStoreDir();
}

public String getStoreDirAbsolutePath()
{
return new File( getStoreDir() ).getAbsolutePath();
return getStoreDir().getAbsolutePath();
}

public File getStoreDirFile()
{
return new File( getStoreDir() );
return getStoreDir();
}

@Override
Expand Down
Expand Up @@ -128,17 +128,11 @@ public EmbeddedDatabaseRule startLazily()
{
return (EmbeddedDatabaseRule) super.startLazily();
}
/*
public EmbeddedDatabaseRule withConfig(Config config )
{
this.config = config;
return this;
}*/

@Override
public String getStoreDir()
public File getStoreDir()
{
return temp.root().getPath();
return temp.root();
}

@Override
Expand Down
Expand Up @@ -82,7 +82,7 @@ public void shouldNotLeaveLuceneIndexFilesHangingAroundIfConstraintCreationFails

SchemaIndexProvider schemaIndexProvider =
db.getDependencyResolver().resolveDependency( SchemaIndexProvider.class );
File schemaStoreDir = schemaIndexProvider.getSchemaIndexStoreDirectory( new File( db.getStoreDir() ) );
File schemaStoreDir = schemaIndexProvider.getSchemaIndexStoreDirectory( db.getStoreDir() );

assertFalse( new IndexFolderLayout( schemaStoreDir, INDEX_IDENTIFIER ).getIndexFolder().exists() );
}
Expand Down
Expand Up @@ -126,7 +126,7 @@ private File archiveFile() throws IOException
{
try ( FileSystemAbstraction fs = new DefaultFileSystemAbstraction() )
{
File indexDir = soleIndexDir( fs, new File( db.getStoreDir() ) );
File indexDir = soleIndexDir( fs, db.getStoreDir() );
File[] files = indexDir.getParentFile()
.listFiles( pathname -> pathname.isFile() && pathname.getName().startsWith( "archive-" ) );
if ( files == null || files.length == 0 )
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.server.database;

import java.io.File;

import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
Expand All @@ -31,7 +33,7 @@ interface Factory
Database newDatabase( Config config, GraphDatabaseFacadeFactory.Dependencies dependencies );
}

String getLocation();
File getLocation();

GraphDatabaseFacade getGraph();

Expand Down
Expand Up @@ -65,10 +65,9 @@ public LifecycleManagingDatabase( Config config, GraphFactory dbFactory,
}

@Override
public String getLocation()
public File getLocation()
{
File file = config.get( DatabaseManagementSystemSettings.database_path );
return file.getAbsolutePath();
return config.get( DatabaseManagementSystemSettings.database_path );
}

@Override
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.server.database;

import java.io.File;

import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;

Expand All @@ -40,7 +42,7 @@ public WrappedDatabase( GraphDatabaseFacade graph )
}

@Override
public String getLocation()
public File getLocation()
{
return graph.getStoreDir();
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.shell.kernel;

import java.io.File;
import java.io.Serializable;
import java.net.URL;
import java.util.Collections;
Expand Down Expand Up @@ -1053,7 +1054,7 @@ public DependencyResolver getDependencyResolver()
}

@Override
public String getStoreDir()
public File getStoreDir()
{
return actual.getStoreDir();
}
Expand Down
2 changes: 1 addition & 1 deletion community/shell/src/test/java/org/neo4j/shell/AppsIT.java
Expand Up @@ -1270,7 +1270,7 @@ private void verifyNumberOfCommits( String query, long expectedCommitCount ) thr
long txIdBeforeQuery = lastClosedTxId();

// When
startClient.start( new String[]{"-path", db.getStoreDir(), "-c", query}, ctrlCHandler );
startClient.start( new String[]{"-path", db.getStoreDir().getAbsolutePath(), "-c", query}, ctrlCHandler );

// then
long txId = lastClosedTxId();
Expand Down
Expand Up @@ -159,7 +159,8 @@ protected GraphDatabaseShellServer getGraphDatabaseShellServer( File path, boole
};

// when
startClient.start( new String[]{"-path", db.getStoreDir(), "-c", "CREATE (n {foo:'bar'});"}, ctrlCHandler );
startClient.start( new String[]{"-path", db.getStoreDir().getAbsolutePath(), "-c", "CREATE (n {foo:'bar'});"},
ctrlCHandler );

// verify
verify( databaseShellServer ).shutdown();
Expand All @@ -175,7 +176,7 @@ public void shouldReportEditionThroughDbInfoApp() throws Exception
StartClient client = new StartClient( new PrintStream( out ), new PrintStream( err ) );

// when
client.start( new String[]{"-path", db.getStoreDir() + "testDb", "-c",
client.start( new String[]{"-path", db.getStoreDir().getAbsolutePath() + "testDb", "-c",
"dbinfo -g Configuration unsupported.dbms.edition"},
ctrlCHandler );
// then
Expand Down Expand Up @@ -218,7 +219,7 @@ protected GraphDatabaseShellServer getGraphDatabaseShellServer( File path, boole
shellServer = new GraphDatabaseShellServer( factory, path, readOnly, configFile );
return shellServer;
}
}.start( new String[]{"-c", "RETURN 1;", "-path", db.getStoreDir() + "test-db", "-config",
}.start( new String[]{"-c", "RETURN 1;", "-path", db.getStoreDir().getAbsolutePath() + "test-db", "-config",
getClass().getResource( "/config-with-bolt-connector.conf" ).getFile()}, mock( CtrlCHandler.class ) );
try
{
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.backup;

import java.io.File;
import java.net.URI;
import java.util.function.Supplier;

Expand Down Expand Up @@ -89,7 +88,7 @@ public OnlineBackupKernelExtension( Config config, final GraphDatabaseAPI graphD
{
TransactionIdStore transactionIdStore = transactionIdStoreSupplier.get();
StoreCopyServer copier = new StoreCopyServer( neoStoreDataSource, checkPointerSupplier.get(),
fileSystemAbstraction, new File( graphDatabaseAPI.getStoreDir() ),
fileSystemAbstraction, graphDatabaseAPI.getStoreDir(),
monitors.newMonitor( StoreCopyServer.Monitor.class ), pageCache, storeCopyCheckPointMutex );
LogicalTransactionStore logicalTransactionStore = logicalTransactionStoreSupplier.get();
LogFileInformation logFileInformation = logFileInformationSupplier.get();
Expand Down
Expand Up @@ -25,7 +25,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Clock;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -229,7 +228,7 @@ public void shouldEventuallyPullTransactionDownToAllReadReplicas() throws Except

private void gatherLabelScanStoreFiles( GraphDatabaseAPI db, Set<Path> labelScanStoreFiles )
{
Path dbStoreDirectory = Paths.get( db.getStoreDir() ).toAbsolutePath();
Path dbStoreDirectory = db.getStoreDir().toPath().toAbsolutePath();
LabelScanStore labelScanStore = db.getDependencyResolver().resolveDependency( LabelScanStore.class );
try ( ResourceIterator<File> files = labelScanStore.snapshotStoreFiles() )
{
Expand Down
Expand Up @@ -73,6 +73,6 @@ public boolean isMaster()

public File getStoreDirectory()
{
return new File( getStoreDir() );
return getStoreDir();
}
}
Expand Up @@ -102,7 +102,7 @@ public DefaultMasterImplSPI( final GraphDatabaseAPI graphDb,
this.checkPointer = checkPointer;
this.neoStoreDataSource = neoStoreDataSource;
this.mutex = mutex;
this.storeDir = new File( graphDb.getStoreDir() );
this.storeDir = graphDb.getStoreDir();
this.txChecksumLookup = new TransactionChecksumLookup( transactionIdStore, logicalTransactionStore );
this.responsePacker = new ResponsePacker( logicalTransactionStore, transactionIdStore, graphDb::storeId );
this.monitors = monitors;
Expand Down
Expand Up @@ -122,7 +122,7 @@ public void shouldCopyStoreFromMasterIfBranched() throws Throwable

// WHEN
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
File storeDir = new File( slave.getStoreDir() );
File storeDir = slave.getStoreDir();
RepairKit starter = cluster.shutdown( slave );
HighlyAvailableGraphDatabase master = cluster.getMaster();
createNode( master, "B1" );
Expand Down
Expand Up @@ -308,7 +308,7 @@ private ClusterManager.RepairKit bringSlaveOfflineAndRemoveStoreFiles( ManagedCl
{
ClusterManager.RepairKit slaveDown = cluster.shutdown( slave );

File storeDir = new File( slave.getStoreDir() );
File storeDir = slave.getStoreDir();
deleteRecursively( storeDir );
storeDir.mkdir();
return slaveDown;
Expand Down
4 changes: 2 additions & 2 deletions enterprise/ha/src/test/java/org/neo4j/test/ha/ClusterIT.java
Expand Up @@ -309,7 +309,7 @@ public void lastTxCommitTimestampShouldGetInitializedOnSlaveIfNotPresent() throw
cluster.sync();

HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
File storeDir = new File( slave.getStoreDir() );
File storeDir = slave.getStoreDir();
ClusterManager.RepairKit slaveRepairKit = cluster.shutdown( slave );

clearLastTransactionCommitTimestampField( storeDir );
Expand Down Expand Up @@ -342,7 +342,7 @@ public void lastTxCommitTimestampShouldBeUnknownAfterStartIfNoFiledOrLogsPresent
cluster.sync();

HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
File storeDir = new File( slave.getStoreDir() );
File storeDir = slave.getStoreDir();
ClusterManager.RepairKit slaveRepairKit = cluster.shutdown( slave );

clearLastTransactionCommitTimestampField( storeDir );
Expand Down
Expand Up @@ -115,7 +115,7 @@ private static void assertConsistentStore( GraphDatabaseAPI db ) throws Exceptio
{
ConsistencyCheckService service = new ConsistencyCheckService();

File storeDir = new File( db.getStoreDir() );
File storeDir = db.getStoreDir();
ConsistencyCheckService.Result result = service.runFullConsistencyCheck( storeDir, Config.empty(),
ProgressMonitorFactory.textual( System.out ), FormattedLogProvider.toOutputStream( System.out ), true );

Expand Down
Expand Up @@ -529,7 +529,7 @@ private void cleanup( GraphDatabaseService gdb ) throws IOException
{
GraphDatabaseAPI db = (GraphDatabaseAPI) gdb;
gdb.shutdown();
FileUtils.deleteDirectory( new File( db.getStoreDir() ) );
FileUtils.deleteDirectory( db.getStoreDir() );
}
}

Expand Down
Expand Up @@ -248,8 +248,8 @@ public void migratingOlderDataAndThanStartAClusterUsingTheNewerDataShouldWork()
clusterManager.safeShutdown();
}

assertConsistentStore( new File( master.getStoreDir() ) );
assertConsistentStore( new File( slave.getStoreDir() ) );
assertConsistentStore( master.getStoreDir() );
assertConsistentStore( slave.getStoreDir() );
}
}

Expand Down

0 comments on commit 0486e14

Please sign in to comment.