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);
}
}
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));
}
}
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));
}
}
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);
}
}
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"));
}
}
Aggregations