如何使用NodeJs SDK访问RA-GRS中的Azure表存储辅助存储



更新我尝试了以下操作,但出现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"}'
}

最新更新