Example #1
0
        public void WaitForPeriodicExport(DocumentDatabase db, PeriodicExportStatus previousStatus, Func <PeriodicExportStatus, Etag> compareSelector)
        {
            PeriodicExportStatus currentStatus = null;
            var done = SpinWait.SpinUntil(() =>
            {
                currentStatus = GetPerodicBackupStatus(db);
                return(compareSelector(currentStatus) != compareSelector(previousStatus));
            }, Debugger.IsAttached ? TimeSpan.FromMinutes(120) : TimeSpan.FromMinutes(15));

            Assert.True(done);
            previousStatus.LastDocsEtag               = currentStatus.LastDocsEtag;
            previousStatus.LastAttachmentsEtag        = currentStatus.LastAttachmentsEtag;
            previousStatus.LastDocsDeletionEtag       = currentStatus.LastDocsDeletionEtag;
            previousStatus.LastAttachmentDeletionEtag = currentStatus.LastAttachmentDeletionEtag;
        }
Example #2
0
        private void WaitForPeriodicExport(Func <string, JsonDocument> getDocument, PeriodicExportStatus previousStatus)
        {
            PeriodicExportStatus currentStatus = null;
            var done = SpinWait.SpinUntil(() =>
            {
                currentStatus = GetPerodicBackupStatus(getDocument);
                return(currentStatus.LastDocsEtag != previousStatus.LastDocsEtag ||
                       currentStatus.LastAttachmentsEtag != previousStatus.LastAttachmentsEtag ||
                       currentStatus.LastDocsDeletionEtag != previousStatus.LastDocsDeletionEtag ||
                       currentStatus.LastAttachmentDeletionEtag != previousStatus.LastAttachmentDeletionEtag);
            }, Debugger.IsAttached ? TimeSpan.FromMinutes(120) : TimeSpan.FromMinutes(15));

            Assert.True(done);
            previousStatus.LastDocsEtag               = currentStatus.LastDocsEtag;
            previousStatus.LastAttachmentsEtag        = currentStatus.LastAttachmentsEtag;
            previousStatus.LastDocsDeletionEtag       = currentStatus.LastDocsDeletionEtag;
            previousStatus.LastAttachmentDeletionEtag = currentStatus.LastAttachmentDeletionEtag;
        }
Example #3
0
 protected void WaitForPeriodicExport(IDatabaseCommands commands, PeriodicExportStatus previousStatus)
 {
     WaitForPeriodicExport(commands.Get, previousStatus);
 }
Example #4
0
 protected void WaitForPeriodicExport(DocumentDatabase db, PeriodicExportStatus previousStatus)
 {
     WaitForPeriodicExport(key => db.Documents.Get(key, null), previousStatus);
 }
Example #5
0
        private void ReadSetupValuesFromDocument()
        {
            using (LogContext.WithDatabase(Database.Name))
            {
                try
                {
                    // Not having a setup doc means this DB isn't enabled for periodic exports
                    var document = Database.Documents.Get(PeriodicExportSetup.RavenDocumentKey, null);
                    if (document == null)
                    {
                        exportConfigs = null;
                        exportStatus  = null;
                        return;
                    }

                    var status = Database.Documents.Get(PeriodicExportStatus.RavenDocumentKey, null);

                    exportStatus  = status == null ? new PeriodicExportStatus() : status.DataAsJson.JsonDeserialization <PeriodicExportStatus>();
                    exportConfigs = document.DataAsJson.JsonDeserialization <PeriodicExportSetup>();


                    awsAccessKey        = Database.Configuration.Settings["Raven/AWSAccessKey"];
                    awsSecretKey        = Database.Configuration.Settings["Raven/AWSSecretKey"];
                    azureStorageAccount = Database.Configuration.Settings["Raven/AzureStorageAccount"];
                    azureStorageKey     = Database.Configuration.Settings["Raven/AzureStorageKey"];

                    if (exportConfigs.IntervalMilliseconds > 0)
                    {
                        var interval = TimeSpan.FromMilliseconds(exportConfigs.IntervalMilliseconds);
                        logger.Info("Incremental periodic export started, will export every" + interval.TotalMinutes + "minutes");

                        var timeSinceLastBackup = SystemTime.UtcNow - exportStatus.LastBackup;
                        var nextBackup          = timeSinceLastBackup >= interval ? TimeSpan.Zero : interval - timeSinceLastBackup;
                        incrementalBackupTimer = new Timer(state => TimerCallback(false), null, nextBackup, interval);
                    }
                    else
                    {
                        logger.Warn("Incremental periodic export interval is set to zero or less, incremental periodic export is now disabled");
                    }

                    if (exportConfigs.FullBackupIntervalMilliseconds > 0)
                    {
                        var interval = TimeSpan.FromMilliseconds(exportConfigs.FullBackupIntervalMilliseconds);
                        logger.Info("Full periodic export started, will export every" + interval.TotalMinutes + "minutes");

                        var timeSinceLastBackup = SystemTime.UtcNow - exportStatus.LastFullBackup;
                        var nextBackup          = timeSinceLastBackup >= interval ? TimeSpan.Zero : interval - timeSinceLastBackup;
                        fullBackupTimer = new Timer(state => TimerCallback(true), null, nextBackup, interval);
                    }
                    else
                    {
                        logger.Warn("Full periodic export interval is set to zero or less, full periodic export is now disabled");
                    }
                }
                catch (Exception ex)
                {
                    logger.ErrorException("Could not read periodic export config", ex);
                    Database.AddAlert(new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt  = SystemTime.UtcNow,
                        Message    = ex.Message,
                        Title      = "Could not read periodic export config",
                        Exception  = ex.ToString(),
                        UniqueKey  = "Periodic Export Config Error"
                    });
                }
            }
        }
Example #6
0
        private void ReadSetupValuesFromDocument()
        {
            using (LogContext.WithResource(Database.Name))
            {
                try
                {
                    // Not having a setup doc means this DB isn't enabled for periodic exports
                    var configurationDocument = Database.ConfigurationRetriever.GetConfigurationDocument <PeriodicExportSetup>(PeriodicExportSetup.RavenDocumentKey);
                    if (configurationDocument == null)
                    {
                        exportConfigs = null;
                        exportStatus  = null;
                        return;
                    }

                    exportStatus  = GetExportStatus();
                    exportConfigs = configurationDocument.MergedDocument;

                    if (exportConfigs.Disabled)
                    {
                        logger.Info("Periodic export is disabled.");
                        return;
                    }

                    awsAccessKey        = Database.ConfigurationRetriever.GetEffectiveConfigurationSetting(Constants.PeriodicExport.AwsAccessKey);
                    awsSecretKey        = Database.ConfigurationRetriever.GetEffectiveConfigurationSetting(Constants.PeriodicExport.AwsSecretKey);
                    azureStorageAccount = Database.ConfigurationRetriever.GetEffectiveConfigurationSetting(Constants.PeriodicExport.AzureStorageAccount);
                    azureStorageKey     = Database.ConfigurationRetriever.GetEffectiveConfigurationSetting(Constants.PeriodicExport.AzureStorageKey);

                    if (exportConfigs.IntervalMilliseconds.GetValueOrDefault() > 0)
                    {
                        IncrementalInterval             = TimeSpan.FromMilliseconds(exportConfigs.IntervalMilliseconds.GetValueOrDefault());
                        incrementalIntermediateInterval = TimeSpan.FromMilliseconds(IncrementalInterval.TotalMilliseconds);

                        logger.Info("Incremental periodic export started, will export every" + IncrementalInterval.TotalMinutes + "minutes");

                        if (IsValidTimespanForTimer(IncrementalInterval))
                        {
                            var timeSinceLastBackup = SystemTime.UtcNow - exportStatus.LastBackup;
                            var nextBackup          = timeSinceLastBackup >= IncrementalInterval ? TimeSpan.Zero : IncrementalInterval - timeSinceLastBackup;

                            incrementalBackupTimer = Database.TimerManager.NewTimer(state => TimerCallback(false), nextBackup, IncrementalInterval);
                        }
                        else
                        {
                            incrementalBackupTimer = Database.TimerManager.NewTimer(state => LongPeriodTimerCallback(false),
                                                                                    TimeSpan.FromMilliseconds(maxTimerTimeoutInMilliseconds), Timeout.InfiniteTimeSpan);
                        }
                    }
                    else
                    {
                        logger.Warn("Incremental periodic export interval is set to zero or less, incremental periodic export is now disabled");
                    }

                    if (exportConfigs.FullBackupIntervalMilliseconds.GetValueOrDefault() > 0)
                    {
                        FullBackupInterval             = TimeSpan.FromMilliseconds(exportConfigs.FullBackupIntervalMilliseconds.GetValueOrDefault());
                        fullBackupIntermediateInterval = TimeSpan.FromMilliseconds(FullBackupInterval.TotalMilliseconds);

                        logger.Info("Full periodic export started, will export every" + FullBackupInterval.TotalMinutes + "minutes");

                        if (IsValidTimespanForTimer(FullBackupInterval))
                        {
                            var timeSinceLastBackup = SystemTime.UtcNow - exportStatus.LastFullBackup;
                            var nextBackup          = timeSinceLastBackup >= FullBackupInterval ? TimeSpan.Zero : FullBackupInterval - timeSinceLastBackup;

                            fullBackupTimer = Database.TimerManager.NewTimer(state => TimerCallback(true), nextBackup, FullBackupInterval);
                        }
                        else
                        {
                            fullBackupTimer = Database.TimerManager.NewTimer(state => LongPeriodTimerCallback(true),
                                                                             TimeSpan.FromMilliseconds(maxTimerTimeoutInMilliseconds), Timeout.InfiniteTimeSpan);
                        }
                    }
                    else
                    {
                        logger.Warn("Full periodic export interval is set to zero or less, full periodic export is now disabled");
                    }
                }
                catch (Exception ex)
                {
                    logger.ErrorException("Could not read periodic export config", ex);
                    Database.AddAlert(new Alert
                    {
                        AlertLevel = AlertLevel.Error,
                        CreatedAt  = SystemTime.UtcNow,
                        Message    = ex.Message,
                        Title      = "Could not read periodic export config",
                        Exception  = ex.ToString(),
                        UniqueKey  = "Periodic Export Config Error"
                    });
                }
            }
        }