Search in sources :

Example 51 with DefaultFileSystemAbstraction

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

the class LoadCommandTest method shouldRespectTheStoreLock.

@Test
public void shouldRespectTheStoreLock() throws IOException, IncorrectUsage {
    Path databaseDirectory = homeDir.resolve("data/databases/foo.db");
    Files.createDirectories(databaseDirectory);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        StoreLocker locker = new StoreLocker(fileSystem)) {
        locker.checkLock(databaseDirectory.toFile());
        execute("foo.db", "--force");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
    }
}
Also used : Path(java.nio.file.Path) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) StoreLocker(org.neo4j.kernel.internal.StoreLocker) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 52 with DefaultFileSystemAbstraction

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

the class GeoDataGenerator method generate.

public void generate(File storeDir) throws IOException {
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        BatchInserter inserter = BatchInserters.inserter(storeDir.getAbsoluteFile(), fileSystem);
        Grid grid = new Grid();
        try {
            for (int i = 0; i < numberOfNodes; i++) {
                grid.createNodeAtRandomLocation(random, inserter);
            }
            for (int i = 0; i < numberOfConnections; i++) {
                grid.createConnection(random, inserter);
            }
        } finally {
            inserter.shutdown();
        }
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction)

Example 53 with DefaultFileSystemAbstraction

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

the class ImportTool method main.

/**
     * Runs the import tool given the supplied arguments.
     *
     * @param incomingArguments arguments for specifying input and configuration for the import.
     * @param defaultSettingsSuitableForTests default configuration geared towards unit/integration
     * test environments, for example lower default buffer sizes.
     */
public static void main(String[] incomingArguments, boolean defaultSettingsSuitableForTests) throws IOException {
    System.err.println("WARNING: neo4j-import is deprecated and support for it will be removed in a future\n" + "version of Neo4j; please use neo4j-admin import instead.\n");
    PrintStream out = System.out;
    PrintStream err = System.err;
    Args args = Args.parse(incomingArguments);
    if (ArrayUtil.isEmpty(incomingArguments) || asksForUsage(args)) {
        printUsage(out);
        return;
    }
    File storeDir;
    Collection<Option<File[]>> nodesFiles, relationshipsFiles;
    boolean enableStacktrace;
    Number processors = null;
    Input input = null;
    int badTolerance;
    Charset inputEncoding;
    boolean skipBadRelationships, skipDuplicateNodes, ignoreExtraColumns;
    Config dbConfig;
    OutputStream badOutput = null;
    IdType idType = null;
    int pageSize = UNSPECIFIED;
    Collector badCollector;
    org.neo4j.unsafe.impl.batchimport.Configuration configuration = null;
    File logsDir;
    File badFile;
    boolean success = false;
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction()) {
        storeDir = args.interpretOption(Options.STORE_DIR.key(), Converters.<File>mandatory(), Converters.toFile(), Validators.DIRECTORY_IS_WRITABLE, Validators.CONTAINS_NO_EXISTING_DATABASE);
        Config config = Config.defaults();
        config.augment(stringMap(GraphDatabaseSettings.neo4j_home.name(), storeDir.getAbsolutePath()));
        logsDir = config.get(GraphDatabaseSettings.logs_directory);
        fs.mkdirs(logsDir);
        badFile = new File(storeDir, BAD_FILE_NAME);
        badOutput = new BufferedOutputStream(fs.openAsOutputStream(badFile, false));
        nodesFiles = extractInputFiles(args, Options.NODE_DATA.key(), err);
        relationshipsFiles = extractInputFiles(args, Options.RELATIONSHIP_DATA.key(), err);
        validateInputFiles(nodesFiles, relationshipsFiles);
        enableStacktrace = args.getBoolean(Options.STACKTRACE.key(), Boolean.FALSE, Boolean.TRUE);
        processors = args.getNumber(Options.PROCESSORS.key(), null);
        idType = args.interpretOption(Options.ID_TYPE.key(), withDefault((IdType) Options.ID_TYPE.defaultValue()), TO_ID_TYPE);
        badTolerance = parseNumberOrUnlimited(args, Options.BAD_TOLERANCE);
        inputEncoding = Charset.forName(args.get(Options.INPUT_ENCODING.key(), defaultCharset().name()));
        skipBadRelationships = args.getBoolean(Options.SKIP_BAD_RELATIONSHIPS.key(), (Boolean) Options.SKIP_BAD_RELATIONSHIPS.defaultValue(), true);
        skipDuplicateNodes = args.getBoolean(Options.SKIP_DUPLICATE_NODES.key(), (Boolean) Options.SKIP_DUPLICATE_NODES.defaultValue(), true);
        ignoreExtraColumns = args.getBoolean(Options.IGNORE_EXTRA_COLUMNS.key(), (Boolean) Options.IGNORE_EXTRA_COLUMNS.defaultValue(), true);
        badCollector = badCollector(badOutput, badTolerance, collect(skipBadRelationships, skipDuplicateNodes, ignoreExtraColumns));
        dbConfig = loadDbConfig(args.interpretOption(Options.DATABASE_CONFIG.key(), Converters.<File>optional(), Converters.toFile(), Validators.REGEX_FILE_EXISTS));
        configuration = importConfiguration(processors, defaultSettingsSuitableForTests, dbConfig, pageSize);
        input = new CsvInput(nodeData(inputEncoding, nodesFiles), defaultFormatNodeFileHeader(), relationshipData(inputEncoding, relationshipsFiles), defaultFormatRelationshipFileHeader(), idType, csvConfiguration(args, defaultSettingsSuitableForTests), badCollector, configuration.maxNumberOfProcessors());
        doImport(out, err, storeDir, logsDir, badFile, fs, nodesFiles, relationshipsFiles, enableStacktrace, input, dbConfig, badOutput, configuration);
        success = true;
    } catch (IllegalArgumentException e) {
        throw andPrintError("Input error", e, false, err);
    } catch (IOException e) {
        throw andPrintError("File error", e, false, err);
    } finally {
        if (!success && badOutput != null) {
            badOutput.close();
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) CsvInput(org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput) Input(org.neo4j.unsafe.impl.batchimport.input.Input) BadCollector(org.neo4j.unsafe.impl.batchimport.input.BadCollector) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) Collectors.badCollector(org.neo4j.unsafe.impl.batchimport.input.Collectors.badCollector) BufferedOutputStream(java.io.BufferedOutputStream) PrintStream(java.io.PrintStream) Args(org.neo4j.helpers.Args) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Charset.defaultCharset(java.nio.charset.Charset.defaultCharset) Charset(java.nio.charset.Charset) CsvInput(org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput) IOException(java.io.IOException) IdType(org.neo4j.unsafe.impl.batchimport.input.csv.IdType) Option(org.neo4j.helpers.Args.Option) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File)

Example 54 with DefaultFileSystemAbstraction

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

the class BackupToolIT method setUp.

@Before
public void setUp() throws Exception {
    backupDir = testDirectory.directory("backups/graph.db").toPath();
    fs = new DefaultFileSystemAbstraction();
    pageCache = StandalonePageCacheFactory.createPageCache(fs);
    backupTool = new BackupTool(new BackupService(), mock(PrintStream.class));
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Before(org.junit.Before)

Example 55 with DefaultFileSystemAbstraction

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

the class ArbiterBootstrapper method start.

@SafeVarargs
@Override
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
    Config config = getConfig(configFile, configOverrides);
    try {
        DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        life.add(new FileSystemLifecycleAdapter(fileSystem));
        life.add(new Neo4jJobScheduler());
        new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService(fileSystem, config), new NotElectableElectionCredentialsProvider());
    } catch (LifecycleException e) {
        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" }) Throwable cause = peel(e, Predicates.<Throwable>instanceOf(LifecycleException.class));
        if (cause instanceof ChannelException) {
            System.err.println("ERROR: " + cause.getMessage() + (cause.getCause() != null ? ", caused by:" + cause.getCause().getMessage() : ""));
        } else {
            System.err.println("ERROR: Unknown error");
            throw e;
        }
    }
    addShutdownHook();
    life.start();
    return 0;
}
Also used : FileSystemLifecycleAdapter(org.neo4j.io.fs.FileSystemLifecycleAdapter) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) NotElectableElectionCredentialsProvider(org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider) Monitors(org.neo4j.kernel.monitoring.Monitors) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) ChannelException(org.jboss.netty.channel.ChannelException)

Aggregations

DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)82 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)43 File (java.io.File)24 Path (java.nio.file.Path)21 PageCache (org.neo4j.io.pagecache.PageCache)21 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)13 IOException (java.io.IOException)12 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)11 Config (org.neo4j.kernel.configuration.Config)11 Config (org.neo4j.configuration.Config)9 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)7 Transaction (org.neo4j.graphdb.Transaction)7 PrintStream (java.io.PrintStream)6 Before (org.junit.Before)6 CommandFailed (org.neo4j.commandline.admin.CommandFailed)6 Args (org.neo4j.helpers.Args)6 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)6 JobScheduler (org.neo4j.scheduler.JobScheduler)6