1
votes

I have a worker role that I have built with Microsoft.WindowsAzure.StorageClient v1.7. On my dev machine, and with my compute emulator, the application works fine. However, when I deploy to Azure, a table storage operation fails silently. The code is below - the BackupResult class inherits from TableServiceEntity:

Trace.WriteLine("Entering cloud storage method");
CloudTableClient client = storageAccount.CreateCloudTableClient();
Trace.WriteLine("Got the client..."); // Last message received.
client.CreateTableIfNotExist("LastRun");
Trace.WriteLine("Created the table (maybe)...");
TableServiceContext context = client.GetDataServiceContext();
Trace.WriteLine("Got the context...");
BackupResult lastResult = context.CreateQuery<BackupResult>("LastRun").ToList().OrderByDescending(x => x.RunTime).FirstOrDefault();
Trace.WriteLine("Returning the last result. It ran at: " + lastResult.ToString());
return lastResult;

No exception is thrown at all, but I do not see any of the trace logs below the marked message, and my application's logic does not proceed outside of this method. My local configuration is identical to my cloud configuration. What could cause such behavior?

2
What do you mean "operation fail silently"? Does it not return proper result in "lastResult" variable? What do you see in trace logs?Gaurav Mantri
@GauravMantri: added some more details to the observations after the code block. Does that help?TSL

2 Answers

1
votes

My psychic debugging abilities tell me that it's not failing - it's just taking a really long time. The .ToList() call will attempt to retrieve every entity in the table. Your dev storage table probably has not too many rows (a few thousand?) while production has a lot more. So it just takes a lot longer. I think you'll also be trying to stick all those entities in memory, which may be causing slowdowns as well if you start using the page file.

You could test this hypothesis by adding a Take(1000) to the query. Obviously that won't give you the correct answer, you just want to see if it completes. My v1.7 skills are a bit rusty, but I think it would look like this:

BackupResult lastResult = context.CreateQuery<BackupResult>("LastRun")
.Take(1000) //BEFORE the .ToList() - very important!
.ToList() 
.OrderByDescending(x => x.RunTime) 
.FirstOrDefault(); 

If the limited query does complete successfully, then the actual solution is to figure out how to do that query quickly. You'd either need to add some condition to the query that reduce the size of the results coming back from table storage, or possibly index your data a different way (eg, incorporate RunTime into the RowKey).

0
votes

Some of the things you may want to look out for:

  1. Diagnostics connection string is pointing to a cloud storage account in your cloud configuration file.
  2. Ensure that the table (LastRun) in cloud storage contains some data.

One thing you could do (or may be you've already done it) is have the application running in emulator is actually using cloud storage account instead of storage emulator.