如何使用 NodeJs SDK 访问 RA-GRS 中的 Azure table 存储二级存储

How to access Azure table storage secondary storage in RA-GRS using NodeJs SDK

已更新 我尝试了以下但得到 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不是读操作吗?可以对辅助存储执行哪些读取操作?

请在检索实体时添加 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"}'
  }