Пример #1
0
        /// <summary>
        /// Iterate over all the provided strategies trying to perform a successful backup.
        /// Will also do consistency checks if specified in <seealso cref="OnlineBackupContext"/>
        /// </summary>
        /// <param name="onlineBackupContext"> filesystem, command arguments and configuration </param>
        /// <exception cref="CommandFailed"> when backup failed or there were issues with consistency checks </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void performBackup(OnlineBackupContext onlineBackupContext) throws org.neo4j.commandline.admin.CommandFailed
        public virtual void PerformBackup(OnlineBackupContext onlineBackupContext)
        {
            // Convenience
            OnlineBackupRequiredArguments requiredArgs = onlineBackupContext.RequiredArguments;
            Path             destination      = onlineBackupContext.ResolvedLocationFromName;
            ConsistencyFlags consistencyFlags = onlineBackupContext.ConsistencyFlags;

            Fallible <BackupStrategyOutcome> throwableWithState = null;
            IList <Exception> causesOfFailure = new List <Exception>();

            foreach (BackupStrategyWrapper backupStrategy in _strategies)
            {
                throwableWithState = backupStrategy.DoBackup(onlineBackupContext);
                if (throwableWithState.State == BackupStrategyOutcome.Success)
                {
                    break;
                }
                if (throwableWithState.State == BackupStrategyOutcome.CorrectStrategyFailed)
                {
                    throw CommandFailedWithCause(throwableWithState).get();
                }
                throwableWithState.Cause.ifPresent(causesOfFailure.add);
            }
            if (throwableWithState == null || !BackupStrategyOutcome.Success.Equals(throwableWithState.State))
            {
                CommandFailed commandFailed = new CommandFailed("Failed to run a backup using the available strategies.");
                causesOfFailure.ForEach(commandFailed.addSuppressed);
                throw commandFailed;
            }
            if (requiredArgs.DoConsistencyCheck)
            {
                PerformConsistencyCheck(onlineBackupContext.Config, requiredArgs, consistencyFlags, DatabaseLayout.of(destination.toFile()));
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void incrementalBackupIsRecoveredAndConsistent() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IncrementalBackupIsRecoveredAndConsistent()
        {
            // given database exists with data
            Cluster cluster = StartCluster(RecordFormat);

            CreateSomeData(cluster);
            string address = cluster.awaitLeader().Config().get(online_backup_server).ToString();

            string         name           = System.Guid.randomUUID().ToString();
            File           backupLocation = new File(_backupStoreDir, name);
            DatabaseLayout backupLayout   = DatabaseLayout.of(backupLocation);

            // when
            assertEquals(0, RunBackupToolFromOtherJvmToGetExitCode("--from", address, "--cc-report-dir=" + _backupStoreDir, "--backup-dir=" + _backupStoreDir, "--name=" + name));

            // and
            CreateSomeData(cluster);
            assertEquals(0, RunBackupToolFromOtherJvmToGetExitCode("--from", address, "--cc-report-dir=" + _backupStoreDir, "--backup-dir=" + _backupStoreDir, "--name=" + name, Arg(ARG_NAME_FALLBACK_FULL, false)));

            // then
            assertFalse("Store should not require recovery", (new RecoveryRequiredChecker(_fileSystemRule, _pageCacheRule.getPageCache(_fileSystemRule), Config.defaults(), new Monitors())).isRecoveryRequiredAt(backupLayout));
            ConsistencyFlags consistencyFlags = new ConsistencyFlags(true, true, true, true, true);

            assertTrue("Consistency check failed", new ConsistencyCheckService()
                       .runFullConsistencyCheck(backupLayout, Config.defaults(), ProgressMonitorFactory.NONE, NullLogProvider.Instance, false, consistencyFlags).Successful);
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void incrementalBackupIsRecoveredAndConsistent() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IncrementalBackupIsRecoveredAndConsistent()
        {
            // given database exists
            int backupPort = PortAuthority.allocatePort();

            StartDb(backupPort);
            string ip = ":" + backupPort;

            string         name           = System.Guid.randomUUID().ToString();
            File           backupLocation = new File(_backupDir, name);
            DatabaseLayout backupLayout   = DatabaseLayout.of(backupLocation);

            // when
            assertEquals(0, RunBackupTool(_testDirectory.absolutePath(), "--from", ip, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--name=" + name));

            // and
            CreateSomeData(_db);
            assertEquals(0, RunBackupTool(_testDirectory.absolutePath(), "--from", ip, "--cc-report-dir=" + _backupDir, "--backup-dir=" + _backupDir, "--name=" + name, arg(ARG_NAME_FALLBACK_FULL, false)));

            // then
            assertFalse("Store should not require recovery", (new RecoveryRequiredChecker(_fileSystemRule, _pageCacheRule.getPageCache(_fileSystemRule), Config.defaults(), new Monitors())).isRecoveryRequiredAt(backupLayout));
            ConsistencyFlags consistencyFlags = new ConsistencyFlags(true, true, true, true, true);

            assertTrue("Consistency check failed", new ConsistencyCheckService()
                       .runFullConsistencyCheck(backupLayout, Config.defaults(), ProgressMonitorFactory.NONE, NullLogProvider.Instance, false, consistencyFlags).Successful);
        }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.consistency.ConsistencyCheckService.Result checkConsistency() throws org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException
        private ConsistencyCheckService.Result CheckConsistency()
        {
            Config config = Config.defaults();
            ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService(DateTime.Now);
            ConsistencyFlags        checkConsistencyConfig  = new ConsistencyFlags(config);

            return(consistencyCheckService.runFullConsistencyCheck(_testDirectory.databaseLayout(), config, ProgressMonitorFactory.NONE, NullLogProvider.Instance, true, checkConsistencyConfig));
        }
Пример #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void performConsistencyCheck(org.neo4j.kernel.configuration.Config config, OnlineBackupRequiredArguments requiredArgs, org.neo4j.consistency.checking.full.ConsistencyFlags consistencyFlags, org.neo4j.io.layout.DatabaseLayout layout) throws org.neo4j.commandline.admin.CommandFailed
        private void PerformConsistencyCheck(Config config, OnlineBackupRequiredArguments requiredArgs, ConsistencyFlags consistencyFlags, DatabaseLayout layout)
        {
            try
            {
                bool verbose   = false;
                File reportDir = requiredArgs.ReportDir.toFile();
                ConsistencyCheckService.Result ccResult = _consistencyCheckService.runFullConsistencyCheck(layout, config, _progressMonitorFactory, _logProvider, _outsideWorld.fileSystem(), verbose, reportDir, consistencyFlags);

                if (!ccResult.Successful)
                {
                    throw new CommandFailed(format("Inconsistencies found. See '%s' for details.", ccResult.ReportFile()), STATUS_CC_INCONSISTENT);
                }
            }
            catch (Exception e)
            {
                if (e is CommandFailed)
                {
                    throw ( CommandFailed )e;
                }
                throw new CommandFailed("Failed to do consistency check on backup: " + e.Message, e, STATUS_CC_ERROR);
            }
        }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Result runFullConsistencyCheck(org.neo4j.io.layout.DatabaseLayout databaseLayout, org.neo4j.kernel.configuration.Config config, org.neo4j.helpers.progress.ProgressMonitorFactory progressFactory, final org.neo4j.logging.LogProvider logProvider, final org.neo4j.io.fs.FileSystemAbstraction fileSystem, final org.neo4j.io.pagecache.PageCache pageCache, final boolean verbose, java.io.File reportDir, org.neo4j.consistency.checking.full.ConsistencyFlags consistencyFlags) throws org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public virtual Result RunFullConsistencyCheck(DatabaseLayout databaseLayout, Config config, ProgressMonitorFactory progressFactory, LogProvider logProvider, FileSystemAbstraction fileSystem, PageCache pageCache, bool verbose, File reportDir, ConsistencyFlags consistencyFlags)
        {
            AssertRecovered(databaseLayout, config, fileSystem, pageCache);
            Log log = logProvider.getLog(this.GetType());

            config.augment(GraphDatabaseSettings.read_only, TRUE);
            config.augment(GraphDatabaseSettings.pagecache_warmup_enabled, FALSE);

            StoreFactory factory = new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fileSystem), pageCache, fileSystem, logProvider, EmptyVersionContextSupplier.EMPTY);

            ConsistencySummaryStatistics summary;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File reportFile = chooseReportPath(reportDir);
            File reportFile = ChooseReportPath(reportDir);

            Suppliers.Lazy <PrintWriter> reportWriterSupplier = GetReportWriterSupplier(fileSystem, reportFile);
            Log reportLog = new ConsistencyReportLog(reportWriterSupplier);

            // Bootstrap kernel extensions
            Monitors                 monitors     = new Monitors();
            LifeSupport              life         = new LifeSupport();
            JobScheduler             jobScheduler = life.Add(JobSchedulerFactory.createInitialisedScheduler());
            TokenHolders             tokenHolders = new TokenHolders(new DelegatingTokenHolder(new ReadOnlyTokenCreator(), Org.Neo4j.Kernel.impl.core.TokenHolder_Fields.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), Org.Neo4j.Kernel.impl.core.TokenHolder_Fields.TYPE_LABEL), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), Org.Neo4j.Kernel.impl.core.TokenHolder_Fields.TYPE_RELATIONSHIP_TYPE));
            DatabaseKernelExtensions extensions   = life.Add(instantiateKernelExtensions(databaseLayout.DatabaseDirectory(), fileSystem, config, new SimpleLogService(logProvider, logProvider), pageCache, jobScheduler, RecoveryCleanupWorkCollector.ignore(), TOOL, monitors, tokenHolders));
            DefaultIndexProviderMap  indexes      = life.Add(new DefaultIndexProviderMap(extensions, config));

            try
            {
                using (NeoStores neoStores = factory.OpenAllNeoStores())
                {
                    // Load tokens before starting extensions, etc.
                    tokenHolders.PropertyKeyTokens().InitialTokens      = neoStores.PropertyKeyTokenStore.Tokens;
                    tokenHolders.LabelTokens().InitialTokens            = neoStores.LabelTokenStore.Tokens;
                    tokenHolders.RelationshipTypeTokens().InitialTokens = neoStores.RelationshipTypeTokenStore.Tokens;

                    life.Start();

                    LabelScanStore labelScanStore = new NativeLabelScanStore(pageCache, databaseLayout, fileSystem, Org.Neo4j.Kernel.Impl.Api.scan.FullStoreChangeStream_Fields.Empty, true, monitors, RecoveryCleanupWorkCollector.ignore());
                    life.Add(labelScanStore);

                    int              numberOfThreads = DefaultConsistencyCheckThreadsNumber();
                    Statistics       statistics;
                    StoreAccess      storeAccess;
                    AccessStatistics stats = new AccessStatistics();
                    if (verbose)
                    {
                        statistics  = new VerboseStatistics(stats, new DefaultCounts(numberOfThreads), log);
                        storeAccess = new AccessStatsKeepingStoreAccess(neoStores, stats);
                    }
                    else
                    {
                        statistics  = Statistics.NONE;
                        storeAccess = new StoreAccess(neoStores);
                    }
                    storeAccess.Initialize();
                    DirectStoreAccess stores = new DirectStoreAccess(storeAccess, labelScanStore, indexes, tokenHolders);
                    FullCheck         check  = new FullCheck(progressFactory, statistics, numberOfThreads, consistencyFlags, config, true);
                    summary = check.Execute(stores, new DuplicatingLog(log, reportLog));
                }
            }
            finally
            {
                life.Shutdown();
                if (reportWriterSupplier.Initialised)
                {
                    reportWriterSupplier.get().close();
                }
            }

            if (!summary.Consistent)
            {
                log.Warn("See '%s' for a detailed consistency report.", reportFile.Path);
                return(Result.failure(reportFile));
            }
            return(Result.success(reportFile));
        }
Пример #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Result runFullConsistencyCheck(org.neo4j.io.layout.DatabaseLayout databaseLayout, org.neo4j.kernel.configuration.Config config, org.neo4j.helpers.progress.ProgressMonitorFactory progressFactory, final org.neo4j.logging.LogProvider logProvider, final org.neo4j.io.fs.FileSystemAbstraction fileSystem, final org.neo4j.io.pagecache.PageCache pageCache, final boolean verbose, org.neo4j.consistency.checking.full.ConsistencyFlags consistencyFlags) throws org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public virtual Result RunFullConsistencyCheck(DatabaseLayout databaseLayout, Config config, ProgressMonitorFactory progressFactory, LogProvider logProvider, FileSystemAbstraction fileSystem, PageCache pageCache, bool verbose, ConsistencyFlags consistencyFlags)
        {
            return(RunFullConsistencyCheck(databaseLayout, config, progressFactory, logProvider, fileSystem, pageCache, verbose, DefaultReportDir(config, databaseLayout.DatabaseDirectory()), consistencyFlags));
        }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Result runFullConsistencyCheck(org.neo4j.io.layout.DatabaseLayout databaseLayout, org.neo4j.kernel.configuration.Config config, org.neo4j.helpers.progress.ProgressMonitorFactory progressFactory, org.neo4j.logging.LogProvider logProvider, org.neo4j.io.fs.FileSystemAbstraction fileSystem, boolean verbose, java.io.File reportDir, org.neo4j.consistency.checking.full.ConsistencyFlags consistencyFlags) throws org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException
        public virtual Result RunFullConsistencyCheck(DatabaseLayout databaseLayout, Config config, ProgressMonitorFactory progressFactory, LogProvider logProvider, FileSystemAbstraction fileSystem, bool verbose, File reportDir, ConsistencyFlags consistencyFlags)
        {
            Log          log          = logProvider.getLog(this.GetType());
            JobScheduler jobScheduler = JobSchedulerFactory.createInitialisedScheduler();
            ConfiguringPageCacheFactory pageCacheFactory = new ConfiguringPageCacheFactory(fileSystem, config, PageCacheTracer.NULL, Org.Neo4j.Io.pagecache.tracing.cursor.PageCursorTracerSupplier_Fields.Null, logProvider.GetLog(typeof(PageCache)), EmptyVersionContextSupplier.EMPTY, jobScheduler);
            PageCache pageCache = pageCacheFactory.OrCreatePageCache;

            try
            {
                return(RunFullConsistencyCheck(databaseLayout, config, progressFactory, logProvider, fileSystem, pageCache, verbose, reportDir, consistencyFlags));
            }
            finally
            {
                try
                {
                    pageCache.Close();
                }
                catch (Exception e)
                {
                    log.Error("Failure during shutdown of the page cache", e);
                }
                try
                {
                    jobScheduler.close();
                }
                catch (Exception e)
                {
                    log.Error("Failure during shutdown of the job scheduler", e);
                }
            }
        }
Пример #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Result runFullConsistencyCheck(org.neo4j.io.layout.DatabaseLayout databaseLayout, org.neo4j.kernel.configuration.Config config, org.neo4j.helpers.progress.ProgressMonitorFactory progressFactory, org.neo4j.logging.LogProvider logProvider, boolean verbose, org.neo4j.consistency.checking.full.ConsistencyFlags consistencyFlags) throws org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException
        public virtual Result RunFullConsistencyCheck(DatabaseLayout databaseLayout, Config config, ProgressMonitorFactory progressFactory, LogProvider logProvider, bool verbose, ConsistencyFlags consistencyFlags)
        {
            FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();

            try
            {
                return(RunFullConsistencyCheck(databaseLayout, config, progressFactory, logProvider, fileSystem, verbose, consistencyFlags));
            }
            finally
            {
                try
                {
                    fileSystem.Dispose();
                }
                catch (IOException e)
                {
                    Log log = logProvider.getLog(this.GetType());
                    log.Error("Failure during shutdown of file system", e);
                }
            }
        }