保护模拟运算表并使其不受应用错误的影响
2010-06-21 00:00:00 来源:WEB开发网BackupTables是登录备份进程的方法。客户可以为每个表格提供一个TableKeyInfo。例如,如果拆分密钥是GUID,下面是如何援引BackupTables方法:
CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint.AbsoluteUri, account.Credentials);
CloudBlobClient blobClient = new CloudBlobClient(account.BlobEndpoint.AbsoluteUri, account.Credentials);
// The more keys listed here, the better for scale
string[] rangeQueries = new string[] { "3", "8", "a", "f" };
string[] tableNames = new string[] { "Customers", "Orders" };
List<TableKeysInfo> keyInfo = new List<TableKeysInfo>();
foreach(string tableName in tableNames)
{
keyInfo.Add( new TableKeysInfo(tableName, rangeQueries));
}
BackupTables(tableClient, blobClient, keyInfo);
BackupTables现在已经完成每个表格以及表格中每个排列范围的迭代,它援引了BackupTableRange,而 BackupTableRange负责将指定排列范围的结果集保存到Blob中。简单地说,此示例按顺序完成上述操作,以加快从Blob中恢复实体数据的进程,就需要将下面的内容并入操作之中。
/// <summary>
/// Backup each table to blobs. Each table will be stored under a container with same name as the table.
/// </summary>
/// <param name="tableClient"></param>
/// <param name="blobClient"></param>
/// <param name="tablesToBackup">
/// The tablesToBackup will contain the table name to a list of keys that will be used to partition the query
/// </param>
public static void BackupTables(CloudTableClient tableClient,
CloudBlobClient blobClient, List<TableKeysInfo> tablesToBackup)
{
if (tableClient == null)
{
throw new ArgumentNullException("tableClient");
}
try
{
// we will use this id as the folder name. The blobs will be stored under:
// <lower cased table name>/<backupid>/
string backupId = DateTime.UtcNow.ToString("yy-MM-dd-HH-mm-ss");
// list each range in each table and backup up each range
foreach (TableKeysInfo tableKeysInfo in tablesToBackup)
{
CloudBlobContainer container = blobClient.GetContainerReference(tableKeysInfo.TableName.ToLower());
container.CreateIfNotExist();
foreach (PartitionKeyRange range in tableKeysInfo.KeyRangeList)
{
BackupTableRange(tableClient, container, tableKeysInfo.TableName, range, backupId);
}
}
}
catch (Exception e)
{
// TODO: log exception for debugging purpose and then rethrow
throw;
}
}
更多精彩
赞助商链接