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.
*/
protected void checkAndLoadStorage(boolean createIfNotExists) {
int pageSize = pageCache.pageSize();
int filePageSize;
try (PagedFile pagedFile = pageCache.map(storageFileName, pageSize, ANY_PAGE_SIZE)) {
extractHeaderRecord(pagedFile);
filePageSize = pageCache.pageSize() - pageCache.pageSize() % getRecordSize();
} catch (NoSuchFileException | StoreNotFoundException e) {
if (createIfNotExists) {
try {
createStore(pageSize);
return;
} catch (IOException e1) {
e.addSuppressed(e1);
}
}
if (e instanceof StoreNotFoundException) {
throw (StoreNotFoundException) e;
}
throw new StoreNotFoundException("Store file not found: " + storageFileName, e);
} catch (IOException e) {
throw new UnderlyingStorageException("Unable to open store file: " + storageFileName, e);
}
loadStorage(filePageSize);
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class NeoStores method verifyRecordFormat.
private void verifyRecordFormat() {
try {
String expectedStoreVersion = recordFormats.storeVersion();
long record = getRecord(pageCache, neoStoreFileName, STORE_VERSION);
if (record != MetaDataRecordFormat.FIELD_NOT_PRESENT) {
String actualStoreVersion = versionLongToString(record);
RecordFormats actualStoreFormat = RecordFormatSelector.selectForVersion(actualStoreVersion);
if (!isCompatibleFormats(actualStoreFormat)) {
throw new UnexpectedStoreVersionException(actualStoreVersion, expectedStoreVersion);
}
}
} catch (NoSuchFileException e) {
// Occurs when there is no file, which is obviously when creating a store.
// Caught as an exception because we want to leave as much interaction with files as possible
// to the page cache.
} catch (IOException e) {
throw new UnderlyingStorageException(e);
}
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class EphemeralFileSystemAbstraction method renameFile.
@Override
public void renameFile(File from, File to, CopyOption... copyOptions) throws IOException {
from = canonicalFile(from);
to = canonicalFile(to);
if (!files.containsKey(from)) {
throw new NoSuchFileException("'" + from + "' doesn't exist");
}
boolean replaceExisting = false;
for (CopyOption copyOption : copyOptions) {
replaceExisting |= copyOption == REPLACE_EXISTING;
}
if (files.containsKey(to) && !replaceExisting) {
throw new FileAlreadyExistsException("'" + to + "' already exists");
}
if (!isDirectory(to.getParentFile())) {
throw new NoSuchFileException("Target directory[" + to.getParent() + "] does not exists");
}
files.put(to, files.remove(from));
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class StoreMigrator method moveMigratedFiles.
@Override
public void moveMigratedFiles(File migrationDir, File storeDir, String versionToUpgradeFrom, String versionToUpgradeTo) throws IOException {
// Move the migrated ones into the store directory
StoreFile.fileOperation(MOVE, fileSystem, migrationDir, storeDir, StoreFile.currentStoreFiles(), // allow to skip non existent source files
true, // allow to overwrite target files
ExistingTargetStrategy.OVERWRITE, StoreFileType.values());
// move the files with the page cache.
try {
Iterable<FileHandle> fileHandles = pageCache.streamFilesRecursive(migrationDir)::iterator;
for (FileHandle fh : fileHandles) {
Predicate<StoreFile> predicate = storeFile -> storeFile.fileName(StoreFileType.STORE).equals(fh.getFile().getName());
if (StreamSupport.stream(StoreFile.currentStoreFiles().spliterator(), false).anyMatch(predicate)) {
final Optional<PagedFile> optionalPagedFile = pageCache.getExistingMapping(fh.getFile());
if (optionalPagedFile.isPresent()) {
optionalPagedFile.get().close();
}
fh.rename(new File(storeDir, fh.getFile().getName()), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (NoSuchFileException e) {
//This means that we had no files only present in the page cache, this is fine.
}
RecordFormats oldFormat = selectForVersion(versionToUpgradeFrom);
RecordFormats newFormat = selectForVersion(versionToUpgradeTo);
boolean movingAwayFromVersionTrailers = oldFormat.hasCapability(VERSION_TRAILERS) && !newFormat.hasCapability(VERSION_TRAILERS);
if (movingAwayFromVersionTrailers) {
StoreFile.removeTrailers(versionToUpgradeFrom, fileSystem, storeDir, pageCache.pageSize());
}
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long logVersion = MetaDataStore.getRecord(pageCache, neoStore, Position.LOG_VERSION);
long lastCommittedTx = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_TRANSACTION_ID);
// update or add upgrade id and time and other necessary neostore records
updateOrAddNeoStoreFieldsAsPartOfMigration(migrationDir, storeDir, versionToUpgradeTo);
// delete old logs
legacyLogs.deleteUnusedLogFiles(storeDir);
if (movingAwayFromVersionTrailers) {
// write a check point in the log in order to make recovery work in the newer version
new StoreMigratorCheckPointer(storeDir, fileSystem).checkPoint(logVersion, lastCommittedTx);
}
}
use of java.nio.file.NoSuchFileException in project jdk8u_jdk by JetBrains.
the class BlockDeviceSize method main.
public static void main(String[] args) throws Throwable {
try (FileChannel ch = FileChannel.open(BLK_PATH, READ);
RandomAccessFile file = new RandomAccessFile(BLK_FNAME, "r")) {
long size1 = ch.size();
long size2 = file.length();
if (size1 != size2) {
throw new RuntimeException("size differs when retrieved" + " in different ways: " + size1 + " != " + size2);
}
System.out.println("OK");
} catch (NoSuchFileException nsfe) {
System.err.println("File " + BLK_FNAME + " not found." + " Skipping test");
} catch (AccessDeniedException ade) {
System.err.println("Access to " + BLK_FNAME + " is denied." + " Run test as root.");
}
}
Aggregations