/// <summary> /// Starts a new configuration epoch. /// </summary> /// <param name="updateConfiguration">If true, the configuration is also uploaded to the azure storage.</param> /// <returns></returns> internal void StartNewEpoch(bool uploadConfiguration) { using (CloudBlobLease lease = new CloudBlobLease(GetConfigurationContainer().GetBlockBlobReference(ConstPool.CURRENT_CONFIGURATION_BLOB_NAME), LeaseTakingPolicy.TryUntilSuccessful)) { if (lease.HasLease) { if (uploadConfiguration) { UploadConfiguration(lease.getAccessConditionWithLeaseId().LeaseId); } try { CloudBlobContainer configurationContainer = GetConfigurationContainer(); ICloudBlob blob = configurationContainer.GetBlockBlobReference(ConstPool.CURRENT_CONFIGURATION_BLOB_NAME); int newEpoch = ++this.Epoch; blob.Metadata[ConstPool.EPOCH_NUMBER] = "" + newEpoch; blob.Metadata[ConstPool.EPOCH_MODIFIED_TIME] = DateTimeOffset.Now.ToString(); blob.SetMetadata(lease.getAccessConditionWithLeaseId()); Console.WriteLine("Epoch " + Epoch + " written to the azure and started."); } catch (StorageException ex) { Console.WriteLine(ex.ToString()); throw ex; } } } SyncPrimaryServersWithSessionState(); SyncSecondaryServersWithSessionState(); }
/// <summary> /// By writing an empty string in metadata[EPOCH_NUMBER] of the configuration blob, all clients will eventually read it, and enter the slow mode. /// </summary> internal void EndCurrentEpoch() { try { using (CloudBlobLease lease = new CloudBlobLease(GetConfigurationContainer().GetBlockBlobReference(ConstPool.CURRENT_CONFIGURATION_BLOB_NAME), LeaseTakingPolicy.TryUntilSuccessful)) { ICloudBlob blob = GetConfigurationContainer().GetBlockBlobReference(ConstPool.CURRENT_CONFIGURATION_BLOB_NAME); blob.Metadata[ConstPool.EPOCH_NUMBER] = ConstPool.RECONFIGURATION_IN_PROGRESS; blob.SetMetadata(lease.getAccessConditionWithLeaseId()); } Thread.Sleep(ConstPool.CACHED_CONFIGURATION_VALIDITY_DURATION); } catch (StorageException ex) { Console.WriteLine(ex.ToString()); throw ex; } }