Пример #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);
     }
 }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCommunicateWhatCausesInabilityToUpgrade()
            public virtual void ShouldCommunicateWhatCausesInabilityToUpgrade()
            {
                // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final UpgradableDatabase upgradableDatabase = getUpgradableDatabase();
                UpgradableDatabase upgradableDatabase = UpgradableDatabase;

                try
                {
                    // when
                    upgradableDatabase.CheckUpgradable(DatabaseLayout);
                    fail("should not have been able to upgrade");
                }
                catch (StoreUpgrader.UnexpectedUpgradingStoreVersionException e)
                {
                    // then
                    assertEquals(string.format(MESSAGE, Version, upgradableDatabase.CurrentVersion(), Version.Neo4jVersion), e.Message);
                }
                catch (StoreUpgrader.UnexpectedUpgradingStoreFormatException e)
                {
                    // then
                    assertNotSame(StandardFormatFamily.INSTANCE, RecordFormatSelector.selectForVersion(Version).FormatFamily);
                    assertEquals(string.format(StoreUpgrader.UnexpectedUpgradingStoreFormatException.MESSAGE, GraphDatabaseSettings.record_format.name()), e.Message);
                }
            }
Пример #3
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));
            }
Пример #4
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);
            }
        }
Пример #6
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;
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Parameterized.Parameters(name = "Migrate: {0}->{1}") public static Iterable<Object[]> data() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public static IEnumerable <object[]> Data()
        {
            FileSystemAbstraction fs            = _fileSystemRule.get();
            PageCache             pageCache     = _pageCacheRule.getPageCache(fs);
            TestDirectory         testDirectory = TestDirectory.testDirectory();

            testDirectory.PrepareDirectory(typeof(StoreMigrationIT), "migration");
            DatabaseLayout    databaseLayout    = testDirectory.DatabaseLayout();
            StoreVersionCheck storeVersionCheck = new StoreVersionCheck(pageCache);
            VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
            LogFiles             logFiles      = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.DatabaseDirectory(), fs).withLogEntryReader(logEntryReader).build();
            LogTailScanner       tailScanner   = new LogTailScanner(logFiles, logEntryReader, new Monitors());
            IList <object[]>     data          = new List <object[]>();
            List <RecordFormats> recordFormats = new List <RecordFormats>();

            RecordFormatSelector.allFormats().forEach(f => addIfNotThere(f, recordFormats));
            foreach (RecordFormats toFormat in recordFormats)
            {
                UpgradableDatabase upgradableDatabase = new UpgradableDatabase(storeVersionCheck, toFormat, tailScanner);
                foreach (RecordFormats fromFormat in recordFormats)
                {
                    try
                    {
                        CreateDb(fromFormat, databaseLayout.DatabaseDirectory());
                        if (!upgradableDatabase.HasCurrentVersion(databaseLayout))
                        {
                            upgradableDatabase.CheckUpgradable(databaseLayout);
                            data.Add(new object[] { fromFormat, toFormat });
                        }
                    }
                    catch (Exception)
                    {
                        //This means that the combination is not migratable.
                    }
                    fs.DeleteRecursively(databaseLayout.DatabaseDirectory());
                }
            }

            return(data);
        }
Пример #8
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);
            }
        }
Пример #9
0
        public virtual void MigrateIfNeeded(DatabaseLayout layout)
        {
            DatabaseLayout migrationStructure = DatabaseLayout.of(layout.DatabaseDirectory(), MIGRATION_DIRECTORY);

            CleanupLegacyLeftOverDirsIn(layout.DatabaseDirectory());

            File migrationStateFile = migrationStructure.File(MIGRATION_STATUS_FILE);

            // if migration directory exists than we might have failed to move files into the store dir so do it again
            if (_upgradableDatabase.hasCurrentVersion(layout) && !_fileSystem.fileExists(migrationStateFile))
            {
                // No migration needed
                return;
            }

            if (UpgradeAllowed)
            {
                MigrateStore(layout, migrationStructure, migrationStateFile);
            }
            else if (!RecordFormatSelector.isStoreAndConfigFormatsCompatible(_config, layout, _fileSystem, _pageCache, _logProvider))
            {
                throw new UpgradeNotAllowedByConfigurationException();
            }
        }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void run(final org.neo4j.io.fs.FileSystemAbstraction fs, final java.io.File storeDirectory, org.neo4j.kernel.configuration.Config config, org.neo4j.logging.LogProvider userLogProvider) throws Exception
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public static void Run(FileSystemAbstraction fs, File storeDirectory, Config config, LogProvider userLogProvider)
        {
            StoreLogService logService = StoreLogService.withUserLogProvider(userLogProvider).withInternalLog(config.Get(store_internal_log_path)).build(fs);

            VisibleMigrationProgressMonitor progressMonitor = new VisibleMigrationProgressMonitor(logService.GetUserLog(typeof(StoreMigration)));

            LifeSupport life = new LifeSupport();

            life.Add(logService);

            // Add participants from kernel extensions...
            DefaultExplicitIndexProvider migrationIndexProvider = new DefaultExplicitIndexProvider();

            Log          log          = userLogProvider.GetLog(typeof(StoreMigration));
            JobScheduler jobScheduler = JobSchedulerFactory.createInitialisedScheduler();

            try
            {
                using (PageCache pageCache = createPageCache(fs, config, jobScheduler))
                {
                    Dependencies deps     = new Dependencies();
                    Monitors     monitors = new Monitors();
                    deps.SatisfyDependencies(fs, config, migrationIndexProvider, pageCache, logService, monitors, RecoveryCleanupWorkCollector.immediate());

                    KernelContext            kernelContext    = new SimpleKernelContext(storeDirectory, DatabaseInfo.UNKNOWN, deps);
                    DatabaseKernelExtensions kernelExtensions = life.Add(new DatabaseKernelExtensions(kernelContext, GraphDatabaseDependencies.newDependencies().kernelExtensions(), deps, ignore()));

                    DatabaseLayout databaseLayout = DatabaseLayout.of(storeDirectory);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.activeFilesBuilder(databaseLayout, fs, pageCache).withConfig(config).build();
                    LogFiles       logFiles    = LogFilesBuilder.activeFilesBuilder(databaseLayout, fs, pageCache).withConfig(config).build();
                    LogTailScanner tailScanner = new LogTailScanner(logFiles, new VersionAwareLogEntryReader <Org.Neo4j.Kernel.impl.transaction.log.ReadableClosablePositionAwareChannel>(), monitors);

                    DefaultIndexProviderMap indexProviderMap = life.Add(new DefaultIndexProviderMap(kernelExtensions, config));

                    // Add the kernel store migrator
                    life.Start();

                    long             startTime = DateTimeHelper.CurrentUnixTimeMillis();
                    DatabaseMigrator migrator  = new DatabaseMigrator(progressMonitor, fs, config, logService, indexProviderMap, migrationIndexProvider, pageCache, RecordFormatSelector.selectForConfig(config, userLogProvider), tailScanner, jobScheduler);
                    migrator.Migrate(databaseLayout);

                    // Append checkpoint so the last log entry will have the latest version
                    AppendCheckpoint(logFiles, tailScanner);

                    long duration = DateTimeHelper.CurrentUnixTimeMillis() - startTime;
                    log.Info(format("Migration completed in %d s%n", duration / 1000));
                }
            }
            catch (Exception e)
            {
                throw new StoreUpgrader.UnableToUpgradeException("Failure during upgrade", e);
            }
            finally
            {
                life.Shutdown();
                jobScheduler.close();
            }
        }
Пример #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBehaveCorrectlyUnderStress() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBehaveCorrectlyUnderStress()
        {
            long   durationInMinutes = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
            File   storeDir          = new File(fromEnv("CHECK_POINT_LOG_ROTATION_STORE_DIRECTORY", _defaultStoreDir));
            long   nodeCount         = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_NODE_COUNT", DEFAULT_NODE_COUNT));
            int    threads           = parseInt(fromEnv("CHECK_POINT_LOG_ROTATION_WORKER_THREADS", DEFAULT_WORKER_THREADS));
            string pageCacheMemory   = fromEnv("CHECK_POINT_LOG_ROTATION_PAGE_CACHE_MEMORY", DEFAULT_PAGE_CACHE_MEMORY);

            Console.WriteLine("1/6\tBuilding initial store...");
            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = new ThreadPoolJobScheduler())
            {
                Config dbConfig = Config.defaults();
                (new ParallelBatchImporter(DatabaseLayout.of(ensureExistsAndEmpty(storeDir)), fileSystem, null, DEFAULT, NullLogService.Instance, ExecutionMonitors.defaultVisible(jobScheduler), EMPTY, dbConfig, RecordFormatSelector.selectForConfig(dbConfig, NullLogProvider.Instance), NO_MONITOR, jobScheduler)).doImport(new NodeCountInputs(nodeCount));
            }

            Console.WriteLine("2/6\tStarting database...");
            GraphDatabaseBuilder builder = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDir);
            GraphDatabaseService db      = builder.SetConfig(GraphDatabaseSettings.pagecache_memory, pageCacheMemory).setConfig(GraphDatabaseSettings.keep_logical_logs, Settings.FALSE).setConfig(GraphDatabaseSettings.check_point_interval_time, CHECK_POINT_INTERVAL_MINUTES + "m").setConfig(GraphDatabaseSettings.tracer, "timer").newGraphDatabase();

            Console.WriteLine("3/6\tWarm up db...");
            using (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads))
            {
                // make sure to run at least one checkpoint during warmup
                long warmUpTimeMillis = TimeUnit.SECONDS.toMillis(CHECK_POINT_INTERVAL_MINUTES * 2);
                workload.Run(warmUpTimeMillis, Workload.TransactionThroughput_Fields.NONE);
            }

            Console.WriteLine("4/6\tStarting workload...");
            TransactionThroughputChecker throughput = new TransactionThroughputChecker();

            using (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads))
            {
                workload.Run(TimeUnit.MINUTES.toMillis(durationInMinutes), throughput);
            }

            Console.WriteLine("5/6\tShutting down...");
            Db.shutdown();

            try
            {
                Console.WriteLine("6/6\tPrinting stats and recorded timings...");
                TimerTransactionTracer.printStats(System.out);
                throughput.AssertThroughput(System.out);
            }
            finally
            {
                Console.WriteLine("Done.");
            }

            // let's cleanup disk space when everything went well
            FileUtils.deleteRecursively(storeDir);
        }
Пример #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void verifyFixedSizeStoresCanRebuildIdGeneratorSlowly()
        public virtual void VerifyFixedSizeStoresCanRebuildIdGeneratorSlowly()
        {
            // Given we have a store ...
            Config config    = Config.defaults(GraphDatabaseSettings.rebuild_idgenerators_fast, "false");
            File   storeFile = _testDirectory.file("nodes");
            File   idFile    = _testDirectory.file("idNodes");

            DynamicArrayStore labelStore = mock(typeof(DynamicArrayStore));
            NodeStore         store      = new NodeStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(_fs), PageCacheRule.getPageCache(_fs), NullLogProvider.Instance, labelStore, RecordFormatSelector.defaultFormat());

            store.Initialise(true);
            store.MakeStoreOk();

            // ... that contain a number of records ...
            NodeRecord record = new NodeRecord(0);

            record.InUse = true;
            int highestId = 50;

            for (int i = 0; i < highestId; i++)
            {
                assertThat(store.NextId(), @is((long)i));
                record.Id = i;
                store.UpdateRecord(record);
            }
            store.HighestPossibleIdInUse = highestId;

            // ... and some have been deleted
            long?[] idsToFree = new long?[] { 2L, 3L, 5L, 7L };
            record.InUse = false;
            foreach (long toDelete in idsToFree)
            {
                record.Id = toDelete;
                store.UpdateRecord(record);
            }

            // Then when we rebuild the id generator
            store.RebuildIdGenerator();
            store.CloseIdGenerator();
            store.OpenIdGenerator();               // simulate a restart to allow id reuse

            // We should observe that the ids above got freed
            IList <long> nextIds = new List <long>();

            nextIds.Add(store.NextId());                 // 2
            nextIds.Add(store.NextId());                 // 3
            nextIds.Add(store.NextId());                 // 5
            nextIds.Add(store.NextId());                 // 7
            nextIds.Add(store.NextId());                 // 51
            assertThat(nextIds, contains(2L, 3L, 5L, 7L, 50L));
            store.Close();
        }
Пример #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void rebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage()
        public virtual void RebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage()
        {
            // Given we have a store ...
            Config config    = Config.defaults(GraphDatabaseSettings.rebuild_idgenerators_fast, "false");
            File   storeFile = _testDirectory.file("nodes");
            File   idFile    = _testDirectory.file("idNodes");

            DynamicArrayStore labelStore = mock(typeof(DynamicArrayStore));
            NodeStore         store      = new NodeStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(_fs), PageCacheRule.getPageCache(_fs), NullLogProvider.Instance, labelStore, RecordFormatSelector.defaultFormat());

            store.Initialise(true);
            store.MakeStoreOk();

            // ... that contain enough records to fill several file pages ...
            int        recordsPerPage = store.RecordsPerPage;
            NodeRecord record         = new NodeRecord(0);

            record.InUse = true;
            int highestId = recordsPerPage * 3;               // 3 pages worth of records

            for (int i = 0; i < highestId; i++)
            {
                assertThat(store.NextId(), @is((long)i));
                record.Id = i;
                store.UpdateRecord(record);
            }
            store.HighestPossibleIdInUse = highestId;

            // ... and some records at the end of a page have been deleted
            long?[] idsToFree = new long?[] { recordsPerPage - 2L, recordsPerPage - 1L };               // id's are zero based, hence -2 and -1
            record.InUse = false;
            foreach (long toDelete in idsToFree)
            {
                record.Id = toDelete;
                store.UpdateRecord(record);
            }

            // Then when we rebuild the id generator
            store.RebuildIdGenerator();
            store.CloseIdGenerator();
            store.OpenIdGenerator();               // simulate a restart to allow id reuse

            // We should observe that the ids above got freed
            IList <long> nextIds = new List <long>();

            nextIds.Add(store.NextId());                 // recordsPerPage - 2
            nextIds.Add(store.NextId());                 // recordsPerPage - 1
            nextIds.Add(store.NextId());                 // recordsPerPage * 3 (we didn't use this id in the create-look above)
            assertThat(nextIds, contains(recordsPerPage - 2L, recordsPerPage - 1L, recordsPerPage * 3L));
            store.Close();
        }
Пример #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void main(String[] arguments) throws java.io.IOException
        public static void Main(string[] arguments)
        {
            Args          args                  = Args.parse(arguments);
            long          nodeCount             = Settings.parseLongWithUnit(args.Get("nodes", null));
            long          relationshipCount     = Settings.parseLongWithUnit(args.Get("relationships", null));
            int           labelCount            = args.GetNumber("labels", 4).intValue();
            int           relationshipTypeCount = args.GetNumber("relationship-types", 4).intValue();
            File          dir        = new File(args.Get(ImportTool.Options.StoreDir.key()));
            long          randomSeed = args.GetNumber("random-seed", currentTimeMillis()).longValue();
            Configuration config     = Configuration.COMMAS;

            Extractors extractors = new Extractors(config.ArrayDelimiter());
            IdType     idType     = IdType.valueOf(args.Get("id-type", IdType.INTEGER.name()));

            Groups groups             = new Groups();
            Header nodeHeader         = ParseNodeHeader(args, idType, extractors, groups);
            Header relationshipHeader = ParseRelationshipHeader(args, idType, extractors, groups);

            Config dbConfig;
            string dbConfigFileName = args.Get(ImportTool.Options.DatabaseConfig.key(), null);

            if (!string.ReferenceEquals(dbConfigFileName, null))
            {
                dbConfig = (new Config.Builder()).withFile(new File(dbConfigFileName)).build();
            }
            else
            {
                dbConfig = Config.defaults();
            }

            bool highIo = args.GetBoolean(ImportTool.Options.HighIo.key());

            LogProvider logging         = NullLogProvider.Instance;
            long        pageCacheMemory = args.GetNumber("pagecache-memory", [email protected]_Fields.MaxPageCacheMemory).longValue();

            [email protected] importConfig = new ConfigurationAnonymousInnerClass(args, highIo, pageCacheMemory);

            float factorBadNodeData         = args.GetNumber("factor-bad-node-data", 0).floatValue();
            float factorBadRelationshipData = args.GetNumber("factor-bad-relationship-data", 0).floatValue();

            Input input = new DataGeneratorInput(nodeCount, relationshipCount, idType, Collector.EMPTY, randomSeed, 0, nodeHeader, relationshipHeader, labelCount, relationshipTypeCount, factorBadNodeData, factorBadRelationshipData);

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), Lifespan life = new Lifespan())
            {
                BatchImporter consumer;
                if (args.GetBoolean("to-csv"))
                {
                    consumer = new CsvOutput(dir, nodeHeader, relationshipHeader, config);
                }
                else
                {
                    Console.WriteLine("Seed " + randomSeed);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.scheduler.JobScheduler jobScheduler = life.add(createScheduler());
                    JobScheduler jobScheduler = life.Add(createScheduler());
                    consumer = BatchImporterFactory.withHighestPriority().instantiate(DatabaseLayout.of(dir), fileSystem, null, importConfig, new SimpleLogService(logging, logging), defaultVisible(jobScheduler), EMPTY, dbConfig, RecordFormatSelector.selectForConfig(dbConfig, logging), NO_MONITOR, jobScheduler);
                    ImportTool.PrintOverview(dir, Collections.emptyList(), Collections.emptyList(), importConfig, System.out);
                }
                consumer.DoImport(input);
            }
        }
Пример #15
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());
            }
        }
Пример #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldImportDataComingFromCsvFiles() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldImportDataComingFromCsvFiles()
        {
            // GIVEN
            Config dbConfig = Config.builder().withSetting(db_timezone, LogTimeZone.SYSTEM.name()).build();

            using (JobScheduler scheduler = new ThreadPoolJobScheduler())
            {
                BatchImporter       importer         = new ParallelBatchImporter(Directory.databaseLayout(), FileSystemRule.get(), null, SmallBatchSizeConfig(), NullLogService.Instance, invisible(), AdditionalInitialIds.EMPTY, dbConfig, RecordFormatSelector.defaultFormat(), NO_MONITOR, scheduler);
                IList <InputEntity> nodeData         = RandomNodeData();
                IList <InputEntity> relationshipData = RandomRelationshipData(nodeData);

                // WHEN
                importer.DoImport(Csv(NodeDataAsFile(nodeData), RelationshipDataAsFile(relationshipData), IdType.String, LowBufferSize(COMMAS), silentBadCollector(0)));
                // THEN
                VerifyImportedData(nodeData, relationshipData);
            }
        }