Database Reference
In-Depth Information
Figure 10-7. Sample application updating a record in the shard
Because records are being updated or deleted, the client code clears the cache to force future SELECT
statements to fetch records from the databases in the shard. The shard library exposes a ResetCache
method that does just that. You can improve this logic by also performing the same update or delete
operation of records in the cache.
Updating or deleting records across databases in the shard is even simpler. The following code
executes an inline SQL statement using a SqlCommand object. Because no database GUID is provided, this
statement executes the statement across all databases in the shard. When you perform updates or
deletes across databases, it's important to set the parallel flag correctly, as shown on line 1:
1)
PYN.EnzoAzureLib.Shard.UseParallel = checkBoxParallel.Checked;
2)
cmd.CommandText = "UPDATE TestUsers2 SET LastUpdated = GETDATE()";
3)
cmd.CommandType = CommandType.Text;
4)
ExecuteShardNonQuery (cmd);
Adding Records to the Shard
You see how easy it is to add records to the shard databases. This shard works best from a performance
standpoint when all databases in the shard have a roughly equal number of records; this is because
parallel processing is performed without any deterministic logic. As a result, the more spread out your
records are in the shard, the faster it is. You can add records in the shard in two ways:
In a single database. If you're loading the shard for the first time, you may decide
to load certain records in specific databases. Or you may decide to load one
database with more records than others, if the hardware is superior.
Search WWH ::




Custom Search