blog.smarx.com

Steve Marx's blog about cloud development

Windows Azure Tables: Expect Continuation Tokens, Seriously!

A few weeks ago, my blog appeared suddenly empty.  More recently, a customer reported that all of his data had seemingly disappeared.  In his case and in mine, we were forgetting an important part of using Windows Azure Tables: continuation tokens.  Read on to understand why continuation tokens are so important to handle properly in your application.

What are continuation tokens?

I’ve talked before about continuation tokens in Windows Azure Tables, in the context of paging over data.  Basically, continuation tokens are the way you can pick up a query where it left off.  In the paging example, you’re explicitly querying for a subset of the results (using the $top parameter in the REST API, or .Take(n) syntax in LINQ).  The storage service returns those results, along with a continuation token.  When you’re ready for the next page, you query again, passing in the continuation token you received from the first query.  This gives you the next set of results and the next continuation token.

Another common place you’ll see continuation tokens is when the results of a query exceed 1000 entities.  Windows Azure Tables returns up to a maximum of 1000 entities in a single request and returns a continuation token when more results are available.

The final place most people expect to see a continuation token is when the request to the server timed out.  In practice, I have yet to see a query exceed the 30-second timeout, but it could, particularly in the case of a scan (non-indexed query) over a large set of entities.

What if you’re not doing those things?

Well, you still need to be ready for continuation tokens.  When my blog appeared empty, I was querying for the top five posts (or in some queries, one post), and I was receiving no results at all.  And no, the query wasn’t timing out.

The answer for what happened, and why you really do need to handle continuation tokens in your code is a bit subtle in the Query Timeout and Pagination MSDN documentation (emphasis added):

A query against the Table service may return a maximum of 1,000 items (tables or entities) for a single request. If there are additional items to be returned, the response to the query request includes custom headers containing a set of continuation tokens. The continuation token headers may be sent to the server with a subsequent request to resume the execution of the query.

The Table service times out when a query operation does not complete within 60 seconds. If the query has returned results up to that point, these results are returned in the response. Continuation tokens are also returned in this case, so that the client may make another request for the remainder of the data.

Continuation tokens may also be returned when a query crosses the partition boundary.

That last line is incredibly important, because whether or not a query crosses a partition boundary is not always in your control.

(Note that the documentation quoted above is referring to an older version of storage… the query timeout is 30 seconds now.)

What’s a partition boundary?

A partition boundary is what it sounds like… it’s the logical barrier between two partitions in the storage service.  In Windows Azure Tables, it’s all about partitions.  Each of your tables is divided into partitions according to the partition key you chose.  Physically, in the data center, each partition might be on a separate server, or they may be on the same server (if they’re small or infrequently accessed).  Partitions are the way that tables scale, and they’re also the way the system responds to heavy load (by isolating “hot” partitions on dedicated servers).

When you perform a query that doesn’t specify a partition key, this is a cross-partition query.  If all the partitions happen to be on the same server, you might get all the results at once.  If the partitions are physically separated in the data center, you’ll get partial results and a continuation token.

What happened on my blog?

In the case of my broken blog query, I was querying for the top five posts without specifying a partition key.  The entries table for my blog only has one partition, so this might seem reasonable.

Without a partition key, though, my query could land on a server that didn’t have the right data.  This hadn’t happened for the entire lifetime of my blog, but a few weeks ago, things moved around in the storage service (which happens all the time as we balance for load or change hardware).  Now my query without a specified partition was initially landing on a server that didn’t actually have my data!  All that server could do was return an empty set of results and a continuation token that made sure my next query would land in my first (and only) partition.

This “empty” server was there to handle additional partitions, if I chose to create them.  This can happen if there used to be more partitions but they’ve been deleted, or if the storage service has allocated future placement there as part of automatic load balancing.  In the future, we may be able to optimize this path to avoid the initial empty round trip.

Because I wasn’t properly dealing with continuation tokens in my code, my blog happily showed an empty page, thinking there were no blog posts at all.

What can be done?

There are a few things you should do to deal with continuation tokens in your code:

  1. If you know it, always specify a partition key in your queries.  This is the primary way I fixed my blog code.
  2. Even if you do (1), your code should properly respond to a response that includes a continuation token.

The simplest way by far to do (2) is to make use of the ExecuteAll(...) and ExecuteAllWithRetries(...) on the TableStorageDataServiceQuery<T> class in the sample storage client library in the SDK.  These methods automatically repeat the query as needed, following the chain of continuation tokens until all results have been retrieved.  From the code comments:

/// <summary>
/// Returns all results of the query and hides the complexity of continuation if 
/// this is desired by a user. Users should be aware that this operation can return 
/// many objects. Uses no retries.
/// Important: this function does not call Execute immediately. Instead, it calls Execute() on 
/// the query only when the result is enumerated. This is a difference to the normal 
/// Execute() and Execute() with retry method.
/// </summary>
/// <returns>An IEnumerable representing the results of the query.</returns>

The bottom line

The bottom line is that any query that doesn’t specify both a partition key and a row key can return a continuation token.  [UPDATE 10/28: More precisely, to avoid continuation tokens, a query must address a single entity completely.]  Fortunately, it’s not hard to deal with this in your code.  You just need to understand it and remember to do it, even if your code is running fine today.

If you want to understand continuation tokens better, I’d recommend reading the Query Timeout and Pagination MSDN documentation as well as my earlier blog post about Paging Over Data in Windows Azure Tables.


Comments

2010-01-13 22:10 GMT
Very nice site! [url=http://opxyiea.com/yoyraoo/2.html]cheap cialis[/url]
2010-01-13 22:10 GMT
Very nice site! cheap cialis http://opxyiea.com/yoyraoo/4.html
2010-01-13 22:10 GMT
Very nice site!
2010-01-15 08:11 GMT
Here first the writer describes the topic very keenly that continuation tokens are the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page, you query again, passing in the continuation token you received from the first query and it leads t the next page very quickly. As a result of this the next set of results and the next continuation token.and this procedure goes on again and again.
2010-01-15 08:12 GMT
Here first the writer describes the topic very keenly that continuation tokens are the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page, you query again, passing in the continuation token you received from the first query and it leads t the next page very quickly. As a result of this the next set of results and the next continuation token.and this procedure goes on again and again.
2010-01-15 08:12 GMT
Here first the writer describes the topic very keenly that continuation tokens are the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page, you query again, passing in the continuation token you received from the first query and it leads t the next page very quickly. As a result of this the next set of results and the next continuation token.and this procedure goes on again and again.
2010-01-15 08:12 GMT
Here first the writer describes the topic very keenly that continuation tokens are the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page, you query again, passing in the continuation token you received from the first query and it leads t the next page very quickly. As a result of this the next set of results and the next continuation token.and this procedure goes on again and again.
2010-01-15 08:12 GMT
Here first the writer describes the topic very keenly that continuation tokens are the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page, you query again, passing in the continuation token you received from the first query and it leads t the next page very quickly. As a result of this the next set of results and the next continuation token.and this procedure goes on again and again.
2010-01-16 07:37 GMT
Hello!
2010-01-17 07:40 GMT
This “empty” server was there to handle additional partitions, if I chose to create them. This can happen if there used to be more partitions but they’ve been deleted, or if the storage service has allocated future placement there as part of automatic load balancing. In the future, we may be able to optimize this path to avoid the initial empty round trip.
2010-01-17 19:07 GMT
Continuation Tokens are important part of Tables in Windows Azure, and I think we need add more variable options in it. Partition Boundary plays an important role for managing the large databases, I am delighted to find many useful information about Continuation Tokens and Partition Boundary. Thanks for sharing.
2010-01-17 19:55 GMT
This project is a custom resource provider that enables you to localize an ASP.NET web site using Windows Azure Table storage as the backing store. This replaces the use of standard RESX files, providing a more flexible way to manage localized resources.
2010-01-18 14:47 GMT
Hello!
2010-01-18 15:05 GMT
Hello!
2010-01-18 22:45 GMT
Hello!
2010-01-20 05:57 GMT
In this article as writer is in struggle of describing the functionality of continuation tokens, the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page. It is more helpful when we are planning to accomplish a lit bit tough and complicated task in a very short time and in efficient way.
2010-01-20 10:13 GMT
Microsoft will revise the wording on its Azure cloud service level agreements (SLAs) following a trip into a Kafkaesque world of secrecy.
2010-01-20 10:14 GMT
Microsoft will revise the wording on its Azure cloud service level agreements (SLAs) following a trip into a Kafkaesque world of secrecy.
2010-01-20 10:14 GMT
Microsoft will revise the wording on its Azure cloud service level agreements following a trip into a Kafkaesque world of secrecy.
2010-01-20 10:14 GMT
Microsoft will revise the wording on its Azure cloud service level agreements following a trip into a Kafkaesque world of secrecy.
2010-01-21 06:18 GMT
I am very glad to see such information which I was searching for a long time.This made very glad Smile
2010-01-21 06:19 GMT
We got a good book on that matter from our local library and most books where not as influensive as your information
2010-01-21 06:19 GMT
Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that.
2010-01-21 06:19 GMT
I am happy to find you distinguished way of writing about Windows Azure, thanks for sharing.
2010-01-21 06:19 GMT
I was searching for a long time.This made very
2010-01-21 11:17 GMT
Thanks for the post Each of your tables is divided into partitions according to the partition key you chose. Physically, in the data center, each partition might be on a separate server, or they may be on the same server (if they’re small or infrequently accessed). i like it.
2010-01-21 11:17 GMT
Thanks for the post Each of your tables is divided into partitions according to the partition key you chose. Physically, in the data center, each partition might be on a separate server, or they may be on the same server (if they’re small or infrequently accessed).
2010-01-21 11:18 GMT
Thanks for the post Each of your tables is divided into partitions according to the partition key you chose. Physically, in the data center, each partition might be on a separate server, or they may be on the same server (if they’re small or infrequently accessed).
2010-01-21 11:19 GMT
Thanks for the post Each of your tables is divided into partitions according to the partition key you chose. Physically, in the data center, each partition might be on a separate server, or they may be on the same server (if they’re small or infrequently accessed).
2010-01-21 12:37 GMT
Continuation token are very useful when handling different instances of a program me, along with other features there is another common place you’ll see continuation tokens is when the results of a query exceed 1000 entities. 
2010-01-22 08:12 GMT
Where? Here :) look my signature
2010-01-22 08:13 GMT
Where? Here :) look my signature
2010-01-22 08:13 GMT
Where? Here :) look my signature
2010-01-22 08:13 GMT
Where? Here :) look my signature
2010-01-22 08:14 GMT
Where? Here :) look my signature
2010-01-22 11:47 GMT
An other useful feature of continuous token is that, the continuation token headers may be sent to the server with a subsequent request to resume the execution of the query, if want to stop the execution of a specific query as well.
2010-01-22 16:11 GMT
The resource provider requires no code changes for migrating an ASP.NET website that uses another resource method; its is driven via standard configuration.
2010-01-23 06:03 GMT
Here my question is that as The continuation token headers may be sent to the server with a subsequent request to resume the execution of the query.Is it possible to restart the same request by using the continuous token. I want to ytilisie this in my project.
2010-01-23 10:55 GMT
I have a question here If the query has returned results up to that point with in 100 sec, these results are returned in the response? Or Continuation tokens are also returned in this case, so that the client may make another request?
2010-01-23 14:24 GMT
At Tradeslot, we design large-scale business-to-business and government-to-business auction platforms. Unlike other auction platforms, we have built a combinatorial auction platform that allows bidders to place expressive bids. Adslot uses the same intellectual property as the auction platform and enables media publishers to sell ad inventory.
2010-01-23 15:58 GMT
if some one new here want to know simply about the continuation token i can say The storage service returns those results, along with a continuation token. When you’re ready for the next page, you query again, passing in the continuation token you received from the first query.
2010-01-24 16:18 GMT
Damn now I have to go back and relook at all my code
2010-01-24 16:18 GMT
Damn now I have to go back and relook at all my code
2010-01-24 21:48 GMT
i like it
2010-01-24 21:49 GMT
i like it
2010-01-24 21:49 GMT
i like it very much
2010-01-24 21:50 GMT
i like it very much,
2010-01-24 21:50 GMT
i like it very much, o
2010-01-24 21:51 GMT
i like it very much, oh
2010-01-24 21:51 GMT
i like it very much, oh.
2010-01-24 21:52 GMT
i like it very much, oh. yes
2010-01-24 21:52 GMT
i like it very much, oh. yes i like
2010-01-24 21:54 GMT
i like it very much, oh. yes i like.
2010-01-25 06:21 GMT
Being alone in a new city, it's awful especially if you don't have any idea about the city or if you don't have any map, not to talk about if you don't know the language of the country the city is in. And if they don't speak English, then it's even worse
2010-01-25 21:01 GMT
The continuation token headers may be sent to the server with a subsequent request to resume the execution of the query.There may also be an option to restart this service.
2010-01-26 13:38 GMT
Continuation tokens are the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page, you query again, passing in the continuation token you received from the first query and it leads t the next page very quickly.
2010-01-27 05:19 GMT
This should be a real labour saver thank you.
2010-01-27 05:19 GMT
This should be a real labour saver thank you.
2010-01-27 05:22 GMT
I am delighted to find many useful information about Continuation Tokens and Partition Boundary. Continuation tokens are the way you can pick up a query where it left off. continuation token i can say The storage service returns those results, along with a continuation token. Thanks for sharing.
2010-01-27 08:14 GMT
Most people expect to see a continuation token is when the request to the server timed out. In practice, I have yet to see a query exceed the 30-second timeout, but it could, particularly in the case of a scan over a large set of entities. SO some one have to wait for this.
2010-01-27 20:34 GMT
Continuation Tokens are the one of the best way to control different functions during the compilation of the software.
2010-01-28 20:03 GMT
obpTLTo
2010-01-29 12:42 GMT
You’ll see continuation tokens is when the results of a query exceed 1000 entities. Windows Azure Tables returns up to a maximum of 1000 entities in a single request and returns a continuation token when more results are available. This method is now being used in many artificial applications.
2010-01-29 13:37 GMT
I recently came across your blog and have been reading along. I don't know what to say except that I have enjoyed reading. Bookmarking it now. Greetings, DENOIE.
2010-01-29 13:38 GMT
I recently came across your blog and have been reading along. I don't know what to say except that I have enjoyed reading. Bookmarking it now. Greetings, DENOIE.
2010-01-29 13:38 GMT
I recently came across your blog and have been reading along. I don't know what to say except that I have enjoyed reading. Bookmarking it now. Greetings, DENOIE.
2010-01-29 13:38 GMT
I recently came across your blog and have been reading along. I don't know what to say except that I have enjoyed reading. Bookmarking it now. Greetings, DENOIE.
2010-01-29 13:38 GMT
I recently came across your blog and have been reading along. I don't know what to say except that I have enjoyed reading. Bookmarking it now. Greetings, DENOIE.
2010-01-29 13:39 GMT
I recently came across your blog and have been reading along. I don't know what to say except that I have enjoyed reading. Bookmarking it now. Greetings, DENOIE.
2010-01-29 19:25 GMT
All these, however, assume that the table storage will be used from an Azure web or worker role. I wanted to see if the Windows Azure Table Store could be used with applications running elsewhere, like on your computer. I’m creating a console application here, but the code can be easily adapted to a WPF, Windows Forms or even an ASP.NET application too.
2010-01-30 08:47 GMT
Incredible: worth the read.
2010-01-31 03:08 GMT
As we use continuation token to start a script in the same fashion The continuation token headers may be sent to the server with a subsequent request to resume the execution of the query.
2010-01-31 09:19 GMT
Microsoft is a big company and windows azure was launched by microsoft and it was a nice one. Ok, for the case that everything disappeared on your website it is very necessary to add the windows azure tables.
Continuation tokens are essential and hope you guys get a good read about it above to know better.
2010-02-02 00:38 GMT
Wow great, I am happy to find it, Thanks for sharing useful information about Windows Azure.
2010-02-03 04:44 GMT
Here first the writer describes the topic very keenly that continuation tokens are the way you can pick up a query where it left off. In the paging example, you’re explicitly querying for a subset of the results.When you’re ready for the next page, you query again, passing in the continuation token you received from the first query and it leads t the next page very quickly. As a result of this the next set of results and the next continuation token.and this procedure goes on again and again.
2010-02-03 14:29 GMT
Pablo is a Software Architect in the SQL Server group at Microsoft. He has worked in various areas of SQL Server and he's currently focused on making data and the web work well together with technologies such as Data Services (Project Astoria).
2010-02-04 00:29 GMT
thank you for posting this article. I have learned something from reading this.
2010-02-04 00:30 GMT
thank you for posting this article. I have learned something from reading this.
2010-02-04 00:30 GMT
thank you for posting this article. I have learned something from reading this.
2010-02-04 00:36 GMT
thank you for posting this article. I have learned something from reading this.
2010-02-04 00:39 GMT
thank you for posting this article. I have learned something from reading this.
2010-02-04 00:40 GMT
thank you for posting this article. I have learned something from reading this.
Chel
2010-02-04 00:43 GMT
this post is surely a help
Rasheed
2010-02-04 00:44 GMT
many thanks to this post! you really have interesting topics
2010-02-04 00:46 GMT
I am happy reading your article because it is very informative. Thank you!
2010-02-04 03:54 GMT
Yo7n9y http://www.cRk2bdPqQls602mIa4bgo.com
2010-02-04 03:54 GMT
Yo7n9y http://www.cRk2bdPqQls602mIa4bgo.com
2010-02-04 06:29 GMT
while working, I realized that most of the time I am having error about query timeout, If the operation is an insert or delete operation, the operation may have succeeded on the server despite an error being returned by the client. This may happen when the client timeout is set to less than 30 seconds, which is the maximum timeout for an insert, update, or delete operation.The information on your blog is very helpful for me.Thank you so much.
2010-02-06 04:30 GMT
Well ofcourse your each table is divided into partion with respect to the key you chose.I guess in data center,every partition may be on a different server or same.But really the continuation token are amazingly helpful.Thank you so much for this.
2010-02-07 05:41 GMT
With the Azure Tables you can store terabytes of data providing excellent scalability with virtually no cap.
2010-02-07 13:26 GMT
Continuation tokens are provided by Table Storage to support query pagination. One aspect that is still unclear for me is the lifetime of the continuation tokens. Indeed, I would suspect that the continuation token to expire at some point. I can't find documentation on this aspect. Am I missing something?
2010-02-07 13:27 GMT
Continuation tokens are provided by Table Storage to support query pagination. One aspect that is still unclear for me is the lifetime of the continuation tokens. Indeed, I would suspect that the continuation token to expire at some point. I can't find documentation on this aspect. Am I missing something?
2010-02-07 13:27 GMT
Continuation tokens are provided by Table Storage to support query pagination. One aspect that is still unclear for me is the lifetime of the continuation tokens. Indeed, I would suspect that the continuation token to expire at some point. I can't find documentation on this aspect. Am I missing something?
2010-02-07 13:28 GMT
Continuation tokens are provided by Table Storage to support query pagination. One aspect that is still unclear for me is the lifetime of the continuation tokens. Indeed, I would suspect that the continuation token to expire at some point. I can't find documentation on this aspect.
2010-02-07 13:28 GMT
Continuation tokens are provided by Table Storage to support query pagination. One aspect that is still unclear for me is the lifetime of the continuation tokens. Indeed, I would suspect that the continuation token to expire at some point. I can't find documentation on this aspect.
2010-02-07 23:48 GMT
Thanks, help me to have good information, good work ..
2010-02-08 05:59 GMT
Microsoft will revise the wording on its Azure cloud service level agreements following a trip into a Kafkaesque world of secrecy.
2010-02-08 17:34 GMT
An other useful feature of continuous token is that, the continuation token headers may be sent to the server with a subsequent request to resume the execution of the query, if want to stop the execution of a specific query as well.

Add a comment

Your name:
Your URL
(will be linked from your name):
Your comment: