use of org.neo4j.kernel.impl.store.format.Capability.VERSION_TRAILERS 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);
}
}
Aggregations