Exemplo n.º 1
0
        internal static async Task <BackupPolicyStore> CreateOrGetBackupPolicyStore(StatefulService statefulService)
        {
            if (_store == null)
            {
                BackupRestoreTrace.TraceSource.WriteNoise(TraceBackupPolicStoreType, "Creating a Backup Policy Store");
                var reliableDictionary = await statefulService.StateManager.GetOrAddAsync <IReliableDictionary <string, BackupPolicy> >(BackupPolicyStoreName);

                _store = new BackupPolicyStore(reliableDictionary, statefulService);
                BackupRestoreTrace.TraceSource.WriteNoise(TraceBackupPolicStoreType, "Created a Backup Policy Store successfully");
            }
            return(_store);
        }
        private async Task <Tuple <BackupMapping, BackupPolicy> > GetEffectiveBackupPartitionAndPolicyForPartition(
            StatefulService statefulService, TimeSpan timeout, CancellationToken cancellationToken, string processQueueTypeTrace)
        {
            BackupPolicy backupPolicy       = null;
            var          backupMappingStore = await BackupMappingStore.CreateOrGetBackupMappingStore(statefulService);

            var backupPolicyStore = await BackupPolicyStore.CreateOrGetBackupPolicyStore(statefulService);

            var backupMappingKey = UtilityHelper.GetBackupMappingKey(this.ServiceUri, this.PartitionId);

            var backupMapping = (await backupMappingStore.GetValueAsync(backupMappingKey, timeout, cancellationToken) ??
                                 await backupMappingStore.GetValueAsync(this.ServiceUri, timeout, cancellationToken)) ??
                                await backupMappingStore.GetValueAsync(UtilityHelper.GetApplicationNameFromService(this.ServiceUri), timeout, cancellationToken);

            if (backupMapping != null)
            {
                backupPolicy = await backupPolicyStore.GetValueAsync(backupMapping.BackupPolicyName, timeout, cancellationToken);
            }

            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace,
                                                     "GetEffectiveBackupPartitionAndPolicyForPartition resulted as BackupMapping {0} ,BackupPolicy {1} ", backupMapping, backupPolicy);

            return(Tuple.Create(backupMapping, backupPolicy));
        }