Search in sources :

Example 1 with StoreLockException

use of org.neo4j.kernel.StoreLockException in project neo4j by neo4j.

the class DumpCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    String database = arguments.parse("database", args);
    Path archive = calculateArchive(database, arguments.parseMandatoryPath("to", args));
    Path databaseDirectory = canonicalPath(toDatabaseDirectory(database));
    try {
        Validators.CONTAINS_EXISTING_DATABASE.validate(databaseDirectory.toFile());
    } catch (IllegalArgumentException e) {
        throw new CommandFailed("database does not exist: " + database, e);
    }
    try (Closeable ignored = StoreLockChecker.check(databaseDirectory)) {
        dump(database, databaseDirectory, archive);
    } catch (StoreLockException e) {
        throw new CommandFailed("the database is in use -- stop Neo4j and try again", e);
    } catch (IOException e) {
        wrapIOException(e);
    } catch (CannotWriteException e) {
        throw new CommandFailed("you do not have permission to dump the database -- is Neo4j running as a " + "different user?", e);
    }
}
Also used : Util.canonicalPath(org.neo4j.commandline.Util.canonicalPath) Path(java.nio.file.Path) Closeable(java.io.Closeable) CommandFailed(org.neo4j.commandline.admin.CommandFailed) StoreLockException(org.neo4j.kernel.StoreLockException) IOException(java.io.IOException)

Example 2 with StoreLockException

use of org.neo4j.kernel.StoreLockException in project neo4j by neo4j.

the class StoreLockerTest method shouldNotObtainLockWhenUnableToOpenLockFile.

@Test
public void shouldNotObtainLockWhenUnableToOpenLockFile() throws Exception {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {

        @Override
        public StoreChannel open(File fileName, String mode) throws IOException {
            throw new IOException("cannot open lock file");
        }

        @Override
        public boolean fileExists(File fileName) {
            return false;
        }
    };
    File storeDir = target.directory("unused");
    try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
        storeLocker.checkLock(storeDir);
        fail();
    } catch (StoreLockException e) {
        String msg = format("Unable to obtain lock on store lock file: %s. " + "Please ensure no other process is using this database, and that the " + "directory is writable (required even for read-only access)", new File(storeDir, STORE_LOCK_FILENAME));
        assertThat(e.getMessage(), is(msg));
    }
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreLockException(org.neo4j.kernel.StoreLockException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Example 3 with StoreLockException

use of org.neo4j.kernel.StoreLockException in project neo4j by neo4j.

the class StoreLockerTest method shouldNotObtainLockWhenStoreDirCannotBeCreated.

@Test
public void shouldNotObtainLockWhenStoreDirCannotBeCreated() throws Exception {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {

        @Override
        public void mkdirs(File fileName) throws IOException {
            throw new IOException("store dir could not be created");
        }

        @Override
        public boolean fileExists(File fileName) {
            return false;
        }
    };
    File storeDir = target.directory("unused");
    try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
        storeLocker.checkLock(storeDir);
        fail();
    } catch (StoreLockException e) {
        String msg = format("Unable to create path for store dir: %s. " + "Please ensure no other process is using this database, and that " + "the directory is writable (required even for read-only access)", storeDir);
        assertThat(e.getMessage(), is(msg));
    }
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreLockException(org.neo4j.kernel.StoreLockException) IOException(java.io.IOException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Example 4 with StoreLockException

use of org.neo4j.kernel.StoreLockException in project neo4j by neo4j.

the class UnbindFromClusterCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    try {
        Config config = loadNeo4jConfig(homeDir, configDir, arguments.parse("database", args));
        File dataDirectory = config.get(DatabaseManagementSystemSettings.data_directory);
        Path pathToSpecificDatabase = config.get(DatabaseManagementSystemSettings.database_path).toPath();
        Validators.CONTAINS_EXISTING_DATABASE.validate(pathToSpecificDatabase.toFile());
        confirmTargetDirectoryIsWritable(pathToSpecificDatabase);
        ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory(dataDirectory);
        clusterStateDirectory.initialize(outsideWorld.fileSystem());
        deleteClusterStateIn(clusterStateDirectory.get().toPath());
    } catch (StoreLockException e) {
        throw new CommandFailed("Database is currently locked. Please shutdown Neo4j.", e);
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    } catch (UnbindFailureException | CannotWriteException | IOException | ClusterStateException e) {
        throw new CommandFailed(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) ClusterStateDirectory(org.neo4j.causalclustering.core.state.ClusterStateDirectory) Config(org.neo4j.kernel.configuration.Config) StoreLockException(org.neo4j.kernel.StoreLockException) IOException(java.io.IOException) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) CommandFailed(org.neo4j.commandline.admin.CommandFailed) ClusterStateException(org.neo4j.causalclustering.core.state.ClusterStateException) File(java.io.File)

Example 5 with StoreLockException

use of org.neo4j.kernel.StoreLockException in project neo4j by neo4j.

the class StoreLockerTest method shouldNotObtainLockWhenStoreAlreadyInUse.

@Test
public void shouldNotObtainLockWhenStoreAlreadyInUse() throws Exception {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {

        @Override
        public boolean fileExists(File fileName) {
            return false;
        }

        @Override
        public StoreChannel open(File fileName, String mode) throws IOException {
            return new DelegatingStoreChannel(super.open(fileName, mode)) {

                @Override
                public FileLock tryLock() throws IOException {
                    // 'null' implies that the file has been externally locked
                    return null;
                }
            };
        }
    };
    try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
        storeLocker.checkLock(target.directory("unused"));
        fail();
    } catch (StoreLockException e) {
        assertThat(e.getMessage(), containsString("Store and its lock file has been locked by another process"));
    }
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreLockException(org.neo4j.kernel.StoreLockException) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Aggregations

StoreLockException (org.neo4j.kernel.StoreLockException)5 File (java.io.File)4 IOException (java.io.IOException)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Test (org.junit.Test)3 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 Path (java.nio.file.Path)2 CommandFailed (org.neo4j.commandline.admin.CommandFailed)2 Closeable (java.io.Closeable)1 ClusterStateDirectory (org.neo4j.causalclustering.core.state.ClusterStateDirectory)1 ClusterStateException (org.neo4j.causalclustering.core.state.ClusterStateException)1 Util.canonicalPath (org.neo4j.commandline.Util.canonicalPath)1 IncorrectUsage (org.neo4j.commandline.admin.IncorrectUsage)1 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)1 Config (org.neo4j.kernel.configuration.Config)1