Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public OnlineBackupContext createContext(String... args) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed
        public virtual OnlineBackupContext CreateContext(params string[] args)
        {
            try
            {
                Arguments arguments = arguments();
                arguments.Parse(args);

                OptionalHostnamePort address = Converters.toOptionalHostnamePortFromRawAddress(arguments.Get(ARG_NAME_BACKUP_SOURCE));
                Path   folder             = this.GetBackupDirectory(arguments);
                string name               = arguments.Get(ARG_NAME_BACKUP_NAME);
                bool   fallbackToFull     = arguments.GetBoolean(ARG_NAME_FALLBACK_FULL);
                bool   doConsistencyCheck = arguments.GetBoolean(ARG_NAME_CHECK_CONSISTENCY);
                long   timeout            = ( long? )arguments.Get(ARG_NAME_TIMEOUT, TimeUtil.parseTimeMillis).Value;
                SelectedBackupProtocol selectedBackupProtocol = SelectedBackupProtocol.fromUserInput(arguments.Get(ARG_NAME_PROTO_OVERRIDE));
                string          pagecacheMemory  = arguments.Get(ARG_NAME_PAGECACHE);
                Optional <Path> additionalConfig = arguments.GetOptionalPath(ARG_NAME_ADDITIONAL_CONFIG_DIR);
                Path            reportDir        = ( Path )arguments.GetOptionalPath(ARG_NAME_REPORT_DIRECTORY).orElseThrow(() =>
                {
                    return(new System.ArgumentException(ARG_NAME_REPORT_DIRECTORY + " must be a path"));
                });
                OnlineBackupRequiredArguments requiredArguments = new OnlineBackupRequiredArguments(address, folder, name, selectedBackupProtocol, fallbackToFull, doConsistencyCheck, timeout, reportDir);

                Path           configFile = _configDir.resolve(Config.DEFAULT_CONFIG_FILE_NAME);
                Config.Builder builder    = Config.fromFile(configFile);
                Path           logPath    = requiredArguments.ResolvedLocationFromName;

                Config config = builder.WithHome(this._homeDir).withSetting(GraphDatabaseSettings.logical_logs_location, logPath.ToString()).withConnectorsDisabled().withNoThrowOnFileLoadFailure().build();

                additionalConfig.map(this.loadAdditionalConfigFile).ifPresent(config.augment);

                // We only replace the page cache memory setting.
                // Any other custom page swapper, etc. settings are preserved and used.
                config.Augment(GraphDatabaseSettings.pagecache_memory, pagecacheMemory);

                // Disable prometheus to avoid binding exceptions
                config.Augment("metrics.prometheus.enabled", Settings.FALSE);

                // Build consistency-checker configuration.
                // Note: We can remove the loading from config file in 4.0.
                System.Func <string, Setting <bool>, bool> oneOf = (a, s) => arguments.Has(a) ? arguments.GetBoolean(a) : config.Get(s);

                ConsistencyFlags consistencyFlags = new ConsistencyFlags(config);

                return(new OnlineBackupContext(requiredArguments, config, consistencyFlags));
            }
            catch (System.ArgumentException e)
            {
                throw new IncorrectUsage(e.Message);
            }
            catch (UncheckedIOException e)
            {
                throw new CommandFailed(e.Message, e);
            }
        }
Пример #2
0
 internal OnlineBackupRequiredArguments(OptionalHostnamePort address, Path directory, string name, SelectedBackupProtocol selectedBackupProtocol, bool fallbackToFull, bool doConsistencyCheck, long timeout, Path reportDir)
 {
     this._address                = address;
     this._directory              = directory;
     this._name                   = name;
     this._fallbackToFull         = fallbackToFull;
     this._doConsistencyCheck     = doConsistencyCheck;
     this._timeout                = timeout;
     this._reportDir              = reportDir;
     this._selectedBackupProtocol = selectedBackupProtocol;
 }
Пример #3
0
        internal virtual AdvertisedSocketAddress ResolveCorrectCCAddress(Config config, OptionalHostnamePort userProvidedAddress)
        {
            AdvertisedSocketAddress defaultValue = ReadDefaultConfigAddressCC(config);

            return(new AdvertisedSocketAddress(userProvidedAddress.Hostname.orElse(defaultValue.Hostname), userProvidedAddress.Port.GetValueOrDefault(defaultValue.Port)));
        }
Пример #4
0
        internal virtual HostnamePort ResolveCorrectHAAddress(Config config, OptionalHostnamePort userProvidedAddress)
        {
            HostnamePort defaultValues = ReadDefaultConfigAddressHA(config);

            return(new HostnamePort(userProvidedAddress.Hostname.orElse(defaultValues.Host), userProvidedAddress.Port.GetValueOrDefault(defaultValues.Port)));
        }
Пример #5
0
        public override Fallible <BackupStageOutcome> PerformIncrementalBackup(DatabaseLayout databaseLayout, Config config, OptionalHostnamePort userProvidedAddress)
        {
            AdvertisedSocketAddress fromAddress = _addressResolver.resolveCorrectCCAddress(config, userProvidedAddress);

            _log.info("Resolved address for catchup protocol is " + fromAddress);
            StoreId storeId;

            try
            {
                storeId = _backupDelegator.fetchStoreId(fromAddress);
                _log.info("Remote store id is " + storeId);
            }
            catch (StoreIdDownloadFailedException e)
            {
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.WrongProtocol, e));
            }
            Optional <StoreId> expectedStoreId = ReadLocalStoreId(databaseLayout);

            if (!expectedStoreId.Present || !expectedStoreId.get().Equals(storeId))
            {
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Failure, new StoreIdDownloadFailedException(format("Remote store id was %s but local is %s", storeId, expectedStoreId))));
            }
            return(Catchup(fromAddress, storeId, databaseLayout));
        }
Пример #6
0
        public override Fallible <BackupStageOutcome> PerformFullBackup(DatabaseLayout targetDatabaseLayout, Config config, OptionalHostnamePort userProvidedAddress)
        {
            AdvertisedSocketAddress fromAddress = _addressResolver.resolveCorrectCCAddress(config, userProvidedAddress);

            _log.info("Resolved address for catchup protocol is " + fromAddress);
            StoreId storeId;

            try
            {
                storeId = _backupDelegator.fetchStoreId(fromAddress);
                _log.info("Remote store id is " + storeId);
            }
            catch (StoreIdDownloadFailedException e)
            {
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.WrongProtocol, e));
            }

            Optional <StoreId> expectedStoreId = ReadLocalStoreId(targetDatabaseLayout);

            if (expectedStoreId.Present)
            {
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Failure, new StoreIdDownloadFailedException(format("Cannot perform a full backup onto preexisting backup. Remote store id was %s but local is %s", storeId, expectedStoreId))));
            }

            try
            {
                _backupDelegator.copy(fromAddress, storeId, targetDatabaseLayout);
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Success, null));
            }
            catch (StoreCopyFailedException e)
            {
                return(new Fallible <BackupStageOutcome>(BackupStageOutcome.Failure, e));
            }
        }