Ejemplo n.º 1
0
        private void UpdatePeriodicBackup(long taskId,
                                          PeriodicBackupConfiguration newConfiguration,
                                          TaskStatus taskState)
        {
            Debug.Assert(taskId == newConfiguration.TaskId);

            var backupStatus = GetBackupStatus(taskId, inMemoryBackupStatus: null);

            if (_periodicBackups.TryGetValue(taskId, out var existingBackupState) == false)
            {
                var newPeriodicBackup = new PeriodicBackup(_inactiveRunningPeriodicBackupsTasks)
                {
                    Configuration = newConfiguration
                };

                var periodicBackup = _periodicBackups.GetOrAdd(taskId, newPeriodicBackup);
                if (periodicBackup != newPeriodicBackup)
                {
                    newPeriodicBackup.Dispose();
                }

                if (taskState == TaskStatus.ActiveByCurrentNode)
                {
                    periodicBackup.UpdateTimer(GetTimer(newConfiguration, backupStatus));
                }

                return;
            }

            var previousConfiguration = existingBackupState.Configuration;

            existingBackupState.Configuration = newConfiguration;

            if (taskState != TaskStatus.ActiveByCurrentNode)
            {
                // this node isn't responsible for the backup task
                existingBackupState.DisableFutureBackups();
                return;
            }

            if (existingBackupState.RunningTask != null)
            {
                // a backup is already running
                // the next one will be re-scheduled by the backup task
                return;
            }

            if (previousConfiguration.HasBackupFrequencyChanged(newConfiguration) == false &&
                existingBackupState.HasScheduledBackup())
            {
                // backup frequency hasn't changed
                // and we have a scheduled backup
                return;
            }

            existingBackupState.UpdateTimer(GetTimer(newConfiguration, backupStatus));
        }
Ejemplo n.º 2
0
        private void UpdatePeriodicBackup(long taskId,
                                          PeriodicBackupConfiguration newConfiguration,
                                          TaskStatus taskState)
        {
            Debug.Assert(taskId == newConfiguration.TaskId);

            var backupStatus = GetBackupStatus(taskId, inMemoryBackupStatus: null);

            if (_periodicBackups.TryGetValue(taskId, out var existingBackupState) == false)
            {
                var newPeriodicBackup = new PeriodicBackup(_inactiveRunningPeriodicBackupsTasks)
                {
                    Configuration = newConfiguration
                };

                var periodicBackup = _periodicBackups.GetOrAdd(taskId, newPeriodicBackup);
                if (periodicBackup != newPeriodicBackup)
                {
                    newPeriodicBackup.Dispose();
                }

                if (taskState == TaskStatus.ActiveByCurrentNode)
                {
                    periodicBackup.UpdateTimer(GetTimer(newConfiguration, backupStatus));
                }

                return;
            }

            var previousConfiguration = existingBackupState.Configuration;

            existingBackupState.Configuration = newConfiguration;

            switch (taskState)
            {
            case TaskStatus.Disabled:
            case TaskStatus.ActiveByOtherNode:
                // the task is disabled or this node isn't responsible for the backup task
                existingBackupState.DisableFutureBackups();
                return;

            case TaskStatus.ClusterDown:
                // this node cannot connect to cluster, the task will continue on this node
                return;

            case TaskStatus.ActiveByCurrentNode:
                // a backup is already running, the next one will be re-scheduled by the backup task if needed
                if (existingBackupState.RunningTask != null)
                {
                    return;
                }

                // backup frequency hasn't changed, and we have a scheduled backup
                if (previousConfiguration.HasBackupFrequencyChanged(newConfiguration) == false && existingBackupState.HasScheduledBackup())
                {
                    return;
                }

                existingBackupState.UpdateTimer(GetTimer(newConfiguration, backupStatus));
                return;

            default:
                throw new ArgumentOutOfRangeException(nameof(taskState), taskState, null);
            }
        }