【问题标题】:How to access Azure table storage secondary storage in RA-GRS using NodeJs SDK如何使用 NodeJs SDK 访问 RA-GRS 中的 Azure 表存储二级存储
【发布时间】:2021-03-05 06:11:59
【问题描述】:

更新 我尝试了以下但得到This operation can only be executed against the primary storage location. 错误:

     var azure = require('azure-storage');
const host = {
    primaryHost: `https://${primaryAccountName}.table.core.windows.net`,
    secondaryHost: `https://${primaryAccountName}-secondary.table.core.windows.net`
  };
var tableSvc = azure.createTableService(primaryAccountName, accessKey, host);

tableSvc.retrieveEntity(tableName, 'hometasks', '1', 
   { locationMode: locationMode.SECONDARY_ONLY }
    , function(error, result, response){
    if(error){
      console.log('Error on retrieveEntity!', error, result, response);
    } else {
      console.log('Entity retrieved', task.published._);
    }
  });

retrieveEntity 不是读操作吗?可以对二级存储执行哪些读取操作?

【问题讨论】:

  • 存储帐户的辅助终结点没有单独的访问密钥。您确定您使用的是正确的访问密钥吗?
  • 首先通过使用 Azure 存储资源管理器进行测试,确认所有端点和密钥都正确。
  • 我更新了问题,我需要使用 locationMode。
  • 您能否重新编辑您的问题并包括您如何创建tableSvc?
  • 我没有重新创建它,表已经创建并存在。@GauravMantri

标签: node.js azure azure-storage azure-table-storage


【解决方案1】:

请在检索实体时添加requestLocationMode 选项,它应该可以正常工作。我尝试使用以下代码:

var azure = require('azure-storage');
const primaryAccountName = 'accountname';
const accessKey = 'accountkey==';
const tableName = 'tablename';

const host = {
  primaryHost: `https://${primaryAccountName}.table.core.windows.net`,
  secondaryHost: `https://${primaryAccountName}-secondary.table.core.windows.net`
};

var tableSvc = azure.createTableService(primaryAccountName, accessKey, host);


tableSvc.retrieveEntity(tableName, '001', '002',
   { locationMode: azure.StorageUtilities.LocationMode.SECONDARY_ONLY,
      requestLocationMode: azure.StorageUtilities.LocationMode.SECONDARY_ONLY}
    , function(error, result, response){
    if (error) {
      console.log('Error on retrieveEntity!', error, result, response);
    } else {
      console.log('Entity retrieved', error, result, response);
    }
  });

这是我得到的回复(部分):

{
  isSuccessful: true,
  statusCode: 200,
  body: {
    'odata.metadata': 'https://accountname-secondary.table.core.windows.net/$metadata#tablename/@Element',
    'odata.etag': `W/"datetime'2021-03-04T06%3A36%3A14.3452027Z'"`,
    PartitionKey: '001',
    RowKey: '002',
    Timestamp: '2021-03-04T06:36:14.3452027Z',
    DataKey: '{"id":"TEST_155397_0","type":"G"}'
  }

【讨论】:

  • 谢谢,它成功了,但这是什么requestLocationMode,为什么requestLocationMode和locationMode 都应该设置?
猜你喜欢
  • 2021-04-13
  • 2018-07-19
  • 1970-01-01
  • 2022-01-18
  • 2019-05-03
  • 1970-01-01
  • 2014-08-29
  • 1970-01-01
  • 2016-12-02
相关资源
最近更新 更多