Azure表服务 - 从辅助表读取

时间:2016-11-10 15:09:37

标签: azure azure-table-storage

我在Azure存储表服务上启用了RA-GRS复制。即使没有故障转移,是否有从辅助读取的选项。除了在帐户名中添加-secondary之外,还需要在连接字符串中进行哪些更改?

2 个答案:

答案 0 :(得分:2)

读取访问地理冗余存储(RA-GRS)确实允许您在没有故障转移事件的情况下从辅助端点进行读取。为此,您需要将secondary附加到连接字符串中的帐户名称。它应该看起来像youraccount-secondary.table.core.windows.net

答案 1 :(得分:0)

如果您正在使用.Net SDK,则无需手动将-secondary附加到帐户名称。要连接到辅助端点,您可以使用TableRequestOptions.LocationMode属性,该属性将自动连接到辅助端点。

看看下面的代码示例。它列出了辅助位置的存储帐户中的表格:

    static void ConnectToSecondary()
    {
        var cred = new StorageCredentials(accountName, accountKey);
        var account = new CloudStorageAccount(cred, true);
        var client = account.CreateCloudTableClient();
        var requestOptions = new TableRequestOptions()
        {
            LocationMode = Microsoft.WindowsAzure.Storage.RetryPolicies.LocationMode.SecondaryOnly
        };
        var tables = client.ListTables(null, requestOptions);
        foreach (var table in tables)
        {
            Console.WriteLine(table.Uri.AbsoluteUri);
        }
    }

这里是fiddler的输出:

GET https://account-secondary.table.core.windows.net/Tables HTTP/1.1
User-Agent: Azure-Storage/7.0.0 (.NET CLR 4.0.30319.42000; Win32NT 6.2.9200.0)
x-ms-version: 2015-07-08
Accept-Charset: UTF-8
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
x-ms-client-request-id: 0f123ca9-1f35-4e46-9590-ebca0912baa8
x-ms-date: Fri, 11 Nov 2016 10:59:14 GMT
Authorization: SharedKey account:sEsvrm3W0Tn7QhkHqHDrS5o2IvldI4NVUL4U276JudQ=
Host: account-secondary.table.core.windows.net
Connection: Keep-Alive