Search in sources :

Example 31 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class TestArrayStore method before.

@Before
public void before() throws Exception {
    File dir = testDirectory.graphDbDir();
    FileSystemAbstraction fs = fileSystemRule.get();
    DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    StoreFactory factory = new StoreFactory(dir, Config.empty(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance());
    neoStores = factory.openAllNeoStores(true);
    arrayStore = neoStores.getPropertyStore().getArrayStore();
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Before(org.junit.Before)

Example 32 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class NeoStoresTest method shouldNotSetHighestTransactionIdWhenNeeded.

@Test
public void shouldNotSetHighestTransactionIdWhenNeeded() throws Throwable {
    // GIVEN
    FileSystemAbstraction fileSystem = fs.get();
    fileSystem.mkdirs(storeDir);
    StoreFactory factory = new StoreFactory(storeDir, pageCache, fileSystem, NullLogProvider.getInstance());
    try (NeoStores neoStore = factory.openAllNeoStores(true)) {
        MetaDataStore store = neoStore.getMetaDataStore();
        store.setLastCommittedAndClosedTransactionId(40, 4444, BASE_TX_COMMIT_TIMESTAMP, LogHeader.LOG_HEADER_SIZE, 0);
        // WHEN
        store.transactionCommitted(39, 3333, BASE_TX_COMMIT_TIMESTAMP);
        // THEN
        assertEquals(new TransactionId(40, 4444, BASE_TX_COMMIT_TIMESTAMP), store.getLastCommittedTransaction());
        assertArrayEquals(store.getLastClosedTransaction(), new long[] { 40, 0, LogHeader.LOG_HEADER_SIZE });
    }
}
Also used : UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Test(org.junit.Test)

Example 33 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class CheckConsistencyCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final String database;
    final boolean verbose;
    final Optional<Path> additionalConfigFile;
    final Path reportDir;
    final Optional<Path> backupPath;
    final boolean checkGraph;
    final boolean checkIndexes;
    final boolean checkLabelScanStore;
    final boolean checkPropertyOwners;
    try {
        database = arguments.parse("database", args);
        backupPath = arguments.parseOptionalPath("backup", args);
        verbose = arguments.parseBoolean("verbose", args);
        additionalConfigFile = arguments.parseOptionalPath("additional-config", args);
        reportDir = arguments.parseOptionalPath("report-dir", args).orElseThrow(() -> new IllegalArgumentException("report-dir must be a valid path"));
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    if (backupPath.isPresent()) {
        if (arguments.has("database", args)) {
            throw new IncorrectUsage("Only one of '--database' and '--backup' can be specified.");
        }
        if (!backupPath.get().toFile().isDirectory()) {
            throw new CommandFailed(format("Specified backup should be a directory: %s", backupPath.get()));
        }
    }
    Config config = loadNeo4jConfig(homeDir, configDir, database, loadAdditionalConfig(additionalConfigFile));
    try {
        // We can remove the loading from config file in 4.0
        if (arguments.has(CHECK_GRAPH, args)) {
            checkGraph = arguments.parseBoolean(CHECK_GRAPH, args);
        } else {
            checkGraph = ConsistencyCheckSettings.consistency_check_graph.from(config);
        }
        if (arguments.has(CHECK_INDEXES, args)) {
            checkIndexes = arguments.parseBoolean(CHECK_INDEXES, args);
        } else {
            checkIndexes = ConsistencyCheckSettings.consistency_check_indexes.from(config);
        }
        if (arguments.has(CHECK_LABEL_SCAN_STORE, args)) {
            checkLabelScanStore = arguments.parseBoolean(CHECK_LABEL_SCAN_STORE, args);
        } else {
            checkLabelScanStore = ConsistencyCheckSettings.consistency_check_label_scan_store.from(config);
        }
        if (arguments.has(CHECK_PROPERTY_OWNERS, args)) {
            checkPropertyOwners = arguments.parseBoolean(CHECK_PROPERTY_OWNERS, args);
        } else {
            checkPropertyOwners = ConsistencyCheckSettings.consistency_check_property_owners.from(config);
        }
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        File storeDir = backupPath.map(Path::toFile).orElse(config.get(database_path));
        checkDbState(storeDir, config);
        ConsistencyCheckService.Result consistencyCheckResult = consistencyCheckService.runFullConsistencyCheck(storeDir, config, ProgressMonitorFactory.textual(System.err), FormattedLogProvider.toOutputStream(System.out), fileSystem, verbose, reportDir.toFile(), new CheckConsistencyConfig(checkGraph, checkIndexes, checkLabelScanStore, checkPropertyOwners));
        if (!consistencyCheckResult.isSuccessful()) {
            throw new CommandFailed(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.reportFile()));
        }
    } catch (ConsistencyCheckIncompleteException | IOException e) {
        throw new CommandFailed("Consistency checking failed." + e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) OptionalCanonicalPath(org.neo4j.commandline.arguments.common.OptionalCanonicalPath) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) Config(org.neo4j.kernel.configuration.Config) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) IOException(java.io.IOException) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) CommandFailed(org.neo4j.commandline.admin.CommandFailed) File(java.io.File)

Example 34 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class RealOutsideWorldTest method closeFilesystemOnExit.

@Test
public void closeFilesystemOnExit() throws IOException {
    RealOutsideWorld outsideWorld = new RealOutsideWorld();
    FileSystemAbstraction fileSystemMock = mock(FileSystemAbstraction.class);
    outsideWorld.fileSystemAbstraction = fileSystemMock;
    systemExitRule.expectExit(0);
    outsideWorld.exit(0);
    verify(fileSystemMock).close();
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Test(org.junit.Test)

Example 35 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class RealOutsideWorldTest method closeFileSystemOnClose.

@Test
public void closeFileSystemOnClose() throws Exception {
    RealOutsideWorld outsideWorld = new RealOutsideWorld();
    FileSystemAbstraction fileSystemMock = mock(FileSystemAbstraction.class);
    outsideWorld.fileSystemAbstraction = fileSystemMock;
    outsideWorld.close();
    verify(fileSystemMock).close();
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Test(org.junit.Test)

Aggregations

FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)125 File (java.io.File)88 Test (org.junit.Test)82 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)34 IOException (java.io.IOException)28 Config (org.neo4j.kernel.configuration.Config)23 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)22 PageCache (org.neo4j.io.pagecache.PageCache)22 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)20 ByteBuffer (java.nio.ByteBuffer)13 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)9 OutputStream (java.io.OutputStream)8 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)8 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)8 Map (java.util.Map)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)7