Exemplo n.º 1
0
 private void VerifyRecordFormat()
 {
     try
     {
         string expectedStoreVersion = _recordFormats.storeVersion();
         long   record = getRecord(_pageCache, _metadataStore, 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)
     {
         // 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);
     }
 }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.impl.store.NeoStores build() throws java.io.IOException
            public virtual NeoStores Build()
            {
                if (Fs == null)
                {
                    Fs = outerInstance.ruleFs();
                }
                if (Config == null)
                {
                    Config = new string[0];
                }
                Config dbConfig = ConfigOf(Config);

                if (PageCache == null)
                {
                    outerInstance.jobScheduler = new ThreadPoolJobScheduler();
                    PageCache = outerInstance.rulePageCache(dbConfig, Fs, outerInstance.jobScheduler);
                }
                if (Format == null)
                {
                    Format = RecordFormatSelector.selectForConfig(dbConfig, NullLogProvider.Instance);
                }
                if (IdGeneratorFactory == null)
                {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                    IdGeneratorFactory = DefaultIdGeneratorFactory::new;
                }
                return(outerInstance.open(Fs, PageCache, Format, IdGeneratorFactory, Config));
            }
Exemplo n.º 3
0
        /// <summary>
        /// Select record format for the given store (if exists) or from the given configuration. If there is no store and
        /// record format is not configured than <seealso cref="DEFAULT_FORMAT"/> is selected.
        /// </summary>
        /// <param name="config"> configuration parameters </param>
        /// <param name="databaseLayout"> database directory structure </param>
        /// <param name="fs"> file system used to access store files </param>
        /// <param name="pageCache"> page cache to read store files </param>
        /// <returns> record format from the store (if it can be read) or configured record format or <seealso cref="DEFAULT_FORMAT"/> </returns>
        /// <exception cref="IllegalArgumentException"> when configured format is different from the format present in the store </exception>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Nonnull public static RecordFormats selectForStoreOrConfig(org.neo4j.kernel.configuration.Config config, org.neo4j.io.layout.DatabaseLayout databaseLayout, org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pageCache, org.neo4j.logging.LogProvider logProvider)
        public static RecordFormats SelectForStoreOrConfig(Config config, DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider)
        {
            RecordFormats configuredFormat = LoadRecordFormat(ConfiguredRecordFormat(config));
            bool          formatConfigured = configuredFormat != null;

            RecordFormats currentFormat         = SelectForStore(databaseLayout, fs, pageCache, logProvider);
            bool          storeWithFormatExists = currentFormat != null;

            if (formatConfigured && storeWithFormatExists)
            {
                if (currentFormat.FormatFamily.Equals(configuredFormat.FormatFamily) && (currentFormat.Generation() == configuredFormat.Generation()))
                {
                    Info(logProvider, "Configured format matches format in the store. Selected: " + currentFormat);
                    return(currentFormat);
                }
                throw new System.ArgumentException(string.Format("Configured format '{0}' is different from the actual format in the store '{1}'", configuredFormat, currentFormat));
            }

            if (!formatConfigured && storeWithFormatExists)
            {
                Info(logProvider, "Format not configured. Selected format from the store: " + currentFormat);
                return(currentFormat);
            }

            if (formatConfigured)
            {
                Info(logProvider, "Selected configured format: " + configuredFormat);
                return(configuredFormat);
            }

            return(_defaultFormat);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCalculateCorrectEstimates() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCalculateCorrectEstimates()
        {
            // given a couple of input files of various layouts
            Input         input  = GenerateData();
            RecordFormats format = LATEST_RECORD_FORMATS;

            [email protected]_Estimates estimates = input.CalculateEstimates(new PropertyValueRecordSizeCalculator(format.Property().getRecordSize(NO_STORE_HEADER), parseInt(GraphDatabaseSettings.string_block_size.DefaultValue), 0, parseInt(GraphDatabaseSettings.array_block_size.DefaultValue), 0));

            // when
            DatabaseLayout        databaseLayout = Directory.databaseLayout();
            Config                config         = Config.defaults();
            FileSystemAbstraction fs             = new DefaultFileSystemAbstraction();

            using (JobScheduler jobScheduler = new ThreadPoolJobScheduler())
            {
                (new ParallelBatchImporter(databaseLayout, fs, null, Configuration.DEFAULT, NullLogService.Instance, ExecutionMonitors.invisible(), AdditionalInitialIds.EMPTY, config, format, NO_MONITOR, jobScheduler)).doImport(input);

                // then compare estimates with actual disk sizes
                VersionContextSupplier contextSupplier = EmptyVersionContextSupplier.EMPTY;
                using (PageCache pageCache = (new ConfiguringPageCacheFactory(fs, config, PageCacheTracer.NULL, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, NullLog.Instance, contextSupplier, jobScheduler)).OrCreatePageCache, NeoStores stores = (new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fs), pageCache, fs, NullLogProvider.Instance, contextSupplier)).openAllNeoStores())
                {
                    AssertRoughlyEqual(estimates.NumberOfNodes(), stores.NodeStore.NumberOfIdsInUse);
                    AssertRoughlyEqual(estimates.NumberOfRelationships(), stores.RelationshipStore.NumberOfIdsInUse);
                    AssertRoughlyEqual(estimates.NumberOfNodeProperties() + estimates.NumberOfRelationshipProperties(), CalculateNumberOfProperties(stores));
                }
                AssertRoughlyEqual(PropertyStorageSize(), estimates.SizeOfNodeProperties() + estimates.SizeOfRelationshipProperties());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Select explicitly configured record format (via given {@code config}) or format from the store. If store does
        /// not exist or has old format (<seealso cref="RecordFormats.generation()"/>) than this method returns
        /// <seealso cref="DEFAULT_FORMAT"/>.
        /// </summary>
        /// <param name="config"> configuration parameters </param>
        /// <param name="databaseLayout"> database directory structure </param>
        /// <param name="fs"> file system used to access store files </param>
        /// <param name="pageCache"> page cache to read store files </param>
        /// <returns> record format from the store (if it can be read) or configured record format or <seealso cref="DEFAULT_FORMAT"/> </returns>
        /// <seealso cref= RecordFormats#generation() </seealso>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Nonnull public static RecordFormats selectNewestFormat(org.neo4j.kernel.configuration.Config config, org.neo4j.io.layout.DatabaseLayout databaseLayout, org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pageCache, org.neo4j.logging.LogProvider logProvider)
        public static RecordFormats SelectNewestFormat(Config config, DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider)
        {
            bool formatConfigured = StringUtils.isNotEmpty(ConfiguredRecordFormat(config));

            if (formatConfigured)
            {
                // format was explicitly configured so select it
                return(SelectForConfig(config, logProvider));
            }
            else
            {
                RecordFormats result = SelectForStore(databaseLayout, fs, pageCache, logProvider);
                if (result == null)
                {
                    // format was not explicitly configured and store does not exist, select default format
                    Info(logProvider, "Selected format '" + _defaultFormat + "' for the new store");
                    result = _defaultFormat;
                }
                else if (FormatFamily.IsHigherFamilyFormat(_defaultFormat, result) || (FormatFamily.IsSameFamily(result, _defaultFormat) && (result.Generation() < _defaultFormat.generation())))
                {
                    // format was not explicitly configured and store has lower format
                    // select default format, upgrade is intended
                    Info(logProvider, "Selected format '" + _defaultFormat + "' for existing store with format '" + result + "'");
                    result = _defaultFormat;
                }
                return(result);
            }
        }
Exemplo n.º 6
0
        private RecordFormats Format(params Capability[] capabilities)
        {
            RecordFormats formats = mock(typeof(BaseRecordFormats));

            when(formats.Capabilities()).thenReturn(capabilities);
            when(formats.HasCompatibleCapabilities(any(typeof(RecordFormats)), any(typeof(CapabilityType)))).thenCallRealMethod();
            return(formats);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Check if store and configured formats are compatible. In case if format is not configured or store does not
        /// exist yet - we consider formats as compatible. </summary>
        /// <param name="config"> configuration parameters </param>
        /// <param name="databaseLayout"> database directory structure </param>
        /// <param name="fs"> file system used to access store files </param>
        /// <param name="pageCache"> page cache to read store files </param>
        /// <param name="logProvider"> log provider </param>
        /// <returns> true if configured and actual format is compatible, false otherwise. </returns>
        public static bool IsStoreAndConfigFormatsCompatible(Config config, DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, LogProvider logProvider)
        {
            RecordFormats configuredFormat = LoadRecordFormat(ConfiguredRecordFormat(config));

            RecordFormats currentFormat = SelectForStore(databaseLayout, fs, pageCache, logProvider);

            return((configuredFormat == null) || (currentFormat == null) || (currentFormat.FormatFamily.Equals(configuredFormat.FormatFamily) && (currentFormat.Generation() == configuredFormat.Generation())));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void keepUserDefinedFormatConfig()
        public virtual void KeepUserDefinedFormatConfig()
        {
            Config        config        = Config.defaults(string_block_size, "36");
            RecordFormats recordFormats = Standard.LATEST_RECORD_FORMATS;

            (new RecordFormatPropertyConfigurator(recordFormats, config)).Configure();
            assertEquals("Should keep used specified value", 36, config.Get(string_block_size).intValue());
        }
Exemplo n.º 9
0
 public StoreUpgraderTest(RecordFormats formats)
 {
     if (!InstanceFieldsInitialized)
     {
         InitializeInstanceFields();
         InstanceFieldsInitialized = true;
     }
     this._formats = formats;
 }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Nonnull private static RecordFormats selectSpecificFormat(String recordFormat)
        private static RecordFormats SelectSpecificFormat(string recordFormat)
        {
            RecordFormats formats = LoadRecordFormat(recordFormat);

            if (formats == null)
            {
                throw new System.ArgumentException("No record format found with the name '" + recordFormat + "'.");
            }
            return(formats);
        }
Exemplo n.º 11
0
 private static void AddIfNotThere(RecordFormats f, List <RecordFormats> recordFormats)
 {
     foreach (RecordFormats format in recordFormats)
     {
         if (format.StoreVersion().Equals(f.StoreVersion()))
         {
             return;
         }
     }
     recordFormats.Add(f);
 }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertStoreFormat(org.neo4j.kernel.impl.store.format.RecordFormats expected) throws Exception
        private void AssertStoreFormat(RecordFormats expected)
        {
            Config config = Config.defaults(GraphDatabaseSettings.pagecache_memory, "8m");

            using (JobScheduler jobScheduler = new ThreadPoolJobScheduler(), PageCache pageCache = ConfigurableStandalonePageCacheFactory.createPageCache(_fileSystemRule.get(), config, jobScheduler))
            {
                RecordFormats actual = RecordFormatSelector.selectForStoreOrConfig(config, _testDirectory.databaseLayout(), _fileSystemRule, pageCache, NullLogProvider.Instance);
                assertNotNull(actual);
                assertEquals(expected.StoreVersion(), actual.StoreVersion());
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createRandomData(int count) throws Exception
        private void CreateRandomData(int count)
        {
            Config        config        = Config.defaults();
            RecordFormats recordFormats = RecordFormatSelector.selectForConfig(config, NullLogProvider.Instance);

            using (RandomDataInput input = new RandomDataInput(this, count), JobScheduler jobScheduler = new ThreadPoolJobScheduler())
            {
                BatchImporter importer = new ParallelBatchImporter(_directory.databaseLayout(), _fileSystemRule.get(), null, DEFAULT, NullLogService.Instance, ExecutionMonitors.invisible(), EMPTY, config, recordFormats, NO_MONITOR, jobScheduler);
                importer.DoImport(input);
            }
        }
Exemplo n.º 14
0
        public override bool Equals(object obj)
        {
            if (!(obj is RecordFormats))
            {
                return(false);
            }

            RecordFormats other = ( RecordFormats )obj;

            return(Node().Equals(other.Node()) && Relationship().Equals(other.Relationship()) && RelationshipGroup().Equals(other.RelationshipGroup()) && Property().Equals(other.Property()) && LabelToken().Equals(other.LabelToken()) && RelationshipTypeToken().Equals(other.RelationshipTypeToken()) && PropertyKeyToken().Equals(other.PropertyKeyToken()) && Dynamic().Equals(other.Dynamic()));
        }
Exemplo n.º 15
0
 protected internal AbstractRecordFormatTest(RecordFormats formats, int entityBits, int propertyBits)
 {
     if (!InstanceFieldsInitialized)
     {
         InitializeInstanceFields();
         InstanceFieldsInitialized = true;
     }
     this._formats      = formats;
     this._entityBits   = entityBits;
     this._propertyBits = propertyBits;
 }
Exemplo n.º 16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.kernel.impl.store.NeoStores open(org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pageCache, org.neo4j.kernel.impl.store.format.RecordFormats format, System.Func<org.neo4j.io.fs.FileSystemAbstraction,org.neo4j.kernel.impl.store.id.IdGeneratorFactory> idGeneratorFactory, String... config) throws java.io.IOException
        private NeoStores Open(FileSystemAbstraction fs, PageCache pageCache, RecordFormats format, System.Func <FileSystemAbstraction, IdGeneratorFactory> idGeneratorFactory, params string[] config)
        {
            Debug.Assert(_neoStores == null, "Already opened");
            TestDirectory testDirectory = TestDirectory.TestDirectoryConflict(fs);

            testDirectory.PrepareDirectory(_testClass, null);
            Config       configuration = ConfigOf(config);
            StoreFactory storeFactory  = new StoreFactory(testDirectory.DatabaseLayout(), configuration, idGeneratorFactory(fs), pageCache, fs, format, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            return(_neoStores = _stores.Length == 0 ? storeFactory.OpenAllNeoStores(true) : storeFactory.OpenNeoStores(true, _stores));
        }
Exemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureIdCapacityCannotBeExceeded()
        public virtual void MakeSureIdCapacityCannotBeExceeded()
        {
            RecordFormats formats = Standard.LATEST_RECORD_FORMATS;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<org.neo4j.kernel.impl.store.format.RecordFormat<? extends org.neo4j.kernel.impl.store.record.AbstractBaseRecord>> recordFormats = java.util.Arrays.asList(formats.node(), formats.dynamic(), formats.labelToken(), formats.property(), formats.propertyKeyToken(), formats.relationship(), formats.relationshipGroup(), formats.relationshipTypeToken());
            IList <RecordFormat <AbstractBaseRecord> > recordFormats = Arrays.asList(formats.Node(), formats.Dynamic(), formats.LabelToken(), formats.Property(), formats.PropertyKeyToken(), formats.Relationship(), formats.RelationshipGroup(), formats.RelationshipTypeToken());

            foreach (RecordFormat format in recordFormats)
            {
                MakeSureIdCapacityCannotBeExceeded(format);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Select configured record format based on available services in class path.
        /// Specific format can be specified by <seealso cref="GraphDatabaseSettings.record_format"/> property.
        /// <para>
        /// If format is not specified <seealso cref="DEFAULT_FORMAT"/> will be used.
        ///
        /// </para>
        /// </summary>
        /// <param name="config"> configuration parameters </param>
        /// <param name="logProvider"> logging provider </param>
        /// <returns> selected record format </returns>
        /// <exception cref="IllegalArgumentException"> if requested format not found </exception>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Nonnull public static RecordFormats selectForConfig(org.neo4j.kernel.configuration.Config config, org.neo4j.logging.LogProvider logProvider)
        public static RecordFormats SelectForConfig(Config config, LogProvider logProvider)
        {
            string recordFormat = ConfiguredRecordFormat(config);

            if (StringUtils.isEmpty(recordFormat))
            {
                Info(logProvider, "Record format not configured, selected default: " + DefaultFormat());
                return(DefaultFormat());
            }
            RecordFormats format = SelectSpecificFormat(recordFormat);

            Info(logProvider, "Selected record format based on config: " + format);
            return(format);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        private void CreateStore(DatabaseLayout migrationDirectoryStructure, RecordFormats newFormat)
        {
            IdGeneratorFactory idGeneratorFactory = new ReadOnlyIdGeneratorFactory(_fileSystem);
            NullLogProvider    logProvider        = NullLogProvider.Instance;
            StoreFactory       storeFactory       = new StoreFactory(migrationDirectoryStructure, _config, idGeneratorFactory, _pageCache, _fileSystem, newFormat, logProvider, EmptyVersionContextSupplier.EMPTY);

            using (NeoStores neoStores = storeFactory.OpenAllNeoStores(true))
            {
                neoStores.MetaDataStore;
                neoStores.LabelTokenStore;
                neoStores.NodeStore;
                neoStores.PropertyStore;
                neoStores.RelationshipGroupStore;
                neoStores.RelationshipStore;
                neoStores.SchemaStore;
            }
        }
Exemplo n.º 21
0
		 private void RebuildCountsFromScratch( DatabaseLayout sourceStructure, DatabaseLayout migrationStructure, long lastTxId, ProgressReporter progressMonitor, string expectedStoreVersion, PageCache pageCache, LogProvider logProvider )
		 {
			  RecordFormats recordFormats = selectForVersion( expectedStoreVersion );
			  IdGeneratorFactory idGeneratorFactory = new ReadOnlyIdGeneratorFactory( _fileSystem );
			  StoreFactory storeFactory = new StoreFactory( sourceStructure, _config, idGeneratorFactory, pageCache, _fileSystem, recordFormats, logProvider, EmptyVersionContextSupplier.EMPTY );
			  using ( NeoStores neoStores = storeFactory.OpenNeoStores( StoreType.NODE, StoreType.RELATIONSHIP, StoreType.LABEL_TOKEN, StoreType.RELATIONSHIP_TYPE_TOKEN ) )
			  {
					neoStores.VerifyStoreOk();
					NodeStore nodeStore = neoStores.NodeStore;
					RelationshipStore relationshipStore = neoStores.RelationshipStore;
					using ( Lifespan life = new Lifespan() )
					{
						 int highLabelId = ( int ) neoStores.LabelTokenStore.HighId;
						 int highRelationshipTypeId = ( int ) neoStores.RelationshipTypeTokenStore.HighId;
						 CountsComputer initializer = new CountsComputer( lastTxId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId, NumberArrayFactory.auto( pageCache, migrationStructure.DatabaseDirectory(), true, [email protected]_Fields.NoMonitor ), progressMonitor );
						 life.Add( ( new CountsTracker( logProvider, _fileSystem, pageCache, _config, migrationStructure, EmptyVersionContextSupplier.EMPTY ) ).setInitializer( initializer ) );
					}
			  }
		 }
Exemplo n.º 22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: TransactionLogCatchUpWriter(org.neo4j.io.layout.DatabaseLayout databaseLayout, org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pageCache, org.neo4j.kernel.configuration.Config config, org.neo4j.logging.LogProvider logProvider, long fromTxId, boolean asPartOfStoreCopy, boolean keepTxLogsInStoreDir, boolean forceTransactionRotations) throws java.io.IOException
        internal TransactionLogCatchUpWriter(DatabaseLayout databaseLayout, FileSystemAbstraction fs, PageCache pageCache, Config config, LogProvider logProvider, long fromTxId, bool asPartOfStoreCopy, bool keepTxLogsInStoreDir, bool forceTransactionRotations)
        {
            this._pageCache                  = pageCache;
            this._log                        = logProvider.getLog(this.GetType());
            this._asPartOfStoreCopy          = asPartOfStoreCopy;
            this._rotateTransactionsManually = forceTransactionRotations;
            RecordFormats recordFormats = RecordFormatSelector.selectForStoreOrConfig(Config.defaults(), databaseLayout, fs, pageCache, logProvider);

            this._stores = (new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fs), pageCache, fs, recordFormats, logProvider, EMPTY)).openNeoStores(META_DATA);
            Dependencies dependencies = new Dependencies();

            dependencies.SatisfyDependency(_stores.MetaDataStore);
            LogFilesBuilder logFilesBuilder = LogFilesBuilder.builder(databaseLayout, fs).withDependencies(dependencies).withLastCommittedTransactionIdSupplier(() => fromTxId - 1).withConfig(CustomisedConfig(config, keepTxLogsInStoreDir, forceTransactionRotations)).withLogVersionRepository(_stores.MetaDataStore);

            this._logFiles = logFilesBuilder.Build();
            this._lifespan.add(_logFiles);
            this._writer         = new TransactionLogWriter(new LogEntryWriter(_logFiles.LogFile.Writer));
            this._databaseLayout = databaseLayout;
            this._expectedTxId   = fromTxId;
        }
Exemplo n.º 23
0
        public virtual void Migrate(DatabaseLayout fromDirectoryStructure, RecordFormats fromFormat, DatabaseLayout toDirectoryStructure, RecordFormats toFormat, ProgressReporter progressReporter, StoreType[] types, params StoreType[] additionalTypesToOpen)
        {
            StoreType[] storesToOpen = ArrayUtil.concat(types, additionalTypesToOpen);
            progressReporter.Start(storesToOpen.Length);

            try (NeoStores fromStores = new StoreFactory(fromDirectoryStructure, _config, new DefaultIdGeneratorFactory(_fs), _pageCache, _fs, fromFormat, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY)
                                        .openNeoStores(true, storesToOpen);
                 NeoStores toStores = (new StoreFactory(toDirectoryStructure, WithPersistedStoreHeadersAsConfigFrom(fromStores, storesToOpen), new DefaultIdGeneratorFactory(_fs), _pageCache, _fs, toFormat, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY)).openNeoStores(true, storesToOpen))
                {
                    foreach (StoreType type in types)
                    {
                        // This condition will exclude counts store first and foremost.
                        if (type.RecordStore)
                        {
                            Migrate(fromStores.getRecordStore(type), toStores.GetRecordStore(type));
                            progressReporter.Progress(1);
                        }
                    }
                }
        }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustCloseAllStoresIfNeoStoresFailToOpen()
        public virtual void MustCloseAllStoresIfNeoStoresFailToOpen()
        {
            PageCache              pageCache      = Rules.pageCache();
            DatabaseLayout         databaseLayout = Rules.directory().databaseLayout();
            Config                 config         = Config.defaults();
            FileSystemAbstraction  fs             = Rules.fileSystem();
            IdGeneratorFactory     idGenFactory   = new DefaultIdGeneratorFactory(fs);
            LogProvider            logProvider    = NullLogProvider.Instance;
            VersionContextSupplier versions       = EmptyVersionContextSupplier.EMPTY;
            RecordFormats          formats        = Standard.LATEST_RECORD_FORMATS;

            (new RecordFormatPropertyConfigurator(formats, config)).configure();
            bool create = true;

            StoreType[]  storeTypes  = StoreType.values();
            OpenOption[] openOptions = new OpenOption[0];
            NeoStores    neoStores   = new NeoStores(databaseLayout, config, idGenFactory, pageCache, logProvider, fs, versions, formats, create, storeTypes, openOptions);
            File         schemaStore = neoStores.SchemaStore.StorageFile;

            neoStores.Close();

            // Make the schema store inaccessible, to sabotage the next initialisation we'll do.
            assumeTrue(schemaStore.setReadable(false));
            assumeTrue(schemaStore.setWritable(false));

            try
            {
                // This should fail due to the permissions we changed above.
                // And when it fails, the already-opened stores should be closed.
                new NeoStores(databaseLayout, config, idGenFactory, pageCache, logProvider, fs, versions, formats, create, storeTypes, openOptions);
                fail("Opening NeoStores should have thrown.");
            }
            catch (Exception)
            {
            }

            // We verify that the successfully opened stores were closed again by the failed NeoStores open,
            // by closing the page cache, which will throw if not all files have been unmapped.
            pageCache.Close();
        }
Exemplo n.º 25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failStoreInitializationWhenHeaderRecordCantBeRead() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailStoreInitializationWhenHeaderRecordCantBeRead()
        {
            File       storeFile  = _dir.file("a");
            File       idFile     = _dir.file("idFile");
            PageCache  pageCache  = mock(typeof(PageCache));
            PagedFile  pagedFile  = mock(typeof(PagedFile));
            PageCursor pageCursor = mock(typeof(PageCursor));

            when(pageCache.Map(eq(storeFile), anyInt(), any(typeof(OpenOption)))).thenReturn(pagedFile);
            when(pagedFile.Io(0L, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK)).thenReturn(pageCursor);
            when(pageCursor.Next()).thenReturn(false);

            RecordFormats recordFormats = Standard.LATEST_RECORD_FORMATS;

            ExpectedException.expect(typeof(StoreNotFoundException));
            ExpectedException.expectMessage("Fail to read header record of store file: " + storeFile.AbsolutePath);

            using (DynamicArrayStore dynamicArrayStore = new DynamicArrayStore(storeFile, idFile, _config, IdType.NODE_LABELS, _idGeneratorFactory, pageCache, NullLogProvider.Instance, Settings.INTEGER.apply(GraphDatabaseSettings.label_block_size.DefaultValue), recordFormats))
            {
                dynamicArrayStore.Initialise(false);
            }
        }
Exemplo n.º 26
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: NeoStores(org.neo4j.io.layout.DatabaseLayout layout, org.neo4j.kernel.configuration.Config config, org.neo4j.kernel.impl.store.id.IdGeneratorFactory idGeneratorFactory, org.neo4j.io.pagecache.PageCache pageCache, final org.neo4j.logging.LogProvider logProvider, org.neo4j.io.fs.FileSystemAbstraction fileSystemAbstraction, org.neo4j.io.pagecache.tracing.cursor.context.VersionContextSupplier versionContextSupplier, org.neo4j.kernel.impl.store.format.RecordFormats recordFormats, boolean createIfNotExist, StoreType[] storeTypes, java.nio.file.OpenOption[] openOptions)
        internal NeoStores(DatabaseLayout layout, Config config, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, FileSystemAbstraction fileSystemAbstraction, VersionContextSupplier versionContextSupplier, RecordFormats recordFormats, bool createIfNotExist, StoreType[] storeTypes, OpenOption[] openOptions)
        {
            this._layout                 = layout;
            this._metadataStore          = layout.MetadataStore();
            this._config                 = config;
            this._idGeneratorFactory     = idGeneratorFactory;
            this._pageCache              = pageCache;
            this._logProvider            = logProvider;
            this._fileSystemAbstraction  = fileSystemAbstraction;
            this._versionContextSupplier = versionContextSupplier;
            this._recordFormats          = recordFormats;
            this._createIfNotExist       = createIfNotExist;
            this._openOptions            = openOptions;

            VerifyRecordFormat();
            _stores = new object[StoreType.values().length];
            try
            {
                foreach (StoreType type in storeTypes)
                {
                    GetOrCreateStore(type);
                }
            }
            catch (Exception initException)
            {
                try
                {
                    Close();
                }
                catch (Exception closeException)
                {
                    initException.addSuppressed(closeException);
                }
                throw initException;
            }
            _initializedStores = storeTypes;
        }
Exemplo n.º 27
0
        public static bool HasCompatibleCapabilities(RecordFormats one, RecordFormats other, CapabilityType type)
        {
            ISet <Capability> myFormatCapabilities    = Stream.of(one.Capabilities()).filter(capability => capability.isType(type)).collect(toSet());
            ISet <Capability> otherFormatCapabilities = Stream.of(other.Capabilities()).filter(capability => capability.isType(type)).collect(toSet());

            if (myFormatCapabilities.SetEquals(otherFormatCapabilities))
            {
                // If they have the same capabilities then of course they are compatible
                return(true);
            }

//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method:
            bool capabilitiesNotRemoved = otherFormatCapabilities.containsAll(myFormatCapabilities);

//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'removeAll' method:
            otherFormatCapabilities.removeAll(myFormatCapabilities);
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            bool allAddedAreAdditive = otherFormatCapabilities.All(Capability::isAdditive);

            // Even if capabilities of the two aren't the same then there's a special case where if the additional
            // capabilities of the other format are all additive then they are also compatible because no data
            // in the existing store needs to be migrated.
            return(capabilitiesNotRemoved && allAddedAreAdditive);
        }
Exemplo n.º 28
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute(String[] args) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed
        public override void Execute(string[] args)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.nio.file.Path databaseDirectory = arguments.parse(args).getMandatoryPath("store");
            Path databaseDirectory = _arguments.parse(args).getMandatoryPath("store");

            Validators.CONTAINS_EXISTING_DATABASE.validate(databaseDirectory.toFile());

            DatabaseLayout databaseLayout = DatabaseLayout.of(databaseDirectory.toFile());

            try
            {
                using (System.IDisposable ignored = StoreLockChecker.Check(databaseLayout.StoreLayout), DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = createInitialisedScheduler(), PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem, jobScheduler))
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String storeVersion = new org.neo4j.kernel.impl.storemigration.StoreVersionCheck(pageCache).getVersion(databaseLayout.metadataStore()).orElseThrow(() -> new org.neo4j.commandline.admin.CommandFailed(String.format("Could not find version metadata in store '%s'", databaseDirectory)));
                    string storeVersion = (new StoreVersionCheck(pageCache)).getVersion(databaseLayout.MetadataStore()).orElseThrow(() => new CommandFailed(string.Format("Could not find version metadata in store '{0}'", databaseDirectory)));

                    const string fmt = "%-30s%s";
                    @out.accept(string.format(fmt, "Store format version:", storeVersion));

                    RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion);
                    @out.accept(string.format(fmt, "Store format introduced in:", format.IntroductionVersion()));

                    findSuccessor(format).map(next => string.format(fmt, "Store format superseded in:", next.introductionVersion())).ifPresent(@out);
                }
            }
            catch (StoreLockException e)
            {
                throw new CommandFailed("the database is in use -- stop Neo4j and try again", e);
            }
            catch (Exception e)
            {
                throw new CommandFailed(e.Message, e);
            }
        }
Exemplo n.º 29
0
 public RelationshipStore(File file, File idFile, Config configuration, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, RecordFormats recordFormats, params OpenOption[] openOptions) : base(file, idFile, configuration, IdType.RELATIONSHIP, idGeneratorFactory, pageCache, logProvider, TYPE_DESCRIPTOR, recordFormats.Relationship(), NO_STORE_HEADER_FORMAT, recordFormats.StoreVersion(), openOptions)
 {
 }
Exemplo n.º 30
0
 public PropertyStore(File file, File idFile, Config configuration, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, DynamicStringStore stringPropertyStore, PropertyKeyTokenStore propertyKeyTokenStore, DynamicArrayStore arrayPropertyStore, RecordFormats recordFormats, params OpenOption[] openOptions) : base(file, idFile, configuration, IdType.PROPERTY, idGeneratorFactory, pageCache, logProvider, TYPE_DESCRIPTOR, recordFormats.Property(), NO_STORE_HEADER_FORMAT, recordFormats.StoreVersion(), openOptions)
 {
     this._stringStore            = stringPropertyStore;
     this._propertyKeyTokenStore  = propertyKeyTokenStore;
     this._arrayStore             = arrayPropertyStore;
     _allowStorePointsAndTemporal = recordFormats.HasCapability(Capability.POINT_PROPERTIES) && recordFormats.HasCapability(Capability.TEMPORAL_PROPERTIES);
 }