1
votes

I am storing some logs in Azure Table Storage. I've identified the PartitionKey I should use. However, I'm having trouble determining what I should use for the RowKey. If I was using Sql Server, I would use an auto-incrementing integer. From what I can tell, having an auto-generated RowKey is not an option with Azure Table Storage. I'm fine using a GUID, however, everyone seems to warn against using a GUID. Yet, I'm not sure what I should be using.

Can anyone provide me a pointer for what I should use as the RowKey for storing log data? I've seen the following syntax (RowKey: {'_': '1'}), as shown below, but can't find out what it means:

var task = { 
  PartitionKey: {'_':'hometasks'},
  RowKey: {'_': '1'}
};

Thanks!

1
Can you describe what this log data is? How do you intend to query this log data.Gaurav Mantri
I intend to grab all of the logs with the same PartitionKey on a regular basis. I expect the data sets to be quite large.user687554

1 Answers

3
votes

There are many approaches you can take. One such approach would be to store date/time value in ticks as RowKey. This would help you in fetching logs data for a particular time range. Just remember that since RowKey is of String data type, you may want to pre-pad it with zeros so that all values are of same length. For example,

DateTime.UtcNow.Ticks.ToString("d20")

With this, you could take 2 approaches:

  1. Store them in chronological order as shown in example above.
  2. Store them in reverse chronological order. The advantage of this approach is that the latest entries will always be added on top of the table. So you could just query the table on PartitionKey and get top 'x' rows and they will be latest. You will do something like:

(DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks).ToString("d20")

You also mentioned in your comment that I expect the data sets to be quite large.. I hope you are not using a single PartitionKey. Because if number of records are quite large and all of them are put in same partition, the performance might be impacted.