Search code examples
node.jsazureazure-storageazure-table-storagefailover

Azure table storage failover using NodeJs SDK


I have configured an Azure Table Storage account to be RA-GRS and used the following code to access it:

const host = {
    primaryHost: `https://${primaryAccountName}.table.core.windows.net`,
    secondaryHost: `https://${primaryAccountName}-secondary.table.core.windows.net`
  };
var tableSvc = azure.createTableService(primaryAccountName, accessKey, host);
const entGen = azure.TableUtilities.entityGenerator;
const locationMode = azure.StorageUtilities.LocationMode;
const tableName = 'testTable';

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

I initiated failover manually and expected once the failover is finished, it picks up the new account and keeps working but it didn't and failed with the following error:

Error on retrieveEntity! Error: getaddrinfo ENOTFOUND test0failover-secondary.table.core.windows.net

Is there any way to achieve a smooth transition to the secondary account? What I am looking for is having read access to the secondary account while failover happening.


Solution

  • This is happening because once you to a manual failover, after the failover is complete your storage account becomes locally-redundant (LRS). You will have to manually convert that account to geo-redundant (RAGRS or GRS).

    From this link:

    After the failover, your storage account type is automatically converted to locally redundant storage (LRS) in the new primary region. You can re-enable geo-redundant storage (GRS) or read-access geo-redundant storage (RA-GRS) for the account. Note that converting from LRS to GRS or RA-GRS incurs an additional cost. For additional information, see Bandwidth Pricing Details.

    After you re-enable GRS for your storage account, Microsoft begins replicating the data in your account to the new secondary region. Replication time is dependent on the amount of data being replicated.