Reputation: 8993
For query, sometimes I got continuation token, I wonder if there is any RetryPolicy
settings against TableServiceContext
to handle the token automatically.
Upvotes: 1
Views: 406
Reputation: 7356
You don't need to use a RetryPolicy for that. There are two options:
Use .AsTableServiceQuery() on your queries. That converts your query into a CloudTableQuery<> object, which natively handles continuation tokens. This is the easiest route. eg:
var query = (from r in Rows
where r.PartitionKey == "whatever"
select r).AsTableServiceQuery();
Otherwise you can use Begin/EndExecuteSegmented() and handle the tokens yourself.
Clarification on CloudTableQuery<>
There's an oblique reference to the behavior of CloudTableQuery<> on Scott Densmore's blog. But I also threw together the following, rather messy, code to prove it. The tests pass, and it does use continuation tokens to retrieve all the inserted entities. If you use HTTP, you can watch it with Fiddler and see the tokens go back and forth.
[Test, Explicit]
public void WriteAndReadALotOfRows()
{
CloudStorageAccount acct = CloudStorageAccount.Parse("PUT IN SOME CREDS HERE");
TableServiceContext ctx = null;
List<TestEntity> testEntities = new List<TestEntity>(2000);
acct.CreateCloudTableClient().CreateTableIfNotExist("Test");
//Create entities
for (int i = 0; i < 2000; i++)
{
if (i % 100 == 0)
{
if (ctx != null)
{
ctx.SaveChangesWithRetries(SaveChangesOptions.Batch);
}
ctx = new TableServiceContext(acct.TableEndpoint.AbsoluteUri, acct.Credentials);
}
TestEntity entity = new TestEntity(i);
testEntities.Add(entity);
ctx.AddObject("Test", entity);
}
ctx.SaveChangesWithRetries(SaveChangesOptions.Batch);
ctx = new TableServiceContext(acct.TableEndpoint.AbsoluteUri, acct.Credentials);
List<TestEntity> retrievedEntities = (from r in ctx.CreateQuery<TestEntity>("Test")
select r).AsTableServiceQuery().ToList();
Assert.AreEqual(testEntities.Count, retrievedEntities.Count);
Console.Out.WriteLine(retrievedEntities.Count); //prints 2000
foreach (var insertedEntity in testEntities)
{
TestEntity retrievedEntity = retrievedEntities.First(r => r.RowKey == insertedEntity.RowKey);
Assert.NotNull(retrievedEntity);
}
}
public class TestEntity : TableServiceEntity
{
public TestEntity()
{
}
public TestEntity(int id)
: base("Test", id.ToString())
{
}
}
Upvotes: 3
Reputation: 23764
check out http://blogs.msdn.com/b/windowsazurestorage/archive/2010/07/09/understanding-windows-azure-storage-billing-bandwidth-transactions-and-capacity.aspx within the text it mentions:
Table Queries – When you query using CloudTableQuery it takes care of handling continuation tokens, so it reissues queries using the continuation token receieved in a previous query request to get remaining entities. As described above, each reissued continuation token query to the service counts as 1 transaction.
Also http://blogs.msdn.com/b/jimoneil/archive/2010/10/05/azure-home-part-7-asynchronous-table-storage-pagination.aspx and http://scottdensmore.typepad.com/blog/2010/04/paging-with-windows-azure-table-storage.html
Upvotes: 1