Skip to main content

Windows Azure Storage and Read-Access Geo Redundant Feature

The end this year brought to me a great news. Azure team announced that we have support for Read Access of Geo Redundant Storage.
Until now, we could activate geo redundant feature, that guaranty us that all the content would be duplicated to another data center and in case of a disaster, Azure would be able to recover our content from the storage. But until the recovery would be made and so on we would not be able to access the content until the cluster failover storage recovery mechanism would be triggered.
Read Access of Geo Redundant Storage is a long and complicate name. But more important than name is what the feature offer to us. From now, if we activate it and the data center used by to store our data goes down, we will be able to use the second one (that is used for geo-redundancy) to access our content. We’ll not be able to write content, but we can read content for it – in read only mode. For application that store updates, configuration or resources this is a crucial thing.
Activating this feature is very simple. Additionally to Locally Redundant and Geo Redundant we have a new option called Read Access Geo-Redundancy (RA-GRS). We need to switch to this 3rd options and we are ready to go.

What other things we should know?
First of all, you should know that you cannot control what the secondary location is for RA-GRS. The same thing happen for Geo Redundant feature. There is a list of predefined data centers that are paired (usually the paired one is on the same continent).
Once you activate this feature, you can access it using “fooAccount-secondary…”. “-secondary” is the key world in this case. The accounts keys are the same as for the primary account. Basically all the access rules and keys are duplicated from the primary account to the secondary account.
The switching between the primary accounts to the secondary account is made automatically when a failover action is triggered by the “matrix”. In that moment all the DNS are updated from the primary account to the second one.  Based on this pattern we don’t need to change from our application the storage URL. When the storage from the primary node will be recover the DNS will be updated again. If you want you could do this from the code because you know the address of the secondary account – but be aware you will respond this actions and take into account the synchronization latency.
All the request of type add/update/delete on the second node will trigger a 403 error code.
We have a field in our storage services that tell us when the last synchronization was made. This field is called “Last Sync Time”.

Specific API
On the second account we have a service API that can be used to get the “Last Sync Time” and find the status of the replication action. The API is called “GetServiceStats()” and can be used for all storage services (Table, Queue and Blob). The response of this service will contain the last sync time and the status of geo-replication. The status can be:

  • Live 
  • Bootstrap – initialize phase, when we change the replication option we can have this status
  • Unavailable – last sync time cannot be calculated because a problem occurred

Also you will notice that there are new metrics that provide us information related to the transaction and synchronization status.
When we are in C#, we can switch the storage client between the primary and the secondary one very easily by changing the value of “LocationMode” property to “LocationMode.SecondaryOnly”. When you are make this switch you will hit and use the secondary storage. This is pretty cool, we don’t need to edit the connection string by our self (10+). If you want to execute write actions on the secondary account a Storage Exception will be throw.
This enum has another 2 values available:

  • PrimaryOnly – all the actions/requests are made only on the first one
  • PrimaryThenSecondary – by default actions/requests hit the primary account. If something happen with him (404) than all the read requests are redirected to the secondary one
  • SecondaryOnly – (already presented) the read request are redirected to the second account

From the cost perceive we will pay for all the storage that we used on the secondary account and all the transactions that are made between this two storage.
Don’t forget that this feature is in preview for now and you need to sign in for the preview using the following link
In the next post we will see how we can set the retry policy in a way that the secondary account will be used when we set the location mode property to “PrimaryThenSecondary”.


Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.