public AppLeaseManager( AzureStorageClient azureStorageClient, IPartitionManager partitionManager, string appLeaseContainerName, string appLeaseInfoBlobName, AppLeaseOptions options) { this.azureStorageClient = azureStorageClient; this.partitionManager = partitionManager; this.appLeaseContainerName = appLeaseContainerName; this.appLeaseInfoBlobName = appLeaseInfoBlobName; this.options = options; this.storageAccountName = this.azureStorageClient.BlobAccountName; this.settings = this.azureStorageClient.Settings; this.taskHub = settings.TaskHubName; this.workerName = settings.WorkerId; this.appName = settings.AppName; this.appLeaseIsEnabled = this.settings.UseAppLease; this.appLeaseContainer = this.azureStorageClient.GetBlobContainerReference(this.appLeaseContainerName); this.appLeaseInfoBlob = this.appLeaseContainer.GetBlobReference(this.appLeaseInfoBlobName); var appNameHashInBytes = BitConverter.GetBytes(Fnv1aHashHelper.ComputeHash(this.appName)); Array.Resize(ref appNameHashInBytes, 16); this.appLeaseId = new Guid(appNameHashInBytes).ToString(); this.isLeaseOwner = false; this.shutdownCompletedEvent = new AsyncManualResetEvent(); }
public static string GetForwardFrontEnd(string runtimeSiteName, HttpScaleEnvironment environment) { if (environment.DynamicComputeHttpScaleMaxFrontEndsPerSite <= 0) { throw new ArgumentOutOfRangeException("DynamicComputeHttpScaleMaxFrontEndsPerSite must be greater than 0"); } // each FE handles scale independently if (environment.DynamicComputeHttpScaleMaxFrontEndsPerSite > 2) { return(environment.CurrentFrontEnd); } // this is degenerated case where no FE is alive, all FE should handle var frontEnds = environment.FrontEnds; if (frontEnds.Count == 0) { return(environment.CurrentFrontEnd); } // if only one FE is alive, it should handle if (frontEnds.Count == 1) { return(frontEnds[0]); } var currentBucket = (int)(Fnv1aHashHelper.ComputeHash(runtimeSiteName) % frontEnds.Count); // if only forward to 1 frontend if (environment.DynamicComputeHttpScaleMaxFrontEndsPerSite == 1) { return(frontEnds[currentBucket]); } // forwarding to 2 frontends at most var forwardFrontEnds = new List <string>(2); forwardFrontEnds.Add(frontEnds[currentBucket]); forwardFrontEnds.Add(frontEnds[(currentBucket + 1) % frontEnds.Count]); if (forwardFrontEnds.Any(n => n == environment.CurrentFrontEnd)) { return(environment.CurrentFrontEnd); } var random = new Random(); return(forwardFrontEnds[random.Next() % forwardFrontEnds.Count]); }