use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class CommonAbstractStore method checkAndLoadStorage.
/**
* This method is called by constructors. Checks the header record and loads the store.
* <p>
* Note: This method will map the file with the page cache. The store file must not
* be accessed directly until it has been unmapped - the store file must only be
* accessed through the page cache.
* @param createIfNotExists If true, creates and initialises the store file if it does not exist already. If false,
* this method will instead throw an exception in that situation.
* @return {@code true} if the store was created as part of this call, otherwise {@code false} if it already existed.
*/
private boolean checkAndLoadStorage(boolean createIfNotExists, CursorContext cursorContext) {
try {
determineRecordSize(storeHeaderFormat.generateHeader());
if (getNumberOfReservedLowIds() > 0) {
// This store has a store-specific header so we have read it before we can be sure that we can map it with correct page size.
// Try to open the store file (w/o creating if it doesn't exist), with page size for the configured header value.
HEADER defaultHeader = storeHeaderFormat.generateHeader();
pagedFile = pageCache.map(storageFile, filePageSize, databaseName, openOptions.newWith(ANY_PAGE_SIZE));
HEADER readHeader = readStoreHeaderAndDetermineRecordSize(pagedFile, cursorContext);
if (!defaultHeader.equals(readHeader)) {
// The header that we read was different from the default one so unmap
pagedFile.close();
pagedFile = null;
}
}
if (pagedFile == null) {
// Map the file with the correct page size
pagedFile = pageCache.map(storageFile, filePageSize, databaseName, openOptions);
}
} catch (NoSuchFileException | StoreNotFoundException e) {
if (pagedFile != null) {
pagedFile.close();
pagedFile = null;
}
if (createIfNotExists) {
try {
// Generate the header and determine correct page size
determineRecordSize(storeHeaderFormat.generateHeader());
// Create the id generator, and also open it because some stores may need the id generator when initializing their store
idGenerator = idGeneratorFactory.create(pageCache, idFile, idType, getNumberOfReservedLowIds(), false, recordFormat.getMaxId(), readOnlyChecker, configuration, cursorContext, openOptions);
// Map the file (w/ the CREATE flag) and initialize the header
pagedFile = pageCache.map(storageFile, filePageSize, databaseName, openOptions.newWith(CREATE));
initialiseNewStoreFile(cursorContext);
// <-- successfully created and initialized
return true;
} catch (IOException e1) {
e.addSuppressed(e1);
}
}
if (e instanceof StoreNotFoundException) {
throw (StoreNotFoundException) e;
}
throw new StoreNotFoundException("Store file not found: " + storageFile, e);
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to open store file: " + storageFile, e);
}
return false;
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class DumpCommandIT method shouldGiveAClearMessageIfTheArchivesParentDoesntExist.
@Test
void shouldGiveAClearMessageIfTheArchivesParentDoesntExist() throws Exception {
doThrow(new NoSuchFileException(archive.getParent().toString())).when(dumper).dump(any(), any(), any(), any(), any());
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
assertEquals("Unable to dump database: NoSuchFileException: " + archive.getParent(), commandFailed.getMessage());
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class LoaderTest method shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist.
@Test
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist() {
Path archive = testDirectory.file("the-archive.dump");
Path destination = Paths.get(testDirectory.absolutePath().toString(), "subdir", "the-destination");
DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(destination);
NoSuchFileException noSuchFileException = assertThrows(NoSuchFileException.class, () -> new Loader().load(archive, databaseLayout));
assertEquals(destination.getParent().toString(), noSuchFileException.getMessage());
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class LoaderTest method shouldGiveAClearErrorMessageIfTheArchiveDoesntExist.
@Test
void shouldGiveAClearErrorMessageIfTheArchiveDoesntExist() throws IOException {
Path archive = testDirectory.file("the-archive.dump");
deleteLayoutFolders(databaseLayout);
NoSuchFileException exception = assertThrows(NoSuchFileException.class, () -> new Loader().load(archive, databaseLayout));
assertEquals(archive.toString(), exception.getMessage());
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class DumpCommand method dump.
private void dump(DatabaseLayout databaseLayout, Path archive) {
Path databasePath = databaseLayout.databaseDirectory();
try {
var format = selectCompressionFormat(ctx.err());
var lockFile = databaseLayout.databaseLockFile().getFileName().toString();
var quarantineMarkerFile = databaseLayout.quarantineMarkerFile().getFileName().toString();
dumper.dump(databasePath, databaseLayout.getTransactionLogsDirectory(), archive, format, path -> oneOf(path, lockFile, quarantineMarkerFile));
} catch (FileAlreadyExistsException e) {
throw new CommandFailedException("Archive already exists: " + e.getMessage(), e);
} catch (NoSuchFileException e) {
if (Paths.get(e.getMessage()).toAbsolutePath().equals(databasePath)) {
throw new CommandFailedException("Database does not exist: " + databaseLayout.getDatabaseName(), e);
}
wrapIOException(e);
} catch (IOException e) {
wrapIOException(e);
}
}
Aggregations