Search in sources :

Example 6 with RecordFormats

use of org.neo4j.kernel.impl.store.format.RecordFormats in project neo4j by neo4j.

the class SchemaIndexMigrator method migrate.

@Override
public void migrate(File storeDir, File migrationDir, MigrationProgressMonitor.Section progressMonitor, String versionToMigrateFrom, String versionToMigrateTo) throws IOException {
    RecordFormats from = RecordFormatSelector.selectForVersion(versionToMigrateFrom);
    RecordFormats to = RecordFormatSelector.selectForVersion(versionToMigrateTo);
    if (!from.hasSameCapabilities(to, CapabilityType.INDEX)) {
        schemaIndexDirectory = schemaIndexProvider.getSchemaIndexStoreDirectory(storeDir);
        labelIndexDirectory = labelScanStoreProvider.getStoreDirectory(storeDir);
        deleteObsoleteIndexes = true;
    }
}
Also used : RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats)

Example 7 with RecordFormats

use of org.neo4j.kernel.impl.store.format.RecordFormats 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);
    }
}
Also used : PropertyDeduplicator(org.neo4j.kernel.impl.storemigration.legacystore.v21.propertydeduplication.PropertyDeduplicator) Arrays(java.util.Arrays) PageCursor(org.neo4j.io.pagecache.PageCursor) NullLogProvider(org.neo4j.logging.NullLogProvider) StringUtils(org.apache.commons.lang3.StringUtils) UNKNOWN_TX_COMMIT_TIMESTAMP(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP) COPY(org.neo4j.kernel.impl.storemigration.FileOperation.COPY) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) Arrays.asList(java.util.Arrays.asList) BASE_TX_COMMIT_TIMESTAMP(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP) Position(org.neo4j.kernel.impl.store.MetaDataStore.Position) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) RecordCursors(org.neo4j.kernel.impl.store.RecordCursors) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) StandardCharsets(java.nio.charset.StandardCharsets) MetaDataRecordFormat(org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat) DELETE(org.neo4j.kernel.impl.storemigration.FileOperation.DELETE) Stream(java.util.stream.Stream) ExecutionSupervisors.withDynamicProcessorAssignment(org.neo4j.unsafe.impl.batchimport.staging.ExecutionSupervisors.withDynamicProcessorAssignment) StoreType(org.neo4j.kernel.impl.store.StoreType) BatchImporter(org.neo4j.unsafe.impl.batchimport.BatchImporter) NodeStore(org.neo4j.kernel.impl.store.NodeStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Collectors(org.neo4j.unsafe.impl.batchimport.input.Collectors) PagedFile(org.neo4j.io.pagecache.PagedFile) VERSION_TRAILERS(org.neo4j.kernel.impl.store.format.Capability.VERSION_TRAILERS) FormatFamily(org.neo4j.kernel.impl.store.format.FormatFamily) Supplier(java.util.function.Supplier) UNKNOWN_TX_CHECKSUM(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.UNKNOWN_TX_CHECKSUM) BufferedOutputStream(java.io.BufferedOutputStream) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) TransactionId(org.neo4j.kernel.impl.store.TransactionId) StandardV2_2(org.neo4j.kernel.impl.store.format.standard.StandardV2_2) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) StandardV2_1(org.neo4j.kernel.impl.store.format.standard.StandardV2_1) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StandardV2_0(org.neo4j.kernel.impl.store.format.standard.StandardV2_0) IdMappers(org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMappers) BiConsumer(java.util.function.BiConsumer) IdGenerators(org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdGenerators) StreamSupport(java.util.stream.StreamSupport) DirectRecordStoreMigrator(org.neo4j.kernel.impl.storemigration.DirectRecordStoreMigrator) CoarseBoundedProgressExecutionMonitor(org.neo4j.unsafe.impl.batchimport.staging.CoarseBoundedProgressExecutionMonitor) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) FileOutputStream(java.io.FileOutputStream) RecordFormatSelector.selectForVersion(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForVersion) IOException(java.io.IOException) NodeRecordFormat(org.neo4j.kernel.impl.store.format.standard.NodeRecordFormat) LegacyLogs(org.neo4j.kernel.impl.storemigration.legacylogs.LegacyLogs) File(java.io.File) Iterables(org.neo4j.helpers.collection.Iterables) ParallelBatchImporter(org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Configuration(org.neo4j.unsafe.impl.batchimport.Configuration) BufferedReader(java.io.BufferedReader) MigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) NoSuchFileException(java.nio.file.NoSuchFileException) BASE_TX_LOG_VERSION(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_LOG_VERSION) BASE_TX_CHECKSUM(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_CHECKSUM) PageCache(org.neo4j.io.pagecache.PageCache) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) MOVE(org.neo4j.kernel.impl.storemigration.FileOperation.MOVE) LogService(org.neo4j.kernel.impl.logging.LogService) List(java.util.List) StoreFileType(org.neo4j.kernel.impl.storemigration.StoreFileType) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Writer(java.io.Writer) Optional(java.util.Optional) Inputs(org.neo4j.unsafe.impl.batchimport.input.Inputs) InputIterable(org.neo4j.unsafe.impl.batchimport.InputIterable) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) InputEntity(org.neo4j.unsafe.impl.batchimport.input.InputEntity) DEFAULT_NAME(org.neo4j.kernel.impl.store.MetaDataStore.DEFAULT_NAME) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) CustomIOConfigValidator(org.neo4j.kernel.impl.util.CustomIOConfigValidator) AdditionalInitialIds(org.neo4j.unsafe.impl.batchimport.AdditionalInitialIds) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StorePropertyCursor(org.neo4j.kernel.impl.api.store.StorePropertyCursor) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) ExistingTargetStrategy(org.neo4j.kernel.impl.storemigration.ExistingTargetStrategy) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) RelationshipRecordFormat(org.neo4j.kernel.impl.store.format.standard.RelationshipRecordFormat) OutputStream(java.io.OutputStream) Config(org.neo4j.kernel.configuration.Config) ReadOnlyIdGeneratorFactory(org.neo4j.kernel.impl.store.id.ReadOnlyIdGeneratorFactory) LockService(org.neo4j.kernel.impl.locking.LockService) FileHandle(org.neo4j.io.pagecache.FileHandle) CapabilityType(org.neo4j.kernel.impl.store.format.CapabilityType) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) FIELD_NOT_PRESENT(org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat.FIELD_NOT_PRESENT) StoreMigratorCheckPointer(org.neo4j.kernel.impl.storemigration.StoreMigratorCheckPointer) ExecutionMonitor(org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitor) BASE_TX_LOG_BYTE_OFFSET(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_LOG_BYTE_OFFSET) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) PagedFile(org.neo4j.io.pagecache.PagedFile) FileHandle(org.neo4j.io.pagecache.FileHandle) NoSuchFileException(java.nio.file.NoSuchFileException) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) PagedFile(org.neo4j.io.pagecache.PagedFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) StoreMigratorCheckPointer(org.neo4j.kernel.impl.storemigration.StoreMigratorCheckPointer)

Example 8 with RecordFormats

use of org.neo4j.kernel.impl.store.format.RecordFormats in project neo4j by neo4j.

the class StoreMigrator method migrate.

@Override
public void migrate(File storeDir, File migrationDir, MigrationProgressMonitor.Section progressMonitor, String versionToMigrateFrom, String versionToMigrateTo) throws IOException {
    if (versionToMigrateFrom.equals(StandardV2_0.STORE_VERSION) || versionToMigrateFrom.equals(StandardV2_1.STORE_VERSION) || versionToMigrateFrom.equals(StandardV2_2.STORE_VERSION)) {
        // These versions are not supported for block devices.
        CustomIOConfigValidator.assertCustomIOConfigNotUsed(config, CUSTOM_IO_EXCEPTION_MESSAGE);
    }
    // Extract information about the last transaction from legacy neostore
    File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    long lastTxId = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_TRANSACTION_ID);
    TransactionId lastTxInfo = extractTransactionIdInformation(neoStore, storeDir, lastTxId);
    LogPosition lastTxLogPosition = extractTransactionLogPosition(neoStore, storeDir, lastTxId);
    // Write the tx checksum to file in migrationDir, because we need it later when moving files into storeDir
    writeLastTxInformation(migrationDir, lastTxInfo);
    writeLastTxLogPosition(migrationDir, lastTxLogPosition);
    if (versionToMigrateFrom.equals("vE.H.0")) {
        // NOTE for 3.0 here is a special case for vE.H.0 "from" record format.
        // Legend has it that 3.0.5 enterprise changed store format without changing store version.
        // This was done to cheat the migrator to avoid doing store migration since the
        // format itself was backwards compatible. Immediately a problem was detected:
        // if a user uses 3.0.5 for a while and then goes back to a previous 3.0.x patch release
        // the db wouldn't recognize it was an incompatible downgrade and start up normally,
        // but read records with scrambled values and pointers, sort of.
        //
        // This condition has two functions:
        //  1. preventing actual store migration between vE.H.0 --> vE.H.0b
        //  2. making vE.H.0b used in any migration where either vE.H.0 or vE.H.0b is the existing format,
        //     this because vE.H.0b is a superset of vE.H.0 and sometimes (for 3.0.5) vE.H.0
        //     actually means vE.H.0b (in later version).
        //
        // In later versions of neo4j there are better mechanics in place so that a non-migration like this
        // can be performed w/o special casing. To not require backporting that functionality
        // this condition is here and should be removed in 3.1.
        versionToMigrateFrom = "vE.H.0b";
    }
    RecordFormats oldFormat = selectForVersion(versionToMigrateFrom);
    RecordFormats newFormat = selectForVersion(versionToMigrateTo);
    if (FormatFamily.isHigherFamilyFormat(newFormat, oldFormat) || (FormatFamily.isSameFamily(oldFormat, newFormat) && isDifferentCapabilities(oldFormat, newFormat))) {
        // TODO if this store has relationship indexes then warn user about that they will be incorrect
        // after migration, because now we're rewriting the relationship ids.
        // Some form of migration is required (a fallback/catch-all option)
        migrateWithBatchImporter(storeDir, migrationDir, lastTxId, lastTxInfo.checksum(), lastTxLogPosition.getLogVersion(), lastTxLogPosition.getByteOffset(), progressMonitor, oldFormat, newFormat);
    }
    if (versionToMigrateFrom.equals(StandardV2_1.STORE_VERSION)) {
        removeDuplicateEntityProperties(storeDir, migrationDir, pageCache, schemaIndexProvider, oldFormat);
    }
// DO NOT migrate logs. LegacyLogs is able to migrate logs, but only changes its format, not any
// contents of it, and since the record format has changed there would be a mismatch between the
// commands in the log and the contents in the store. If log migration is to be performed there
// must be a proper translation happening while doing so.
}
Also used : RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) PagedFile(org.neo4j.io.pagecache.PagedFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) TransactionId(org.neo4j.kernel.impl.store.TransactionId) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 9 with RecordFormats

use of org.neo4j.kernel.impl.store.format.RecordFormats in project neo4j by neo4j.

the class UpgradableDatabase method checkUpgradeable.

/**
     * Assumed to only be called if {@link #hasCurrentVersion(File)} returns {@code false}.
     *
     * @param storeDirectory the store to check for upgradability is in.
     * @return the {@link RecordFormats} the current store (which is upgradable) is currently in.
     * @throws UpgradeMissingStoreFilesException if store cannot be upgraded due to some store files are missing.
     * @throws UpgradingStoreVersionNotFoundException if store cannot be upgraded due to store
     * version cannot be determined.
     * @throws UnexpectedUpgradingStoreVersionException if store cannot be upgraded due to an unexpected store
     * version found.
     * @throws UnexpectedUpgradingStoreFormatException if store cannot be upgraded due to an unexpected store
     * format found.
     * @throws DatabaseNotCleanlyShutDownException if store cannot be upgraded due to not being cleanly shut down.
     */
public RecordFormats checkUpgradeable(File storeDirectory) {
    Result result = storeVersionCheck.hasVersion(new File(storeDirectory, MetaDataStore.DEFAULT_NAME), format.storeVersion());
    if (result.outcome.isSuccessful()) {
        // Although this method should not have been called in this case.
        return format;
    }
    RecordFormats fromFormat;
    try {
        fromFormat = RecordFormatSelector.selectForVersion(result.actualVersion);
        // of the config setting to change since downgrades aren't possible but the store can still be opened.
        if (FormatFamily.isLowerFamilyFormat(format, fromFormat)) {
            throw new StoreUpgrader.UnexpectedUpgradingStoreFormatException();
        }
        if (FormatFamily.isSameFamily(fromFormat, format) && (fromFormat.generation() > format.generation())) {
            // Tried to downgrade, that isn't supported
            result = new Result(Outcome.attemptedStoreDowngrade, fromFormat.storeVersion(), new File(storeDirectory, MetaDataStore.DEFAULT_NAME).getAbsolutePath());
        } else {
            result = fromFormat.hasCapability(Capability.VERSION_TRAILERS) ? checkCleanShutDownByVersionTrailer(storeDirectory, fromFormat) : checkCleanShutDownByCheckPoint(storeDirectory);
            if (result.outcome.isSuccessful()) {
                return fromFormat;
            }
        }
    } catch (IllegalArgumentException e) {
        result = new Result(Outcome.unexpectedStoreVersion, result.actualVersion, result.storeFilename);
    }
    switch(result.outcome) {
        case missingStoreFile:
            throw new StoreUpgrader.UpgradeMissingStoreFilesException(getPathToStoreFile(storeDirectory, result));
        case storeVersionNotFound:
            throw new StoreUpgrader.UpgradingStoreVersionNotFoundException(getPathToStoreFile(storeDirectory, result));
        case attemptedStoreDowngrade:
            throw new StoreUpgrader.AttemptedDowngradeException();
        case unexpectedStoreVersion:
            throw new StoreUpgrader.UnexpectedUpgradingStoreVersionException(result.actualVersion, format.storeVersion());
        case storeNotCleanlyShutDown:
            throw new StoreUpgrader.DatabaseNotCleanlyShutDownException();
        default:
            throw new IllegalArgumentException("Unexpected outcome: " + result.outcome.name());
    }
}
Also used : UpgradeMissingStoreFilesException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradeMissingStoreFilesException) UnexpectedUpgradingStoreVersionException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreVersionException) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) UpgradingStoreVersionNotFoundException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UpgradingStoreVersionNotFoundException) DatabaseNotCleanlyShutDownException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.DatabaseNotCleanlyShutDownException) File(java.io.File) UnexpectedUpgradingStoreFormatException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnexpectedUpgradingStoreFormatException) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Example 10 with RecordFormats

use of org.neo4j.kernel.impl.store.format.RecordFormats in project neo4j by neo4j.

the class BatchingNeoStoresTest method shouldNotOpenStoreWithNodesOrRelationshipsInIt.

@Test
public void shouldNotOpenStoreWithNodesOrRelationshipsInIt() throws Exception {
    // GIVEN
    someDataInTheDatabase();
    // WHEN
    try {
        RecordFormats recordFormats = RecordFormatSelector.selectForConfig(Config.empty(), NullLogProvider.getInstance());
        BatchingNeoStores.batchingNeoStores(fsr.get(), storeDir, recordFormats, DEFAULT, NullLogService.getInstance(), EMPTY, Config.empty());
        fail("Should fail on existing data");
    } catch (IllegalStateException e) {
        // THEN
        assertThat(e.getMessage(), containsString("already contains"));
    }
}
Also used : RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Test(org.junit.Test)

Aggregations

RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)43 Test (org.junit.jupiter.api.Test)13 IOException (java.io.IOException)10 Config (org.neo4j.configuration.Config)8 PageCache (org.neo4j.io.pagecache.PageCache)8 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)7 NullLogProvider (org.neo4j.logging.NullLogProvider)7 Config (org.neo4j.kernel.configuration.Config)6 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)6 File (java.io.File)5 Path (java.nio.file.Path)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)5 NeoStores (org.neo4j.kernel.impl.store.NeoStores)5 ForcedSecondaryUnitRecordFormats (org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)4 PagedFile (org.neo4j.io.pagecache.PagedFile)4 LogProvider (org.neo4j.logging.LogProvider)4 NoSuchFileException (java.nio.file.NoSuchFileException)3