Esempio n. 1
0
        private static void TestFamily(Action <MsgPack.Packer> packerAction, FormatFamily expected)
        {
            var stream = new MemoryStream();

            packerAction(MsgPack.Packer.Create(stream, PackerCompatibilityOptions.None));
            stream.Position = 0;

            var unpacker = new Unpacker(stream);

            FormatFamily actual;

            Assert.True(unpacker.TryPeekFormatFamily(out actual));
            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void migrate(org.neo4j.io.layout.DatabaseLayout directoryLayout, org.neo4j.io.layout.DatabaseLayout migrationLayout, org.neo4j.kernel.impl.util.monitoring.ProgressReporter progressReporter, String versionToMigrateFrom, String versionToMigrateTo) throws java.io.IOException
        public override void Migrate(DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressReporter, string versionToMigrateFrom, string versionToMigrateTo)
        {
            // Extract information about the last transaction from legacy neostore
            File          neoStore          = directoryLayout.MetadataStore();
            long          lastTxId          = MetaDataStore.getRecord(_pageCache, neoStore, MetaDataStore.Position.LAST_TRANSACTION_ID);
            TransactionId lastTxInfo        = ExtractTransactionIdInformation(neoStore, lastTxId);
            LogPosition   lastTxLogPosition = ExtractTransactionLogPosition(neoStore, directoryLayout, lastTxId);

            // Write the tx checksum to file in migrationStructure, because we need it later when moving files into storeDir
            WriteLastTxInformation(migrationLayout, lastTxInfo);
            WriteLastTxLogPosition(migrationLayout, 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(directoryLayout, migrationLayout, lastTxId, lastTxInfo.Checksum(), lastTxLogPosition.LogVersion, lastTxLogPosition.ByteOffset, progressReporter, oldFormat, newFormat);
            }
            // update necessary neostore records
            LogPosition logPosition = ReadLastTxLogPosition(migrationLayout);

            UpdateOrAddNeoStoreFieldsAsPartOfMigration(migrationLayout, directoryLayout, versionToMigrateTo, logPosition);
        }
Esempio n. 3
0
 private bool IsCompatibleFormats(RecordFormats storeFormat)
 {
     return(FormatFamily.isSameFamily(_recordFormats, storeFormat) && _recordFormats.hasCompatibleCapabilities(storeFormat, CapabilityType.FORMAT) && _recordFormats.generation() >= storeFormat.Generation());
 }
Esempio n. 4
0
        /// <summary>
        /// Assumed to only be called if <seealso cref="hasCurrentVersion(DatabaseLayout)"/> returns {@code false}.
        /// </summary>
        /// <param name="dbDirectoryLayout"> database directory structure. </param>
        /// <returns> the <seealso cref="RecordFormats"/> the current store (which is upgradable) is currently in. </returns>
        /// <exception cref="UpgradeMissingStoreFilesException"> if store cannot be upgraded due to some store files are missing. </exception>
        /// <exception cref="UpgradingStoreVersionNotFoundException"> if store cannot be upgraded due to store
        /// version cannot be determined. </exception>
        /// <exception cref="UnexpectedUpgradingStoreVersionException"> if store cannot be upgraded due to an unexpected store
        /// version found. </exception>
        /// <exception cref="UnexpectedUpgradingStoreFormatException"> if store cannot be upgraded due to an unexpected store
        /// format found. </exception>
        /// <exception cref="DatabaseNotCleanlyShutDownException"> if store cannot be upgraded due to not being cleanly shut down. </exception>
        public virtual RecordFormats CheckUpgradable(DatabaseLayout dbDirectoryLayout)
        {
            File   neostoreFile = dbDirectoryLayout.MetadataStore();
            Result result       = _storeVersionCheck.hasVersion(neostoreFile, _format.storeVersion());

            if (result.Outcome.Successful)
            {
                // This store already has the format that we want
                // Although this method should not have been called in this case.
                return(_format);
            }

            RecordFormats fromFormat;

            try
            {
                fromFormat = RecordFormatSelector.selectForVersion(result.ActualVersion);

                // If we are trying to open an enterprise store when configured to use community format, then inform the user
                // 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(Result.Outcome.attemptedStoreDowngrade, fromFormat.StoreVersion(), neostoreFile.AbsolutePath);
                }
                else
                {
                    result = CheckCleanShutDownByCheckPoint();
                    if (result.Outcome.Successful)
                    {
                        return(fromFormat);
                    }
                }
            }
            catch (System.ArgumentException)
            {
                result = new Result(Result.Outcome.unexpectedStoreVersion, result.ActualVersion, result.StoreFilename);
            }

            switch (result.Outcome.innerEnumValue)
            {
            case Result.Outcome.InnerEnum.missingStoreFile:
                throw new StoreUpgrader.UpgradeMissingStoreFilesException(GetPathToStoreFile(dbDirectoryLayout, result));

            case Result.Outcome.InnerEnum.storeVersionNotFound:
                throw new StoreUpgrader.UpgradingStoreVersionNotFoundException(GetPathToStoreFile(dbDirectoryLayout, result));

            case Result.Outcome.InnerEnum.attemptedStoreDowngrade:
                throw new StoreUpgrader.AttemptedDowngradeException();

            case Result.Outcome.InnerEnum.unexpectedStoreVersion:
                throw new StoreUpgrader.UnexpectedUpgradingStoreVersionException(result.ActualVersion, _format.storeVersion());

            case Result.Outcome.InnerEnum.storeNotCleanlyShutDown:
                throw new StoreUpgrader.DatabaseNotCleanlyShutDownException();

            default:
                throw new System.ArgumentException("Unexpected outcome: " + result.Outcome.name());
            }
        }
Esempio n. 5
0
        public bool TryPeekFormatFamily(out FormatFamily family)
        {
            if (TryPrepareNextByte())
            {
                if ((_nextByte <= PosFixIntMaxByte) ||
                    (_nextByte >= UInt8PrefixByte && _nextByte <= Int64PrefixByte) ||
                    (_nextByte >= NegFixIntMinByte))
                {
                    family = FormatFamily.Integer;
                    return(true);
                }

                if ((_nextByte >= FixMapMinPrefixByte && _nextByte <= FixMapMaxPrefixByte) ||
                    _nextByte == Map16PrefixByte ||
                    _nextByte == Map32PrefixByte)
                {
                    family = FormatFamily.Map;
                    return(true);
                }

                if ((_nextByte >= FixArrayMinPrefixByte && _nextByte <= FixArrayMaxPrefixByte) ||
                    _nextByte == Array16PrefixByte ||
                    _nextByte == Array32PrefixByte)
                {
                    family = FormatFamily.Array;
                    return(true);
                }

                if ((_nextByte >= FixStrMinPrefixByte && _nextByte <= FixStrMaxPrefixByte) ||
                    (_nextByte >= Str8PrefixByte && _nextByte <= Str32PrefixByte))
                {
                    family = FormatFamily.String;
                    return(true);
                }

                switch (_nextByte)
                {
                case NullByte:
                    family = FormatFamily.Null;
                    return(true);

                case TrueByte:
                case FalseByte:
                    family = FormatFamily.Boolean;
                    return(true);

                case Bin8PrefixByte:
                case Bin16PrefixByte:
                case Bin32PrefixByte:
                    family = FormatFamily.Binary;
                    return(true);

                case Float32PrefixByte:
                case Float64PrefixByte:
                    family = FormatFamily.Float;
                    return(true);
                }
            }

            family = default(FormatFamily);
            return(false);
        }