use of org.neo4j.kernel.internal.locker.FileLockException in project neo4j by neo4j.
the class LoadCommand method loadDump.
protected void loadDump() throws IOException {
Config config = buildConfig();
DatabaseLayout databaseLayout = Neo4jLayout.of(config).databaseLayout(database.name());
ctx.fs().mkdirs(databaseLayout.databaseDirectory());
ctx.fs().mkdirs(databaseLayout.getNeo4jLayout().transactionLogsRootDirectory());
try (Closeable ignore = LockChecker.checkDatabaseLock(databaseLayout)) {
deleteIfNecessary(databaseLayout, force);
load(from, databaseLayout);
} catch (FileLockException e) {
throw new CommandFailedException("The database is in use. Stop database '" + database.name() + "' and try again.", e);
} catch (IOException e) {
wrapIOException(e);
} catch (CannotWriteException e) {
throw new CommandFailedException("You do not have permission to load the database.", e);
}
StoreVersionLoader.Result result = loader.getStoreVersion(ctx.fs(), config, databaseLayout);
if (!result.isLatest) {
ctx.err().printf("The loaded database is not on the latest format (current:%s, latest:%s). Set %s=true to enable migration.%n", result.currentFormatName, result.latestFormatName, GraphDatabaseSettings.allow_upgrade.name());
}
}
use of org.neo4j.kernel.internal.locker.FileLockException in project neo4j by neo4j.
the class DumpCommand method execute.
@Override
public void execute() {
var databaseName = database.name();
Path archive = buildArchivePath(databaseName, to.toAbsolutePath());
var memoryTracker = EmptyMemoryTracker.INSTANCE;
Config config = CommandHelpers.buildConfig(ctx, allowCommandExpansion);
DatabaseLayout databaseLayout = Neo4jLayout.of(config).databaseLayout(databaseName);
try {
Validators.CONTAINS_EXISTING_DATABASE.validate(databaseLayout.databaseDirectory());
} catch (IllegalArgumentException e) {
throw new CommandFailedException("Database does not exist: " + databaseName, e);
}
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
if (fileSystem.fileExists(databaseLayout.file(StoreUpgrader.MIGRATION_DIRECTORY))) {
throw new CommandFailedException("Store migration folder detected - A dump can not be taken during a store migration. Make sure " + "store migration is completed before trying again.");
}
} catch (IOException e) {
wrapIOException(e);
}
try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
checkDbState(databaseLayout, config, memoryTracker);
dump(databaseLayout, archive);
} catch (FileLockException e) {
throw new CommandFailedException("The database is in use. Stop database '" + databaseName + "' and try again.", e);
} catch (IOException e) {
wrapIOException(e);
} catch (CannotWriteException e) {
throw new CommandFailedException("You do not have permission to dump the database.", e);
}
}
use of org.neo4j.kernel.internal.locker.FileLockException in project neo4j by neo4j.
the class CheckConsistencyCommand method execute.
@Override
public void execute() {
options.warnOnUsageOfDeprecatedOptions(spec, ctx);
if (target.backup != null) {
target.backup = target.backup.toAbsolutePath();
if (!Files.isDirectory(target.backup)) {
throw new CommandFailedException("Report directory path doesn't exist or not a directory: " + target.backup);
}
}
Config config = loadNeo4jConfig(ctx.homeDir(), ctx.confDir(), additionalConfig);
var memoryTracker = EmptyMemoryTracker.INSTANCE;
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
DatabaseLayout databaseLayout = Optional.ofNullable(target.backup).map(DatabaseLayout::ofFlat).orElseGet(() -> Neo4jLayout.of(config).databaseLayout(target.database.name()));
checkDatabaseExistence(databaseLayout);
try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
checkDbState(databaseLayout, config, memoryTracker);
// Only output progress indicator if a console receives the output
ProgressMonitorFactory progressMonitorFactory = ProgressMonitorFactory.NONE;
if (System.console() != null) {
progressMonitorFactory = ProgressMonitorFactory.textual(System.out);
}
ConsistencyCheckService.Result consistencyCheckResult;
try (Log4jLogProvider logProvider = Util.configuredLogProvider(config, System.out)) {
consistencyCheckResult = consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, progressMonitorFactory, logProvider, fileSystem, verbose, options.getReportDir().normalize(), new ConsistencyFlags(options.isCheckGraph(), options.isCheckIndexes(), options.isCheckIndexStructure()));
}
if (!consistencyCheckResult.isSuccessful()) {
throw new CommandFailedException(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.reportFile()));
}
} catch (FileLockException e) {
throw new CommandFailedException("The database is in use. Stop database '" + databaseLayout.getDatabaseName() + "' and try again.", e);
} catch (CannotWriteException e) {
throw new CommandFailedException("You do not have permission to check database consistency.", e);
}
} catch (ConsistencyCheckIncompleteException | IOException e) {
throw new CommandFailedException("Consistency checking failed." + e.getMessage(), e);
}
}
use of org.neo4j.kernel.internal.locker.FileLockException in project neo4j by neo4j.
the class StoreInfoCommand method printInfo.
private static String printInfo(FileSystemAbstraction fs, DatabaseLayout databaseLayout, PageCache pageCache, StorageEngineFactory storageEngineFactory, Config config, boolean structured, boolean failSilently) {
var memoryTracker = EmptyMemoryTracker.INSTANCE;
try (var ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
var storeVersionCheck = storageEngineFactory.versionCheck(fs, databaseLayout, Config.defaults(), pageCache, NullLogService.getInstance(), PageCacheTracer.NULL);
var storeVersion = storeVersionCheck.storeVersion(CursorContext.NULL).orElseThrow(() -> new CommandFailedException(format("Could not find version metadata in store '%s'", databaseLayout.databaseDirectory())));
var versionInformation = storageEngineFactory.versionInformation(storeVersion);
var recoveryRequired = checkRecoveryState(fs, databaseLayout, config, memoryTracker);
var txIdStore = storageEngineFactory.readOnlyTransactionIdStore(fs, databaseLayout, pageCache, CursorContext.NULL);
// Latest committed tx id found in metadata store. May be behind if recovery is required.
var lastTxId = txIdStore.getLastCommittedTransactionId();
var successorString = versionInformation.successor().map(StoreVersion::introductionNeo4jVersion).orElse(null);
var storeInfo = StoreInfo.notInUseResult(databaseLayout.getDatabaseName(), storeVersion, versionInformation.introductionNeo4jVersion(), successorString, lastTxId, recoveryRequired);
return storeInfo.print(structured);
} catch (FileLockException e) {
if (!failSilently) {
throw new CommandFailedException(format("Failed to execute command as the database '%s' is in use. " + "Please stop it and try again.", databaseLayout.getDatabaseName()), e);
}
return StoreInfo.inUseResult(databaseLayout.getDatabaseName()).print(structured);
} catch (CommandFailedException e) {
throw e;
} catch (Exception e) {
throw new CommandFailedException(format("Failed to execute command: '%s'.", e.getMessage()), e);
}
}
Aggregations