/// <summary> /// Helper function to return the RTableConfig /// Note that even if 3 (say) accounts are specified in the xml, /// the test codes can specify that only accounts #0 and #2 are used to construct the RTable. /// </summary> /// <param name="viewId"></param> /// <param name="convertXStoreTableMode"></param> /// <param name="readViewHeadIndex"></param> /// <returns></returns> private ReplicatedTableConfiguration GetRTableConfiguration(long viewId, bool convertXStoreTableMode, int readViewHeadIndex = 0) { if (viewId <= 0) { throw new Exception(string.Format("GetRTableConfigText() was called with invalid viewId {0}", viewId)); } // 1 - Create a default view var viewConfig = new ReplicatedTableConfigurationStore { ViewId = viewId, ReadViewHeadIndex = readViewHeadIndex, }; int numberOfStorageAccounts = this.rtableTestConfiguration.StorageInformation.AccountNames.Count(); for (int i = 0; i < this.actualStorageAccountsUsed.Count; i++) { int index = this.actualStorageAccountsUsed[i]; if (index < 0 || index > numberOfStorageAccounts) { throw new Exception(string.Format("this.actualStorageAccountsUsed[{0}] = {1} is out of range.", i, index)); } ReplicaInfo replica = new ReplicaInfo { StorageAccountName = this.rtableTestConfiguration.StorageInformation.AccountNames[index], Status = ReplicaStatus.ReadWrite, }; if (readViewHeadIndex != 0 && i < readViewHeadIndex) { replica.Status = ReplicaStatus.WriteOnly; } viewConfig.ReplicaChain.Add(replica); } // 2 - Create a default table config. that references the "DefaultView" var tableConfig = new ReplicatedTableConfiguredTable { TableName = DefaultTableConfigName, ViewName = DefaultViewName, ConvertToRTable = convertXStoreTableMode, UseAsDefault = true, }; // 3 - Create the final RTable configuration ReplicatedTableConfiguration configuration = new ReplicatedTableConfiguration(); configuration.SetView(DefaultViewName, viewConfig); configuration.SetTable(tableConfig); return(configuration); }
/// <summary> /// Modify the contents of the RTable configuration blob to use the updated viewId /// </summary> /// <param name="updatedViewId"></param> /// <param name="convertXStoreTableMode"></param> /// <param name="readViewHeadIndex"></param> private void ModifyConfigurationBlob(long updatedViewId, bool convertXStoreTableMode, int readViewHeadIndex, List <int> blobIndexes) { try { List <ReplicatedTableConfiguration> configurations; List <ReplicatedTableReadBlobResult> result = this.configurationService.RetrieveConfiguration(out configurations); foreach (var blobIndex in blobIndexes) { if (blobIndex >= result.Count) { var msg = string.Format("BlobIndex={0} >= ResultCount={1}", blobIndex, result.Count); throw new Exception(msg); } if (result[blobIndex].Code != ReadBlobCode.Success) { throw new Exception(result.ToString()); } string currentConfigText = configurations[blobIndex].ToJson(); Console.WriteLine("Blob#{0}:\nCurrentConfigText = {1}", blobIndex, currentConfigText); } ReplicatedTableConfiguration newConfig = this.GetRTableConfiguration(updatedViewId, convertXStoreTableMode, readViewHeadIndex); string updatedConfigText = newConfig.ToJson(); Console.WriteLine("\nModifying blobs:\nUpdatedConfigText = {0}", updatedConfigText); ReplicatedTableQuorumWriteResult writeResult = this.configurationService.UploadConfigurationToBlobs(blobIndexes, newConfig); if (writeResult.Code != ReplicatedTableQuorumWriteCode.Success) { throw new Exception(writeResult.ToString()); } } catch (Exception ex) { Console.WriteLine("ModifyConfigurationBlob() encountered exception {0}", ex.ToString()); throw; } }
/// <summary> /// Create the contents of the RTable configuration, and upload it to the appropriate container and blob. /// </summary> private void UploadRTableConfigToBlob(int viewId, bool convertXStoreTableMode, int numberOfBlobs) { // upload the RTable config Console.WriteLine("Uploading RTable config ..."); for (int blobIndex = 0; blobIndex < numberOfBlobs; blobIndex++) { string connectionString; CloudBlobClient cloudBloblClient = this.GenerateCloudBlobClient( this.rtableTestConfiguration.StorageInformation.AccountNames[blobIndex], this.rtableTestConfiguration.StorageInformation.AccountKeys[blobIndex], this.rtableTestConfiguration.StorageInformation.DomainName, out connectionString); CloudBlobContainer container = cloudBloblClient.GetContainerReference(this.rtableTestConfiguration.RTableInformation.ContainerName); container.CreateIfNotExists(); } ReplicatedTableConfiguration rtableConfig = this.GetRTableConfiguration(viewId, convertXStoreTableMode); this.configurationService.UpdateConfiguration(rtableConfig, false); }
protected void UpdateConfiguration(List <ReplicaInfo> replicaChain, int readViewHeadIndex, bool convertXStoreTableMode = false, long viewId = 0) { for (int i = 0; i < replicaChain.Count; i++) { replicaChain[i].Status = ReplicaStatus.ReadWrite; if (readViewHeadIndex != 0 && i < readViewHeadIndex) { replicaChain[i].Status = ReplicaStatus.WriteOnly; } } // - view config var viewConfig = new ReplicatedTableConfigurationStore { ViewId = viewId, ReadViewHeadIndex = readViewHeadIndex, ReplicaChain = replicaChain, }; // - table config var tableConfig = new ReplicatedTableConfiguredTable { TableName = DefaultTableConfigName, ViewName = DefaultViewName, ConvertToRTable = convertXStoreTableMode, UseAsDefault = true, }; // - Update RTable configuration ReplicatedTableConfiguration configuration = new ReplicatedTableConfiguration(); configuration.SetView(DefaultViewName, viewConfig); configuration.SetTable(tableConfig); this.configurationService.UpdateConfiguration(configuration, false); }