static AzureTableDefaultPolicies() { MaxTableCreationRetries = 60; PauseBetweenTableCreationRetries = TimeSpan.FromSeconds(1); MaxTableOperationRetries = 5; PauseBetweenTableOperationRetries = TimeSpan.FromMilliseconds(100); MaxBusyRetries = 120; PauseBetweenBusyRetries = TimeSpan.FromMilliseconds(500); #if DEBUG if (Debugger.IsAttached) { PauseBetweenTableCreationRetries = PauseBetweenTableCreationRetries.Multiply(100); PauseBetweenTableOperationRetries = PauseBetweenTableOperationRetries.Multiply(100); PauseBetweenBusyRetries = PauseBetweenBusyRetries.Multiply(10); } #endif TableCreationRetryPolicy = new LinearRetry(PauseBetweenTableCreationRetries, MaxTableCreationRetries); // 60 x 1s TableCreationTimeout = PauseBetweenTableCreationRetries.Multiply(MaxTableCreationRetries).Multiply(3); // 3 min TableOperationRetryPolicy = new LinearRetry(PauseBetweenTableOperationRetries, MaxTableOperationRetries); // 5 x 100ms TableOperationTimeout = PauseBetweenTableOperationRetries.Multiply(MaxTableOperationRetries).Multiply(6); // 3 sec BusyRetriesTimeout = PauseBetweenBusyRetries.Multiply(MaxBusyRetries); // 1 minute }
/// <summary> /// Constructor /// </summary> public BlobHelper() { this._account = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["DataConnectionString"].ConnectionString); this._blobClient = _account.CreateCloudBlobClient(); LinearRetry linearRetry = new LinearRetry(TimeSpan.FromMilliseconds(500), 3); this._blobClient.RetryPolicy = linearRetry; }
// Constructor - pass in a storage connection string. public BlobHelper(string connectionString) { Account = CloudStorageAccount.Parse(connectionString); BlobClient = Account.CreateCloudBlobClient(); IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.Zero, 4); BlobClient.RetryPolicy = linearRetryPolicy; }
public QueueHelper(string connection, string queueName) { var account = CloudStorageAccount.Parse(connection); var retry = new LinearRetry(TimeSpan.FromSeconds(1), 3); queueClient = account.CreateCloudQueueClient(); queueClient.RetryPolicy = retry; queue = queueClient.GetQueueReference(queueName); queue.CreateIfNotExists(); }
// Constructor - get settings from a hosted service configuration or .NET configuration file. public BlobHelper(string configurationSettingName, bool hostedService) { if (hostedService) { var connectionString = RoleEnvironment.GetConfigurationSettingValue(configurationSettingName); Account = CloudStorageAccount.Parse(connectionString); } else { var connectionString = ConfigurationManager.ConnectionStrings[configurationSettingName].ConnectionString; Account = CloudStorageAccount.Parse(connectionString); } BlobClient = Account.CreateCloudBlobClient(); IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.Zero, 4); BlobClient.RetryPolicy = linearRetryPolicy; }
public static CloudBlobClient GetCloudBlobClient() { if (BlobClient == null) { if (IsDevUrl()) { CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; BlobClient = storageAccount.CreateCloudBlobClient(); } else { var accountName = ConfigHelper.AzureAccountName; string accountKey = ConfigHelper.AzureAccountKey; var credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accountKey); CloudStorageAccount azureStorageAccount = new CloudStorageAccount(credentials, true); BlobClient = azureStorageAccount.CreateCloudBlobClient(); // retry policy. // could do with a little work. IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(ConfigHelper.RetryAttemptDelayInSeconds), ConfigHelper.MaxRetryAttempts); BlobClient.RetryPolicy = linearRetryPolicy; } } return BlobClient; }
/// <summary> /// Replicates a blob from the current storage account /// to a target storage account /// </summary> /// <param name="targetConnectionString">Connection string of the target storage account</param> /// <param name="sourceContainerName">The source container</param> /// <param name="targetContainerName">The target container</param> /// <param name="blobName">The blob to replicate</param> /// <param name="log">TextWriter used for logging</param> /// <returns>The target CloudBlobContainer, used for checking status</returns> public async Task<CloudBlobContainer> ReplicateBlobAsync( string targetConnectionString, string sourceContainerName, string targetContainerName, string blobName, TextWriter log) { var taskId = string.Empty; //Create a connection to where the blob currently lives CloudBlobClient sourceBlobClient = _account.CreateCloudBlobClient(); //Create remote client var targetAccount = CloudStorageAccount.Parse( targetConnectionString); CloudBlobClient targetBlobClient = targetAccount.CreateCloudBlobClient(); var sourceContainer = sourceBlobClient.GetContainerReference(sourceContainerName); var targetContainer = targetBlobClient.GetContainerReference(targetContainerName); //Can be uncommented and used during debugging // to avoid deploying the entire app to two regions //bool created = await targetContainer.CreateIfNotExistsAsync(); //if (created) //{ // var perms = await sourceContainer.GetPermissionsAsync(); // await targetContainer.SetPermissionsAsync(perms); //} CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(blobName); //Must use a shared access signature when copying across accounts // else the target cannot read from source and you will get a 404 // Subtract 1 hour and add 1 hour to account for time drift between // servers string signature = sourceBlob.GetSharedAccessSignature( new SharedAccessBlobPolicy { Permissions = SharedAccessBlobPermissions.Read, SharedAccessStartTime = System.DateTime.Now.AddHours(-1), SharedAccessExpiryTime = System.DateTime.Now.AddHours(1) }); var sourceUri = new Uri(sourceBlob.Uri.AbsoluteUri + signature); CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(blobName); try { //Set a retry policy to try again in 10 seconds, 3 max attempts. var retryPolicy = new LinearRetry(new TimeSpan(0, 0, 10), 3); var options = new BlobRequestOptions { RetryPolicy = retryPolicy }; //The StartCopy method uses spare bandwidth, there is //no SLA on how fast this will be copied. taskId = targetBlob.StartCopy(sourceUri, options: options); } catch (Exception oops) { await log.WriteLineAsync(oops.Message); } return targetContainer; }
public void VerifyBackoffTimeOverflow() { ExponentialRetry exponentialRetry = new ExponentialRetry(TimeSpan.FromSeconds(4), 100000); VerifyBackoffTimeOverflow(exponentialRetry, 100000); LinearRetry linearRetry = new LinearRetry(TimeSpan.FromSeconds(4), 100000); VerifyBackoffTimeOverflow(linearRetry, 100000); }
public void VerifyLinearRetryBackOffTime() { OperationContext opContext = new OperationContext(); TimeSpan retryInterval; IRetryPolicy retryPolicy = new LinearRetry(TimeSpan.FromSeconds(10), 4); Assert.IsTrue(retryPolicy.ShouldRetry(0, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval); Assert.IsTrue(retryPolicy.ShouldRetry(1, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval); Assert.IsTrue(retryPolicy.ShouldRetry(2, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval); Assert.IsTrue(retryPolicy.ShouldRetry(3, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval); Assert.IsFalse(retryPolicy.ShouldRetry(4, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval); retryPolicy = new LinearRetry(); Assert.IsTrue(retryPolicy.ShouldRetry(0, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval); Assert.IsTrue(retryPolicy.ShouldRetry(1, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval); Assert.IsTrue(retryPolicy.ShouldRetry(2, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval); Assert.IsFalse(retryPolicy.ShouldRetry(3, 503, new Exception(), out retryInterval, opContext)); Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval); }
public static CloudBlobClient GetCloudBlobClient(string url, bool isSrc, string accountKey = null) { CloudBlobClient blobClient = null; if (isSrc) { blobClient = SrcBlobClient; } else { blobClient = TargetBlobClient; } if (blobClient == null) { var accountName = GetAccountNameFromUrl(url); if (string.IsNullOrWhiteSpace(accountKey)) { if (isSrc) { accountKey = ConfigHelper.SrcAzureAccountKey; } else { accountKey = ConfigHelper.TargetAzureAccountKey; } } var storageAccount = GetCloudStorageAccount(url, accountKey, accountName); blobClient = storageAccount.CreateCloudBlobClient(); // retry policy. // could do with a little work. IRetryPolicy linearRetryPolicy = new LinearRetry( TimeSpan.FromSeconds( ConfigHelper.RetryAttemptDelayInSeconds), ConfigHelper.MaxRetryAttempts); blobClient.RetryPolicy = linearRetryPolicy; } return blobClient; }
public static CloudBlobClient GetCloudBlobClient(string accountName, string accountKey) { var storageAccount = GetCloudStorageAccount( accountKey, accountName); var blobClient = storageAccount.CreateCloudBlobClient(); // retry policy. // could do with a little work. IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(ConfigHelper.RetryAttemptDelayInSeconds), ConfigHelper.MaxRetryAttempts); blobClient.RetryPolicy = linearRetryPolicy; return blobClient; }
public static CloudBlobClient GetCloudBlobClient(string accName, string accKey, bool isDev=false) { accountName = accName; accountKey = accKey; if (BlobClient == null) { if (isDev) { CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; BlobClient = storageAccount.CreateCloudBlobClient(); } else { var credentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accountKey); CloudStorageAccount azureStorageAccount = new CloudStorageAccount(credentials, true); BlobClient = azureStorageAccount.CreateCloudBlobClient(); // retry policy. // could do with a little work. IRetryPolicy linearRetryPolicy = new LinearRetry( TimeSpan.FromSeconds( 5), 10); BlobClient.RetryPolicy = linearRetryPolicy; } } return BlobClient; }